Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change default tx deadline to 10m (#7451) [hotfix for prod] #7468

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/constants/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'

// TODO(WEB-1984): Convert the deadline to minutes and remove unecessary conversions from
// seconds to minutes in the codebase.
// 30 minutes, denominated in seconds
export const DEFAULT_DEADLINE_FROM_NOW = 60 * 30
// 10 minutes, denominated in seconds
export const DEFAULT_DEADLINE_FROM_NOW = 60 * 10
export const L2_DEADLINE_FROM_NOW = 60 * 5

// transaction popup dismisal amounts
Expand Down
2 changes: 1 addition & 1 deletion src/state/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const defaultState = {
user: {},
_persist: {
rehydrated: true,
version: 0,
version: 1,
},
application: {
chainId: null,
Expand Down
6 changes: 4 additions & 2 deletions src/state/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import { createMigrate, MigrationManifest, PersistedState, PersistMigrate } from
import { MigrationConfig } from 'redux-persist/es/createMigrate'

import { migration0 } from './migrations/0'
import { migration1 } from './migrations/1'
import { legacyLocalStorageMigration } from './migrations/legacy'

/**
* These run once per state re-hydration when a version mismatch is detected.
* Keep them as lightweight as possible.
*
* Migration functions should not assume that any value exists in localStorage previously,
* because a user may be visiting the site for the first time or have cleared their localStorage.
* Migration functions should not assume that any value exists in the persisted data previously,
* because a user may be visiting the site for the first time or have cleared their data.
*/

// The target version number is the key
export const migrations: MigrationManifest = {
0: migration0,
1: migration1,
}

// We use a custom migration function for the initial state, because redux-persist
Expand Down
85 changes: 85 additions & 0 deletions src/state/migrations/1.test.ts
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()
})
})
28 changes: 28 additions & 0 deletions src/state/migrations/1.ts
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
}
2 changes: 1 addition & 1 deletion src/state/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type AppState = ReturnType<typeof appReducer>

const persistConfig: PersistConfig<AppState> = {
key: 'interface',
version: 0, // see migrations.ts for more details about this version
version: 1, // see migrations.ts for more details about this version
storage: localForage.createInstance({
name: 'redux',
}),
Expand Down
Loading