mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
import { cloneDeep } from 'lodash';
|
|
import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets';
|
|
|
|
const version = 66;
|
|
|
|
/**
|
|
* Changes the useLedgerLive boolean property to the ledgerTransportType enum
|
|
*/
|
|
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 defaultTransportType = window.navigator.hid
|
|
? LedgerTransportTypes.webhid
|
|
: LedgerTransportTypes.u2f;
|
|
const useLedgerLive = Boolean(state.PreferencesController?.useLedgerLive);
|
|
const newState = {
|
|
...state,
|
|
PreferencesController: {
|
|
...state?.PreferencesController,
|
|
ledgerTransportType: useLedgerLive
|
|
? LedgerTransportTypes.live
|
|
: defaultTransportType,
|
|
},
|
|
};
|
|
delete newState.PreferencesController.useLedgerLive;
|
|
return newState;
|
|
}
|