1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Create constants for all keyring types (#16575)

This commit is contained in:
David Walsh 2022-11-21 08:23:35 -06:00 committed by GitHub
parent 8a529bca47
commit 9530797a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 77 additions and 52 deletions

View File

@ -1,4 +1,6 @@
import { draftTransactionInitialState } from '../ui/ducks/send'; import { draftTransactionInitialState } from '../ui/ducks/send';
import { KEYRING_TYPES } from '../shared/constants/keyrings';
const state = { const state = {
invalidCustomNetwork: { invalidCustomNetwork: {
state: 'CLOSED', state: 'CLOSED',
@ -1114,14 +1116,14 @@ const state = {
unapprovedTypedMessages: {}, unapprovedTypedMessages: {},
unapprovedTypedMessagesCount: 0, unapprovedTypedMessagesCount: 0,
keyringTypes: [ keyringTypes: [
'Simple Key Pair', KEYRING_TYPES.IMPORTED,
'HD Key Tree', KEYRING_TYPES.HD_KEY_TREE,
'Trezor Hardware', KEYRING_TYPES.TREZOR,
'Ledger Hardware', KEYRING_TYPES.LEDGER,
], ],
keyrings: [ keyrings: [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: [ accounts: [
'0x64a845a5b02460acf8a3d84503b0d68d028b4bb4', '0x64a845a5b02460acf8a3d84503b0d68d028b4bb4',
'0xb19ac54efa18cc3a14a5b821bfec73d284bf0c5e', '0xb19ac54efa18cc3a14a5b821bfec73d284bf0c5e',

View File

@ -1,6 +1,8 @@
import KeyringController from 'eth-keyring-controller'; import KeyringController from 'eth-keyring-controller';
import log from 'loglevel'; import log from 'loglevel';
import { KEYRING_TYPES } from '../../../shared/constants/keyrings';
const seedPhraseVerifier = { const seedPhraseVerifier = {
/** /**
* Verifies if the seed words can restore the accounts. * Verifies if the seed words can restore the accounts.
@ -20,7 +22,9 @@ const seedPhraseVerifier = {
} }
const keyringController = new KeyringController({}); const keyringController = new KeyringController({});
const Keyring = keyringController.getKeyringClassForType('HD Key Tree'); const Keyring = keyringController.getKeyringClassForType(
KEYRING_TYPES.HD_KEY_TREE,
);
const opts = { const opts = {
mnemonic: seedPhrase, mnemonic: seedPhrase,
numberOfAccounts: createdAccounts.length, numberOfAccounts: createdAccounts.length,

View File

@ -6,12 +6,13 @@ import { cloneDeep } from 'lodash';
import KeyringController from 'eth-keyring-controller'; import KeyringController from 'eth-keyring-controller';
import firstTimeState from '../first-time-state'; import firstTimeState from '../first-time-state';
import mockEncryptor from '../../../test/lib/mock-encryptor'; import mockEncryptor from '../../../test/lib/mock-encryptor';
import { KEYRING_TYPES } from '../../../shared/constants/keyrings';
import seedPhraseVerifier from './seed-phrase-verifier'; import seedPhraseVerifier from './seed-phrase-verifier';
describe('SeedPhraseVerifier', () => { describe('SeedPhraseVerifier', () => {
describe('verifyAccounts', () => { describe('verifyAccounts', () => {
const password = 'passw0rd1'; const password = 'passw0rd1';
const hdKeyTree = 'HD Key Tree'; const hdKeyTree = KEYRING_TYPES.HD_KEY_TREE;
let keyringController; let keyringController;
let primaryKeyring; let primaryKeyring;

View File

@ -66,11 +66,9 @@ import {
GAS_DEV_API_BASE_URL, GAS_DEV_API_BASE_URL,
SWAPS_CLIENT_ID, SWAPS_CLIENT_ID,
} from '../../shared/constants/swaps'; } from '../../shared/constants/swaps';
import { KEYRING_TYPES } from '../../shared/constants/keyrings';
import { CHAIN_IDS } from '../../shared/constants/network'; import { CHAIN_IDS } from '../../shared/constants/network';
import { import { DEVICE_NAMES } from '../../shared/constants/hardware-wallets';
DEVICE_NAMES,
KEYRING_TYPES,
} from '../../shared/constants/hardware-wallets';
import { import {
CaveatTypes, CaveatTypes,
RestrictedMethods, RestrictedMethods,
@ -2136,8 +2134,9 @@ export default class MetamaskController extends EventEmitter {
ethQuery, ethQuery,
); );
const [primaryKeyring] = const [primaryKeyring] = keyringController.getKeyringsByType(
keyringController.getKeyringsByType('HD Key Tree'); KEYRING_TYPES.HD_KEY_TREE,
);
if (!primaryKeyring) { if (!primaryKeyring) {
throw new Error('MetamaskController - No HD Key Tree found'); throw new Error('MetamaskController - No HD Key Tree found');
} }
@ -2262,9 +2261,12 @@ export default class MetamaskController extends EventEmitter {
}); });
// Accounts // Accounts
const [hdKeyring] = this.keyringController.getKeyringsByType('HD Key Tree'); const [hdKeyring] = this.keyringController.getKeyringsByType(
const simpleKeyPairKeyrings = KEYRING_TYPES.HD_KEY_TREE,
this.keyringController.getKeyringsByType('Simple Key Pair'); );
const simpleKeyPairKeyrings = this.keyringController.getKeyringsByType(
KEYRING_TYPES.IMPORTED,
);
const hdAccounts = await hdKeyring.getAccounts(); const hdAccounts = await hdKeyring.getAccounts();
const simpleKeyPairKeyringAccounts = await Promise.all( const simpleKeyPairKeyringAccounts = await Promise.all(
simpleKeyPairKeyrings.map((keyring) => keyring.getAccounts()), simpleKeyPairKeyrings.map((keyring) => keyring.getAccounts()),
@ -2361,7 +2363,9 @@ export default class MetamaskController extends EventEmitter {
* Gets the mnemonic of the user's primary keyring. * Gets the mnemonic of the user's primary keyring.
*/ */
getPrimaryKeyringMnemonic() { getPrimaryKeyringMnemonic() {
const [keyring] = this.keyringController.getKeyringsByType('HD Key Tree'); const [keyring] = this.keyringController.getKeyringsByType(
KEYRING_TYPES.HD_KEY_TREE,
);
if (!keyring.mnemonic) { if (!keyring.mnemonic) {
throw new Error('Primary keyring mnemonic unavailable.'); throw new Error('Primary keyring mnemonic unavailable.');
} }
@ -2592,8 +2596,9 @@ export default class MetamaskController extends EventEmitter {
* @returns {} keyState * @returns {} keyState
*/ */
async addNewAccount(accountCount) { async addNewAccount(accountCount) {
const [primaryKeyring] = const [primaryKeyring] = this.keyringController.getKeyringsByType(
this.keyringController.getKeyringsByType('HD Key Tree'); KEYRING_TYPES.HD_KEY_TREE,
);
if (!primaryKeyring) { if (!primaryKeyring) {
throw new Error('MetamaskController - No HD Key Tree found'); throw new Error('MetamaskController - No HD Key Tree found');
} }
@ -2636,8 +2641,9 @@ export default class MetamaskController extends EventEmitter {
* encoded as an array of UTF-8 bytes. * encoded as an array of UTF-8 bytes.
*/ */
async verifySeedPhrase() { async verifySeedPhrase() {
const [primaryKeyring] = const [primaryKeyring] = this.keyringController.getKeyringsByType(
this.keyringController.getKeyringsByType('HD Key Tree'); KEYRING_TYPES.HD_KEY_TREE,
);
if (!primaryKeyring) { if (!primaryKeyring) {
throw new Error('MetamaskController - No HD Key Tree found'); throw new Error('MetamaskController - No HD Key Tree found');
} }
@ -2758,7 +2764,7 @@ export default class MetamaskController extends EventEmitter {
async importAccountWithStrategy(strategy, args) { async importAccountWithStrategy(strategy, args) {
const privateKey = await accountImporter.importAccount(strategy, args); const privateKey = await accountImporter.importAccount(strategy, args);
const keyring = await this.keyringController.addNewKeyring( const keyring = await this.keyringController.addNewKeyring(
'Simple Key Pair', KEYRING_TYPES.IMPORTED,
[privateKey], [privateKey],
); );
const [firstAccount] = await keyring.getAccounts(); const [firstAccount] = await keyring.getAccounts();

View File

@ -10,10 +10,8 @@ import browser from 'webextension-polyfill';
import { TRANSACTION_STATUSES } from '../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../shared/constants/transaction';
import createTxMeta from '../../test/lib/createTxMeta'; import createTxMeta from '../../test/lib/createTxMeta';
import { NETWORK_TYPES } from '../../shared/constants/network'; import { NETWORK_TYPES } from '../../shared/constants/network';
import { import { KEYRING_TYPES } from '../../shared/constants/keyrings';
KEYRING_TYPES, import { DEVICE_NAMES } from '../../shared/constants/hardware-wallets';
DEVICE_NAMES,
} from '../../shared/constants/hardware-wallets';
import { addHexPrefix } from './lib/util'; import { addHexPrefix } from './lib/util';
const Ganache = require('../../test/e2e/ganache'); const Ganache = require('../../test/e2e/ganache');
@ -192,7 +190,7 @@ describe('MetaMaskController', function () {
it('adds private key to keyrings in KeyringController', async function () { it('adds private key to keyrings in KeyringController', async function () {
const simpleKeyrings = const simpleKeyrings =
metamaskController.keyringController.getKeyringsByType( metamaskController.keyringController.getKeyringsByType(
'Simple Key Pair', KEYRING_TYPES.IMPORTED,
); );
const privKeyBuffer = simpleKeyrings[0].wallets[0].privateKey; const privKeyBuffer = simpleKeyrings[0].wallets[0].privateKey;
const pubKeyBuffer = simpleKeyrings[0].wallets[0].publicKey; const pubKeyBuffer = simpleKeyrings[0].wallets[0].publicKey;

View File

@ -3,12 +3,11 @@
* keyring types. Both simple and HD are treated as default but we do special * keyring types. Both simple and HD are treated as default but we do special
* case accounts managed by a hardware wallet. * case accounts managed by a hardware wallet.
*/ */
export const KEYRING_TYPES = { export const HARDWARE_KEYRING_TYPES = {
LEDGER: 'Ledger Hardware', LEDGER: 'Ledger Hardware',
TREZOR: 'Trezor Hardware', TREZOR: 'Trezor Hardware',
LATTICE: 'Lattice Hardware', LATTICE: 'Lattice Hardware',
QR: 'QR Hardware Wallet Device', QR: 'QR Hardware Wallet Device',
IMPORTED: 'Simple Key Pair',
}; };
export const DEVICE_NAMES = { export const DEVICE_NAMES = {

View File

@ -0,0 +1,7 @@
import { HARDWARE_KEYRING_TYPES } from './hardware-wallets';
export const KEYRING_TYPES = {
HD_KEY_TREE: 'HD Key Tree',
IMPORTED: 'Simple Key Pair',
...HARDWARE_KEYRING_TYPES,
};

View File

@ -1,4 +1,5 @@
import { CHAIN_IDS } from '../../shared/constants/network'; import { CHAIN_IDS } from '../../shared/constants/network';
import { KEYRING_TYPES } from '../../shared/constants/keyrings';
const createGetSmartTransactionFeesApiResponse = () => { const createGetSmartTransactionFeesApiResponse = () => {
return { return {
@ -251,10 +252,10 @@ export const createSwapsMockStore = () => {
}, },
}, },
selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
keyringTypes: ['Simple Key Pair', 'HD Key Tree'], keyringTypes: [KEYRING_TYPES.IMPORTED, KEYRING_TYPES.HD_KEY_TREE],
keyrings: [ keyrings: [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: [ accounts: [
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
'c5b8dbac4c1d3f152cdeb400e2313f309c410acb', 'c5b8dbac4c1d3f152cdeb400e2313f309c410acb',
@ -262,7 +263,7 @@ export const createSwapsMockStore = () => {
], ],
}, },
{ {
type: 'Simple Key Pair', type: KEYRING_TYPES.IMPORTED,
accounts: ['0xd85a4b6a394794842887b8284293d69163007bbb'], accounts: ['0xd85a4b6a394794842887b8284293d69163007bbb'],
}, },
], ],

View File

@ -3,6 +3,7 @@ import sinon from 'sinon';
import configureMockStore from 'redux-mock-store'; import configureMockStore from 'redux-mock-store';
import { fireEvent, screen } from '@testing-library/react'; import { fireEvent, screen } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/lib/render-helpers'; import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { KEYRING_TYPES } from '../../../../shared/constants/keyrings';
import AccountMenu from '.'; import AccountMenu from '.';
describe('Account Menu', () => { describe('Account Menu', () => {
@ -36,11 +37,11 @@ describe('Account Menu', () => {
], ],
keyrings: [ keyrings: [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: ['0xAdress'], accounts: ['0xAdress'],
}, },
{ {
type: 'Simple Key Pair', type: KEYRING_TYPES.IMPORTED,
accounts: ['0x1'], accounts: ['0x1'],
}, },
], ],

View File

@ -2,10 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useI18nContext } from '../../../hooks/useI18nContext'; import { useI18nContext } from '../../../hooks/useI18nContext';
import { import { KEYRING_TYPES } from '../../../../shared/constants/keyrings';
KEYRING_NAMES, import { KEYRING_NAMES } from '../../../../shared/constants/hardware-wallets';
KEYRING_TYPES,
} from '../../../../shared/constants/hardware-wallets';
export default function KeyRingLabel({ keyring }) { export default function KeyRingLabel({ keyring }) {
const t = useI18nContext(); const t = useI18nContext();

View File

@ -11,6 +11,8 @@ import { renderWithProvider } from '../../../../../test/lib/render-helpers';
import * as actions from '../../../../store/actions'; import * as actions from '../../../../store/actions';
import { CHAIN_IDS } from '../../../../../shared/constants/network'; import { CHAIN_IDS } from '../../../../../shared/constants/network';
import { KEYRING_TYPES } from '../../../../../shared/constants/keyrings';
import UnconnectedAccountAlert from '.'; import UnconnectedAccountAlert from '.';
describe('Unconnected Account Alert', () => { describe('Unconnected Account Alert', () => {
@ -47,7 +49,7 @@ describe('Unconnected Account Alert', () => {
const keyrings = [ const keyrings = [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: [ accounts: [
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b', '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',

View File

@ -21,6 +21,7 @@ import {
import { useI18nContext } from '../../../hooks/useI18nContext'; import { useI18nContext } from '../../../hooks/useI18nContext';
import { getEnvironmentType } from '../../../../app/scripts/lib/util'; import { getEnvironmentType } from '../../../../app/scripts/lib/util';
import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app'; import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app';
import { KEYRING_TYPES } from '../../../../shared/constants/keyrings';
import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics'; import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics';
import { MetaMetricsContext } from '../../../contexts/metametrics'; import { MetaMetricsContext } from '../../../contexts/metametrics';
@ -40,7 +41,7 @@ export default function AccountOptionsMenu({ anchorElement, onClose }) {
const trackEvent = useContext(MetaMetricsContext); const trackEvent = useContext(MetaMetricsContext);
const blockExplorerLinkText = useSelector(getBlockExplorerLinkText); const blockExplorerLinkText = useSelector(getBlockExplorerLinkText);
const isRemovable = keyring.type !== 'HD Key Tree'; const isRemovable = keyring.type !== KEYRING_TYPES.HD_KEY_TREE;
const routeToAddBlockExplorerUrl = () => { const routeToAddBlockExplorerUrl = () => {
history.push(`${NETWORKS_ROUTE}#blockExplorerUrl`); history.push(`${NETWORKS_ROUTE}#blockExplorerUrl`);

View File

@ -3,6 +3,7 @@ import configureStore from 'redux-mock-store';
import { fireEvent, screen, waitFor } from '@testing-library/react'; import { fireEvent, screen, waitFor } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/lib/render-helpers'; import { renderWithProvider } from '../../../../test/lib/render-helpers';
import { CHAIN_IDS } from '../../../../shared/constants/network'; import { CHAIN_IDS } from '../../../../shared/constants/network';
import { KEYRING_TYPES } from '../../../../shared/constants/keyrings';
import MenuBar from './menu-bar'; import MenuBar from './menu-bar';
const initState = { const initState = {
@ -20,7 +21,7 @@ const initState = {
}, },
keyrings: [ keyrings: [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'], accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
}, },
], ],

View File

@ -2,6 +2,7 @@ import React from 'react';
import configureMockStore from 'redux-mock-store'; import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk'; import thunk from 'redux-thunk';
import { renderWithProvider } from '../../../../test/jest/rendering'; import { renderWithProvider } from '../../../../test/jest/rendering';
import { KEYRING_TYPES } from '../../../../shared/constants/keyrings';
import TokenOverview from './token-overview'; import TokenOverview from './token-overview';
describe('TokenOverview', () => { describe('TokenOverview', () => {
@ -21,11 +22,11 @@ describe('TokenOverview', () => {
selectedAddress: '0x1', selectedAddress: '0x1',
keyrings: [ keyrings: [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: ['0x1', '0x2'], accounts: ['0x1', '0x2'],
}, },
{ {
type: 'Ledger Hardware', type: KEYRING_TYPES.LEDGER,
accounts: [], accounts: [],
}, },
], ],

View File

@ -15,7 +15,7 @@ import { updateTransactionGasFees } from '../../store/actions';
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck'; import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util'; import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util';
import { KEYRING_TYPES } from '../../../shared/constants/hardware-wallets'; import { KEYRING_TYPES } from '../../../shared/constants/keyrings';
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils'; import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
import { stripHexPrefix } from '../../../shared/modules/hexstring-utils'; import { stripHexPrefix } from '../../../shared/modules/hexstring-utils';

View File

@ -12,6 +12,7 @@ import {
} from '../../pages/send/send.constants'; } from '../../pages/send/send.constants';
import { CHAIN_IDS } from '../../../shared/constants/network'; import { CHAIN_IDS } from '../../../shared/constants/network';
import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas'; import { GAS_ESTIMATE_TYPES, GAS_LIMITS } from '../../../shared/constants/gas';
import { KEYRING_TYPES } from '../../../shared/constants/keyrings';
import { import {
ASSET_TYPES, ASSET_TYPES,
TOKEN_STANDARDS, TOKEN_STANDARDS,
@ -1276,7 +1277,7 @@ describe('Send Slice', () => {
identities: { '0xAddress': { address: '0xAddress' } }, identities: { '0xAddress': { address: '0xAddress' } },
keyrings: [ keyrings: [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: ['0xAddress'], accounts: ['0xAddress'],
}, },
], ],

View File

@ -8,6 +8,7 @@ import qrCode from 'qrcode-generator';
import Button from '../../components/ui/button'; import Button from '../../components/ui/button';
import LoadingScreen from '../../components/ui/loading-screen'; import LoadingScreen from '../../components/ui/loading-screen';
import { MINUTE, SECOND } from '../../../shared/constants/time'; import { MINUTE, SECOND } from '../../../shared/constants/time';
import { KEYRING_TYPES } from '../../../shared/constants/keyrings';
const PASSWORD_PROMPT_SCREEN = 'PASSWORD_PROMPT_SCREEN'; const PASSWORD_PROMPT_SCREEN = 'PASSWORD_PROMPT_SCREEN';
const REVEAL_SEED_SCREEN = 'REVEAL_SEED_SCREEN'; const REVEAL_SEED_SCREEN = 'REVEAL_SEED_SCREEN';
@ -81,7 +82,7 @@ export default class MobileSyncPage extends Component {
async exportAccounts() { async exportAccounts() {
const addresses = []; const addresses = [];
this.props.keyrings.forEach((keyring) => { this.props.keyrings.forEach((keyring) => {
if (keyring.type === 'Simple Key Pair') { if (keyring.type === KEYRING_TYPES.IMPORTED) {
addresses.push(keyring.accounts[0]); addresses.push(keyring.accounts[0]);
} }
}); });

View File

@ -7,6 +7,7 @@ import { ensInitialState } from '../../ducks/ens';
import { renderWithProvider } from '../../../test/jest'; import { renderWithProvider } from '../../../test/jest';
import { CHAIN_IDS } from '../../../shared/constants/network'; import { CHAIN_IDS } from '../../../shared/constants/network';
import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas'; import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas';
import { KEYRING_TYPES } from '../../../shared/constants/keyrings';
import { INITIAL_SEND_STATE_FOR_EXISTING_DRAFT } from '../../../test/jest/mocks'; import { INITIAL_SEND_STATE_FOR_EXISTING_DRAFT } from '../../../test/jest/mocks';
import Send from './send'; import Send from './send';
@ -68,7 +69,7 @@ const baseStore = {
selectedAddress: '0x0', selectedAddress: '0x0',
keyrings: [ keyrings: [
{ {
type: 'HD Key Tree', type: KEYRING_TYPES.HD_KEY_TREE,
accounts: ['0x0'], accounts: ['0x0'],
}, },
], ],

View File

@ -22,8 +22,8 @@ import {
CHAIN_IDS, CHAIN_IDS,
NETWORK_TYPES, NETWORK_TYPES,
} from '../../shared/constants/network'; } from '../../shared/constants/network';
import { KEYRING_TYPES } from '../../shared/constants/keyrings';
import { import {
KEYRING_TYPES,
WEBHID_CONNECTED_STATUSES, WEBHID_CONNECTED_STATUSES,
LEDGER_TRANSPORT_TYPES, LEDGER_TRANSPORT_TYPES,
TRANSPORT_STATES, TRANSPORT_STATES,
@ -243,7 +243,7 @@ export function getAccountType(state) {
case KEYRING_TYPES.LEDGER: case KEYRING_TYPES.LEDGER:
case KEYRING_TYPES.LATTICE: case KEYRING_TYPES.LATTICE:
return 'hardware'; return 'hardware';
case 'Simple Key Pair': case KEYRING_TYPES.IMPORTED:
return 'imported'; return 'imported';
default: default:
return 'default'; return 'default';

View File

@ -1,5 +1,5 @@
import mockState from '../../test/data/mock-state.json'; import mockState from '../../test/data/mock-state.json';
import { KEYRING_TYPES } from '../../shared/constants/hardware-wallets'; import { KEYRING_TYPES } from '../../shared/constants/keyrings';
import * as selectors from './selectors'; import * as selectors from './selectors';
describe('Selectors', () => { describe('Selectors', () => {
@ -18,7 +18,7 @@ describe('Selectors', () => {
describe('#isHardwareWallet', () => { describe('#isHardwareWallet', () => {
it('returns false if it is not a HW wallet', () => { it('returns false if it is not a HW wallet', () => {
mockState.metamask.keyrings[0].type = 'Simple Key Pair'; mockState.metamask.keyrings[0].type = KEYRING_TYPES.IMPORTED;
expect(selectors.isHardwareWallet(mockState)).toBe(false); expect(selectors.isHardwareWallet(mockState)).toBe(false);
}); });
@ -35,7 +35,7 @@ describe('Selectors', () => {
describe('#getHardwareWalletType', () => { describe('#getHardwareWalletType', () => {
it('returns undefined if it is not a HW wallet', () => { it('returns undefined if it is not a HW wallet', () => {
mockState.metamask.keyrings[0].type = 'Simple Key Pair'; mockState.metamask.keyrings[0].type = KEYRING_TYPES.IMPORTED;
expect(selectors.getHardwareWalletType(mockState)).toBeUndefined(); expect(selectors.getHardwareWalletType(mockState)).toBeUndefined();
}); });