mirror of
https://github.com/zhigang1992/xverse-web-extension.git
synced 2026-04-30 21:52:45 +08:00
feat: add a store migration to use xverse btc api url as default (#830)
* feat: add a store migration to use xverse btc api url as default * style: comments * chore: fix for knip * chore: add a knip pre push hook * chore: prepush * fix: be more defensive
This commit is contained in:
4
.husky/pre-push
Executable file
4
.husky/pre-push
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npm run knip
|
||||
@@ -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<WalletState> = {
|
||||
version: 6,
|
||||
version: 8,
|
||||
key: 'walletState',
|
||||
storage: chromeStorage.local,
|
||||
migrate: createMigrate(migrations as any, { debug: false }),
|
||||
|
||||
@@ -164,8 +164,10 @@ export type WalletStateV5 = Omit<
|
||||
|
||||
export type WalletStateV6 = Omit<WalletStateV5, 'allowNestedSegWitAddress'>;
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user