diff --git a/src/state/migrations/clearAssets.ts b/src/state/migrations/clearAssets.ts index 72b1170f226..988dc6928ce 100644 --- a/src/state/migrations/clearAssets.ts +++ b/src/state/migrations/clearAssets.ts @@ -1,29 +1,7 @@ -import type { ReduxState } from 'state/reducer' +import type { PersistPartial } from 'redux-persist/es/persistReducer' +import type { AssetsState } from 'state/slices/assetsSlice/assetsSlice' import { initialState } from 'state/slices/assetsSlice/assetsSlice' -export const clearAssets = (state: ReduxState): ReduxState => { - return { - ...state, - assets: initialState, - // This is very ugly but also very correct - // Typically, to achieve this, we would dispatch nftapi.util.resetApiState as a side effect - // But we can't do this here because circular deps, so we have to do it manually - // https://redux-toolkit.js.org/rtk-query/api/created-api/api-slice-utils#resetapistate - assetApi: { - queries: {}, - mutations: {}, - provided: {}, - subscriptions: {}, - config: { - online: true, - focused: true, - middlewareRegistered: true, - refetchOnFocus: false, - refetchOnReconnect: true, - refetchOnMountOrArgChange: false, - keepUnusedDataFor: 60, - reducerPath: 'assetApi', - }, - }, - } +export const clearAssets = (_state: AssetsState): AssetsState & PersistPartial => { + return initialState as AssetsState & PersistPartial } diff --git a/src/state/migrations/clearMarketData.ts b/src/state/migrations/clearMarketData.ts index e0b711a8f72..e1fc2b15cf4 100644 --- a/src/state/migrations/clearMarketData.ts +++ b/src/state/migrations/clearMarketData.ts @@ -1,10 +1,8 @@ -import type { ReduxState } from 'state/reducer' +import type { PersistPartial } from 'redux-persist/es/persistReducer' import { initialState } from 'state/slices/marketDataSlice/marketDataSlice' +import type { MarketDataState } from 'state/slices/marketDataSlice/types' -export const clearMarketData = (state: ReduxState): ReduxState => { +export const clearMarketData = (_state: MarketDataState): MarketDataState & PersistPartial => { // Migration to clear marketData state - return { - ...state, - marketData: initialState, - } + return initialState as MarketDataState & PersistPartial } diff --git a/src/state/migrations/clearNfts.ts b/src/state/migrations/clearNfts.ts index e8ab1b10007..dcb4f01d386 100644 --- a/src/state/migrations/clearNfts.ts +++ b/src/state/migrations/clearNfts.ts @@ -1,31 +1,7 @@ import type { PersistPartial } from 'redux-persist/es/persistReducer' import type { NftState } from 'state/apis/nft/nftApi' import { initialState } from 'state/apis/nft/nftApi' -import type { ReduxState } from 'state/reducer' -export const clearNfts = (state: ReduxState): ReduxState => { - return { - ...state, - nft: initialState as NftState & PersistPartial, - // This is very ugly but also very correct - // Typically, to achieve this, we would dispatch nftapi.util.resetApiState as a side effect - // But we can't do this here because circular deps, so we have to do it manually - // https://redux-toolkit.js.org/rtk-query/api/created-api/api-slice-utils#resetapistate - nftApi: { - queries: {}, - mutations: {}, - provided: {}, - subscriptions: {}, - config: { - online: true, - focused: false, - middlewareRegistered: true, - refetchOnFocus: false, - refetchOnReconnect: true, - refetchOnMountOrArgChange: false, - keepUnusedDataFor: 60, - reducerPath: 'nftApi', - }, - }, - } +export const clearNfts = (_state: NftState): NftState & PersistPartial => { + return initialState as NftState & PersistPartial } diff --git a/src/state/migrations/clearOpportunities.ts b/src/state/migrations/clearOpportunities.ts index 44dfd5f9d35..bcf3ad44a8b 100644 --- a/src/state/migrations/clearOpportunities.ts +++ b/src/state/migrations/clearOpportunities.ts @@ -1,13 +1,11 @@ import type { PersistPartial } from 'redux-persist/es/persistReducer' -import type { ReduxState } from 'state/reducer' import type { OpportunitiesState } from 'state/slices/opportunitiesSlice/types' import { initialState } from '../slices/opportunitiesSlice/opportunitiesSlice' -export const clearOpportunities = (state: ReduxState): ReduxState => { +export const clearOpportunities = ( + _state: OpportunitiesState, +): OpportunitiesState & PersistPartial => { // Migration to clear opportunitiesApi and opportunitiesApi state - return { - ...state, - opportunities: initialState as OpportunitiesState & PersistPartial, - } + return initialState as OpportunitiesState & PersistPartial } diff --git a/src/state/migrations/clearPortfolio.ts b/src/state/migrations/clearPortfolio.ts index bbe09a9083f..0bff1421d94 100644 --- a/src/state/migrations/clearPortfolio.ts +++ b/src/state/migrations/clearPortfolio.ts @@ -1,31 +1,7 @@ import type { PersistPartial } from 'redux-persist/es/persistReducer' -import type { ReduxState } from 'state/reducer' import type { Portfolio } from 'state/slices/portfolioSlice/portfolioSliceCommon' import { initialState } from 'state/slices/portfolioSlice/portfolioSliceCommon' -export const clearPortfolio = (state: ReduxState): ReduxState => { - return { - ...state, - portfolio: initialState as Portfolio & PersistPartial, - // This is very ugly but also very correct - // Typically, to achieve this, we would dispatch nftapi.util.resetApiState as a side effect - // But we can't do this here because circular deps, so we have to do it manually - // https://redux-toolkit.js.org/rtk-query/api/created-api/api-slice-utils#resetapistate - portfolioApi: { - queries: {}, - mutations: {}, - provided: {}, - subscriptions: {}, - config: { - online: true, - focused: true, - middlewareRegistered: true, - refetchOnFocus: false, - refetchOnReconnect: true, - refetchOnMountOrArgChange: false, - keepUnusedDataFor: 60, - reducerPath: 'portfolioApi', - }, - }, - } +export const clearPortfolio = (_state: Portfolio): Portfolio & PersistPartial => { + return initialState as Portfolio & PersistPartial } diff --git a/src/state/migrations/clearSnapshot.ts b/src/state/migrations/clearSnapshot.ts index bf48031b61c..3a1dcb4ae27 100644 --- a/src/state/migrations/clearSnapshot.ts +++ b/src/state/migrations/clearSnapshot.ts @@ -1,12 +1,8 @@ import type { PersistPartial } from 'redux-persist/es/persistReducer' import type { SnapshotState } from 'state/apis/snapshot/snapshot' import { initialState } from 'state/apis/snapshot/snapshot' -import type { ReduxState } from 'state/reducer' -export const clearSnapshot = (state: ReduxState): ReduxState => { +export const clearSnapshot = (_state: SnapshotState): SnapshotState & PersistPartial => { // Migration to clear snapshot API - return { - ...state, - snapshot: initialState as SnapshotState & PersistPartial, - } + return initialState as SnapshotState & PersistPartial } diff --git a/src/state/migrations/clearWalletConnectWalletsMetadata.ts b/src/state/migrations/clearWalletConnectWalletsMetadata.ts index 2b1df52881d..a6f396dcd81 100644 --- a/src/state/migrations/clearWalletConnectWalletsMetadata.ts +++ b/src/state/migrations/clearWalletConnectWalletsMetadata.ts @@ -1,20 +1,18 @@ -import type { ReduxState } from 'state/reducer' +import type { PersistPartial } from 'redux-persist/es/persistReducer' +import type { Portfolio } from 'state/slices/portfolioSlice/portfolioSliceCommon' -export const clearWalletConnectWalletsMetadata = (state: ReduxState): ReduxState => { - const updatedWalletIds = state.portfolio.wallet.ids.filter(id => !id.startsWith('wc:')) +export const clearWalletConnectWalletsMetadata = (state: Portfolio): Portfolio & PersistPartial => { + const updatedWalletIds = state.wallet.ids.filter(id => !id.startsWith('wc:')) const updatedWalletById = Object.fromEntries( - Object.entries(state.portfolio.wallet.byId).filter(([walletId]) => !walletId.startsWith('wc:')), + Object.entries(state.wallet.byId).filter(([walletId]) => !walletId.startsWith('wc:')), ) return { ...state, - portfolio: { - ...state.portfolio, - wallet: { - ...state.portfolio.wallet, - ids: updatedWalletIds, - byId: updatedWalletById, - }, + wallet: { + ...state.wallet, + ids: updatedWalletIds, + byId: updatedWalletById, }, - } + } as Portfolio & PersistPartial } diff --git a/src/state/migrations/index.ts b/src/state/migrations/index.ts index 5245623fbb2..86bfc449ac1 100644 --- a/src/state/migrations/index.ts +++ b/src/state/migrations/index.ts @@ -1,14 +1,5 @@ import type { MigrationManifest } from 'redux-persist' -import { clearAssets } from './clearAssets' -import { clearMarketData } from './clearMarketData' -import { clearNfts } from './clearNfts' -import { clearOpportunities } from './clearOpportunities' -import { clearPortfolio } from './clearPortfolio' -import { clearSnapshot } from './clearSnapshot' -import { clearTxHistory } from './clearTxHistory' -import { clearWalletConnectWalletsMetadata } from './clearWalletConnectWalletsMetadata' - export const clearTxHistoryMigrations = { // Uncomment me when introducing the first migration for this slice // 0: clearTxHistory, @@ -43,138 +34,3 @@ export const clearSnapshotMigrations = { // Uncomment me when introducing the first migration for this slice // 0: clearSnapshot, } as unknown as Omit - -export const migrations = { - 0: clearOpportunities, - 1: clearOpportunities, - 2: clearPortfolio, - 3: clearOpportunities, - 4: clearOpportunities, - 5: clearNfts, - 6: clearAssets, - 7: clearPortfolio, - 8: clearOpportunities, - 9: clearAssets, - 10: clearTxHistory, - 11: clearAssets, - 12: clearAssets, - 13: clearPortfolio, - 14: clearTxHistory, - 15: clearAssets, - 16: clearOpportunities, - 17: clearTxHistory, - 18: clearTxHistory, - 19: clearMarketData, - 20: clearTxHistory, - 21: clearAssets, - 22: clearTxHistory, - 23: clearPortfolio, - 24: clearTxHistory, - 25: clearAssets, - 26: clearAssets, - 27: clearPortfolio, - 28: clearAssets, - 29: clearAssets, - 30: clearTxHistory, - 31: clearAssets, - 32: clearSnapshot, - 33: clearAssets, - 34: clearTxHistory, - 35: clearAssets, - 36: clearTxHistory, - 37: clearPortfolio, - 38: clearOpportunities, - 39: clearAssets, - 40: clearAssets, - 41: clearAssets, - 42: clearAssets, - 43: clearAssets, - 44: clearAssets, - 45: clearAssets, - 46: clearAssets, - 47: clearAssets, - 48: clearAssets, - 49: clearAssets, - 50: clearPortfolio, - 51: clearAssets, - 52: clearPortfolio, - 53: clearAssets, - 54: clearAssets, - 55: clearAssets, - 56: clearPortfolio, - 57: clearAssets, - 58: clearAssets, - 59: clearAssets, - 60: clearAssets, - 61: clearOpportunities, - 62: clearAssets, - 63: clearAssets, - 64: clearPortfolio, - 65: clearAssets, - 66: clearAssets, - 67: clearAssets, - 68: clearAssets, - 69: clearAssets, - 70: clearAssets, - 71: clearAssets, - 72: clearAssets, - 73: clearAssets, - 74: clearAssets, - 75: clearAssets, - 76: clearAssets, - 77: clearAssets, - 78: clearAssets, - 79: clearAssets, - 80: clearAssets, - 81: clearAssets, - 82: clearAssets, - 83: clearAssets, - 84: clearAssets, - 85: clearAssets, - 86: clearAssets, - 87: clearWalletConnectWalletsMetadata, - 88: clearAssets, - 89: clearAssets, - 90: clearAssets, - 91: clearAssets, - 92: clearTxHistory, - 93: clearAssets, - 94: clearAssets, - 95: clearTxHistory, - 96: clearTxHistory, - 97: clearAssets, - 98: clearAssets, - 99: clearAssets, - 100: clearAssets, - 101: clearAssets, - 102: clearAssets, - 103: clearAssets, - 104: clearTxHistory, - 105: clearPortfolio, - 106: clearOpportunities, - 107: clearAssets, - 108: clearAssets, - 109: clearAssets, - 110: clearAssets, - 111: clearAssets, - 112: clearAssets, - 113: clearAssets, - 114: clearAssets, - 115: clearAssets, - 116: clearAssets, - 117: clearAssets, - 118: clearTxHistory, - 119: clearTxHistory, - 120: clearTxHistory, - 121: clearTxHistory, - 122: clearTxHistory, - 123: clearTxHistory, - 124: clearTxHistory, - 125: clearTxHistory, - 126: clearTxHistory, - 127: clearTxHistory, - 128: clearTxHistory, - 129: clearTxHistory, - 130: clearTxHistory, - 131: clearTxHistory, -} as unknown as Omit diff --git a/src/test/mocks/store.ts b/src/test/mocks/store.ts index e804f0ac70e..7a8389ed53b 100644 --- a/src/test/mocks/store.ts +++ b/src/test/mocks/store.ts @@ -137,11 +137,19 @@ export const mockStore: ReduxState = { }, }, assets: { + _persist: { + version: 0, + rehydrated: false, + }, byId: {}, ids: [], relatedAssetIndex: {}, }, marketData: { + _persist: { + version: 0, + rehydrated: false, + }, crypto: { byId: {}, ids: [],