Skip to content

Commit

Permalink
fix: crash issue on startup when there are no accounts in the store [E…
Browse files Browse the repository at this point in the history
…NG-5643] (#758)

* Add missing return when seed exists but is not logged in

* Fix migration to not use selected account
  • Loading branch information
victorkirov authored Nov 6, 2024
1 parent ae49c96 commit 8e6a7d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/app/components/guards/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function AuthGuard({ children }: PropsWithChildren) {
await seedVault.getSeed();
} catch (error) {
navigate('/login', { state: { from: pathname } });
return;
}

await loadWallet(() => {
Expand Down
15 changes: 6 additions & 9 deletions src/app/hooks/useSeedVaultMigration.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { SeedVaultStorageKeys } from '@secretkeylabs/xverse-core';
import ChromeStorage from '@utils/chromeStorage';
import { useDispatch } from 'react-redux';
import useSeedVault from './useSeedVault';
import useSelectedAccount from './useSelectedAccount';
import useWalletReducer from './useWalletReducer';
import useWalletSelector from './useWalletSelector';

const useSeedVaultMigration = () => {
const SeedVault = useSeedVault();
const { accountsList } = useWalletSelector();
const { switchAccount } = useWalletReducer();
const selectedAccount = useSelectedAccount();
const dispatch = useDispatch();
const { btcPaymentAddressType } = useWalletSelector();
const { changeBtcPaymentAddressType } = useWalletReducer();

const isVaultUpdated = async () => {
const currentVaultVersion = await ChromeStorage.local.getItem<string>(
Expand All @@ -35,10 +31,11 @@ const useSeedVaultMigration = () => {
await SeedVault.restoreVault(encryptedKey, passwordSalt);
localStorage.removeItem('SEED_VAULT_MIGRATION_BACKUP');
/**
* The migration clears the redux store cache, so if the user quits the extension without going to the home screen the cache would be empty for the next session,
* this is a workaround to trigger flushing the redux-store state to cache,
* The migration clears the redux store cache, so if the user quits the extension without going to the home
* screen the cache would be empty for the next session, this is a workaround to trigger flushing the redux-store
* state to cache,
*/
switchAccount(selectedAccount!);
changeBtcPaymentAddressType(btcPaymentAddressType);
};

const migrateCachedStorage = async () => {
Expand Down

0 comments on commit 8e6a7d3

Please sign in to comment.