Skip to content

Commit

Permalink
fix: add remove account reset logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jinming0618 committed Dec 2, 2024
1 parent a8b5e41 commit 670b68b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion apps/mobile/src/screens/Address/useDeleteAccountModal.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { AuthenticationModal } from '@/components/AuthenticationModal/AuthenticationModal';
import { apiMnemonic, apisLock } from '@/core/apis';
import { keyringService } from '@/core/services';
import { KeyringAccountWithAlias, useRemoveAccount } from '@/hooks/account';
import { resetNavigationTo, useRabbyAppNavigation } from '@/hooks/navigation';
import { useEnterPassphraseModal } from '@/hooks/useEnterPassphraseModal';
import { KEYRING_TYPE } from '@rabby-wallet/keyring-utils';
import { useMemoizedFn } from 'ahooks';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

export const useDeleteAccountModal = () => {
const { t } = useTranslation();
const invokeEnterPassphrase = useEnterPassphraseModal('address');
const removeAccount = useRemoveAccount();
const navigation = useRabbyAppNavigation();

const handleShouldGoStartPage = useMemoizedFn(async () => {
const hasAccountsInKeyring =
(await keyringService.getCountOfAccountsInKeyring()) > 0;
if (!hasAccountsInKeyring) {
resetNavigationTo(navigation, 'GetStarted2024');
}
});

const handlePresentDeleteModalPress = useCallback(
async ({
Expand Down Expand Up @@ -54,6 +66,7 @@ export const useDeleteAccountModal = () => {
: { authType: ['biometrics', 'password'] }),
onFinished: async () => {
await removeAccount(account);
await handleShouldGoStartPage();
onFinished?.();
},
validationHandler: async (password: string) => {
Expand All @@ -65,7 +78,7 @@ export const useDeleteAccountModal = () => {
},
});
},
[invokeEnterPassphrase, removeAccount, t],
[invokeEnterPassphrase, removeAccount, t, handleShouldGoStartPage],
);

return handlePresentDeleteModalPress;
Expand Down

0 comments on commit 670b68b

Please sign in to comment.