From a19a5d60d3412e0926a6ea9ee64e559ada1d35f9 Mon Sep 17 00:00:00 2001 From: ryanml Date: Fri, 20 Jan 2023 08:14:40 -0700 Subject: [PATCH] Convert shared/constants/hardware-wallets.js -> Typescript (#17310) --- .storybook/test-data.js | 12 +-- app/scripts/controllers/preferences.js | 6 +- app/scripts/lib/seed-phrase-verifier.js | 4 +- app/scripts/lib/seed-phrase-verifier.test.js | 4 +- app/scripts/metamask-controller.js | 74 +++++++++--------- app/scripts/metamask-controller.test.js | 36 +++++---- app/scripts/migrations/066.js | 8 +- app/scripts/migrations/066.test.js | 12 +-- shared/constants/hardware-wallets.js | 74 ------------------ shared/constants/hardware-wallets.ts | 71 +++++++++++++++++ shared/constants/keyrings.js | 7 -- test/jest/mock-store.js | 11 ++- .../app/account-menu/account-menu.test.js | 6 +- .../app/account-menu/keyring-label.js | 24 +++--- .../unconnected-account-alert.test.js | 4 +- .../ledger-instruction-field.js | 49 ++++++------ .../app/menu-bar/account-options-menu.js | 4 +- ui/components/app/menu-bar/menu-bar.test.js | 4 +- .../wallet-overview/token-overview.test.js | 6 +- ui/ducks/app/app.js | 8 +- ui/ducks/app/app.test.js | 4 +- ui/ducks/metamask/metamask.js | 6 +- ui/ducks/send/send.test.js | 4 +- .../connect-hardware/account-list.js | 8 +- .../create-account/connect-hardware/index.js | 12 +-- .../connect-hardware/select-hardware.js | 78 +++++++++++-------- .../select-hardware.stories.js | 6 +- ui/pages/mobile-sync/mobile-sync.component.js | 4 +- ui/pages/send/send.test.js | 4 +- .../advanced-tab/advanced-tab.component.js | 16 ++-- ui/selectors/selectors.js | 32 ++++---- ui/selectors/selectors.test.js | 20 ++--- ui/store/actions.js | 16 ++-- ui/store/actions.test.js | 19 +++-- 34 files changed, 339 insertions(+), 314 deletions(-) delete mode 100644 shared/constants/hardware-wallets.js create mode 100644 shared/constants/hardware-wallets.ts delete mode 100644 shared/constants/keyrings.js diff --git a/.storybook/test-data.js b/.storybook/test-data.js index aa30f26dd..43fe494da 100644 --- a/.storybook/test-data.js +++ b/.storybook/test-data.js @@ -1,5 +1,5 @@ import { draftTransactionInitialState } from '../ui/ducks/send'; -import { KEYRING_TYPES } from '../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../shared/constants/hardware-wallets'; const state = { invalidCustomNetwork: { @@ -1163,14 +1163,14 @@ const state = { unapprovedTypedMessages: {}, unapprovedTypedMessagesCount: 0, keyringTypes: [ - KEYRING_TYPES.IMPORTED, - KEYRING_TYPES.HD_KEY_TREE, - KEYRING_TYPES.TREZOR, - KEYRING_TYPES.LEDGER, + HardwareKeyringTypes.imported, + HardwareKeyringTypes.hdKeyTree, + HardwareKeyringTypes.trezor, + HardwareKeyringTypes.ledger, ], keyrings: [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: [ '0x64a845a5b02460acf8a3d84503b0d68d028b4bb4', '0xb19ac54efa18cc3a14a5b821bfec73d284bf0c5e', diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index cc2b79e41..99f891d84 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -3,7 +3,7 @@ import { normalize as normalizeAddress } from 'eth-sig-util'; import { ethers } from 'ethers'; import { IPFS_DEFAULT_GATEWAY_URL } from '../../../shared/constants/network'; import { isPrefixedFormattedHexString } from '../../../shared/modules/network.utils'; -import { LEDGER_TRANSPORT_TYPES } from '../../../shared/constants/hardware-wallets'; +import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets'; import { THEME_TYPE } from '../../../ui/pages/settings/settings-tab/settings-tab.constant'; import { NETWORK_EVENTS } from './network'; @@ -64,8 +64,8 @@ export default class PreferencesController { ipfsGateway: IPFS_DEFAULT_GATEWAY_URL, infuraBlocked: null, ledgerTransportType: window.navigator.hid - ? LEDGER_TRANSPORT_TYPES.WEBHID - : LEDGER_TRANSPORT_TYPES.U2F, + ? LedgerTransportTypes.webhid + : LedgerTransportTypes.u2f, improvedTokenAllowanceEnabled: false, transactionSecurityCheckEnabled: false, theme: THEME_TYPE.OS, diff --git a/app/scripts/lib/seed-phrase-verifier.js b/app/scripts/lib/seed-phrase-verifier.js index 58d4acdf9..f273084ef 100644 --- a/app/scripts/lib/seed-phrase-verifier.js +++ b/app/scripts/lib/seed-phrase-verifier.js @@ -1,7 +1,7 @@ import KeyringController from 'eth-keyring-controller'; import log from 'loglevel'; -import { KEYRING_TYPES } from '../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; const seedPhraseVerifier = { /** @@ -23,7 +23,7 @@ const seedPhraseVerifier = { const keyringController = new KeyringController({}); const Keyring = keyringController.getKeyringClassForType( - KEYRING_TYPES.HD_KEY_TREE, + HardwareKeyringTypes.hdKeyTree, ); const opts = { mnemonic: seedPhrase, diff --git a/app/scripts/lib/seed-phrase-verifier.test.js b/app/scripts/lib/seed-phrase-verifier.test.js index aaa161d80..02ad1c9cc 100644 --- a/app/scripts/lib/seed-phrase-verifier.test.js +++ b/app/scripts/lib/seed-phrase-verifier.test.js @@ -6,13 +6,13 @@ import { cloneDeep } from 'lodash'; import KeyringController from 'eth-keyring-controller'; import firstTimeState from '../first-time-state'; import mockEncryptor from '../../../test/lib/mock-encryptor'; -import { KEYRING_TYPES } from '../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; import seedPhraseVerifier from './seed-phrase-verifier'; describe('SeedPhraseVerifier', () => { describe('verifyAccounts', () => { const password = 'passw0rd1'; - const hdKeyTree = KEYRING_TYPES.HD_KEY_TREE; + const { hdKeyTree } = HardwareKeyringTypes; let keyringController; let primaryKeyring; diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 3021127a6..8c20da34e 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -69,9 +69,11 @@ import { GAS_DEV_API_BASE_URL, SWAPS_CLIENT_ID, } from '../../shared/constants/swaps'; -import { KEYRING_TYPES } from '../../shared/constants/keyrings'; import { CHAIN_IDS } from '../../shared/constants/network'; -import { DEVICE_NAMES } from '../../shared/constants/hardware-wallets'; +import { + HardwareDeviceNames, + HardwareKeyringTypes, +} from '../../shared/constants/hardware-wallets'; import { CaveatTypes, RestrictedMethods, @@ -2272,7 +2274,7 @@ export default class MetamaskController extends EventEmitter { ); const [primaryKeyring] = keyringController.getKeyringsByType( - KEYRING_TYPES.HD_KEY_TREE, + HardwareKeyringTypes.hdKeyTree, ); if (!primaryKeyring) { throw new Error('MetamaskController - No HD Key Tree found'); @@ -2399,10 +2401,10 @@ export default class MetamaskController extends EventEmitter { // Accounts const [hdKeyring] = this.keyringController.getKeyringsByType( - KEYRING_TYPES.HD_KEY_TREE, + HardwareKeyringTypes.hdKeyTree, ); const simpleKeyPairKeyrings = this.keyringController.getKeyringsByType( - KEYRING_TYPES.IMPORTED, + HardwareKeyringTypes.hdKeyTree, ); const hdAccounts = await hdKeyring.getAccounts(); const simpleKeyPairKeyringAccounts = await Promise.all( @@ -2563,7 +2565,7 @@ export default class MetamaskController extends EventEmitter { */ getPrimaryKeyringMnemonic() { const [keyring] = this.keyringController.getKeyringsByType( - KEYRING_TYPES.HD_KEY_TREE, + HardwareKeyringTypes.hdKeyTree, ); if (!keyring.mnemonic) { throw new Error('Primary keyring mnemonic unavailable.'); @@ -2578,16 +2580,16 @@ export default class MetamaskController extends EventEmitter { async getKeyringForDevice(deviceName, hdPath = null) { let keyringName = null; switch (deviceName) { - case DEVICE_NAMES.TREZOR: + case HardwareDeviceNames.trezor: keyringName = TrezorKeyring.type; break; - case DEVICE_NAMES.LEDGER: + case HardwareDeviceNames.ledger: keyringName = LedgerBridgeKeyring.type; break; - case DEVICE_NAMES.QR: + case HardwareDeviceNames.qr: keyringName = QRHardwareKeyring.type; break; - case DEVICE_NAMES.LATTICE: + case HardwareDeviceNames.lattice: keyringName = LatticeKeyring.type; break; default: @@ -2602,10 +2604,10 @@ export default class MetamaskController extends EventEmitter { if (hdPath && keyring.setHdPath) { keyring.setHdPath(hdPath); } - if (deviceName === DEVICE_NAMES.LATTICE) { + if (deviceName === HardwareDeviceNames.lattice) { keyring.appName = 'MetaMask'; } - if (deviceName === DEVICE_NAMES.TREZOR) { + if (deviceName === HardwareDeviceNames.trezor) { const model = keyring.getModel(); this.appStateController.setTrezorModel(model); } @@ -2616,7 +2618,7 @@ export default class MetamaskController extends EventEmitter { } async attemptLedgerTransportCreation() { - const keyring = await this.getKeyringForDevice(DEVICE_NAMES.LEDGER); + const keyring = await this.getKeyringForDevice(HardwareDeviceNames.ledger); return await keyring.attemptMakeApp(); } @@ -2694,12 +2696,12 @@ export default class MetamaskController extends EventEmitter { async getAccountType(address) { const keyring = await this.keyringController.getKeyringForAccount(address); switch (keyring.type) { - case KEYRING_TYPES.TREZOR: - case KEYRING_TYPES.LATTICE: - case KEYRING_TYPES.QR: - case KEYRING_TYPES.LEDGER: + case HardwareKeyringTypes.trezor: + case HardwareKeyringTypes.lattice: + case HardwareKeyringTypes.qr: + case HardwareKeyringTypes.ledger: return 'hardware'; - case KEYRING_TYPES.IMPORTED: + case HardwareKeyringTypes.imported: return 'imported'; default: return 'MetaMask'; @@ -2717,16 +2719,16 @@ export default class MetamaskController extends EventEmitter { async getDeviceModel(address) { const keyring = await this.keyringController.getKeyringForAccount(address); switch (keyring.type) { - case KEYRING_TYPES.TREZOR: + case HardwareKeyringTypes.trezor: return keyring.getModel(); - case KEYRING_TYPES.QR: + case HardwareKeyringTypes.qr: return keyring.getName(); - case KEYRING_TYPES.LEDGER: + case HardwareKeyringTypes.ledger: // TODO: get model after ledger keyring exposes method - return DEVICE_NAMES.LEDGER; - case KEYRING_TYPES.LATTICE: + return HardwareDeviceNames.ledger; + case HardwareKeyringTypes.lattice: // TODO: get model after lattice keyring exposes method - return DEVICE_NAMES.LATTICE; + return HardwareDeviceNames.lattice; default: return 'N/A'; } @@ -2769,7 +2771,9 @@ export default class MetamaskController extends EventEmitter { newAccounts.forEach((address) => { if (!oldAccounts.includes(address)) { const label = this.getAccountLabel( - deviceName === DEVICE_NAMES.QR ? keyring.getName() : deviceName, + deviceName === HardwareDeviceNames.qr + ? keyring.getName() + : deviceName, index, hdPathDescription, ); @@ -2796,7 +2800,7 @@ export default class MetamaskController extends EventEmitter { */ async addNewAccount(accountCount) { const [primaryKeyring] = this.keyringController.getKeyringsByType( - KEYRING_TYPES.HD_KEY_TREE, + HardwareKeyringTypes.hdKeyTree, ); if (!primaryKeyring) { throw new Error('MetamaskController - No HD Key Tree found'); @@ -2841,7 +2845,7 @@ export default class MetamaskController extends EventEmitter { */ async verifySeedPhrase() { const [primaryKeyring] = this.keyringController.getKeyringsByType( - KEYRING_TYPES.HD_KEY_TREE, + HardwareKeyringTypes.hdKeyTree, ); if (!primaryKeyring) { throw new Error('MetamaskController - No HD Key Tree found'); @@ -2963,7 +2967,7 @@ export default class MetamaskController extends EventEmitter { async importAccountWithStrategy(strategy, args) { const privateKey = await accountImporter.importAccount(strategy, args); const keyring = await this.keyringController.addNewKeyring( - KEYRING_TYPES.IMPORTED, + HardwareKeyringTypes.imported, [privateKey], ); const [firstAccount] = await keyring.getAccounts(); @@ -3246,7 +3250,7 @@ export default class MetamaskController extends EventEmitter { const keyring = await this.keyringController.getKeyringForAccount(address); switch (keyring.type) { - case KEYRING_TYPES.LEDGER: { + case HardwareKeyringTypes.ledger: { return new Promise((_, reject) => { reject( new Error('Ledger does not support eth_getEncryptionPublicKey.'), @@ -3254,7 +3258,7 @@ export default class MetamaskController extends EventEmitter { }); } - case KEYRING_TYPES.TREZOR: { + case HardwareKeyringTypes.trezor: { return new Promise((_, reject) => { reject( new Error('Trezor does not support eth_getEncryptionPublicKey.'), @@ -3262,7 +3266,7 @@ export default class MetamaskController extends EventEmitter { }); } - case KEYRING_TYPES.LATTICE: { + case HardwareKeyringTypes.lattice: { return new Promise((_, reject) => { reject( new Error('Lattice does not support eth_getEncryptionPublicKey.'), @@ -3270,7 +3274,7 @@ export default class MetamaskController extends EventEmitter { }); } - case KEYRING_TYPES.QR: { + case HardwareKeyringTypes.qr: { return Promise.reject( new Error('QR hardware does not support eth_getEncryptionPublicKey.'), ); @@ -4397,7 +4401,7 @@ export default class MetamaskController extends EventEmitter { const newValue = this.preferencesController.setLedgerTransportPreference(transportType); - const keyring = await this.getKeyringForDevice(DEVICE_NAMES.LEDGER); + const keyring = await this.getKeyringForDevice(HardwareDeviceNames.ledger); if (keyring?.updateTransportMethod) { return keyring.updateTransportMethod(newValue).catch((e) => { // If there was an error updating the transport, we should @@ -4486,14 +4490,14 @@ export default class MetamaskController extends EventEmitter { */ setLocked() { const [trezorKeyring] = this.keyringController.getKeyringsByType( - KEYRING_TYPES.TREZOR, + HardwareKeyringTypes.trezor, ); if (trezorKeyring) { trezorKeyring.dispose(); } const [ledgerKeyring] = this.keyringController.getKeyringsByType( - KEYRING_TYPES.LEDGER, + HardwareKeyringTypes.ledger, ); ledgerKeyring?.destroy?.(); diff --git a/app/scripts/metamask-controller.test.js b/app/scripts/metamask-controller.test.js index 7e6b02fd1..730be9d44 100644 --- a/app/scripts/metamask-controller.test.js +++ b/app/scripts/metamask-controller.test.js @@ -10,8 +10,10 @@ import browser from 'webextension-polyfill'; import { TransactionStatus } from '../../shared/constants/transaction'; import createTxMeta from '../../test/lib/createTxMeta'; import { NETWORK_TYPES } from '../../shared/constants/network'; -import { KEYRING_TYPES } from '../../shared/constants/keyrings'; -import { DEVICE_NAMES } from '../../shared/constants/hardware-wallets'; +import { + HardwareDeviceNames, + HardwareKeyringTypes, +} from '../../shared/constants/hardware-wallets'; import { addHexPrefix, deferredPromise } from './lib/util'; const Ganache = require('../../test/e2e/ganache'); @@ -205,7 +207,7 @@ describe('MetaMaskController', function () { it('adds private key to keyrings in KeyringController', async function () { const simpleKeyrings = metamaskController.keyringController.getKeyringsByType( - KEYRING_TYPES.IMPORTED, + HardwareKeyringTypes.imported, ); const privKeyBuffer = simpleKeyrings[0].wallets[0].privateKey; const pubKeyBuffer = simpleKeyrings[0].wallets[0].publicKey; @@ -479,15 +481,15 @@ describe('MetaMaskController', function () { it('should add the Trezor Hardware keyring', async function () { sinon.spy(metamaskController.keyringController, 'addNewKeyring'); await metamaskController - .connectHardware(DEVICE_NAMES.TREZOR, 0) + .connectHardware(HardwareDeviceNames.trezor, 0) .catch(() => null); const keyrings = await metamaskController.keyringController.getKeyringsByType( - KEYRING_TYPES.TREZOR, + HardwareKeyringTypes.trezor, ); assert.deepEqual( metamaskController.keyringController.addNewKeyring.getCall(0).args, - [KEYRING_TYPES.TREZOR], + [HardwareKeyringTypes.trezor], ); assert.equal(keyrings.length, 1); }); @@ -495,15 +497,15 @@ describe('MetaMaskController', function () { it('should add the Ledger Hardware keyring', async function () { sinon.spy(metamaskController.keyringController, 'addNewKeyring'); await metamaskController - .connectHardware(DEVICE_NAMES.LEDGER, 0) + .connectHardware(HardwareDeviceNames.ledger, 0) .catch(() => null); const keyrings = await metamaskController.keyringController.getKeyringsByType( - KEYRING_TYPES.LEDGER, + HardwareKeyringTypes.ledger, ); assert.deepEqual( metamaskController.keyringController.addNewKeyring.getCall(0).args, - [KEYRING_TYPES.LEDGER], + [HardwareKeyringTypes.ledger], ); assert.equal(keyrings.length, 1); }); @@ -526,10 +528,10 @@ describe('MetaMaskController', function () { it('should be locked by default', async function () { await metamaskController - .connectHardware(DEVICE_NAMES.TREZOR, 0) + .connectHardware(HardwareDeviceNames.trezor, 0) .catch(() => null); const status = await metamaskController.checkHardwareStatus( - DEVICE_NAMES.TREZOR, + HardwareDeviceNames.trezor, ); assert.equal(status, false); }); @@ -549,12 +551,12 @@ describe('MetaMaskController', function () { it('should wipe all the keyring info', async function () { await metamaskController - .connectHardware(DEVICE_NAMES.TREZOR, 0) + .connectHardware(HardwareDeviceNames.trezor, 0) .catch(() => null); - await metamaskController.forgetDevice(DEVICE_NAMES.TREZOR); + await metamaskController.forgetDevice(HardwareDeviceNames.trezor); const keyrings = await metamaskController.keyringController.getKeyringsByType( - KEYRING_TYPES.TREZOR, + HardwareKeyringTypes.trezor, ); assert.deepEqual(keyrings[0].accounts, []); @@ -593,11 +595,11 @@ describe('MetaMaskController', function () { sinon.spy(metamaskController.preferencesController, 'setSelectedAddress'); sinon.spy(metamaskController.preferencesController, 'setAccountLabel'); await metamaskController - .connectHardware(DEVICE_NAMES.TREZOR, 0, `m/44'/1'/0'/0`) + .connectHardware(HardwareDeviceNames.trezor, 0, `m/44'/1'/0'/0`) .catch(() => null); await metamaskController.unlockHardwareWalletAccount( accountToUnlock, - DEVICE_NAMES.TREZOR, + HardwareDeviceNames.trezor, `m/44'/1'/0'/0`, ); }); @@ -614,7 +616,7 @@ describe('MetaMaskController', function () { it('should set unlockedAccount in the keyring', async function () { const keyrings = await metamaskController.keyringController.getKeyringsByType( - KEYRING_TYPES.TREZOR, + HardwareKeyringTypes.trezor, ); assert.equal(keyrings[0].unlockedAccount, accountToUnlock); }); diff --git a/app/scripts/migrations/066.js b/app/scripts/migrations/066.js index 31c109ba7..a6eb8523b 100644 --- a/app/scripts/migrations/066.js +++ b/app/scripts/migrations/066.js @@ -1,5 +1,5 @@ import { cloneDeep } from 'lodash'; -import { LEDGER_TRANSPORT_TYPES } from '../../../shared/constants/hardware-wallets'; +import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets'; const version = 66; @@ -20,15 +20,15 @@ export default { function transformState(state) { const defaultTransportType = window.navigator.hid - ? LEDGER_TRANSPORT_TYPES.WEBHID - : LEDGER_TRANSPORT_TYPES.U2F; + ? LedgerTransportTypes.webhid + : LedgerTransportTypes.u2f; const useLedgerLive = Boolean(state.PreferencesController?.useLedgerLive); const newState = { ...state, PreferencesController: { ...state?.PreferencesController, ledgerTransportType: useLedgerLive - ? LEDGER_TRANSPORT_TYPES.LIVE + ? LedgerTransportTypes.live : defaultTransportType, }, }; diff --git a/app/scripts/migrations/066.test.js b/app/scripts/migrations/066.test.js index 24af0ba45..a4d4ae66c 100644 --- a/app/scripts/migrations/066.test.js +++ b/app/scripts/migrations/066.test.js @@ -1,4 +1,4 @@ -import { LEDGER_TRANSPORT_TYPES } from '../../../shared/constants/hardware-wallets'; +import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets'; import migration66 from './066'; describe('migration #66', () => { @@ -29,7 +29,7 @@ describe('migration #66', () => { const newStorage = await migration66.migrate(oldStorage); expect( newStorage.data.PreferencesController.ledgerTransportType, - ).toStrictEqual(LEDGER_TRANSPORT_TYPES.U2F); + ).toStrictEqual(LedgerTransportTypes.u2f); }); it('should set ledgerTransportType to `u2f` if no useLedgerLive property exists and webhid is not available', async () => { @@ -43,7 +43,7 @@ describe('migration #66', () => { const newStorage = await migration66.migrate(oldStorage); expect( newStorage.data.PreferencesController.ledgerTransportType, - ).toStrictEqual(LEDGER_TRANSPORT_TYPES.U2F); + ).toStrictEqual(LedgerTransportTypes.u2f); }); it('should set ledgerTransportType to `u2f` if useLedgerLive is false and webhid is not available', async () => { @@ -59,7 +59,7 @@ describe('migration #66', () => { const newStorage = await migration66.migrate(oldStorage); expect( newStorage.data.PreferencesController.ledgerTransportType, - ).toStrictEqual(LEDGER_TRANSPORT_TYPES.U2F); + ).toStrictEqual(LedgerTransportTypes.u2f); }); it('should set ledgerTransportType to `webhid` if useLedgerLive is false and webhid is available', async () => { @@ -77,7 +77,7 @@ describe('migration #66', () => { const newStorage = await migration66.migrate(oldStorage); expect( newStorage.data.PreferencesController.ledgerTransportType, - ).toStrictEqual(LEDGER_TRANSPORT_TYPES.WEBHID); + ).toStrictEqual(LedgerTransportTypes.webhid); }); it('should set ledgerTransportType to `ledgerLive` if useLedgerLive is true', async () => { @@ -111,6 +111,6 @@ describe('migration #66', () => { const newStorage = await migration66.migrate(oldStorage); expect( newStorage.data.PreferencesController.ledgerTransportType, - ).toStrictEqual(LEDGER_TRANSPORT_TYPES.LIVE); + ).toStrictEqual(LedgerTransportTypes.live); }); }); diff --git a/shared/constants/hardware-wallets.js b/shared/constants/hardware-wallets.js deleted file mode 100644 index 981c2cf48..000000000 --- a/shared/constants/hardware-wallets.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Accounts can be instantiated from simple, HD or the multiple hardware wallet - * keyring types. Both simple and HD are treated as default but we do special - * case accounts managed by a hardware wallet. - */ -export const HARDWARE_KEYRING_TYPES = { - LEDGER: 'Ledger Hardware', - TREZOR: 'Trezor Hardware', - LATTICE: 'Lattice Hardware', - QR: 'QR Hardware Wallet Device', -}; - -export const DEVICE_NAMES = { - LEDGER: 'ledger', - TREZOR: 'trezor', - QR: 'QR Hardware', - LATTICE: 'lattice', -}; - -export const KEYRING_NAMES = { - LEDGER: 'Ledger', - TREZOR: 'Trezor', - QR: 'QR', - LATTICE: 'Lattice1', -}; - -/** - * Used for setting the users preference for ledger transport type - */ -export const LEDGER_TRANSPORT_TYPES = { - LIVE: 'ledgerLive', - WEBHID: 'webhid', - U2F: 'u2f', -}; - -export const LEDGER_USB_VENDOR_ID = '0x2c97'; - -export const WEBHID_CONNECTED_STATUSES = { - CONNECTED: 'connected', - NOT_CONNECTED: 'notConnected', - UNKNOWN: 'unknown', -}; - -export const TRANSPORT_STATES = { - NONE: 'NONE', - VERIFIED: 'VERIFIED', - DEVICE_OPEN_FAILURE: 'DEVICE_OPEN_FAILURE', - UNKNOWN_FAILURE: 'UNKNOWN_FAILURE', -}; - -export const AFFILIATE_LINKS = { - LEDGER: 'https://shop.ledger.com/?r=17c4991a03fa', - GRIDPLUS: 'https://gridplus.io/?afmc=7p', - TREZOR: - 'https://shop.trezor.io/product/trezor-one-black?offer_id=35&aff_id=11009', - KEYSTONE: - 'https://shop.keyst.one/?rfsn=6088257.656b3e9&utm_source=refersion&utm_medium=affiliate&utm_campaign=6088257.656b3e9', - AIRGAP: 'https://airgap.it/', - COOLWALLET: 'https://www.coolwallet.io/', - DCENT: 'https://dcentwallet.com/', -}; - -export const AFFILIATE_TUTORIAL_LINKS = { - LEDGER: - 'https://support.ledger.com/hc/en-us/articles/4404366864657-Set-up-and-use-MetaMask-to-access-your-Ledger-Ethereum-ETH-account?docs=true', - GRIDPLUS: 'https://docs.gridplus.io/setup/metamask', - TREZOR: 'https://wiki.trezor.io/Apps:MetaMask', - KEYSTONE: - 'https://support.keyst.one/3rd-party-wallets/eth-and-web3-wallets-keystone/bind-metamask-with-keystone', - AIRGAP: 'https://support.airgap.it/guides/metamask/', - COOLWALLET: 'https://www.coolwallet.io/metamask-step-by-step-guides/', - DCENT: - 'https://medium.com/dcentwallet/dcent-wallet-now-supports-qr-based-protocol-to-link-with-metamask-57555f02603f', -}; diff --git a/shared/constants/hardware-wallets.ts b/shared/constants/hardware-wallets.ts new file mode 100644 index 000000000..71cdeb038 --- /dev/null +++ b/shared/constants/hardware-wallets.ts @@ -0,0 +1,71 @@ +/** + * Accounts can be instantiated from simple, HD or the multiple hardware wallet + * keyring types. Both simple and HD are treated as default but we do special + * case accounts managed by a hardware wallet. + */ +export enum HardwareKeyringTypes { + ledger = 'Ledger Hardware', + trezor = 'Trezor Hardware', + lattice = 'Lattice Hardware', + qr = 'QR Hardware Wallet Device', + hdKeyTree = 'HD Key Tree', + imported = 'Simple Key Pair', +} + +export enum HardwareKeyringNames { + ledger = 'Ledger', + trezor = 'Trezor', + lattice = 'Lattice1', + qr = 'QR', +} + +export enum HardwareDeviceNames { + ledger = 'ledger', + trezor = 'trezor', + lattice = 'lattice', + qr = 'QR Hardware', +} + +export enum HardwareTransportStates { + none = 'NONE', + verified = 'VERIFIED', + deviceOpenFailure = 'DEVICE_OPEN_FAILURE', + unknownFailure = 'UNKNOWN_FAILURE', +} + +export enum HardwareAffiliateLinks { + ledger = 'https://shop.ledger.com/?r=17c4991a03fa', + gridplus = 'https://gridplus.io/?afmc=7p', + trezor = 'https://shop.trezor.io/product/trezor-one-black?offer_id=35&aff_id=11009', + keystone = 'https://shop.keyst.one/?rfsn=6088257.656b3e9&utm_source=refersion&utm_medium=affiliate&utm_campaign=6088257.656b3e9', + airgap = 'https://airgap.it/', + coolwallet = 'https://www.coolwallet.io/', + dcent = 'https://dcentwallet.com/', +} + +export enum HardwareAffiliateTutorialLinks { + ledger = 'https://support.ledger.com/hc/en-us/articles/4404366864657-Set-up-and-use-MetaMask-to-access-your-Ledger-Ethereum-ETH-account?docs=true', + gridplus = 'https://docs.gridplus.io/setup/metamask', + trezor = 'https://wiki.trezor.io/Apps:MetaMask', + keystone = 'https://support.keyst.one/3rd-party-wallets/eth-and-web3-wallets-keystone/bind-metamask-with-keystone', + airgap = 'https://support.airgap.it/guides/metamask/', + coolwallet = 'https://www.coolwallet.io/metamask-step-by-step-guides/', + dcent = 'https://medium.com/dcentwallet/dcent-wallet-now-supports-qr-based-protocol-to-link-with-metamask-57555f02603f', +} + +/** + * Used for setting the users preference for ledger transport type + */ +export enum LedgerTransportTypes { + live = 'ledgerLive', + webhid = 'webhid', + u2f = 'u2f', +} + +export enum WebHIDConnectedStatuses { + connected = 'connected', + notConnected = 'notConnected', + unknown = 'unknown', +} + +export const LEDGER_USB_VENDOR_ID = '0x2c97'; diff --git a/shared/constants/keyrings.js b/shared/constants/keyrings.js deleted file mode 100644 index bcbd17953..000000000 --- a/shared/constants/keyrings.js +++ /dev/null @@ -1,7 +0,0 @@ -import { HARDWARE_KEYRING_TYPES } from './hardware-wallets'; - -export const KEYRING_TYPES = { - HD_KEY_TREE: 'HD Key Tree', - IMPORTED: 'Simple Key Pair', - ...HARDWARE_KEYRING_TYPES, -}; diff --git a/test/jest/mock-store.js b/test/jest/mock-store.js index 3fdc80b6f..ac261ab6a 100644 --- a/test/jest/mock-store.js +++ b/test/jest/mock-store.js @@ -1,5 +1,5 @@ import { CHAIN_IDS } from '../../shared/constants/network'; -import { KEYRING_TYPES } from '../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../shared/constants/hardware-wallets'; const createGetSmartTransactionFeesApiResponse = () => { return { @@ -253,10 +253,13 @@ export const createSwapsMockStore = () => { }, }, selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', - keyringTypes: [KEYRING_TYPES.IMPORTED, KEYRING_TYPES.HD_KEY_TREE], + keyringTypes: [ + HardwareKeyringTypes.imported, + HardwareKeyringTypes.hdKeyTree, + ], keyrings: [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: [ '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', 'c5b8dbac4c1d3f152cdeb400e2313f309c410acb', @@ -264,7 +267,7 @@ export const createSwapsMockStore = () => { ], }, { - type: KEYRING_TYPES.IMPORTED, + type: HardwareKeyringTypes.imported, accounts: ['0xd85a4b6a394794842887b8284293d69163007bbb'], }, ], diff --git a/ui/components/app/account-menu/account-menu.test.js b/ui/components/app/account-menu/account-menu.test.js index 4366556b6..ab1da08c3 100644 --- a/ui/components/app/account-menu/account-menu.test.js +++ b/ui/components/app/account-menu/account-menu.test.js @@ -3,7 +3,7 @@ import sinon from 'sinon'; import configureMockStore from 'redux-mock-store'; import { fireEvent, screen } from '@testing-library/react'; import { renderWithProvider } from '../../../../test/lib/render-helpers'; -import { KEYRING_TYPES } from '../../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets'; import AccountMenu from '.'; describe('Account Menu', () => { @@ -37,11 +37,11 @@ describe('Account Menu', () => { ], keyrings: [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: ['0xAdress'], }, { - type: KEYRING_TYPES.IMPORTED, + type: HardwareKeyringTypes.imported, accounts: ['0x1'], }, ], diff --git a/ui/components/app/account-menu/keyring-label.js b/ui/components/app/account-menu/keyring-label.js index 3549a95b4..985c54ae5 100644 --- a/ui/components/app/account-menu/keyring-label.js +++ b/ui/components/app/account-menu/keyring-label.js @@ -2,8 +2,10 @@ import React from 'react'; import PropTypes from 'prop-types'; import { useI18nContext } from '../../../hooks/useI18nContext'; -import { KEYRING_TYPES } from '../../../../shared/constants/keyrings'; -import { KEYRING_NAMES } from '../../../../shared/constants/hardware-wallets'; +import { + HardwareKeyringNames, + HardwareKeyringTypes, +} from '../../../../shared/constants/hardware-wallets'; export default function KeyRingLabel({ keyring }) { const t = useI18nContext(); @@ -17,20 +19,20 @@ export default function KeyRingLabel({ keyring }) { const { type } = keyring; switch (type) { - case KEYRING_TYPES.QR: - label = KEYRING_NAMES.QR; + case HardwareKeyringTypes.qr: + label = HardwareKeyringNames.qr; break; - case KEYRING_TYPES.IMPORTED: + case HardwareKeyringTypes.imported: label = t('imported'); break; - case KEYRING_TYPES.TREZOR: - label = KEYRING_NAMES.TREZOR; + case HardwareKeyringTypes.trezor: + label = HardwareKeyringNames.trezor; break; - case KEYRING_TYPES.LEDGER: - label = KEYRING_NAMES.LEDGER; + case HardwareKeyringTypes.ledger: + label = HardwareKeyringNames.ledger; break; - case KEYRING_TYPES.LATTICE: - label = KEYRING_NAMES.LATTICE; + case HardwareKeyringTypes.lattice: + label = HardwareKeyringNames.lattice; break; default: return null; diff --git a/ui/components/app/alerts/unconnected-account-alert/unconnected-account-alert.test.js b/ui/components/app/alerts/unconnected-account-alert/unconnected-account-alert.test.js index d8fe1ddef..42fe9d67e 100644 --- a/ui/components/app/alerts/unconnected-account-alert/unconnected-account-alert.test.js +++ b/ui/components/app/alerts/unconnected-account-alert/unconnected-account-alert.test.js @@ -11,7 +11,7 @@ import { renderWithProvider } from '../../../../../test/lib/render-helpers'; import * as actions from '../../../../store/actions'; import { CHAIN_IDS } from '../../../../../shared/constants/network'; -import { KEYRING_TYPES } from '../../../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../../../shared/constants/hardware-wallets'; import UnconnectedAccountAlert from '.'; @@ -49,7 +49,7 @@ describe('Unconnected Account Alert', () => { const keyrings = [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: [ '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b', diff --git a/ui/components/app/ledger-instruction-field/ledger-instruction-field.js b/ui/components/app/ledger-instruction-field/ledger-instruction-field.js index f7a287927..ac331902f 100644 --- a/ui/components/app/ledger-instruction-field/ledger-instruction-field.js +++ b/ui/components/app/ledger-instruction-field/ledger-instruction-field.js @@ -2,10 +2,10 @@ import React, { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import PropTypes from 'prop-types'; import { - LEDGER_TRANSPORT_TYPES, + LedgerTransportTypes, + WebHIDConnectedStatuses, + HardwareTransportStates, LEDGER_USB_VENDOR_ID, - WEBHID_CONNECTED_STATUSES, - TRANSPORT_STATES, } from '../../../../shared/constants/hardware-wallets'; import { PLATFORM_FIREFOX, @@ -68,8 +68,8 @@ export default function LedgerInstructionField({ showDataInstruction }) { useEffect(() => { const initialConnectedDeviceCheck = async () => { if ( - ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID && - webHidConnectedStatus !== WEBHID_CONNECTED_STATUSES.CONNECTED + ledgerTransportType === LedgerTransportTypes.webhid && + webHidConnectedStatus !== WebHIDConnectedStatuses.connected ) { const devices = await window.navigator.hid.getDevices(); const webHidIsConnected = devices.some( @@ -78,37 +78,41 @@ export default function LedgerInstructionField({ showDataInstruction }) { dispatch( setLedgerWebHidConnectedStatus( webHidIsConnected - ? WEBHID_CONNECTED_STATUSES.CONNECTED - : WEBHID_CONNECTED_STATUSES.NOT_CONNECTED, + ? WebHIDConnectedStatuses.connected + : WebHIDConnectedStatuses.notConnected, ), ); } }; const determineTransportStatus = async () => { if ( - ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID && - webHidConnectedStatus === WEBHID_CONNECTED_STATUSES.CONNECTED && - transportStatus === TRANSPORT_STATES.NONE + ledgerTransportType === LedgerTransportTypes.webhid && + webHidConnectedStatus === WebHIDConnectedStatuses.connected && + transportStatus === HardwareTransportStates.none ) { try { const transportedCreated = await attemptLedgerTransportCreation(); dispatch( setLedgerTransportStatus( transportedCreated - ? TRANSPORT_STATES.VERIFIED - : TRANSPORT_STATES.UNKNOWN_FAILURE, + ? HardwareTransportStates.verified + : HardwareTransportStates.unknownFailure, ), ); } catch (e) { if (e.message.match('Failed to open the device')) { dispatch( - setLedgerTransportStatus(TRANSPORT_STATES.DEVICE_OPEN_FAILURE), + setLedgerTransportStatus( + HardwareTransportStates.deviceOpenFailure, + ), ); } else if (e.message.match('the device is already open')) { - dispatch(setLedgerTransportStatus(TRANSPORT_STATES.VERIFIED)); + dispatch( + setLedgerTransportStatus(HardwareTransportStates.verified), + ); } else { dispatch( - setLedgerTransportStatus(TRANSPORT_STATES.UNKNOWN_FAILURE), + setLedgerTransportStatus(HardwareTransportStates.unknownFailure), ); } } @@ -120,12 +124,12 @@ export default function LedgerInstructionField({ showDataInstruction }) { useEffect(() => { return () => { - dispatch(setLedgerTransportStatus(TRANSPORT_STATES.NONE)); + dispatch(setLedgerTransportStatus(HardwareTransportStates.none)); }; }, [dispatch]); - const usingLedgerLive = ledgerTransportType === LEDGER_TRANSPORT_TYPES.LIVE; - const usingWebHID = ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID; + const usingLedgerLive = ledgerTransportType === LedgerTransportTypes.live; + const usingWebHID = ledgerTransportType === LedgerTransportTypes.webhid; const isFirefox = getPlatform() === PLATFORM_FIREFOX; @@ -165,7 +169,7 @@ export default function LedgerInstructionField({ showDataInstruction }) { {t('ledgerConnectionInstructionCloseOtherApps')} , - transportStatus === TRANSPORT_STATES.DEVICE_OPEN_FAILURE, + transportStatus === HardwareTransportStates.deviceOpenFailure, )} {renderInstructionStep( @@ -184,8 +188,8 @@ export default function LedgerInstructionField({ showDataInstruction }) { dispatch( setLedgerWebHidConnectedStatus({ webHidConnectedStatus: webHidIsConnected - ? WEBHID_CONNECTED_STATUSES.CONNECTED - : WEBHID_CONNECTED_STATUSES.NOT_CONNECTED, + ? WebHIDConnectedStatuses.connected + : WebHIDConnectedStatuses.notConnected, }), ); } else { @@ -199,8 +203,7 @@ export default function LedgerInstructionField({ showDataInstruction }) { , usingWebHID && - webHidConnectedStatus === - WEBHID_CONNECTED_STATUSES.NOT_CONNECTED, + webHidConnectedStatus === WebHIDConnectedStatuses.notConnected, COLORS.WARNING_DEFAULT, )} diff --git a/ui/components/app/menu-bar/account-options-menu.js b/ui/components/app/menu-bar/account-options-menu.js index 20f0a1549..e2c3b2905 100644 --- a/ui/components/app/menu-bar/account-options-menu.js +++ b/ui/components/app/menu-bar/account-options-menu.js @@ -21,7 +21,7 @@ import { import { useI18nContext } from '../../../hooks/useI18nContext'; import { getEnvironmentType } from '../../../../app/scripts/lib/util'; import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app'; -import { KEYRING_TYPES } from '../../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets'; import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics'; import { MetaMetricsContext } from '../../../contexts/metametrics'; @@ -41,7 +41,7 @@ export default function AccountOptionsMenu({ anchorElement, onClose }) { const trackEvent = useContext(MetaMetricsContext); const blockExplorerLinkText = useSelector(getBlockExplorerLinkText); - const isRemovable = keyring.type !== KEYRING_TYPES.HD_KEY_TREE; + const isRemovable = keyring.type !== HardwareKeyringTypes.hdKeyTree; const routeToAddBlockExplorerUrl = () => { history.push(`${NETWORKS_ROUTE}#blockExplorerUrl`); diff --git a/ui/components/app/menu-bar/menu-bar.test.js b/ui/components/app/menu-bar/menu-bar.test.js index 7bc041fe2..2a4037ab8 100644 --- a/ui/components/app/menu-bar/menu-bar.test.js +++ b/ui/components/app/menu-bar/menu-bar.test.js @@ -3,7 +3,7 @@ import configureStore from 'redux-mock-store'; import { fireEvent, screen, waitFor } from '@testing-library/react'; import { renderWithProvider } from '../../../../test/lib/render-helpers'; import { CHAIN_IDS } from '../../../../shared/constants/network'; -import { KEYRING_TYPES } from '../../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets'; import MenuBar from './menu-bar'; const initState = { @@ -21,7 +21,7 @@ const initState = { }, keyrings: [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'], }, ], diff --git a/ui/components/app/wallet-overview/token-overview.test.js b/ui/components/app/wallet-overview/token-overview.test.js index f29e4dcd2..6c371b602 100644 --- a/ui/components/app/wallet-overview/token-overview.test.js +++ b/ui/components/app/wallet-overview/token-overview.test.js @@ -2,7 +2,7 @@ import React from 'react'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; import { renderWithProvider } from '../../../../test/jest/rendering'; -import { KEYRING_TYPES } from '../../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets'; import TokenOverview from './token-overview'; describe('TokenOverview', () => { @@ -22,11 +22,11 @@ describe('TokenOverview', () => { selectedAddress: '0x1', keyrings: [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: ['0x1', '0x2'], }, { - type: KEYRING_TYPES.LEDGER, + type: HardwareKeyringTypes.ledger, accounts: [], }, ], diff --git a/ui/ducks/app/app.js b/ui/ducks/app/app.js index 9b62a4b71..1707d0a26 100644 --- a/ui/ducks/app/app.js +++ b/ui/ducks/app/app.js @@ -1,6 +1,6 @@ import { - WEBHID_CONNECTED_STATUSES, - TRANSPORT_STATES, + WebHIDConnectedStatuses, + HardwareTransportStates, } from '../../../shared/constants/hardware-wallets'; import * as actionConstants from '../../store/actionConstants'; @@ -49,8 +49,8 @@ export default function reduceApp(state = {}, action) { gasLoadingAnimationIsShowing: false, smartTransactionsError: null, smartTransactionsErrorMessageDismissed: false, - ledgerWebHidConnectedStatus: WEBHID_CONNECTED_STATUSES.UNKNOWN, - ledgerTransportStatus: TRANSPORT_STATES.NONE, + ledgerWebHidConnectedStatus: WebHIDConnectedStatuses.unknown, + ledgerTransportStatus: HardwareTransportStates.none, newNetworkAdded: '', newCollectibleAddedMessage: '', portfolioTooltipWasShownInThisSession: false, diff --git a/ui/ducks/app/app.test.js b/ui/ducks/app/app.test.js index e52aebf0f..4a036d633 100644 --- a/ui/ducks/app/app.test.js +++ b/ui/ducks/app/app.test.js @@ -1,5 +1,5 @@ import * as actionConstants from '../../store/actionConstants'; -import { DEVICE_NAMES } from '../../../shared/constants/hardware-wallets'; +import { HardwareDeviceNames } from '../../../shared/constants/hardware-wallets'; import reduceApp from './app'; const actions = actionConstants; @@ -261,7 +261,7 @@ describe('App State', () => { const state = reduceApp(metamaskState, { type: actions.SET_HARDWARE_WALLET_DEFAULT_HD_PATH, value: { - device: DEVICE_NAMES.LEDGER, + device: HardwareDeviceNames.ledger, path: "m/44'/60'/0'", }, }); diff --git a/ui/ducks/metamask/metamask.js b/ui/ducks/metamask/metamask.js index 0a8a26501..04e8f61bc 100644 --- a/ui/ducks/metamask/metamask.js +++ b/ui/ducks/metamask/metamask.js @@ -15,7 +15,7 @@ import { updateTransactionGasFees } from '../../store/actions'; import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck'; import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util'; -import { KEYRING_TYPES } from '../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; import { stripHexPrefix } from '../../../shared/modules/hexstring-utils'; @@ -433,7 +433,7 @@ export function getLedgerTransportType(state) { export function isAddressLedger(state, address) { const keyring = findKeyringForAddress(state, address); - return keyring?.type === KEYRING_TYPES.LEDGER; + return keyring?.type === HardwareKeyringTypes.ledger; } /** @@ -445,6 +445,6 @@ export function isAddressLedger(state, address) { */ export function doesUserHaveALedgerAccount(state) { return state.metamask.keyrings.some((kr) => { - return kr.type === KEYRING_TYPES.LEDGER; + return kr.type === HardwareKeyringTypes.ledger; }); } diff --git a/ui/ducks/send/send.test.js b/ui/ducks/send/send.test.js index 98d402cf4..9a6cd5c19 100644 --- a/ui/ducks/send/send.test.js +++ b/ui/ducks/send/send.test.js @@ -13,7 +13,7 @@ import { } from '../../pages/send/send.constants'; import { CHAIN_IDS } from '../../../shared/constants/network'; import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas'; -import { KEYRING_TYPES } from '../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; import { AssetType, TokenStandard, @@ -1278,7 +1278,7 @@ describe('Send Slice', () => { identities: { '0xAddress': { address: '0xAddress' } }, keyrings: [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: ['0xAddress'], }, ], diff --git a/ui/pages/create-account/connect-hardware/account-list.js b/ui/pages/create-account/connect-hardware/account-list.js index 9a180b3a2..2fe153ca0 100644 --- a/ui/pages/create-account/connect-hardware/account-list.js +++ b/ui/pages/create-account/connect-hardware/account-list.js @@ -8,7 +8,7 @@ import Dropdown from '../../../components/ui/dropdown'; import { getURLHostName } from '../../../helpers/utils/util'; -import { DEVICE_NAMES } from '../../../../shared/constants/hardware-wallets'; +import { HardwareDeviceNames } from '../../../../shared/constants/hardware-wallets'; import { EVENT } from '../../../../shared/constants/metametrics'; class AccountList extends Component { @@ -65,9 +65,9 @@ class AccountList extends Component { renderHeader() { const { device } = this.props; const shouldShowHDPaths = [ - DEVICE_NAMES.LEDGER, - DEVICE_NAMES.LATTICE, - DEVICE_NAMES.TREZOR, + HardwareDeviceNames.ledger, + HardwareDeviceNames.lattice, + HardwareDeviceNames.trezor, ].includes(device.toLowerCase()); return (
diff --git a/ui/pages/create-account/connect-hardware/index.js b/ui/pages/create-account/connect-hardware/index.js index 14b854648..93776d715 100644 --- a/ui/pages/create-account/connect-hardware/index.js +++ b/ui/pages/create-account/connect-hardware/index.js @@ -13,8 +13,8 @@ import { getMostRecentOverviewPage } from '../../../ducks/history/history'; import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics'; import { SECOND } from '../../../../shared/constants/time'; import { - DEVICE_NAMES, - LEDGER_TRANSPORT_TYPES, + HardwareDeviceNames, + LedgerTransportTypes, } from '../../../../shared/constants/hardware-wallets'; import ZENDESK_URLS from '../../../helpers/constants/zendesk-url'; import SelectHardware from './select-hardware'; @@ -89,9 +89,9 @@ class ConnectHardwareForm extends Component { async checkIfUnlocked() { for (const device of [ - DEVICE_NAMES.TREZOR, - DEVICE_NAMES.LEDGER, - DEVICE_NAMES.LATTICE, + HardwareDeviceNames.trezor, + HardwareDeviceNames.ledger, + HardwareDeviceNames.lattice, ]) { const path = this.props.defaultHdPaths[device]; const unlocked = await this.props.checkHardwareStatus(device, path); @@ -364,7 +364,7 @@ ConnectHardwareForm.propTypes = { connectedAccounts: PropTypes.array.isRequired, defaultHdPaths: PropTypes.object, mostRecentOverviewPage: PropTypes.string.isRequired, - ledgerTransportType: PropTypes.oneOf(Object.values(LEDGER_TRANSPORT_TYPES)), + ledgerTransportType: PropTypes.oneOf(Object.values(LedgerTransportTypes)), }; const mapStateToProps = (state) => ({ diff --git a/ui/pages/create-account/connect-hardware/select-hardware.js b/ui/pages/create-account/connect-hardware/select-hardware.js index d06e19009..1329ca90c 100644 --- a/ui/pages/create-account/connect-hardware/select-hardware.js +++ b/ui/pages/create-account/connect-hardware/select-hardware.js @@ -8,10 +8,10 @@ import LogoTrezor from '../../../components/ui/logo/logo-trezor'; import LogoLattice from '../../../components/ui/logo/logo-lattice'; import { - DEVICE_NAMES, - LEDGER_TRANSPORT_TYPES, - AFFILIATE_LINKS, - AFFILIATE_TUTORIAL_LINKS, + HardwareDeviceNames, + LedgerTransportTypes, + HardwareAffiliateLinks, + HardwareAffiliateTutorialLinks, } from '../../../../shared/constants/hardware-wallets'; import ZENDESK_URLS from '../../../helpers/constants/zendesk-url'; import { EVENT } from '../../../../shared/constants/metametrics'; @@ -25,7 +25,7 @@ export default class SelectHardware extends Component { static propTypes = { connectToHardwareWallet: PropTypes.func.isRequired, browserSupported: PropTypes.bool.isRequired, - ledgerTransportType: PropTypes.oneOf(Object.values(LEDGER_TRANSPORT_TYPES)), + ledgerTransportType: PropTypes.oneOf(Object.values(LedgerTransportTypes)), }; state = { @@ -43,9 +43,11 @@ export default class SelectHardware extends Component { return ( @@ -56,9 +58,11 @@ export default class SelectHardware extends Component { return ( @@ -69,9 +73,11 @@ export default class SelectHardware extends Component { return ( @@ -82,9 +88,11 @@ export default class SelectHardware extends Component { return ( @@ -164,13 +172,13 @@ export default class SelectHardware extends Component { renderTutorialsteps() { switch (this.state.selectedDevice) { - case DEVICE_NAMES.LEDGER: + case HardwareDeviceNames.ledger: return this.renderLedgerTutorialSteps(); - case DEVICE_NAMES.TREZOR: + case HardwareDeviceNames.trezor: return this.renderTrezorTutorialSteps(); - case DEVICE_NAMES.LATTICE: + case HardwareDeviceNames.lattice: return this.renderLatticeTutorialSteps(); - case DEVICE_NAMES.QR: + case HardwareDeviceNames.qr: return this.renderQRHardwareWalletSteps(); default: return ''; @@ -179,7 +187,7 @@ export default class SelectHardware extends Component { renderLedgerTutorialSteps() { const steps = []; - if (this.props.ledgerTransportType === LEDGER_TRANSPORT_TYPES.LIVE) { + if (this.props.ledgerTransportType === LedgerTransportTypes.live) { steps.push({ renderButtons: false, title: this.context.t('step1LedgerWallet'), @@ -230,7 +238,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked Ledger Buy Now', }); - window.open(AFFILIATE_LINKS.LEDGER, '_blank'); + window.open(HardwareAffiliateLinks.ledger, '_blank'); }} > {this.context.t('buyNow')} @@ -243,7 +251,10 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked Ledger Tutorial', }); - window.open(AFFILIATE_TUTORIAL_LINKS.LEDGER, '_blank'); + window.open( + HardwareAffiliateTutorialLinks.ledger, + '_blank', + ); }} > {this.context.t('tutorial')} @@ -298,7 +309,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked GridPlus Buy Now', }); - window.open(AFFILIATE_LINKS.GRIDPLUS, '_blank'); + window.open(HardwareAffiliateLinks.gridplus, '_blank'); }} > {this.context.t('buyNow')} @@ -311,7 +322,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked GidPlus Tutorial', }); - window.open(AFFILIATE_TUTORIAL_LINKS.GRIDPLUS, '_blank'); + window.open(HardwareAffiliateTutorialLinks.gridplus, '_blank'); }} > {this.context.t('tutorial')} @@ -364,7 +375,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked Trezor Buy Now', }); - window.open(AFFILIATE_LINKS.TREZOR, '_blank'); + window.open(HardwareAffiliateLinks.trezor, '_blank'); }} > {this.context.t('buyNow')} @@ -377,7 +388,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked Trezor Tutorial', }); - window.open(AFFILIATE_TUTORIAL_LINKS.TREZOR, '_blank'); + window.open(HardwareAffiliateTutorialLinks.trezor, '_blank'); }} > {this.context.t('tutorial')} @@ -418,7 +429,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked Keystone Buy Now', }); - window.open(AFFILIATE_LINKS.KEYSTONE, '_blank'); + window.open(HardwareAffiliateLinks.keystone, '_blank'); }} > {this.context.t('buyNow')} @@ -431,7 +442,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked Keystone Tutorial', }); - window.open(AFFILIATE_TUTORIAL_LINKS.KEYSTONE, '_blank'); + window.open(HardwareAffiliateTutorialLinks.keystone, '_blank'); }} > {this.context.t('tutorial')} @@ -453,7 +464,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked AirGap Vault Buy Now', }); - window.open(AFFILIATE_LINKS.AIRGAP, '_blank'); + window.open(HardwareAffiliateLinks.airgap, '_blank'); }} > {this.context.t('downloadNow')} @@ -466,7 +477,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked AirGap Vault Tutorial', }); - window.open(AFFILIATE_TUTORIAL_LINKS.AIRGAP, '_blank'); + window.open(HardwareAffiliateTutorialLinks.airgap, '_blank'); }} > {this.context.t('tutorial')} @@ -488,7 +499,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked CoolWallet Buy Now', }); - window.open(AFFILIATE_LINKS.COOLWALLET, '_blank'); + window.open(HardwareAffiliateLinks.coolwallet, '_blank'); }} > {this.context.t('buyNow')} @@ -501,7 +512,10 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked CoolWallet Tutorial', }); - window.open(AFFILIATE_TUTORIAL_LINKS.COOLWALLET, '_blank'); + window.open( + HardwareAffiliateTutorialLinks.coolwallet, + '_blank', + ); }} > {this.context.t('tutorial')} @@ -521,7 +535,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked DCent Buy Now', }); - window.open(AFFILIATE_LINKS.DCENT, '_blank'); + window.open(HardwareAffiliateLinks.dcent, '_blank'); }} > {this.context.t('buyNow')} @@ -534,7 +548,7 @@ export default class SelectHardware extends Component { category: EVENT.CATEGORIES.NAVIGATION, event: 'Clicked DCent Tutorial', }); - window.open(AFFILIATE_TUTORIAL_LINKS.DCENT, '_blank'); + window.open(HardwareAffiliateTutorialLinks.dcent, '_blank'); }} > {this.context.t('tutorial')} diff --git a/ui/pages/create-account/connect-hardware/select-hardware.stories.js b/ui/pages/create-account/connect-hardware/select-hardware.stories.js index ed3ae7e8a..07ddac48a 100644 --- a/ui/pages/create-account/connect-hardware/select-hardware.stories.js +++ b/ui/pages/create-account/connect-hardware/select-hardware.stories.js @@ -1,6 +1,6 @@ import React from 'react'; import { action } from '@storybook/addon-actions'; -import { LEDGER_TRANSPORT_TYPES } from '../../../../shared/constants/hardware-wallets'; +import { LedgerTransportTypes } from '../../../../shared/constants/hardware-wallets'; import SelectHardware from './select-hardware'; export default { @@ -15,7 +15,7 @@ export const DefaultStory = () => { connectToHardwareWallet={(selectedDevice) => action(`Continue connect to ${selectedDevice}`)() } - ledgerTransportType={LEDGER_TRANSPORT_TYPES.LIVE} + ledgerTransportType={LedgerTransportTypes.live} /> ); }; @@ -27,7 +27,7 @@ export const BrowserNotSupported = () => { undefined} - ledgerTransportType={LEDGER_TRANSPORT_TYPES.LIVE} + ledgerTransportType={LedgerTransportTypes.live} /> ); }; diff --git a/ui/pages/mobile-sync/mobile-sync.component.js b/ui/pages/mobile-sync/mobile-sync.component.js index ecad8d466..9c0dc96fe 100644 --- a/ui/pages/mobile-sync/mobile-sync.component.js +++ b/ui/pages/mobile-sync/mobile-sync.component.js @@ -8,7 +8,7 @@ import qrCode from 'qrcode-generator'; import Button from '../../components/ui/button'; import LoadingScreen from '../../components/ui/loading-screen'; import { MINUTE, SECOND } from '../../../shared/constants/time'; -import { KEYRING_TYPES } from '../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; const PASSWORD_PROMPT_SCREEN = 'PASSWORD_PROMPT_SCREEN'; const REVEAL_SEED_SCREEN = 'REVEAL_SEED_SCREEN'; @@ -82,7 +82,7 @@ export default class MobileSyncPage extends Component { async exportAccounts() { const addresses = []; this.props.keyrings.forEach((keyring) => { - if (keyring.type === KEYRING_TYPES.IMPORTED) { + if (keyring.type === HardwareKeyringTypes.imported) { addresses.push(keyring.accounts[0]); } }); diff --git a/ui/pages/send/send.test.js b/ui/pages/send/send.test.js index 1d5ca3841..ddd2596d8 100644 --- a/ui/pages/send/send.test.js +++ b/ui/pages/send/send.test.js @@ -10,7 +10,7 @@ import { setBackgroundConnection, } from '../../../test/jest'; import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas'; -import { KEYRING_TYPES } from '../../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets'; import { INITIAL_SEND_STATE_FOR_EXISTING_DRAFT } from '../../../test/jest/mocks'; import Send from './send'; @@ -86,7 +86,7 @@ const baseStore = { selectedAddress: '0x0', keyrings: [ { - type: KEYRING_TYPES.HD_KEY_TREE, + type: HardwareKeyringTypes.hdKeyTree, accounts: ['0x0'], }, ], diff --git a/ui/pages/settings/advanced-tab/advanced-tab.component.js b/ui/pages/settings/advanced-tab/advanced-tab.component.js index 0cd79f476..3a57a9ad2 100644 --- a/ui/pages/settings/advanced-tab/advanced-tab.component.js +++ b/ui/pages/settings/advanced-tab/advanced-tab.component.js @@ -16,7 +16,7 @@ import { } from '../../../helpers/utils/settings-search'; import { - LEDGER_TRANSPORT_TYPES, + LedgerTransportTypes, LEDGER_USB_VENDOR_ID, } from '../../../../shared/constants/hardware-wallets'; import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics'; @@ -49,7 +49,7 @@ export default class AdvancedTab extends PureComponent { setAutoLockTimeLimit: PropTypes.func.isRequired, setShowFiatConversionOnTestnetsPreference: PropTypes.func.isRequired, setShowTestNetworks: PropTypes.func.isRequired, - ledgerTransportType: PropTypes.oneOf(Object.values(LEDGER_TRANSPORT_TYPES)), + ledgerTransportType: PropTypes.oneOf(Object.values(LedgerTransportTypes)), setLedgerTransportPreference: PropTypes.func.isRequired, setDismissSeedBackUpReminder: PropTypes.func.isRequired, dismissSeedBackUpReminder: PropTypes.bool.isRequired, @@ -473,18 +473,18 @@ export default class AdvancedTab extends PureComponent { const transportTypeOptions = [ { name: LEDGER_TRANSPORT_NAMES.LIVE, - value: LEDGER_TRANSPORT_TYPES.LIVE, + value: LedgerTransportTypes.live, }, { name: LEDGER_TRANSPORT_NAMES.U2F, - value: LEDGER_TRANSPORT_TYPES.U2F, + value: LedgerTransportTypes.u2f, }, ]; if (window.navigator.hid) { transportTypeOptions.push({ name: LEDGER_TRANSPORT_NAMES.WEBHID, - value: LEDGER_TRANSPORT_TYPES.WEBHID, + value: LedgerTransportTypes.webhid, }); } @@ -520,14 +520,14 @@ export default class AdvancedTab extends PureComponent { selectedOption={ledgerTransportType} onChange={async (transportType) => { if ( - ledgerTransportType === LEDGER_TRANSPORT_TYPES.LIVE && - transportType === LEDGER_TRANSPORT_TYPES.WEBHID + ledgerTransportType === LedgerTransportTypes.live && + transportType === LedgerTransportTypes.webhid ) { this.setState({ showLedgerTransportWarning: true }); } setLedgerTransportPreference(transportType); if ( - transportType === LEDGER_TRANSPORT_TYPES.WEBHID && + transportType === LedgerTransportTypes.webhid && userHasALedgerAccount ) { await window.navigator.hid.requestDevice({ diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 2b1c402cf..1d6df6047 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -22,11 +22,11 @@ import { CHAIN_IDS, NETWORK_TYPES, } from '../../shared/constants/network'; -import { KEYRING_TYPES } from '../../shared/constants/keyrings'; import { - WEBHID_CONNECTED_STATUSES, - LEDGER_TRANSPORT_TYPES, - TRANSPORT_STATES, + HardwareKeyringTypes, + WebHIDConnectedStatuses, + LedgerTransportTypes, + HardwareTransportStates, } from '../../shared/constants/hardware-wallets'; import { @@ -130,7 +130,7 @@ export function hasUnsignedQRHardwareTransaction(state) { } const { from } = txParams; const { keyrings } = state.metamask; - const qrKeyring = keyrings.find((kr) => kr.type === KEYRING_TYPES.QR); + const qrKeyring = keyrings.find((kr) => kr.type === HardwareKeyringTypes.qr); if (!qrKeyring) { return false; } @@ -148,7 +148,7 @@ export function hasUnsignedQRHardwareMessage(state) { } const { from } = msgParams; const { keyrings } = state.metamask; - const qrKeyring = keyrings.find((kr) => kr.type === KEYRING_TYPES.QR); + const qrKeyring = keyrings.find((kr) => kr.type === HardwareKeyringTypes.qr); if (!qrKeyring) { return false; } @@ -239,11 +239,11 @@ export function getAccountType(state) { const type = currentKeyring && currentKeyring.type; switch (type) { - case KEYRING_TYPES.TREZOR: - case KEYRING_TYPES.LEDGER: - case KEYRING_TYPES.LATTICE: + case HardwareKeyringTypes.trezor: + case HardwareKeyringTypes.ledger: + case HardwareKeyringTypes.lattice: return 'hardware'; - case KEYRING_TYPES.IMPORTED: + case HardwareKeyringTypes.imported: return 'imported'; default: return 'default'; @@ -982,10 +982,11 @@ export const getUnreadNotificationsCount = createSelector( */ function getAllowedAnnouncementIds(state) { const currentKeyring = getCurrentKeyring(state); - const currentKeyringIsLedger = currentKeyring?.type === KEYRING_TYPES.LEDGER; + const currentKeyringIsLedger = + currentKeyring?.type === HardwareKeyringTypes.ledger; const supportsWebHid = window.navigator.hid !== undefined; const currentlyUsingLedgerLive = - getLedgerTransportType(state) === LEDGER_TRANSPORT_TYPES.LIVE; + getLedgerTransportType(state) === LedgerTransportTypes.live; return { 1: false, @@ -1118,13 +1119,12 @@ export function getTokenList(state) { export function doesAddressRequireLedgerHidConnection(state, address) { const addressIsLedger = isAddressLedger(state, address); const transportTypePreferenceIsWebHID = - getLedgerTransportType(state) === LEDGER_TRANSPORT_TYPES.WEBHID; + getLedgerTransportType(state) === LedgerTransportTypes.webhid; const webHidIsNotConnected = - getLedgerWebHidConnectedStatus(state) !== - WEBHID_CONNECTED_STATUSES.CONNECTED; + getLedgerWebHidConnectedStatus(state) !== WebHIDConnectedStatuses.connected; const ledgerTransportStatus = getLedgerTransportStatus(state); const transportIsNotSuccessfullyCreated = - ledgerTransportStatus !== TRANSPORT_STATES.VERIFIED; + ledgerTransportStatus !== HardwareTransportStates.verified; return ( addressIsLedger && diff --git a/ui/selectors/selectors.test.js b/ui/selectors/selectors.test.js index 38ea67b43..7b269b37f 100644 --- a/ui/selectors/selectors.test.js +++ b/ui/selectors/selectors.test.js @@ -1,5 +1,5 @@ import mockState from '../../test/data/mock-state.json'; -import { KEYRING_TYPES } from '../../shared/constants/keyrings'; +import { HardwareKeyringTypes } from '../../shared/constants/hardware-wallets'; import * as selectors from './selectors'; describe('Selectors', () => { @@ -18,38 +18,38 @@ describe('Selectors', () => { describe('#isHardwareWallet', () => { it('returns false if it is not a HW wallet', () => { - mockState.metamask.keyrings[0].type = KEYRING_TYPES.IMPORTED; + mockState.metamask.keyrings[0].type = HardwareKeyringTypes.imported; expect(selectors.isHardwareWallet(mockState)).toBe(false); }); it('returns true if it is a Ledger HW wallet', () => { - mockState.metamask.keyrings[0].type = KEYRING_TYPES.LEDGER; + mockState.metamask.keyrings[0].type = HardwareKeyringTypes.ledger; expect(selectors.isHardwareWallet(mockState)).toBe(true); }); it('returns true if it is a Trezor HW wallet', () => { - mockState.metamask.keyrings[0].type = KEYRING_TYPES.TREZOR; + mockState.metamask.keyrings[0].type = HardwareKeyringTypes.trezor; expect(selectors.isHardwareWallet(mockState)).toBe(true); }); }); describe('#getHardwareWalletType', () => { it('returns undefined if it is not a HW wallet', () => { - mockState.metamask.keyrings[0].type = KEYRING_TYPES.IMPORTED; + mockState.metamask.keyrings[0].type = HardwareKeyringTypes.imported; expect(selectors.getHardwareWalletType(mockState)).toBeUndefined(); }); it('returns "Ledger Hardware" if it is a Ledger HW wallet', () => { - mockState.metamask.keyrings[0].type = KEYRING_TYPES.LEDGER; + mockState.metamask.keyrings[0].type = HardwareKeyringTypes.ledger; expect(selectors.getHardwareWalletType(mockState)).toBe( - KEYRING_TYPES.LEDGER, + HardwareKeyringTypes.ledger, ); }); it('returns "Trezor Hardware" if it is a Trezor HW wallet', () => { - mockState.metamask.keyrings[0].type = KEYRING_TYPES.TREZOR; + mockState.metamask.keyrings[0].type = HardwareKeyringTypes.trezor; expect(selectors.getHardwareWalletType(mockState)).toBe( - KEYRING_TYPES.TREZOR, + HardwareKeyringTypes.trezor, ); }); }); @@ -87,7 +87,7 @@ describe('Selectors', () => { ...mockState.metamask, keyrings: [ { - type: KEYRING_TYPES.LEDGER, + type: HardwareKeyringTypes.ledger, accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'], }, ], diff --git a/ui/store/actions.js b/ui/store/actions.js index 21cdc6289..1f039b3e2 100644 --- a/ui/store/actions.js +++ b/ui/store/actions.js @@ -30,8 +30,8 @@ import { switchedToUnconnectedAccount } from '../ducks/alerts/unconnected-accoun import { getUnconnectedAccountAlertEnabledness } from '../ducks/metamask/metamask'; import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils'; import { - DEVICE_NAMES, - LEDGER_TRANSPORT_TYPES, + HardwareDeviceNames, + LedgerTransportTypes, LEDGER_USB_VENDOR_ID, } from '../../shared/constants/hardware-wallets'; import { EVENT } from '../../shared/constants/metametrics'; @@ -425,12 +425,12 @@ export function connectHardware(deviceName, page, hdPath, t) { let accounts; try { - if (deviceName === DEVICE_NAMES.LEDGER) { + if (deviceName === HardwareDeviceNames.ledger) { await submitRequestToBackground('establishLedgerTransportPreference'); } if ( - deviceName === DEVICE_NAMES.LEDGER && - ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID + deviceName === HardwareDeviceNames.ledger && + ledgerTransportType === LedgerTransportTypes.webhid ) { const connectedDevices = await window.navigator.hid.requestDevice({ filters: [{ vendorId: LEDGER_USB_VENDOR_ID }], @@ -451,14 +451,14 @@ export function connectHardware(deviceName, page, hdPath, t) { } catch (error) { log.error(error); if ( - deviceName === DEVICE_NAMES.LEDGER && - ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID && + deviceName === HardwareDeviceNames.ledger && + ledgerTransportType === LedgerTransportTypes.webhid && error.message.match('Failed to open the device') ) { dispatch(displayWarning(t('ledgerDeviceOpenFailureMessage'))); throw new Error(t('ledgerDeviceOpenFailureMessage')); } else { - if (deviceName !== DEVICE_NAMES.QR) { + if (deviceName !== HardwareDeviceNames.qr) { dispatch(displayWarning(error.message)); } throw error; diff --git a/ui/store/actions.test.js b/ui/store/actions.test.js index 3015521ba..985b278fa 100644 --- a/ui/store/actions.test.js +++ b/ui/store/actions.test.js @@ -4,7 +4,7 @@ import thunk from 'redux-thunk'; import enLocale from '../../app/_locales/en/messages.json'; import MetaMaskController from '../../app/scripts/metamask-controller'; import { TransactionStatus } from '../../shared/constants/transaction'; -import { DEVICE_NAMES } from '../../shared/constants/hardware-wallets'; +import { HardwareDeviceNames } from '../../shared/constants/hardware-wallets'; import { GAS_LIMITS } from '../../shared/constants/gas'; import * as actions from './actions'; import { _setBackgroundConnection } from './action-queue'; @@ -443,7 +443,10 @@ describe('Actions', () => { _setBackgroundConnection(background); await store.dispatch( - actions.checkHardwareStatus(DEVICE_NAMES.LEDGER, `m/44'/60'/0'/0`), + actions.checkHardwareStatus( + HardwareDeviceNames.ledger, + `m/44'/60'/0'/0`, + ), ); expect(checkHardwareStatus.callCount).toStrictEqual(1); }); @@ -483,7 +486,7 @@ describe('Actions', () => { _setBackgroundConnection(background); - await store.dispatch(actions.forgetDevice(DEVICE_NAMES.LEDGER)); + await store.dispatch(actions.forgetDevice(HardwareDeviceNames.ledger)); expect(forgetDevice.callCount).toStrictEqual(1); }); @@ -525,7 +528,11 @@ describe('Actions', () => { _setBackgroundConnection(background); await store.dispatch( - actions.connectHardware(DEVICE_NAMES.LEDGER, 0, `m/44'/60'/0'/0`), + actions.connectHardware( + HardwareDeviceNames.ledger, + 0, + `m/44'/60'/0'/0`, + ), ); expect(connectHardware.callCount).toStrictEqual(1); }); @@ -551,7 +558,7 @@ describe('Actions', () => { ]; await expect( - store.dispatch(actions.connectHardware(DEVICE_NAMES.LEDGER)), + store.dispatch(actions.connectHardware(HardwareDeviceNames.ledger)), ).rejects.toThrow('error'); expect(store.getActions()).toStrictEqual(expectedActions); @@ -575,7 +582,7 @@ describe('Actions', () => { await store.dispatch( actions.unlockHardwareWalletAccounts( [0], - DEVICE_NAMES.LEDGER, + HardwareDeviceNames.ledger, `m/44'/60'/0'/0`, '', ),