Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(setup-wallet): avoid intial flow if the user has wallets #3188

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apps/wallet-mobile/src/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppRoutes>()
const navRef = React.createRef<NavigationContainerRef<ReactNavigation.RootParamList>>()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 => {
Expand All @@ -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)
}
11 changes: 8 additions & 3 deletions apps/wallet-mobile/src/WalletNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import {NftDetailsNavigator} from './NftDetails/NftDetailsNavigator'
import {NftsNavigator} from './Nfts/NftsNavigator'
import {SearchProvider} from './Search/SearchContext'
import {TxHistoryNavigator} from './TxHistory'
import {useAuthOsEnabled} from './yoroi-wallets/auth'
import {useWalletManager} from './wallet-manager/WalletManagerContext'
import {useAuthSetting, useIsAuthWithOsSupported} from './yoroi-wallets/auth'
import {isHaskellShelley} from './yoroi-wallets/cardano/utils'
import {useHasWallets} from './yoroi-wallets/hooks'

const Tab = createBottomTabNavigator<WalletTabRoutes>()
const WalletTabNavigator = () => {
Expand Down Expand Up @@ -149,8 +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/
Expand All @@ -175,7 +180,7 @@ export const WalletNavigator = () => {
detachPreviousScreen: false /* https://github.com/react-navigation/react-navigation/issues/9883 */,
}}
>
{showBiometricsScreen && authOsEnabled && (
{!hasWallets && showBiometricsScreen && isAuthOsSupported && authSetting !== 'os' && (
banklesss marked this conversation as resolved.
Show resolved Hide resolved
<Stack.Screen //
name="choose-biometric-login"
options={{headerShown: false}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {useAuthOsEnabled, useAuthSetting, useAuthWithOs} from '../../../yoroi-wallets/auth'
import {useAuthSetting, useAuthWithOs, useIsAuthWithOsSupported} from '../../../yoroi-wallets/auth'
import {useCrashReports} from '../../../yoroi-wallets/hooks'
import {usePrivacyMode} from '../../Settings/PrivacyMode/PrivacyMode'
import {useNavigateTo} from '../common/navigation'
Expand All @@ -36,7 +36,7 @@ export const ApplicationSettingsScreen = () => {
const {enabled: crashReportEnabled} = useCrashReports()

const authSetting = useAuthSetting()
const authOsEnabled = useAuthOsEnabled()
const isAuthOsSupported = useIsAuthWithOsSupported()
const navigateTo = useNavigateTo()
const {authWithOs} = useAuthWithOs({onSuccess: navigateTo.enableLoginWithPin})

Expand Down Expand Up @@ -126,12 +126,12 @@ export const ApplicationSettingsScreen = () => {
icon={<Icon.Bio {...iconProps} />}
label={strings.biometricsSignIn}
info={strings.biometricsSignInInfo}
disabled={!authOsEnabled}
disabled={!isAuthOsSupported}
>
<Switch
value={authSetting === 'os'}
onValueChange={onToggleAuthWithOs}
disabled={!authOsEnabled || isTogglePrivacyModeLoading}
disabled={!isAuthOsSupported || isTogglePrivacyModeLoading}
/>
</SettingsItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions apps/wallet-mobile/src/yoroi-wallets/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {YoroiWallet} from '../cardano/types'
import {decryptData, encryptData} from '../encryption'
import {AuthenticationPrompt, Keychain} from '../storage'

export const useAuthOsEnabled = (options?: UseQueryOptions<boolean, Error>) => {
export const useIsAuthWithOsSupported = (options?: UseQueryOptions<boolean, Error>) => {
banklesss marked this conversation as resolved.
Show resolved Hide resolved
const queryClient = useQueryClient()
const query = useQuery({
queryKey: ['authOsEnabled'],
queryFn: authOsEnabled,
queryKey: ['isAuthOsSupported'],
queryFn: isAuthOsSupported,
suspense: true,
...options,
})
Expand Down Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {canAuthWithOS} from '../auth/auth'

describe('authOsEnabled', () => {
describe('isAuthOsSupported', () => {
describe('android', () => {
describe('with fingerprint', () => {
it('can auth', () => {
Expand Down
80 changes: 40 additions & 40 deletions apps/wallet-mobile/translations/messages/src/WalletNavigator.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,149 +4,149 @@
"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
}
},
{
"id": "components.txhistory.txnavigationbuttons.sendButton",
"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
}
},
{
"id": "components.txhistory.txnavigationbuttons.receiveButton",
"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
}
},
{
"id": "components.common.navigation.dashboardButton",
"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
}
},
{
"id": "components.common.navigation.delegateButton",
"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
}
},
{
"id": "components.settings.walletsettingscreen.tabTitle",
"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
}
},
{
"id": "global.staking",
"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
}
},
{
"id": "components.common.navigation.nftGallery",
"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
}
},
{
"id": "menu",
"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
}
},
{
"id": "components.walletselection.walletselectionscreen.header",
"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
}
}
]
Loading