diff --git a/packages/adena-extension/src/hooks/use-current-account.tsx b/packages/adena-extension/src/hooks/use-current-account.tsx index 54ce9e3f9..608652aaa 100644 --- a/packages/adena-extension/src/hooks/use-current-account.tsx +++ b/packages/adena-extension/src/hooks/use-current-account.tsx @@ -32,8 +32,6 @@ export const useCurrentAccount = (): { return false; } await accountService.changeCurrentAccount(changedAccount); - const clone = wallet.clone(); - clone.currentAccountId = changedAccount.id; setCurrentAccount(changedAccount); dispatchChangedEvent(changedAccount); return true; diff --git a/packages/adena-extension/src/hooks/use-remove-account.tsx b/packages/adena-extension/src/hooks/use-remove-account.tsx index eff50e476..0810e0a04 100644 --- a/packages/adena-extension/src/hooks/use-remove-account.tsx +++ b/packages/adena-extension/src/hooks/use-remove-account.tsx @@ -25,8 +25,8 @@ export const useRemoveAccount = (): { clone.removeAccount(account); const nextAccount = clone.accounts[clone.accounts.length - 1]; clone.currentAccountId = nextAccount.id; - await updateWallet(clone); await changeCurrentAccount(nextAccount); + await updateWallet(clone); return true; }; diff --git a/packages/adena-extension/src/hooks/web/google-login/use-google-login-screen.ts b/packages/adena-extension/src/hooks/web/google-login/use-google-login-screen.ts index db6deac37..750eb8358 100644 --- a/packages/adena-extension/src/hooks/web/google-login/use-google-login-screen.ts +++ b/packages/adena-extension/src/hooks/web/google-login/use-google-login-screen.ts @@ -102,7 +102,11 @@ const useGoogleLoginScreen = (): UseGoogleLoginReturn => { const web3AuthKeyring = await Web3AuthKeyring.fromPrivateKeyStr(privateKey); const account = await SingleAccount.createBy(web3AuthKeyring, clone.nextAccountName); clone.addAccount(account); - await changeCurrentAccount(account); + clone.addKeyring(web3AuthKeyring); + const storedAccount = clone.accounts.find((storedAccount) => storedAccount.id === account.id); + if (storedAccount) { + await changeCurrentAccount(storedAccount); + } await updateWallet(clone); navigate(RoutePath.WebAccountAddedComplete); }, diff --git a/packages/adena-extension/src/hooks/web/setup-airgap/use-setup-airgap-screen.ts b/packages/adena-extension/src/hooks/web/setup-airgap/use-setup-airgap-screen.ts index 91d0597c3..29787ffec 100644 --- a/packages/adena-extension/src/hooks/web/setup-airgap/use-setup-airgap-screen.ts +++ b/packages/adena-extension/src/hooks/web/setup-airgap/use-setup-airgap-screen.ts @@ -107,8 +107,10 @@ const useSetupAirgapScreen = (): UseSetupAirgapScreenReturn => { const clone = wallet.clone(); clone.addAccount(account); clone.addKeyring(addressKeyring); - - await changeCurrentAccount(account); + const storedAccount = clone.accounts.find((storedAccount) => storedAccount.id === account.id); + if (storedAccount) { + await changeCurrentAccount(storedAccount); + } await updateWallet(clone); navigate(RoutePath.WebAccountAddedComplete); }, [address, walletService]); diff --git a/packages/adena-extension/src/hooks/web/use-account-import-screen.ts b/packages/adena-extension/src/hooks/web/use-account-import-screen.ts index 54cdfd45e..8481d7d44 100644 --- a/packages/adena-extension/src/hooks/web/use-account-import-screen.ts +++ b/packages/adena-extension/src/hooks/web/use-account-import-screen.ts @@ -114,9 +114,11 @@ const useAccountImportScreen = ({ wallet }: { wallet: Wallet }): UseAccountImpor const clone = wallet.clone(); clone.addAccount(account); clone.addKeyring(keyring); - + const storedAccount = clone.accounts.find((storedAccount) => storedAccount.id === account.id); + if (storedAccount) { + await changeCurrentAccount(storedAccount); + } await updateWallet(clone); - await changeCurrentAccount(account); navigate(RoutePath.WebAccountAddedComplete); } }, [step, privateKey, ableToSkipQuestionnaire, makePrivateKeyAccountAndKeyring]); diff --git a/packages/adena-extension/src/hooks/web/use-wallet-create-screen.ts b/packages/adena-extension/src/hooks/web/use-wallet-create-screen.ts index 8a70d8474..fb0b83819 100644 --- a/packages/adena-extension/src/hooks/web/use-wallet-create-screen.ts +++ b/packages/adena-extension/src/hooks/web/use-wallet-create-screen.ts @@ -72,8 +72,13 @@ const useWalletCreateScreen = (): UseWalletCreateReturn => { const clone = wallet.clone(); clone.addAccount(account); clone.addKeyring(keyring); + const storedAccount = clone.accounts.find( + (storedAccount) => storedAccount.id === account.id, + ); + if (storedAccount) { + await changeCurrentAccount(storedAccount); + } await updateWallet(clone); - await changeCurrentAccount(account); navigate(RoutePath.WebAccountAddedComplete); } else { const createdWallet = await AdenaWallet.createByMnemonic(seeds); diff --git a/packages/adena-extension/src/pages/popup/certify/remove-account/index.tsx b/packages/adena-extension/src/pages/popup/certify/remove-account/index.tsx index 39545387e..701b1dc46 100644 --- a/packages/adena-extension/src/pages/popup/certify/remove-account/index.tsx +++ b/packages/adena-extension/src/pages/popup/certify/remove-account/index.tsx @@ -28,7 +28,7 @@ export const RemoveAccount = (): JSX.Element => { } setState('LOADING'); await removeAccount(currentAccount); - navigate(RoutePath.Home); + navigate(RoutePath.Wallet); }; return ( diff --git a/packages/adena-extension/src/pages/popup/wallet/account-details/index.tsx b/packages/adena-extension/src/pages/popup/wallet/account-details/index.tsx index a020da25f..688ba84e7 100644 --- a/packages/adena-extension/src/pages/popup/wallet/account-details/index.tsx +++ b/packages/adena-extension/src/pages/popup/wallet/account-details/index.tsx @@ -6,7 +6,6 @@ import AccountDetails from '@components/pages/account-details/account-details'; import { useLoadAccounts } from '@hooks/use-load-accounts'; import { useNetwork } from '@hooks/use-network'; import { useAccountName } from '@hooks/use-account-name'; -import { useCurrentAccount } from '@hooks/use-current-account'; import { CommonFullContentLayout } from '@components/atoms'; import useLink from '@hooks/use-link'; import { AdenaStorage } from '@common/storage'; @@ -20,7 +19,6 @@ const AccountDetailsContainer: React.FC = () => { const { accounts } = useLoadAccounts(); const { currentNetwork } = useNetwork(); const { accountNames, changeAccountName } = useAccountName(); - const { changeCurrentAccount } = useCurrentAccount(); const [originName, setOriginName] = useState(''); const [name, setName] = useState(''); const [address, setAddress] = useState(''); @@ -55,9 +53,6 @@ const AccountDetailsContainer: React.FC = () => { }, [address]); const moveExportPrivateKey = useCallback(async () => { - if (account) { - await changeCurrentAccount(account); - } const sessionStorage = AdenaStorage.session(); await sessionStorage.set(WALLET_EXPORT_TYPE_STORAGE_KEY, 'PRIVATE_KEY'); openSecurity();