Skip to content

Commit

Permalink
feat: upgrade shouldRedirectToSetPasswordBefore2024.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016x committed Dec 2, 2024
1 parent 6592cd3 commit 4e3abf2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
9 changes: 6 additions & 3 deletions apps/mobile/src/components/AddAddressSelectMethod/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -30,14 +33,14 @@ export const AddAddressSelectMethod: React.FC<Props> = ({
<NormalScreenContainer overwriteStyle={styles.wrapper}>
<View style={styles.section}>
<ListItem
onPress={() => {
onPress={async () => {
trigger('impactLight', {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false,
});

if (
shouldRedirectToSetPasswordBefore2024({
await shouldRedirectToSetPasswordBefore2024({
backScreen: RootNames.CreateSelectMethod,
})
) {
Expand Down
2 changes: 0 additions & 2 deletions apps/mobile/src/core/apis/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions apps/mobile/src/core/apis/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions apps/mobile/src/hooks/useLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,23 @@ export function useSetPasswordFirst() {
);

const shouldRedirectToSetPasswordBefore2024 = React.useCallback(
({
async ({
backScreen,
isFirstImportPassword,
}: {
backScreen?: (SettingNavigatorParamList['SetPassword'] & {
backScreen: (SettingNavigatorParamList['SetPassword'] & {
actionAfterSetup: 'backScreen';
})['replaceScreen'];
isFirstImportPassword?: boolean;
}) => {
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;
}

Expand All @@ -331,7 +335,7 @@ export function useSetPasswordFirst() {
}
return false;
},
[navigation, lockInfo],
[navigation],
);

return {
Expand Down
12 changes: 6 additions & 6 deletions apps/mobile/src/screens/Address/ImportMethods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ function ImportMethods(): JSX.Element {
<Card
style={styles.importItem}
hasArrow={state?.isNotNewUserProc}
onPress={() => {
onPress={async () => {
trigger('impactLight', {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false,
});
if (
// only has address in this set password
state?.isNotNewUserProc &&
shouldRedirectToSetPasswordBefore2024({
(await shouldRedirectToSetPasswordBefore2024({
backScreen: RootNames.ImportMnemonic2024,
})
}))
) {
return;
}
Expand All @@ -89,16 +89,16 @@ function ImportMethods(): JSX.Element {
<Card
hasArrow={state?.isNotNewUserProc}
style={styles.importItem}
onPress={() => {
onPress={async () => {
trigger('impactLight', {
enableVibrateFallback: true,
ignoreAndroidSystemSettings: false,
});
if (
state?.isNotNewUserProc &&
shouldRedirectToSetPasswordBefore2024({
(await shouldRedirectToSetPasswordBefore2024({
backScreen: RootNames.ImportPrivateKey2024,
})
}))
) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down

0 comments on commit 4e3abf2

Please sign in to comment.