-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(polymarket): add dismissable reducer and fix ticker (#1128)
Co-authored-by: Bill He <[email protected]>
- Loading branch information
Showing
11 changed files
with
121 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { PayloadAction } from '@reduxjs/toolkit'; | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export interface DismissableState { | ||
hasSeenPredictionMarketIntroDialog: boolean; | ||
} | ||
|
||
const initialState: DismissableState = { | ||
hasSeenPredictionMarketIntroDialog: false, | ||
}; | ||
|
||
export const dismissableSlice = createSlice({ | ||
name: 'Dismissable', | ||
initialState, | ||
reducers: { | ||
setHasSeenPredictionMarketIntroDialog: (state, action: PayloadAction<boolean>) => { | ||
state.hasSeenPredictionMarketIntroDialog = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setHasSeenPredictionMarketIntroDialog } = dismissableSlice.actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { type RootState } from './_store'; | ||
|
||
export const getHasSeenPredictionMarketIntroDialog = (state: RootState) => | ||
state.dismissable.hasSeenPredictionMarketIntroDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { PersistedState } from 'redux-persist'; | ||
|
||
import { DismissableState } from '../dismissable'; | ||
import { parseStorageItem } from './utils'; | ||
|
||
export type V2State = PersistedState & { dismissable: DismissableState }; | ||
/** | ||
* Third migration, moving over the hasSeenPredictionMarketsIntro localStorage item | ||
* | ||
*/ | ||
export function migration2(state: PersistedState | undefined): V2State { | ||
if (!state) { | ||
throw new Error('state must be defined'); | ||
} | ||
|
||
const hasSeenPredictionMarketsIntro = parseStorageItem<boolean>( | ||
localStorage.getItem('dydx.HasSeenPredictionMarketsIntro') | ||
); | ||
|
||
localStorage.removeItem('dydx.HasSeenPredictionMarketsIntro'); | ||
|
||
return { | ||
...state, | ||
dismissable: { | ||
hasSeenPredictionMarketIntroDialog: hasSeenPredictionMarketsIntro ?? false, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { afterEach, describe, expect, it } from 'vitest'; | ||
|
||
import { V1State } from '../1'; | ||
import { migration2 } from '../2'; | ||
|
||
const V1_STATE: V1State = { | ||
_persist: { version: 1, rehydrated: true }, | ||
wallet: { | ||
sourceAccount: { | ||
address: undefined, | ||
chain: undefined, | ||
encryptedSignature: undefined, | ||
walletInfo: undefined, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('migration2', () => { | ||
afterEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
it('should add hasSeenPredictionMarketIntroDialog property set to false', () => { | ||
const result = migration2(V1_STATE); | ||
expect(result.dismissable.hasSeenPredictionMarketIntroDialog).toBe(false); | ||
}); | ||
|
||
it('should overwrite hasSeenPredictionMarketIntroDialog if it already exists', () => { | ||
const result = migration2(V1_STATE); | ||
expect(result.dismissable.hasSeenPredictionMarketIntroDialog).toBe(false); | ||
}); | ||
|
||
it('should copy localStorage values to dismissable object', () => { | ||
localStorage.setItem('dydx.HasSeenPredictionMarketsIntro', 'true'); | ||
|
||
const result = migration2(V1_STATE); | ||
|
||
expect(result.dismissable.hasSeenPredictionMarketIntroDialog).toBe(true); | ||
// Check if localStorage items were removed | ||
expect(localStorage.getItem('dydx.HasSeenPredictionMarketsIntro')).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters