2021-03-29 23:05:36 +02:00
|
|
|
import { cloneDeep } from 'lodash';
|
|
|
|
|
|
|
|
const version = 56;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove tokens that don't have an address due to
|
|
|
|
* lack of previous addToken validation. Also removes
|
|
|
|
* an unwanted, undefined image property
|
|
|
|
*/
|
|
|
|
export default {
|
|
|
|
version,
|
|
|
|
async migrate(originalVersionedData) {
|
|
|
|
const versionedData = cloneDeep(originalVersionedData);
|
|
|
|
versionedData.meta.version = version;
|
|
|
|
|
|
|
|
const { PreferencesController } = versionedData.data;
|
|
|
|
|
2021-08-18 04:18:53 +02:00
|
|
|
if (Array.isArray(PreferencesController?.tokens)) {
|
2021-03-29 23:05:36 +02:00
|
|
|
PreferencesController.tokens = PreferencesController.tokens.filter(
|
|
|
|
({ address }) => address,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2021-08-18 04:18:53 +02:00
|
|
|
PreferencesController?.accountTokens &&
|
2021-03-29 23:05:36 +02:00
|
|
|
typeof PreferencesController.accountTokens === 'object'
|
|
|
|
) {
|
|
|
|
Object.keys(PreferencesController.accountTokens).forEach((account) => {
|
|
|
|
const chains = Object.keys(
|
|
|
|
PreferencesController.accountTokens[account],
|
|
|
|
);
|
|
|
|
chains.forEach((chain) => {
|
2022-07-31 20:26:40 +02:00
|
|
|
PreferencesController.accountTokens[account][chain] =
|
|
|
|
PreferencesController.accountTokens[account][chain].filter(
|
|
|
|
({ address }) => address,
|
|
|
|
);
|
2021-03-29 23:05:36 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2021-08-18 04:18:53 +02:00
|
|
|
PreferencesController?.assetImages &&
|
2021-03-29 23:05:36 +02:00
|
|
|
'undefined' in PreferencesController.assetImages
|
|
|
|
) {
|
|
|
|
delete PreferencesController.assetImages.undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return versionedData;
|
|
|
|
},
|
|
|
|
};
|