Skip to content

Commit ff16301

Browse files
committed
feat: show warning if user tries to switch apps during LN receive
1 parent 71877d6 commit ff16301

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

src/AppOnboarded.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const AppOnboarded = (): ReactElement => {
6060
const appStateSubscription = AppState.addEventListener(
6161
'change',
6262
(nextAppState) => {
63+
dispatch(updateUi({ appState: nextAppState }));
64+
6365
// on App to foreground
6466
if (
6567
appState.current.match(/inactive|background/) &&

src/screens/Wallets/Receive/ReceiveQR.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { createLightningInvoice } from '../../../store/utils/lightning';
4141
import { updatePendingInvoice } from '../../../store/slices/metadata';
4242
import { generateNewReceiveAddress } from '../../../store/actions/wallet';
4343
import {
44+
appStateSelector,
4445
isLDKReadySelector,
4546
viewControllerIsOpenSelector,
4647
} from '../../../store/reselect/ui';
@@ -93,6 +94,7 @@ const ReceiveQR = ({
9394
const addressType = useAppSelector(addressTypeSelector);
9495
const isGeoBlocked = useAppSelector(isGeoBlockedSelector);
9596
const isLDKReady = useAppSelector(isLDKReadySelector);
97+
const appState = useAppSelector(appStateSelector);
9698
const { id, amount, message, tags, jitOrder } =
9799
useAppSelector(receiveSelector);
98100
const lightningBalance = useLightningBalance(false);
@@ -244,6 +246,16 @@ const ReceiveQR = ({
244246
dispatch,
245247
]);
246248

249+
useEffect(() => {
250+
if (receiveNavigationIsOpen && enableInstant && appState !== 'active') {
251+
showToast({
252+
type: 'error',
253+
title: t('receive_foreground_title'),
254+
description: t('receive_foreground_msg'),
255+
});
256+
}
257+
}, [t, appState, enableInstant, receiveNavigationIsOpen]);
258+
247259
const uri = useMemo((): string => {
248260
if (!receiveNavigationIsOpen) {
249261
return '';

src/store/reselect/ui.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,5 @@ export const fromAddressViewerSelector = createSelector(
110110
[uiState],
111111
(ui) => ui.fromAddressViewer,
112112
);
113+
114+
export const appStateSelector = createSelector([uiState], (ui) => ui.appState);

src/store/shapes/ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ export const initialUiState: TUiState = {
4343
viewControllers: defaultViewControllers,
4444
fromAddressViewer: false, // When true, ensures tx inputs are not cleared when sweeping from address viewer.
4545
paymentMethod: 'onchain',
46+
appState: 'active',
4647
};

src/store/types/ui.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AppStateStatus } from 'react-native';
12
import { LNURLWithdrawParams, LNURLPayParams } from 'js-lnurl';
23
import { EActivityType, TOnchainActivityItem } from './activity';
34
import { ReceiveStackParamList } from '../../navigation/bottom-sheet/ReceiveNavigation';
@@ -91,4 +92,5 @@ export type TUiState = {
9192
language: string;
9293
fromAddressViewer: boolean;
9394
paymentMethod: 'onchain' | 'lightning';
95+
appState: AppStateStatus;
9496
};

src/utils/i18n/locales/en/wallet.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,5 +686,13 @@
686686
},
687687
"receive_insufficient_text": {
688688
"string": "Insufficient receiving capacity to receive this amount over Lightning."
689+
},
690+
"receive_foreground_title": {
691+
"string": "Keep Bitkit In Foreground",
692+
"developer_comment": "This message appears when the user is shown an LN invoice but tries to switch to another app"
693+
},
694+
"receive_foreground_msg": {
695+
"string": "Payments to your spending balance might fail if you switch between apps.",
696+
"developer_comment": "This message appears when the user is shown an LN invoice but tries to switch to another app"
689697
}
690698
}

0 commit comments

Comments
 (0)