Skip to content

Commit

Permalink
fixes android not replacing route on first wallet import
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Jan 10, 2025
1 parent ede2624 commit 5e38d8e
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/hooks/useImportingWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -366,6 +364,10 @@ export default function useImportingWallet({ showImportModal = true } = {}) {
}, 100);
});
}

walletLoadingStore.setState({
loadingState: null,
});
};
asyncFn();
}
Expand Down

0 comments on commit 5e38d8e

Please sign in to comment.