-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { migrate, version } from './137'; | ||
|
||
const oldVersion = 136; | ||
|
||
describe(`migration #${version}`, () => { | ||
it('updates the version metadata', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: {}, | ||
}; | ||
const newStorage = await migrate(oldStorage); | ||
expect(newStorage.meta).toStrictEqual({ version }); | ||
}); | ||
|
||
describe(`migration #${version}`, () => { | ||
it('removes the redesignedTransactionsEnabled preference if it is set to true', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
redesignedTransactionsEnabled: true, | ||
}, | ||
}, | ||
}; | ||
const expectedData = { | ||
PreferencesController: {}, | ||
}; | ||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(expectedData); | ||
}); | ||
|
||
it('removes the redesignedTransactionsEnabled preference if it is set to false', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
redesignedTransactionsEnabled: false, | ||
}, | ||
}, | ||
}; | ||
const expectedData = { | ||
PreferencesController: {}, | ||
}; | ||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(expectedData); | ||
}); | ||
|
||
it('does nothing to other PreferencesController state if there is not a redesignedTransactionsEnabled preference', async () => { | ||
const oldStorage = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
PreferencesController: { | ||
existingPreference: true, | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedData = { | ||
PreferencesController: { | ||
existingPreference: true, | ||
}, | ||
}; | ||
|
||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(expectedData); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { cloneDeep } from 'lodash'; | ||
|
||
type VersionedData = { | ||
meta: { version: number }; | ||
data: Record<string, unknown>; | ||
}; | ||
|
||
export const version = 137; | ||
|
||
/** | ||
* This migration deletes the preference `redesignedTransactionsEnabled` if the | ||
* user has existing data. | ||
* | ||
* @param originalVersionedData - Versioned MetaMask extension state, exactly | ||
* what we persist to dist. | ||
* @param originalVersionedData.meta - State metadata. | ||
* @param originalVersionedData.meta.version - The current state version. | ||
* @param originalVersionedData.data - The persisted MetaMask state, keyed by | ||
* controller. | ||
* @returns Updated versioned MetaMask extension state. | ||
*/ | ||
export async function migrate( | ||
originalVersionedData: VersionedData, | ||
): Promise<VersionedData> { | ||
const versionedData = cloneDeep(originalVersionedData); | ||
versionedData.meta.version = version; | ||
transformState(versionedData.data); | ||
return versionedData; | ||
} | ||
|
||
function transformState(state: Record<string, unknown>): void { | ||
const preferencesControllerState = state?.PreferencesController as | ||
| Record<string, unknown> | ||
| undefined; | ||
|
||
const preferences = preferencesControllerState?.preferences as | ||
| Record<string, unknown> | ||
| undefined; | ||
|
||
if (preferences && preferences.redesignedTransactionsEnabled) { | ||
// Existing MetaMask users will have the option off by default | ||
delete preferences.redesignedTransactionsEnabled; | ||
} | ||
} |