diff --git a/src/components/AuthCheck.tsx b/src/components/AuthCheck.tsx index ed6e52922..9446336b0 100644 --- a/src/components/AuthCheck.tsx +++ b/src/components/AuthCheck.tsx @@ -31,22 +31,26 @@ const AuthCheck = ({ const requirePin = route?.params?.requirePin ?? false; onSuccess = route?.params?.onSuccess ?? onSuccess; - return ( - - {requireBiometrics && !requirePin ? ( + if (requireBiometrics && !requirePin) { + return ( + onSuccess?.()} onFailure={(): void => setRequireBiometrics(false)} /> - ) : ( - onSuccess?.()} - /> - )} + + ); + } + + return ( + + onSuccess?.()} + /> ); }; diff --git a/src/components/InactivityTracker.tsx b/src/components/InactivityTracker.tsx index c8d23ba4c..880846c88 100644 --- a/src/components/InactivityTracker.tsx +++ b/src/components/InactivityTracker.tsx @@ -50,8 +50,10 @@ const InactivityTracker = ({ }); }, [resetInactivityTimeout]); + const panProps = pinOnIdle ? panResponder.panHandlers : {}; + return ( - + {children} ); diff --git a/src/navigation/root/RootNavigator.tsx b/src/navigation/root/RootNavigator.tsx index 811730151..c9532e751 100644 --- a/src/navigation/root/RootNavigator.tsx +++ b/src/navigation/root/RootNavigator.tsx @@ -24,10 +24,10 @@ import { NavigationContainer } from '../../styles/components'; import { processInputData } from '../../utils/scanner'; import { checkClipboardData } from '../../utils/clipboard'; import { useRenderCount } from '../../hooks/helpers'; +import { getStore } from '../../store/helpers'; import { updateUi } from '../../store/actions/ui'; import { resetSendTransaction } from '../../store/actions/wallet'; import { isAuthenticatedSelector } from '../../store/reselect/ui'; -import { pinOnIdleSelector, pinSelector } from '../../store/reselect/settings'; import AuthCheck from '../../components/AuthCheck'; import Dialog from '../../components/Dialog'; import WalletNavigator from '../wallet/WalletNavigator'; @@ -99,8 +99,6 @@ const RootNavigator = (): ReactElement => { const appState = useRef(AppState.currentState); const [showDialog, setShowDialog] = useState(false); const [shouldCheckClipboard, setShouldCheckClipboard] = useState(false); - const pin = useSelector(pinSelector); - const pinOnIdle = useSelector(pinOnIdleSelector); const isAuthenticated = useSelector(isAuthenticatedSelector); const renderCount = useRenderCount(); @@ -169,28 +167,19 @@ const RootNavigator = (): ReactElement => { const appStateSubscription = AppState.addEventListener( 'change', (nextAppState): void => { + // get state fresh from store everytime + const uiStore = getStore().ui; + // on App to foreground if (appState.current.match(/background/) && nextAppState === 'active') { // prevent redirecting while on AuthCheck - if (isAuthenticated) { + if (uiStore.isAuthenticated) { checkClipboard().then(); } else { setShouldCheckClipboard(true); } } - // on App to background - if ( - appState.current.match(/active|inactive/) && - nextAppState === 'background' - ) { - // lock the app on background if pinOnIdle is enabled - if (pin && pinOnIdle) { - updateUi({ isAuthenticated: false }); - setShouldCheckClipboard(true); - } - } - appState.current = nextAppState; }, ); diff --git a/src/utils/i18n/locales/en/lightning.json b/src/utils/i18n/locales/en/lightning.json index 83e64102f..b7c908c82 100644 --- a/src/utils/i18n/locales/en/lightning.json +++ b/src/utils/i18n/locales/en/lightning.json @@ -41,7 +41,7 @@ "setting_up_step4": "Opening Connection", "result_header": "Connecting", "result_text": "Lightning connection initiated. You will be able to use instant payments in ±10 minutes.", - "timeout_header": "Timed Out", + "timeout_header": "Please keep Bitkit open.", "timeout_text": "Bitkit will keep trying to open your Lightning connection in the background. Please keep the app open.", "awesome": "Awesome!", "transfer_funds": "Transfer Funds", diff --git a/src/utils/i18n/locales/en/other.json b/src/utils/i18n/locales/en/other.json index 50f87b801..8e8bc055b 100644 --- a/src/utils/i18n/locales/en/other.json +++ b/src/utils/i18n/locales/en/other.json @@ -73,5 +73,5 @@ "high_text2_beta": "Please consider moving some of your funds. We recommend using only small amounts while Bitkit is in beta.", "high_button_more": "Learn More", "caution_header": "Caution:\nBeta Risk.", - "caution_text": "Beta software may put your money at risk. We recommend using only small amounts (like $10) while Bitkit is in beta." + "caution_text": "Beta software may put your money at risk. We recommend using only small amounts while Bitkit is in beta." } diff --git a/src/utils/settings/index.ts b/src/utils/settings/index.ts index 3d8698dde..6c607eb81 100644 --- a/src/utils/settings/index.ts +++ b/src/utils/settings/index.ts @@ -1,5 +1,4 @@ import { resetKeychainValue, setKeychainValue } from '../keychain'; -import { getSettingsStore } from '../../store/helpers'; import { removeTodo } from '../../store/actions/todos'; import { updateSettings } from '../../store/actions/settings'; import { PIN_ATTEMPTS } from '../../components/PinPad'; @@ -17,10 +16,11 @@ export const addPin = async (newPin: string): Promise => { * Edit PIN keychain data and update settings state */ export const editPin = async (newPin: string): Promise => { + updateSettings({ pin: true }); + await Promise.all([ setKeychainValue({ key: 'pin', value: newPin }), setKeychainValue({ key: 'pinAttemptsRemaining', value: PIN_ATTEMPTS }), - updateSettings({ pin: true }), ]); }; @@ -29,38 +29,18 @@ export const editPin = async (newPin: string): Promise => { * Wipes PIN data from device memory. */ export const removePin = async (): Promise => { + removeTodo('pin'); + // reset to defaults + updateSettings({ + pin: false, + pinOnLaunch: true, + pinOnIdle: false, + pinForPayments: false, + biometrics: false, + }); + await Promise.all([ - // reset to defaults - updateSettings({ - pin: false, - pinOnLaunch: true, - pinForPayments: false, - biometrics: false, - }), setKeychainValue({ key: 'pinAttemptsRemaining', value: PIN_ATTEMPTS }), resetKeychainValue({ key: 'pin' }), - removeTodo('pin'), ]); }; - -/** - * Returns if the user's various methods of authentication are enabled or disabled. - */ -export const hasEnabledAuthentication = (): { - pin: boolean; - pinOnLaunch: boolean; - pinForPayments: boolean; - biometrics: boolean; -} => { - try { - const { pin, pinOnLaunch, pinForPayments, biometrics } = getSettingsStore(); - return { pin, pinOnLaunch, pinForPayments, biometrics }; - } catch { - return { - pin: false, - pinOnLaunch: false, - pinForPayments: false, - biometrics: false, - }; - } -};