diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 000000000..be56d0bf4 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npm run knip diff --git a/src/app/stores/index.ts b/src/app/stores/index.ts index c8863adcf..9aee1e2f3 100644 --- a/src/app/stores/index.ts +++ b/src/app/stores/index.ts @@ -1,4 +1,5 @@ /* eslint-disable no-underscore-dangle */ +import { defaultMainnet, type SettingsNetwork } from '@secretkeylabs/xverse-core'; import { markAlertsForShow } from '@utils/alertTracker'; import chromeStorage from '@utils/chromeStorage'; import { applyMiddleware, combineReducers, createStore } from 'redux'; @@ -15,6 +16,7 @@ import type { WalletStateV4, WalletStateV5, WalletStateV6, + WalletStateV7, } from './wallet/actions/migrationTypes'; import { type AvatarInfo, type WalletState } from './wallet/actions/types'; import walletReducer, { initialWalletState, rehydrateError } from './wallet/reducer'; @@ -154,11 +156,41 @@ const migrations = { const { allowNestedSegWitAddress, ...migratedState } = state; return migratedState as WalletState; }, - 7: (state: WalletStateV6): WalletState => ({ + 7: ( + // NOTE: because we forgot to bump the store version on L222, need to be defensive here + // and only initialise if not defined + state: WalletStateV6 & { showBalanceInBtc: boolean; hasBackedUpWallet: boolean }, + ): WalletStateV7 => ({ ...state, - showBalanceInBtc: false, - hasBackedUpWallet: true, + showBalanceInBtc: state.showBalanceInBtc ?? false, + hasBackedUpWallet: state.hasBackedUpWallet ?? true, }), + 8: (state: WalletStateV7): WalletState => { + const migrateMainnetNetwork = (currentNetwork: SettingsNetwork) => ({ + ...currentNetwork, + btcApiUrl: + currentNetwork.btcApiUrl === 'https://mempool.space/api' + ? defaultMainnet.btcApiUrl + : currentNetwork.btcApiUrl, + fallbackBtcApiUrl: + !currentNetwork.fallbackBtcApiUrl || + currentNetwork.fallbackBtcApiUrl === 'https://btc-1.xverse.app' + ? defaultMainnet.fallbackBtcApiUrl + : currentNetwork.fallbackBtcApiUrl, + }); + return { + ...state, + savedNetworks: + state.savedNetworks?.map((network: SettingsNetwork) => + network.type === 'Mainnet' ? migrateMainnetNetwork(network) : network, + ) ?? initialWalletState.savedNetworks, + network: + (state.network?.type === 'Mainnet' + ? migrateMainnetNetwork(state.network) + : state.network) ?? initialWalletState.network, + }; + }, + /* * * When adding a new migration, add the new wallet state type to the migrationTypes file * and add the migration here. @@ -188,7 +220,7 @@ const migrations = { }; const WalletPersistConfig: PersistConfig = { - version: 6, + version: 8, key: 'walletState', storage: chromeStorage.local, migrate: createMigrate(migrations as any, { debug: false }), diff --git a/src/app/stores/wallet/actions/migrationTypes.ts b/src/app/stores/wallet/actions/migrationTypes.ts index dbc8f6509..492d2339e 100644 --- a/src/app/stores/wallet/actions/migrationTypes.ts +++ b/src/app/stores/wallet/actions/migrationTypes.ts @@ -164,8 +164,10 @@ export type WalletStateV5 = Omit< export type WalletStateV6 = Omit; -type WalletStateV7 = WalletStateV6 & { - // should be exported and used when we add next migration +export type WalletStateV7 = WalletStateV6 & { showBalanceInBtc: boolean; hasBackedUpWallet: boolean; }; + +// should be exported and used when we add next migration +type WalletStateV8 = WalletStateV7; // no changes. just a data migration