1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/app/scripts/migrations/068.js
Alex Donesky 81ea24f08a
Feat/collectibles display (#12873)
* Wiring up Collectibles lists/items

* wip

* more wip

* more more wip

* yet more wip

* wippp

* more wipppp

* closer

* wroking

* more wip

* cleanup

* cleanup

* add-collectible form validation

* update default ipfs-gateway

* update refresh button

* fix proptypes issue + add more padding to asset background

* css tweaking

* more cleanup

* more cleanup

* more cleanup

* add migration

* address feedback

* fix migration + cleanup

* bumping controllers version + adapting new collectiblesController shape

* fix yarn dedupe
2021-12-01 10:10:17 -06:00

62 lines
1.4 KiB
JavaScript

import { cloneDeep } from 'lodash';
import { IPFS_DEFAULT_GATEWAY_URL } from '../../../shared/constants/network';
const version = 68;
function addUrlProtocolPrefix(urlString) {
if (!urlString.match(/(^http:\/\/)|(^https:\/\/)/u)) {
return `https://${urlString}`;
}
return urlString;
}
export default {
version,
async migrate(originalVersionedData) {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
const state = versionedData.data;
const newState = transformState(state);
versionedData.data = newState;
return versionedData;
},
};
function transformState(state) {
const PreferencesController = state?.PreferencesController || {};
const preferences = PreferencesController.preferences || {};
const oldIpfsGateWay = preferences.ipfsGateway;
let newState;
if (oldIpfsGateWay && oldIpfsGateWay !== 'dweb.link') {
const newIpfsGateway = new URL(
addUrlProtocolPrefix(oldIpfsGateWay),
).toString();
newState = {
...state,
PreferencesController: {
...PreferencesController,
preferences: {
...preferences,
ipfsGateway: newIpfsGateway,
},
},
};
} else {
newState = {
...state,
PreferencesController: {
...PreferencesController,
preferences: {
...preferences,
ipfsGateway: IPFS_DEFAULT_GATEWAY_URL,
},
},
};
}
return newState;
}