mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
|
import { cloneDeep } from 'lodash';
|
||
|
import { LEDGER_TRANSPORT_TYPES } 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
|
||
|
? LEDGER_TRANSPORT_TYPES.WEBHID
|
||
|
: LEDGER_TRANSPORT_TYPES.U2F;
|
||
|
const useLedgerLive = Boolean(state.PreferencesController?.useLedgerLive);
|
||
|
const newState = {
|
||
|
...state,
|
||
|
PreferencesController: {
|
||
|
...state?.PreferencesController,
|
||
|
ledgerTransportType: useLedgerLive
|
||
|
? LEDGER_TRANSPORT_TYPES.LIVE
|
||
|
: defaultTransportType,
|
||
|
},
|
||
|
};
|
||
|
delete newState.PreferencesController.useLedgerLive;
|
||
|
return newState;
|
||
|
}
|