diff --git a/sections/futures/MarketDetails/useGetMarketData.ts b/sections/futures/MarketDetails/useGetMarketData.ts index 3b40eb2b58..b7ab413878 100644 --- a/sections/futures/MarketDetails/useGetMarketData.ts +++ b/sections/futures/MarketDetails/useGetMarketData.ts @@ -16,7 +16,7 @@ import { import { useAppSelector } from 'state/hooks'; import { selectPreviousDayPrices } from 'state/prices/selectors'; import { isFiatCurrency } from 'utils/currencies'; -import { formatCurrency, formatDollars, formatPercent, zeroBN } from 'utils/formatters/number'; +import { formatDollars, formatPercent, zeroBN } from 'utils/formatters/number'; import { isDecimalFour } from 'utils/futures'; import { MarketDataKey } from './utils'; diff --git a/state/app/reducer.ts b/state/app/reducer.ts index ff04cdfa84..f863a0895e 100644 --- a/state/app/reducer.ts +++ b/state/app/reducer.ts @@ -6,7 +6,7 @@ import { isUserDeniedError } from 'utils/formatters/error'; import { AppState, GasPrice, ModalType, Transaction } from './types'; -const initialState: AppState = { +export const APP_INITIAL_STATE: AppState = { openModal: null, gasPrice: { baseFeePerGas: '0', // Note that this is used for estimating price and should not be included in the transaction @@ -19,7 +19,7 @@ const initialState: AppState = { const appSlice = createSlice({ name: 'app', - initialState, + initialState: APP_INITIAL_STATE, reducers: { setOpenModal: (state, action: PayloadAction) => { state.openModal = action.payload; diff --git a/state/balances/reducer.ts b/state/balances/reducer.ts index 07c2eb516f..c01d15c5ba 100644 --- a/state/balances/reducer.ts +++ b/state/balances/reducer.ts @@ -13,7 +13,7 @@ export const ZERO_BALANCES = { tokenBalances: {}, }; -const initialState: BalancesState = { +export const BALANCES_INITIAL_STATE: BalancesState = { status: FetchStatus.Idle, error: undefined, ...ZERO_BALANCES, @@ -21,7 +21,7 @@ const initialState: BalancesState = { const balancesSlice = createSlice({ name: 'balances', - initialState, + initialState: BALANCES_INITIAL_STATE, reducers: { clearBalances: (state) => { state.synthBalances = []; diff --git a/state/earn/reducer.ts b/state/earn/reducer.ts index bea887ee45..9e3062de1d 100644 --- a/state/earn/reducer.ts +++ b/state/earn/reducer.ts @@ -5,7 +5,7 @@ import { FetchStatus } from 'state/types'; import { fetchEarnTokenPrices, stakeTokens, unstakeTokens } from './actions'; import { EarnState } from './types'; -const initialState: EarnState = { +export const EARN_INITIAL_STATE: EarnState = { balance: '0', earnedRewards: '0', rewardRate: '0', @@ -25,7 +25,7 @@ const initialState: EarnState = { const earnSlice = createSlice({ name: 'earn', - initialState, + initialState: EARN_INITIAL_STATE, reducers: { setEarnDetails: (state, action) => { state.balance = action.payload.balance; diff --git a/state/exchange/reducer.ts b/state/exchange/reducer.ts index dc2a38b4af..1b9ad96065 100644 --- a/state/exchange/reducer.ts +++ b/state/exchange/reducer.ts @@ -18,7 +18,7 @@ import { } from './actions'; import { ExchangeState } from './types'; -const initialState: ExchangeState = { +export const EXCHANGES_INITIAL_STATE: ExchangeState = { baseCurrencyKey: undefined, quoteCurrencyKey: 'sUSD', txProvider: undefined, @@ -53,7 +53,7 @@ const initialState: ExchangeState = { const exchangeSlice = createSlice({ name: 'exchange', - initialState, + initialState: EXCHANGES_INITIAL_STATE, reducers: { setQuoteAmount: (state, action) => { state.ratio = undefined; diff --git a/state/home/reducer.ts b/state/home/reducer.ts index 4d6e0b3956..9ac015b151 100644 --- a/state/home/reducer.ts +++ b/state/home/reducer.ts @@ -10,14 +10,14 @@ type HomeState = { marketsQueryStatus: FetchStatus; }; -const initialState: HomeState = { +export const HOME_INITIAL_STATE: HomeState = { optimismMarkets: [], marketsQueryStatus: FetchStatus.Idle, }; export const homeSlice = createSlice({ name: 'home', - initialState, + initialState: HOME_INITIAL_STATE, reducers: {}, extraReducers: (builder) => { builder.addCase(fetchOptimismMarkets.pending, (state) => { diff --git a/state/migrations.ts b/state/migrations.ts index 24c0834318..4cb2ff4bea 100644 --- a/state/migrations.ts +++ b/state/migrations.ts @@ -1,5 +1,14 @@ +import { APP_INITIAL_STATE } from './app/reducer'; +import { BALANCES_INITIAL_STATE } from './balances/reducer'; +import { EARN_INITIAL_STATE } from './earn/reducer'; +import { EXCHANGES_INITIAL_STATE } from './exchange/reducer'; import { FUTURES_INITIAL_STATE } from './futures/reducer'; +import { HOME_INITIAL_STATE } from './home/reducer'; +import { PREFERENCES_INITIAL_STATE } from './preferences/reducer'; import { PRICES_INITIAL_STATE } from './prices/reducer'; +import { STAKING_INITIAL_STATE } from './staking/reducer'; +import { STATS_INITIAL_STATE } from './stats/reducer'; +import { WALLET_INITIAL_STATE } from './wallet/reducer'; export const migrations = { 4: (state: any) => { @@ -21,6 +30,22 @@ export const migrations = { prices: PRICES_INITIAL_STATE, }; }, + 7: (state: any) => { + return { + ...state, + app: APP_INITIAL_STATE, + balances: BALANCES_INITIAL_STATE, + earn: EARN_INITIAL_STATE, + exchanges: EXCHANGES_INITIAL_STATE, + futures: FUTURES_INITIAL_STATE, + home: HOME_INITIAL_STATE, + preferences: PREFERENCES_INITIAL_STATE, + prices: PRICES_INITIAL_STATE, + staking: STAKING_INITIAL_STATE, + stats: STATS_INITIAL_STATE, + wallet: WALLET_INITIAL_STATE, + }; + }, }; export default migrations; diff --git a/state/preferences/reducer.ts b/state/preferences/reducer.ts index 708208ad20..c0f73985bd 100644 --- a/state/preferences/reducer.ts +++ b/state/preferences/reducer.ts @@ -6,7 +6,7 @@ import { Language } from 'translations/constants'; import { PreferncesState } from './types'; -const initialState: PreferncesState = { +export const PREFERENCES_INITIAL_STATE: PreferncesState = { currentTheme: 'dark', language: DEFAULT_LANGUAGE, currency: { @@ -19,7 +19,7 @@ const initialState: PreferncesState = { const preferencesSlice = createSlice({ name: 'preferences', - initialState, + initialState: PREFERENCES_INITIAL_STATE, reducers: { setTheme: (state, action: PayloadAction) => { state.currentTheme = action.payload; diff --git a/state/staking/reducer.ts b/state/staking/reducer.ts index 5073f3e155..7f101d1642 100644 --- a/state/staking/reducer.ts +++ b/state/staking/reducer.ts @@ -16,7 +16,7 @@ import { } from './actions'; import { StakingState } from './types'; -const initialState: StakingState = { +export const STAKING_INITIAL_STATE: StakingState = { kwentaBalance: '0', escrowedKwentaBalance: '0', vKwentaBalance: '0', @@ -45,7 +45,7 @@ const initialState: StakingState = { const stakingSlice = createSlice({ name: 'staking', - initialState, + initialState: STAKING_INITIAL_STATE, reducers: { setStakeStatus: (state, action) => { state.stakeStatus = action.payload; diff --git a/state/stats/reducer.ts b/state/stats/reducer.ts index 5b2eba8320..13c1db381f 100644 --- a/state/stats/reducer.ts +++ b/state/stats/reducer.ts @@ -4,13 +4,13 @@ import { StatsTimeframe } from 'hooks/useStatsData'; import { StatsState } from './types'; -const initialState: StatsState = { +export const STATS_INITIAL_STATE: StatsState = { selectedTimeframe: '1M', }; const statsSlice = createSlice({ name: 'stats', - initialState, + initialState: STATS_INITIAL_STATE, reducers: { setSelectedTimeframe: (state, action: PayloadAction) => { state.selectedTimeframe = action.payload; diff --git a/state/store.ts b/state/store.ts index b85d7eb3cf..fdaa26f60b 100644 --- a/state/store.ts +++ b/state/store.ts @@ -34,7 +34,7 @@ const LOG_REDUX = process.env.NODE_ENV !== 'production'; const persistConfig = { key: 'root1', storage, - version: 6, + version: 7, blacklist: ['app', 'wallet'], migrate: createMigrate(migrations, { debug: true }), }; diff --git a/state/wallet/reducer.ts b/state/wallet/reducer.ts index af0c16c386..7c07d3b36e 100644 --- a/state/wallet/reducer.ts +++ b/state/wallet/reducer.ts @@ -3,14 +3,14 @@ import { createSlice } from '@reduxjs/toolkit'; import { resetNetwork } from './actions'; import { WalletState } from './types'; -const initialState: WalletState = { +export const WALLET_INITIAL_STATE: WalletState = { walletAddress: undefined, networkId: undefined, }; const walletSlice = createSlice({ name: 'wallet', - initialState, + initialState: WALLET_INITIAL_STATE, reducers: { setWalletAddress: (state, action) => { state.walletAddress = action.payload;