-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix: change default tx deadline to 10m (#7451) * fix: change deadline to 10m * test: add unit tests * fix: improve unit tests Co-authored-by: eddie <66155195+just-toby@users.noreply.github.com>
- Loading branch information
1 parent
b29968d
commit 3f510aa
Showing
6 changed files
with
121 additions
and
6 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,85 @@ | ||
import { createMigrate } from 'redux-persist' | ||
import { RouterPreference } from 'state/routing/types' | ||
import { SlippageTolerance } from 'state/user/types' | ||
|
||
import { migration1, PersistAppStateV1 } from './1' | ||
|
||
const previousState: PersistAppStateV1 = { | ||
user: { | ||
userLocale: null, | ||
userRouterPreference: RouterPreference.API, | ||
userHideClosedPositions: false, | ||
userSlippageTolerance: SlippageTolerance.Auto, | ||
userSlippageToleranceHasBeenMigratedToAuto: true, | ||
userDeadline: 1800, | ||
tokens: {}, | ||
pairs: {}, | ||
timestamp: Date.now(), | ||
hideBaseWalletBanner: false, | ||
}, | ||
_persist: { | ||
version: 0, | ||
rehydrated: true, | ||
}, | ||
} | ||
|
||
describe('migration to v1', () => { | ||
it('should migrate the default deadline', async () => { | ||
const migrator = createMigrate( | ||
{ | ||
1: migration1, | ||
}, | ||
{ debug: false } | ||
) | ||
const result: any = await migrator(previousState, 1) | ||
expect(result?.user?.userDeadline).toEqual(600) | ||
expect(result?._persist.version).toEqual(1) | ||
|
||
expect(result?.user?.userLocale).toEqual(null) | ||
expect(result?.user?.userRouterPreference).toEqual(RouterPreference.API) | ||
expect(result?.user?.userHideClosedPositions).toEqual(false) | ||
expect(result?.user?.userSlippageTolerance).toEqual(SlippageTolerance.Auto) | ||
expect(result?.user?.userSlippageToleranceHasBeenMigratedToAuto).toEqual(true) | ||
expect(result?.user?.tokens).toEqual({}) | ||
expect(result?.user?.pairs).toEqual({}) | ||
expect(result?.user?.timestamp).toEqual(previousState.user?.timestamp) | ||
expect(result?.user?.hideBaseWalletBanner).toEqual(false) | ||
}) | ||
|
||
it('should not migrate a non-default value', async () => { | ||
const migrator = createMigrate( | ||
{ | ||
1: migration1, | ||
}, | ||
{ debug: false } | ||
) | ||
const result: any = await migrator( | ||
{ | ||
...previousState, | ||
user: { | ||
...previousState.user, | ||
userDeadline: 300, | ||
}, | ||
} as PersistAppStateV1, | ||
1 | ||
) | ||
expect(result?.user?.userDeadline).toEqual(300) | ||
}) | ||
|
||
it('should not migrate if user state is not set', async () => { | ||
const migrator = createMigrate( | ||
{ | ||
1: migration1, | ||
}, | ||
{ debug: false } | ||
) | ||
const result: any = await migrator( | ||
{ | ||
...previousState, | ||
user: undefined, | ||
} as PersistAppStateV1, | ||
1 | ||
) | ||
expect(result?.user?.userDeadline).toBeUndefined() | ||
}) | ||
}) |
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 { DEFAULT_DEADLINE_FROM_NOW } from 'constants/misc' | ||
import { PersistState } from 'redux-persist' | ||
import { UserState } from 'state/user/reducer' | ||
|
||
export type PersistAppStateV1 = { | ||
_persist: PersistState | ||
} & { user?: UserState } | ||
|
||
/** | ||
* Migration to change the default user deadline from 30 minutes to 10 minutes. | ||
* We only migrate if the saved deadline is the old default. | ||
*/ | ||
export const migration1 = (state: PersistAppStateV1 | undefined) => { | ||
if (state?.user && state.user?.userDeadline === 1800) { | ||
return { | ||
...state, | ||
user: { | ||
...state.user, | ||
userDeadline: DEFAULT_DEADLINE_FROM_NOW, | ||
}, | ||
_persist: { | ||
...state._persist, | ||
version: 1, | ||
}, | ||
} | ||
} | ||
return state | ||
} |
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