From 42e1414fe3b718c737aa3c3ddf352290a0334d2c Mon Sep 17 00:00:00 2001 From: Javier Bueno Date: Wed, 10 Apr 2024 16:44:31 +0200 Subject: [PATCH 1/6] fix(setup-wallet): avoid intial flow if the user has wallets --- apps/wallet-mobile/src/WalletNavigator.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/wallet-mobile/src/WalletNavigator.tsx b/apps/wallet-mobile/src/WalletNavigator.tsx index f58c96167d..4c6efb2f60 100644 --- a/apps/wallet-mobile/src/WalletNavigator.tsx +++ b/apps/wallet-mobile/src/WalletNavigator.tsx @@ -29,8 +29,10 @@ import {NftDetailsNavigator} from './NftDetails/NftDetailsNavigator' import {NftsNavigator} from './Nfts/NftsNavigator' import {SearchProvider} from './Search/SearchContext' import {TxHistoryNavigator} from './TxHistory' +import {useWalletManager} from './wallet-manager/WalletManagerContext' import {useAuthOsEnabled} from './yoroi-wallets/auth' import {isHaskellShelley} from './yoroi-wallets/cardano/utils' +import {useHasWallets} from './yoroi-wallets/hooks' const Tab = createBottomTabNavigator() const WalletTabNavigator = () => { @@ -151,6 +153,8 @@ export const WalletNavigator = () => { useLinksRequestAction() const authOsEnabled = useAuthOsEnabled() const {showBiometricsScreen} = useShowBiometricsScreen() + const walletManager = useWalletManager() + const hasWallets = useHasWallets(walletManager) // initialRoute doesn't update the state of the navigator, only at first render // https://reactnavigation.org/docs/auth-flow/ @@ -175,7 +179,7 @@ export const WalletNavigator = () => { detachPreviousScreen: false /* https://github.com/react-navigation/react-navigation/issues/9883 */, }} > - {showBiometricsScreen && authOsEnabled && ( + {!hasWallets && showBiometricsScreen && authOsEnabled && ( Date: Wed, 10 Apr 2024 17:07:58 +0200 Subject: [PATCH 2/6] fix: address mode sigle --- .../SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx | 2 +- .../useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx index 7ac3b8ce8f..613953ef2a 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.tsx @@ -57,7 +57,7 @@ const useSizeModal = () => { } // when restoring, later will be part of the onboarding -const addressMode: AddressMode = 'multiple' +const addressMode: AddressMode = 'single' export const WalletDetailsScreen = () => { const bold = useBold() const {styles} = useStyles() diff --git a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx index 90d73e6200..bfab406ea2 100644 --- a/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx +++ b/apps/wallet-mobile/src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.tsx @@ -58,7 +58,7 @@ const useSizeModal = () => { } // when restoring, later will be part of the onboarding -const addressMode: AddressMode = 'multiple' +const addressMode: AddressMode = 'single' export const RestoreWalletDetailsScreen = () => { const bold = useBold() const {styles} = useStyles() From 5e777112f2464df3b2dab9b5e7ba65ddda1939f9 Mon Sep 17 00:00:00 2001 From: Javier Bueno Date: Wed, 10 Apr 2024 17:18:57 +0200 Subject: [PATCH 3/6] refactor: auth enabled hook --- apps/wallet-mobile/src/AppNavigator.tsx | 16 ++-- apps/wallet-mobile/src/WalletNavigator.tsx | 7 +- .../ApplicationSettingsScreen.tsx | 8 +- .../src/yoroi-wallets/auth/auth.ts | 8 +- .../storage/KeychainStorage.test.ts | 2 +- .../messages/src/WalletNavigator.json | 80 +++++++++---------- 6 files changed, 61 insertions(+), 60 deletions(-) diff --git a/apps/wallet-mobile/src/AppNavigator.tsx b/apps/wallet-mobile/src/AppNavigator.tsx index 8e5d688132..12c15a79b0 100644 --- a/apps/wallet-mobile/src/AppNavigator.tsx +++ b/apps/wallet-mobile/src/AppNavigator.tsx @@ -25,7 +25,7 @@ import {DeveloperScreen} from './legacy/DeveloperScreen' import {AppRoutes} from './navigation' import {SearchProvider} from './Search/SearchContext' import {WalletNavigator} from './WalletNavigator' -import {AuthSetting, useAuthOsEnabled, useAuthSetting, useAuthWithOs} from './yoroi-wallets/auth' +import {AuthSetting, useAuthSetting, useAuthWithOs, useIsAuthWithOsSupported} from './yoroi-wallets/auth' const Stack = createStackNavigator() const navRef = React.createRef>() @@ -208,8 +208,8 @@ const useAutoLogout = () => { const authSetting = useAuthSetting() const strings = useStrings() const {logout} = useAuth() - const authOsEnabled = useAuthOsEnabled() - const osAuthDisabled = !authOsEnabled && authSetting === 'os' + const isAuthOsSupported = useIsAuthWithOsSupported() + const osAuthDisabled = !isAuthOsSupported && authSetting === 'os' useBackgroundTimeout({ onTimeout: logout, @@ -246,7 +246,7 @@ const useHideScreenInAppSwitcher = () => { type FirstAction = 'auth-with-pin' | 'auth-with-os' | 'request-new-pin' | 'first-run' | 'show-agreement-changed-notice' const getFirstAction = ( - authOsEnabled: boolean, + isAuthOsSupported: boolean, authSetting: AuthSetting, agreement: LegalAgreement | undefined, ): FirstAction => { @@ -255,16 +255,16 @@ const getFirstAction = ( if (isString(authSetting) && !hasAccepted) return 'show-agreement-changed-notice' if (authSetting === 'pin') return 'auth-with-pin' - if (authSetting === 'os' && authOsEnabled) return 'auth-with-os' - if (authSetting === 'os' && !authOsEnabled) return 'request-new-pin' + if (authSetting === 'os' && isAuthOsSupported) return 'auth-with-os' + if (authSetting === 'os' && !isAuthOsSupported) return 'request-new-pin' return 'first-run' // setup not completed } const useFirstAction = () => { const authSetting = useAuthSetting() - const authOsEnabled = useAuthOsEnabled() + const isAuthOsSupported = useIsAuthWithOsSupported() const terms = useLegalAgreement() - return getFirstAction(authOsEnabled, authSetting, terms) + return getFirstAction(isAuthOsSupported, authSetting, terms) } diff --git a/apps/wallet-mobile/src/WalletNavigator.tsx b/apps/wallet-mobile/src/WalletNavigator.tsx index 4c6efb2f60..e23d81540c 100644 --- a/apps/wallet-mobile/src/WalletNavigator.tsx +++ b/apps/wallet-mobile/src/WalletNavigator.tsx @@ -30,7 +30,7 @@ import {NftsNavigator} from './Nfts/NftsNavigator' import {SearchProvider} from './Search/SearchContext' import {TxHistoryNavigator} from './TxHistory' import {useWalletManager} from './wallet-manager/WalletManagerContext' -import {useAuthOsEnabled} from './yoroi-wallets/auth' +import {useAuthSetting, useIsAuthWithOsSupported} from './yoroi-wallets/auth' import {isHaskellShelley} from './yoroi-wallets/cardano/utils' import {useHasWallets} from './yoroi-wallets/hooks' @@ -151,10 +151,11 @@ export const WalletNavigator = () => { const strings = useStrings() const {theme} = useTheme() useLinksRequestAction() - const authOsEnabled = useAuthOsEnabled() + const isAuthOsSupported = useIsAuthWithOsSupported() const {showBiometricsScreen} = useShowBiometricsScreen() const walletManager = useWalletManager() const hasWallets = useHasWallets(walletManager) + const authSetting = useAuthSetting() // initialRoute doesn't update the state of the navigator, only at first render // https://reactnavigation.org/docs/auth-flow/ @@ -179,7 +180,7 @@ export const WalletNavigator = () => { detachPreviousScreen: false /* https://github.com/react-navigation/react-navigation/issues/9883 */, }} > - {!hasWallets && showBiometricsScreen && authOsEnabled && ( + {!hasWallets && showBiometricsScreen && isAuthOsSupported && authSetting !== 'os' && ( { const {enabled: crashReportEnabled} = useCrashReports() const authSetting = useAuthSetting() - const authOsEnabled = useAuthOsEnabled() + const isAuthOsSupported = useIsAuthWithOsSupported() const navigateTo = useNavigateTo() const {authWithOs} = useAuthWithOs({onSuccess: navigateTo.enableLoginWithPin}) @@ -126,12 +126,12 @@ export const ApplicationSettingsScreen = () => { icon={} label={strings.biometricsSignIn} info={strings.biometricsSignInInfo} - disabled={!authOsEnabled} + disabled={!isAuthOsSupported} > diff --git a/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts b/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts index 4b130890c2..8598eefd9e 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts @@ -14,11 +14,11 @@ import {YoroiWallet} from '../cardano/types' import {decryptData, encryptData} from '../encryption' import {AuthenticationPrompt, Keychain} from '../storage' -export const useAuthOsEnabled = (options?: UseQueryOptions) => { +export const useIsAuthWithOsSupported = (options?: UseQueryOptions) => { const queryClient = useQueryClient() const query = useQuery({ - queryKey: ['authOsEnabled'], - queryFn: authOsEnabled, + queryKey: ['isAuthOsSupported'], + queryFn: isAuthOsSupported, suspense: true, ...options, }) @@ -269,7 +269,7 @@ export type AuthSetting = 'pin' | 'os' | undefined export const AUTH_WITH_OS: AuthSetting = 'os' export const AUTH_WITH_PIN: AuthSetting = 'pin' -export const authOsEnabled = () => { +export const isAuthOsSupported = () => { return Platform.select({ android: async () => canAuthWithOS({ diff --git a/apps/wallet-mobile/src/yoroi-wallets/storage/KeychainStorage.test.ts b/apps/wallet-mobile/src/yoroi-wallets/storage/KeychainStorage.test.ts index 0081b445b9..b3a352a9ad 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/storage/KeychainStorage.test.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/storage/KeychainStorage.test.ts @@ -1,6 +1,6 @@ import {canAuthWithOS} from '../auth/auth' -describe('authOsEnabled', () => { +describe('isAuthOsSupported', () => { describe('android', () => { describe('with fingerprint', () => { it('can auth', () => { diff --git a/apps/wallet-mobile/translations/messages/src/WalletNavigator.json b/apps/wallet-mobile/translations/messages/src/WalletNavigator.json index 5444c4691b..b897a5e8a5 100644 --- a/apps/wallet-mobile/translations/messages/src/WalletNavigator.json +++ b/apps/wallet-mobile/translations/messages/src/WalletNavigator.json @@ -4,14 +4,14 @@ "defaultMessage": "!!!Transactions", "file": "src/WalletNavigator.tsx", "start": { - "line": 223, + "line": 227, "column": 22, - "index": 7793 + "index": 8024 }, "end": { - "line": 226, + "line": 230, "column": 3, - "index": 7896 + "index": 8127 } }, { @@ -19,14 +19,14 @@ "defaultMessage": "!!!Send", "file": "src/WalletNavigator.tsx", "start": { - "line": 227, + "line": 231, "column": 14, - "index": 7912 + "index": 8143 }, "end": { - "line": 230, + "line": 234, "column": 3, - "index": 8011 + "index": 8242 } }, { @@ -34,14 +34,14 @@ "defaultMessage": "!!!Receive", "file": "src/WalletNavigator.tsx", "start": { - "line": 231, + "line": 235, "column": 17, - "index": 8030 + "index": 8261 }, "end": { - "line": 234, + "line": 238, "column": 3, - "index": 8135 + "index": 8366 } }, { @@ -49,14 +49,14 @@ "defaultMessage": "!!!Dashboard", "file": "src/WalletNavigator.tsx", "start": { - "line": 235, + "line": 239, "column": 19, - "index": 8156 + "index": 8387 }, "end": { - "line": 238, + "line": 242, "column": 3, - "index": 8253 + "index": 8484 } }, { @@ -64,14 +64,14 @@ "defaultMessage": "!!!Delegate", "file": "src/WalletNavigator.tsx", "start": { - "line": 239, + "line": 243, "column": 18, - "index": 8273 + "index": 8504 }, "end": { - "line": 242, + "line": 246, "column": 3, - "index": 8368 + "index": 8599 } }, { @@ -79,14 +79,14 @@ "defaultMessage": "!!!Wallet", "file": "src/WalletNavigator.tsx", "start": { - "line": 243, + "line": 247, "column": 16, - "index": 8386 + "index": 8617 }, "end": { - "line": 246, + "line": 250, "column": 3, - "index": 8484 + "index": 8715 } }, { @@ -94,14 +94,14 @@ "defaultMessage": "!!!Staking", "file": "src/WalletNavigator.tsx", "start": { - "line": 247, + "line": 251, "column": 17, - "index": 8503 + "index": 8734 }, "end": { - "line": 250, + "line": 254, "column": 3, - "index": 8568 + "index": 8799 } }, { @@ -109,14 +109,14 @@ "defaultMessage": "!!!NFT Gallery", "file": "src/WalletNavigator.tsx", "start": { - "line": 251, + "line": 255, "column": 14, - "index": 8584 + "index": 8815 }, "end": { - "line": 254, + "line": 258, "column": 3, - "index": 8678 + "index": 8909 } }, { @@ -124,14 +124,14 @@ "defaultMessage": "!!!Menu", "file": "src/WalletNavigator.tsx", "start": { - "line": 255, + "line": 259, "column": 14, - "index": 8694 + "index": 8925 }, "end": { - "line": 258, + "line": 262, "column": 3, - "index": 8746 + "index": 8977 } }, { @@ -139,14 +139,14 @@ "defaultMessage": "!!!My wallets", "file": "src/WalletNavigator.tsx", "start": { - "line": 259, + "line": 263, "column": 31, - "index": 8779 + "index": 9010 }, "end": { - "line": 262, + "line": 266, "column": 3, - "index": 8888 + "index": 9119 } } ] \ No newline at end of file From b1282ec682257800252c1a30040fa5ffe796434f Mon Sep 17 00:00:00 2001 From: banklesss <105349292+banklesss@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:32:50 +0200 Subject: [PATCH 4/6] Update apps/wallet-mobile/src/WalletNavigator.tsx Co-authored-by: Juliano Lazzarotto <30806844+stackchain@users.noreply.github.com> Signed-off-by: banklesss <105349292+banklesss@users.noreply.github.com> --- apps/wallet-mobile/src/WalletNavigator.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/wallet-mobile/src/WalletNavigator.tsx b/apps/wallet-mobile/src/WalletNavigator.tsx index e23d81540c..da56684079 100644 --- a/apps/wallet-mobile/src/WalletNavigator.tsx +++ b/apps/wallet-mobile/src/WalletNavigator.tsx @@ -180,7 +180,9 @@ export const WalletNavigator = () => { detachPreviousScreen: false /* https://github.com/react-navigation/react-navigation/issues/9883 */, }} > - {!hasWallets && showBiometricsScreen && isAuthOsSupported && authSetting !== 'os' && ( +const shouldAskToUseAuthWithOs = !hasWallets && showBiometricsScreen && isAuthOsSupported && authSetting !== 'os' + + {shouldAskToUseAuthWithOs && ( Date: Wed, 10 Apr 2024 17:33:36 +0200 Subject: [PATCH 5/6] refactor: auth enabled hook --- apps/wallet-mobile/src/WalletNavigator.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/wallet-mobile/src/WalletNavigator.tsx b/apps/wallet-mobile/src/WalletNavigator.tsx index da56684079..37b56f3244 100644 --- a/apps/wallet-mobile/src/WalletNavigator.tsx +++ b/apps/wallet-mobile/src/WalletNavigator.tsx @@ -157,6 +157,8 @@ export const WalletNavigator = () => { const hasWallets = useHasWallets(walletManager) const authSetting = useAuthSetting() + const shouldAskToUseAuthWithOs = !hasWallets && showBiometricsScreen && isAuthOsSupported && authSetting !== 'os' + // initialRoute doesn't update the state of the navigator, only at first render // https://reactnavigation.org/docs/auth-flow/ if (initialRoute === 'exchange-result') { @@ -180,8 +182,6 @@ export const WalletNavigator = () => { detachPreviousScreen: false /* https://github.com/react-navigation/react-navigation/issues/9883 */, }} > -const shouldAskToUseAuthWithOs = !hasWallets && showBiometricsScreen && isAuthOsSupported && authSetting !== 'os' - {shouldAskToUseAuthWithOs && ( Date: Wed, 10 Apr 2024 17:35:11 +0200 Subject: [PATCH 6/6] refactor: auth enabled hook --- apps/wallet-mobile/src/AppNavigator.tsx | 6 +++--- apps/wallet-mobile/src/WalletNavigator.tsx | 4 ++-- .../ApplicationSettings/ApplicationSettingsScreen.tsx | 4 ++-- apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/wallet-mobile/src/AppNavigator.tsx b/apps/wallet-mobile/src/AppNavigator.tsx index 12c15a79b0..cfdfb3a24d 100644 --- a/apps/wallet-mobile/src/AppNavigator.tsx +++ b/apps/wallet-mobile/src/AppNavigator.tsx @@ -25,7 +25,7 @@ import {DeveloperScreen} from './legacy/DeveloperScreen' import {AppRoutes} from './navigation' import {SearchProvider} from './Search/SearchContext' import {WalletNavigator} from './WalletNavigator' -import {AuthSetting, useAuthSetting, useAuthWithOs, useIsAuthWithOsSupported} from './yoroi-wallets/auth' +import {AuthSetting, useAuthSetting, useAuthWithOs, useIsAuthOsSupported} from './yoroi-wallets/auth' const Stack = createStackNavigator() const navRef = React.createRef>() @@ -208,7 +208,7 @@ const useAutoLogout = () => { const authSetting = useAuthSetting() const strings = useStrings() const {logout} = useAuth() - const isAuthOsSupported = useIsAuthWithOsSupported() + const isAuthOsSupported = useIsAuthOsSupported() const osAuthDisabled = !isAuthOsSupported && authSetting === 'os' useBackgroundTimeout({ @@ -263,7 +263,7 @@ const getFirstAction = ( const useFirstAction = () => { const authSetting = useAuthSetting() - const isAuthOsSupported = useIsAuthWithOsSupported() + const isAuthOsSupported = useIsAuthOsSupported() const terms = useLegalAgreement() return getFirstAction(isAuthOsSupported, authSetting, terms) diff --git a/apps/wallet-mobile/src/WalletNavigator.tsx b/apps/wallet-mobile/src/WalletNavigator.tsx index 37b56f3244..63a5c7cebb 100644 --- a/apps/wallet-mobile/src/WalletNavigator.tsx +++ b/apps/wallet-mobile/src/WalletNavigator.tsx @@ -30,7 +30,7 @@ import {NftsNavigator} from './Nfts/NftsNavigator' import {SearchProvider} from './Search/SearchContext' import {TxHistoryNavigator} from './TxHistory' import {useWalletManager} from './wallet-manager/WalletManagerContext' -import {useAuthSetting, useIsAuthWithOsSupported} from './yoroi-wallets/auth' +import {useAuthSetting, useIsAuthOsSupported} from './yoroi-wallets/auth' import {isHaskellShelley} from './yoroi-wallets/cardano/utils' import {useHasWallets} from './yoroi-wallets/hooks' @@ -151,7 +151,7 @@ export const WalletNavigator = () => { const strings = useStrings() const {theme} = useTheme() useLinksRequestAction() - const isAuthOsSupported = useIsAuthWithOsSupported() + const isAuthOsSupported = useIsAuthOsSupported() const {showBiometricsScreen} = useShowBiometricsScreen() const walletManager = useWalletManager() const hasWallets = useHasWallets(walletManager) diff --git a/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx b/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx index 8067067099..90d373fcd3 100644 --- a/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx +++ b/apps/wallet-mobile/src/features/Settings/ApplicationSettings/ApplicationSettingsScreen.tsx @@ -11,7 +11,7 @@ import {useLanguage} from '../../../i18n' import {defaultLanguage} from '../../../i18n/languages' import {CONFIG, isNightly, isProduction} from '../../../legacy/config' import {lightPalette} from '../../../theme' -import {useAuthSetting, useAuthWithOs, useIsAuthWithOsSupported} from '../../../yoroi-wallets/auth' +import {useAuthSetting, useAuthWithOs, useIsAuthOsSupported} from '../../../yoroi-wallets/auth' import {useCrashReports} from '../../../yoroi-wallets/hooks' import {usePrivacyMode} from '../../Settings/PrivacyMode/PrivacyMode' import {useNavigateTo} from '../common/navigation' @@ -36,7 +36,7 @@ export const ApplicationSettingsScreen = () => { const {enabled: crashReportEnabled} = useCrashReports() const authSetting = useAuthSetting() - const isAuthOsSupported = useIsAuthWithOsSupported() + const isAuthOsSupported = useIsAuthOsSupported() const navigateTo = useNavigateTo() const {authWithOs} = useAuthWithOs({onSuccess: navigateTo.enableLoginWithPin}) diff --git a/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts b/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts index 8598eefd9e..cf6a1ac38c 100644 --- a/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts +++ b/apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts @@ -14,7 +14,7 @@ import {YoroiWallet} from '../cardano/types' import {decryptData, encryptData} from '../encryption' import {AuthenticationPrompt, Keychain} from '../storage' -export const useIsAuthWithOsSupported = (options?: UseQueryOptions) => { +export const useIsAuthOsSupported = (options?: UseQueryOptions) => { const queryClient = useQueryClient() const query = useQuery({ queryKey: ['isAuthOsSupported'],