From 5e38d8ead6344f21903f2b53049815154b7f42fa Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Fri, 10 Jan 2025 11:22:01 -0500 Subject: [PATCH] fixes android not replacing route on first wallet import --- src/hooks/useImportingWallet.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/hooks/useImportingWallet.ts b/src/hooks/useImportingWallet.ts index 096099c8f61..b9ba5867c1a 100644 --- a/src/hooks/useImportingWallet.ts +++ b/src/hooks/useImportingWallet.ts @@ -31,12 +31,14 @@ import { ReviewPromptAction } from '@/storage/schema'; import { ChainId } from '@/state/backendNetworks/types'; import { backupsStore } from '@/state/backups/backups'; import { IS_TEST } from '@/env'; +import { walletLoadingStore } from '@/state/walletLoading/walletLoading'; +import { WalletLoadingStates } from '@/helpers/walletLoadingStates'; export default function useImportingWallet({ showImportModal = true } = {}) { const { accountAddress } = useAccountSettings(); const { selectedWallet, wallets } = useWallets(); - const { getParent: dangerouslyGetParent, navigate, replace, setParams } = useNavigation(); + const { getParent: dangerouslyGetParent, navigate, replace, setParams, reset } = useNavigation(); const initializeWallet = useInitializeWallet(); const isWalletEthZero = useIsWalletEthZero(); const [isImporting, setImporting] = useState(false); @@ -281,6 +283,9 @@ export default function useImportingWallet({ showImportModal = true } = {}) { if (!wasImporting && isImporting) { const asyncFn = async () => { const input = resolvedAddress ? resolvedAddress : sanitizeSeedPhrase(seedPhrase); + walletLoadingStore.setState({ + loadingState: WalletLoadingStates.IMPORTING_WALLET, + }); if (!showImportModal) { await walletInit( @@ -312,23 +317,16 @@ export default function useImportingWallet({ showImportModal = true } = {}) { .then(success => { ios && handleSetImporting(false); if (success) { - dangerouslyGetParent?.()?.goBack(); InteractionManager.runAfterInteractions(async () => { - if (previousWalletCount === 0) { - // on Android replacing is not working well, so we navigate and then remove the screen below - const action = navigate; - action(Routes.SWIPE_LAYOUT, { - params: { initialized: true }, + Navigation.handleAction( + Routes.SWIPE_LAYOUT, + { screen: Routes.WALLET_SCREEN, - }); - } else { - dangerouslyGetParent?.()?.goBack(); - - navigate(Routes.SWIPE_LAYOUT, { params: { initialized: true }, - screen: Routes.WALLET_SCREEN, - }); - } + }, + previousWalletCount === 0 + ); + if (android) { handleSetImporting(false); } @@ -366,6 +364,10 @@ export default function useImportingWallet({ showImportModal = true } = {}) { }, 100); }); } + + walletLoadingStore.setState({ + loadingState: null, + }); }; asyncFn(); }