mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
62 lines
1.4 KiB
JavaScript
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;
|
||
|
}
|