diff --git a/apps/mobile/src/components/AddAddressSelectMethod/index.tsx b/apps/mobile/src/components/AddAddressSelectMethod/index.tsx index 04c972148..ba18b54c9 100644 --- a/apps/mobile/src/components/AddAddressSelectMethod/index.tsx +++ b/apps/mobile/src/components/AddAddressSelectMethod/index.tsx @@ -11,10 +11,13 @@ import { useTheme2024 } from '@/hooks/theme'; import { createGetStyles2024 } from '@/utils/styles'; import { ListItem } from '@/components2024/ListItem/ListItem'; import { trigger } from 'react-native-haptic-feedback'; +import { useSetPasswordFirst } from '@/hooks/useLock'; interface Props { onDone: (isNoMnemonic?: boolean) => void; - shouldRedirectToSetPasswordBefore2024: any; + shouldRedirectToSetPasswordBefore2024: ReturnType< + typeof useSetPasswordFirst + >['shouldRedirectToSetPasswordBefore2024']; navigateTo: (screen: AppRootName, params?: object) => void; } @@ -30,14 +33,14 @@ export const AddAddressSelectMethod: React.FC = ({ { + onPress={async () => { trigger('impactLight', { enableVibrateFallback: true, ignoreAndroidSystemSettings: false, }); if ( - shouldRedirectToSetPasswordBefore2024({ + await shouldRedirectToSetPasswordBefore2024({ backScreen: RootNames.CreateSelectMethod, }) ) { diff --git a/apps/mobile/src/core/apis/account.ts b/apps/mobile/src/core/apis/account.ts index 356f7d6d0..17a15af17 100644 --- a/apps/mobile/src/core/apis/account.ts +++ b/apps/mobile/src/core/apis/account.ts @@ -8,8 +8,6 @@ import { IDisplayedAccountWithBalance } from '@/hooks/accountToDisplay'; import { TotalBalanceResponse } from '@rabby-wallet/rabby-api/dist/types'; import { getAddressCacheBalance } from './balance'; import { requestKeyring } from './keyring'; -import { CHAINS_ENUM } from '@/constant/chains'; -import { apiAccount } from '.'; function ensureDisplayKeyring(keyring: KeyringIntf | DisplayKeyring) { if (keyring instanceof DisplayKeyring) { diff --git a/apps/mobile/src/core/apis/lock.ts b/apps/mobile/src/core/apis/lock.ts index 1182fd236..5cd1e7d57 100644 --- a/apps/mobile/src/core/apis/lock.ts +++ b/apps/mobile/src/core/apis/lock.ts @@ -131,6 +131,14 @@ export async function updateWalletPassword( return result; } +export async function shouldAskSetPassword() { + const lockInfo = await getRabbyLockInfo(); + + if (!lockInfo.isUseCustomPwd) return true; + + return keyringService.getCountOfAccountsInKeyring() === 0; +} + export async function resetPasswordOnUI(newPassword: string) { const result = getInitError(newPassword); if (result.error) return result; diff --git a/apps/mobile/src/hooks/useLock.ts b/apps/mobile/src/hooks/useLock.ts index 808efef14..457fdbd65 100644 --- a/apps/mobile/src/hooks/useLock.ts +++ b/apps/mobile/src/hooks/useLock.ts @@ -300,11 +300,11 @@ export function useSetPasswordFirst() { ); const shouldRedirectToSetPasswordBefore2024 = React.useCallback( - ({ + async ({ backScreen, isFirstImportPassword, }: { - backScreen?: (SettingNavigatorParamList['SetPassword'] & { + backScreen: (SettingNavigatorParamList['SetPassword'] & { actionAfterSetup: 'backScreen'; })['replaceScreen']; isFirstImportPassword?: boolean; @@ -312,7 +312,11 @@ export function useSetPasswordFirst() { if (!APP_FEATURE_SWITCH.customizePassword) { return false; } - if (lockInfo.pwdStatus === PasswordStatus.Custom) { + // if (lockInfo.pwdStatus === PasswordStatus.Custom) { + // return false; + // } + const shouldAsk = await apisLock.shouldAskSetPassword(); + if (!shouldAsk) { return false; } @@ -331,7 +335,7 @@ export function useSetPasswordFirst() { } return false; }, - [navigation, lockInfo], + [navigation], ); return { diff --git a/apps/mobile/src/screens/Address/ImportMethods.tsx b/apps/mobile/src/screens/Address/ImportMethods.tsx index 8d5d76d7f..2ff9bb614 100644 --- a/apps/mobile/src/screens/Address/ImportMethods.tsx +++ b/apps/mobile/src/screens/Address/ImportMethods.tsx @@ -64,7 +64,7 @@ function ImportMethods(): JSX.Element { { + onPress={async () => { trigger('impactLight', { enableVibrateFallback: true, ignoreAndroidSystemSettings: false, @@ -72,9 +72,9 @@ function ImportMethods(): JSX.Element { if ( // only has address in this set password state?.isNotNewUserProc && - shouldRedirectToSetPasswordBefore2024({ + (await shouldRedirectToSetPasswordBefore2024({ backScreen: RootNames.ImportMnemonic2024, - }) + })) ) { return; } @@ -89,16 +89,16 @@ function ImportMethods(): JSX.Element { { + onPress={async () => { trigger('impactLight', { enableVibrateFallback: true, ignoreAndroidSystemSettings: false, }); if ( state?.isNotNewUserProc && - shouldRedirectToSetPasswordBefore2024({ + (await shouldRedirectToSetPasswordBefore2024({ backScreen: RootNames.ImportPrivateKey2024, - }) + })) ) { return; } diff --git a/apps/mobile/src/screens/Address/ImportPrivateKeyScreen2024.tsx b/apps/mobile/src/screens/Address/ImportPrivateKeyScreen2024.tsx index f77936ba2..b2b5ac552 100644 --- a/apps/mobile/src/screens/Address/ImportPrivateKeyScreen2024.tsx +++ b/apps/mobile/src/screens/Address/ImportPrivateKeyScreen2024.tsx @@ -86,14 +86,14 @@ export const ImportPrivateKeyScreen2024 = () => { } }, [privateKey, t]); - const handleConfirm = React.useCallback(() => { + const handleConfirm = React.useCallback(async () => { // verify private key for setPassword if (!verfiyPrivateKey()) { return; } if ( - shouldRedirectToSetPasswordBefore2024({ + await shouldRedirectToSetPasswordBefore2024({ backScreen: RootNames.ImportSuccess2024, isFirstImportPassword: true, }) diff --git a/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx b/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx index 1ceb61ebb..0a76ba0c3 100644 --- a/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx +++ b/apps/mobile/src/screens/Address/ImportSeedPhraseScreen2024.tsx @@ -229,14 +229,14 @@ export const ImportSeedPhraseScreen2024 = () => { } }, [mnemonics, t]); - const handleConfirm = React.useCallback(() => { + const handleConfirm = React.useCallback(async () => { // verify mnemonics for setPassword if (!verfiyMnemonics()) { return; } if ( - shouldRedirectToSetPasswordBefore2024({ + await shouldRedirectToSetPasswordBefore2024({ backScreen: RootNames.ImportSuccess2024, isFirstImportPassword: true, })