Skip to content

Commit

Permalink
fix: update migration (#2004) (#2005)
Browse files Browse the repository at this point in the history
* update migration

* lint error

Co-authored-by: troyb.eth <me@troyb.xyz>
  • Loading branch information
platschi and Tburm authored Feb 10, 2023
1 parent b54a691 commit 83dad14
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion sections/futures/MarketDetails/useGetMarketData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions state/app/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,7 +19,7 @@ const initialState: AppState = {

const appSlice = createSlice({
name: 'app',
initialState,
initialState: APP_INITIAL_STATE,
reducers: {
setOpenModal: (state, action: PayloadAction<ModalType>) => {
state.openModal = action.payload;
Expand Down
4 changes: 2 additions & 2 deletions state/balances/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export const ZERO_BALANCES = {
tokenBalances: {},
};

const initialState: BalancesState = {
export const BALANCES_INITIAL_STATE: BalancesState = {
status: FetchStatus.Idle,
error: undefined,
...ZERO_BALANCES,
};

const balancesSlice = createSlice({
name: 'balances',
initialState,
initialState: BALANCES_INITIAL_STATE,
reducers: {
clearBalances: (state) => {
state.synthBalances = [];
Expand Down
4 changes: 2 additions & 2 deletions state/earn/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions state/exchange/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -53,7 +53,7 @@ const initialState: ExchangeState = {

const exchangeSlice = createSlice({
name: 'exchange',
initialState,
initialState: EXCHANGES_INITIAL_STATE,
reducers: {
setQuoteAmount: (state, action) => {
state.ratio = undefined;
Expand Down
4 changes: 2 additions & 2 deletions state/home/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
25 changes: 25 additions & 0 deletions state/migrations.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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;
4 changes: 2 additions & 2 deletions state/preferences/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -19,7 +19,7 @@ const initialState: PreferncesState = {

const preferencesSlice = createSlice({
name: 'preferences',
initialState,
initialState: PREFERENCES_INITIAL_STATE,
reducers: {
setTheme: (state, action: PayloadAction<ThemeName>) => {
state.currentTheme = action.payload;
Expand Down
4 changes: 2 additions & 2 deletions state/staking/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions state/stats/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatsTimeframe>) => {
state.selectedTimeframe = action.payload;
Expand Down
2 changes: 1 addition & 1 deletion state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
};
Expand Down
4 changes: 2 additions & 2 deletions state/wallet/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 83dad14

Please sign in to comment.