Skip to content

Commit 6db63fe

Browse files
committed
added migrations
1 parent f535fcd commit 6db63fe

File tree

2 files changed

+224
-0
lines changed

2 files changed

+224
-0
lines changed

app/scripts/migrations/078.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { cloneDeep } from 'lodash';
2+
3+
const version = 78;
4+
5+
/**
6+
* Remove collectiblesDropdownState and collectiblesDetectionNoticeDismissed:.
7+
*/
8+
export default {
9+
version,
10+
async migrate(originalVersionedData) {
11+
const versionedData = cloneDeep(originalVersionedData);
12+
versionedData.meta.version = version;
13+
const state = versionedData.data;
14+
const newState = transformState(state);
15+
versionedData.data = newState;
16+
return versionedData;
17+
},
18+
};
19+
20+
function transformState(state) {
21+
if (state?.metamask?.collectiblesDetectionNoticeDismissed) {
22+
delete state.metamask.collectiblesDetectionNoticeDismissed;
23+
}
24+
if (state?.metamask?.collectiblesDropdownState) {
25+
delete state.metamask.collectiblesDropdownState;
26+
}
27+
return state;
28+
}

app/scripts/migrations/078.test.js

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import migration78 from './078';
2+
3+
describe('migration #78', () => {
4+
it('should update the version metadata', async () => {
5+
const oldStorage = {
6+
meta: {
7+
version: 77,
8+
},
9+
};
10+
11+
const newStorage = await migration78.migrate(oldStorage);
12+
expect(newStorage.meta).toStrictEqual({
13+
version: 78,
14+
});
15+
});
16+
17+
it('should remove the "collectiblesDetectionNoticeDismissed" and "collectiblesDropdownState"', async () => {
18+
const oldStorage = {
19+
meta: {
20+
version: 77,
21+
},
22+
data: {
23+
metamask: {
24+
collectiblesDetectionNoticeDismissed: false,
25+
nftsDropdownState: {},
26+
},
27+
},
28+
};
29+
30+
const newStorage = await migration78.migrate(oldStorage);
31+
expect(newStorage).toStrictEqual({
32+
meta: {
33+
version: 78,
34+
},
35+
data: {
36+
metamask: {
37+
nftDetectionNoticeDismissed: false,
38+
nftsDropdownState: {},
39+
},
40+
},
41+
});
42+
});
43+
44+
it('should make no changes if "collectiblesDetectionNoticeDismissed" never existed', async () => {
45+
const oldStorage = {
46+
meta: {
47+
version: 77,
48+
},
49+
data: {
50+
metamask: {
51+
isInitialized: true,
52+
isUnlocked: true,
53+
isAccountMenuOpen: false,
54+
identities: {
55+
'0x00000': {
56+
address: '0x00000',
57+
lastSelected: 1675966229118,
58+
name: 'Account 1',
59+
},
60+
'0x00001': {
61+
address: '0x00001',
62+
name: 'Account 2',
63+
},
64+
},
65+
unapprovedTxs: {},
66+
frequentRpcList: [],
67+
addressBook: {},
68+
popupGasPollTokens: [],
69+
notificationGasPollTokens: [],
70+
fullScreenGasPollTokens: [],
71+
recoveryPhraseReminderHasBeenShown: false,
72+
recoveryPhraseReminderLastShown: 1675966206345,
73+
outdatedBrowserWarningLastShown: 1675966206345,
74+
showTestnetMessageInDropdown: true,
75+
showBetaHeader: false,
76+
trezorModel: null,
77+
qrHardware: {},
78+
},
79+
},
80+
};
81+
82+
const newStorage = await migration78.migrate(oldStorage);
83+
expect(newStorage).toStrictEqual({
84+
meta: {
85+
version: 78,
86+
},
87+
data: {
88+
metamask: {
89+
isInitialized: true,
90+
isUnlocked: true,
91+
isAccountMenuOpen: false,
92+
identities: {
93+
'0x00000': {
94+
address: '0x00000',
95+
lastSelected: 1675966229118,
96+
name: 'Account 1',
97+
},
98+
'0x00001': {
99+
address: '0x00001',
100+
name: 'Account 2',
101+
},
102+
},
103+
unapprovedTxs: {},
104+
frequentRpcList: [],
105+
addressBook: {},
106+
popupGasPollTokens: [],
107+
notificationGasPollTokens: [],
108+
fullScreenGasPollTokens: [],
109+
recoveryPhraseReminderHasBeenShown: false,
110+
recoveryPhraseReminderLastShown: 1675966206345,
111+
outdatedBrowserWarningLastShown: 1675966206345,
112+
showTestnetMessageInDropdown: true,
113+
showBetaHeader: false,
114+
trezorModel: null,
115+
qrHardware: {},
116+
},
117+
},
118+
});
119+
});
120+
it('should make no changes if "collectiblesDropdownState" never existed', async () => {
121+
const oldStorage = {
122+
meta: {
123+
version: 77,
124+
},
125+
data: {
126+
metamask: {
127+
isInitialized: true,
128+
isUnlocked: true,
129+
isAccountMenuOpen: false,
130+
identities: {
131+
'0x00000': {
132+
address: '0x00000',
133+
lastSelected: 1675966229118,
134+
name: 'Account 1',
135+
},
136+
'0x00001': {
137+
address: '0x00001',
138+
name: 'Account 2',
139+
},
140+
},
141+
unapprovedTxs: {},
142+
frequentRpcList: [],
143+
addressBook: {},
144+
popupGasPollTokens: [],
145+
notificationGasPollTokens: [],
146+
fullScreenGasPollTokens: [],
147+
recoveryPhraseReminderHasBeenShown: false,
148+
recoveryPhraseReminderLastShown: 1675966206345,
149+
outdatedBrowserWarningLastShown: 1675966206345,
150+
showTestnetMessageInDropdown: true,
151+
showBetaHeader: false,
152+
trezorModel: null,
153+
qrHardware: {},
154+
},
155+
},
156+
};
157+
158+
const newStorage = await migration78.migrate(oldStorage);
159+
expect(newStorage).toStrictEqual({
160+
meta: {
161+
version: 78,
162+
},
163+
data: {
164+
metamask: {
165+
isInitialized: true,
166+
isUnlocked: true,
167+
isAccountMenuOpen: false,
168+
identities: {
169+
'0x00000': {
170+
address: '0x00000',
171+
lastSelected: 1675966229118,
172+
name: 'Account 1',
173+
},
174+
'0x00001': {
175+
address: '0x00001',
176+
name: 'Account 2',
177+
},
178+
},
179+
unapprovedTxs: {},
180+
frequentRpcList: [],
181+
addressBook: {},
182+
popupGasPollTokens: [],
183+
notificationGasPollTokens: [],
184+
fullScreenGasPollTokens: [],
185+
recoveryPhraseReminderHasBeenShown: false,
186+
recoveryPhraseReminderLastShown: 1675966206345,
187+
outdatedBrowserWarningLastShown: 1675966206345,
188+
showTestnetMessageInDropdown: true,
189+
showBetaHeader: false,
190+
trezorModel: null,
191+
qrHardware: {},
192+
},
193+
},
194+
});
195+
});
196+
});

0 commit comments

Comments
 (0)