mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 17:33:23 +01:00
Refactor KeyringTypes constant (#17490)
The `HardwareKeyringTypes` constant has been renamed to `KeyringTypes` and moved to a separate constants module, to reflect that it contains more than just hardware wallet keyring types. This corrects a mistake made recently during a TypeScript conversion.
This commit is contained in:
parent
a854cfdb93
commit
d6b49ae383
@ -1,5 +1,5 @@
|
||||
import { draftTransactionInitialState } from '../ui/ducks/send';
|
||||
import { HardwareKeyringTypes } from '../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../shared/constants/keyring';
|
||||
|
||||
const state = {
|
||||
invalidCustomNetwork: {
|
||||
@ -1168,14 +1168,14 @@ const state = {
|
||||
unapprovedTypedMessages: {},
|
||||
unapprovedTypedMessagesCount: 0,
|
||||
keyringTypes: [
|
||||
HardwareKeyringTypes.imported,
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
HardwareKeyringTypes.trezor,
|
||||
HardwareKeyringTypes.ledger,
|
||||
KeyringType.imported,
|
||||
KeyringType.hdKeyTree,
|
||||
KeyringType.trezor,
|
||||
KeyringType.ledger,
|
||||
],
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: [
|
||||
'0x64a845a5b02460acf8a3d84503b0d68d028b4bb4',
|
||||
'0xb19ac54efa18cc3a14a5b821bfec73d284bf0c5e',
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { KeyringController } from '@metamask/eth-keyring-controller';
|
||||
import log from 'loglevel';
|
||||
|
||||
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
|
||||
const seedPhraseVerifier = {
|
||||
/**
|
||||
@ -23,7 +23,7 @@ const seedPhraseVerifier = {
|
||||
|
||||
const keyringController = new KeyringController({});
|
||||
const keyringBuilder = keyringController.getKeyringBuilderForType(
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
KeyringType.hdKeyTree,
|
||||
);
|
||||
const keyring = keyringBuilder();
|
||||
const opts = {
|
||||
|
@ -6,13 +6,13 @@ import { cloneDeep } from 'lodash';
|
||||
import { KeyringController } from '@metamask/eth-keyring-controller';
|
||||
import firstTimeState from '../first-time-state';
|
||||
import mockEncryptor from '../../../test/lib/mock-encryptor';
|
||||
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
import seedPhraseVerifier from './seed-phrase-verifier';
|
||||
|
||||
describe('SeedPhraseVerifier', () => {
|
||||
describe('verifyAccounts', () => {
|
||||
const password = 'passw0rd1';
|
||||
const { hdKeyTree } = HardwareKeyringTypes;
|
||||
const { hdKeyTree } = KeyringType;
|
||||
|
||||
let keyringController;
|
||||
let primaryKeyring;
|
||||
|
@ -74,10 +74,8 @@ import {
|
||||
SWAPS_CLIENT_ID,
|
||||
} from '../../shared/constants/swaps';
|
||||
import { CHAIN_IDS, NETWORK_TYPES } from '../../shared/constants/network';
|
||||
import {
|
||||
HardwareDeviceNames,
|
||||
HardwareKeyringTypes,
|
||||
} from '../../shared/constants/hardware-wallets';
|
||||
import { HardwareDeviceNames } from '../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../shared/constants/keyring';
|
||||
import {
|
||||
CaveatTypes,
|
||||
RestrictedMethods,
|
||||
@ -2372,7 +2370,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
);
|
||||
|
||||
const [primaryKeyring] = keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
KeyringType.hdKeyTree,
|
||||
);
|
||||
if (!primaryKeyring) {
|
||||
throw new Error('MetamaskController - No HD Key Tree found');
|
||||
@ -2496,10 +2494,10 @@ export default class MetamaskController extends EventEmitter {
|
||||
|
||||
// Accounts
|
||||
const [hdKeyring] = this.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
KeyringType.hdKeyTree,
|
||||
);
|
||||
const simpleKeyPairKeyrings = this.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
KeyringType.hdKeyTree,
|
||||
);
|
||||
const hdAccounts = await hdKeyring.getAccounts();
|
||||
const simpleKeyPairKeyringAccounts = await Promise.all(
|
||||
@ -2663,7 +2661,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
*/
|
||||
getPrimaryKeyringMnemonic() {
|
||||
const [keyring] = this.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
KeyringType.hdKeyTree,
|
||||
);
|
||||
if (!keyring.mnemonic) {
|
||||
throw new Error('Primary keyring mnemonic unavailable.');
|
||||
@ -2803,12 +2801,12 @@ export default class MetamaskController extends EventEmitter {
|
||||
async getAccountType(address) {
|
||||
const keyring = await this.keyringController.getKeyringForAccount(address);
|
||||
switch (keyring.type) {
|
||||
case HardwareKeyringTypes.trezor:
|
||||
case HardwareKeyringTypes.lattice:
|
||||
case HardwareKeyringTypes.qr:
|
||||
case HardwareKeyringTypes.ledger:
|
||||
case KeyringType.trezor:
|
||||
case KeyringType.lattice:
|
||||
case KeyringType.qr:
|
||||
case KeyringType.ledger:
|
||||
return 'hardware';
|
||||
case HardwareKeyringTypes.imported:
|
||||
case KeyringType.imported:
|
||||
return 'imported';
|
||||
default:
|
||||
return 'MetaMask';
|
||||
@ -2826,14 +2824,14 @@ export default class MetamaskController extends EventEmitter {
|
||||
async getDeviceModel(address) {
|
||||
const keyring = await this.keyringController.getKeyringForAccount(address);
|
||||
switch (keyring.type) {
|
||||
case HardwareKeyringTypes.trezor:
|
||||
case KeyringType.trezor:
|
||||
return keyring.getModel();
|
||||
case HardwareKeyringTypes.qr:
|
||||
case KeyringType.qr:
|
||||
return keyring.getName();
|
||||
case HardwareKeyringTypes.ledger:
|
||||
case KeyringType.ledger:
|
||||
// TODO: get model after ledger keyring exposes method
|
||||
return HardwareDeviceNames.ledger;
|
||||
case HardwareKeyringTypes.lattice:
|
||||
case KeyringType.lattice:
|
||||
// TODO: get model after lattice keyring exposes method
|
||||
return HardwareDeviceNames.lattice;
|
||||
default:
|
||||
@ -2907,7 +2905,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
*/
|
||||
async addNewAccount(accountCount) {
|
||||
const [primaryKeyring] = this.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
KeyringType.hdKeyTree,
|
||||
);
|
||||
if (!primaryKeyring) {
|
||||
throw new Error('MetamaskController - No HD Key Tree found');
|
||||
@ -2952,7 +2950,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
*/
|
||||
async verifySeedPhrase() {
|
||||
const [primaryKeyring] = this.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
KeyringType.hdKeyTree,
|
||||
);
|
||||
if (!primaryKeyring) {
|
||||
throw new Error('MetamaskController - No HD Key Tree found');
|
||||
@ -3074,7 +3072,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
async importAccountWithStrategy(strategy, args) {
|
||||
const privateKey = await accountImporter.importAccount(strategy, args);
|
||||
const keyring = await this.keyringController.addNewKeyring(
|
||||
HardwareKeyringTypes.imported,
|
||||
KeyringType.imported,
|
||||
[privateKey],
|
||||
);
|
||||
const [firstAccount] = await keyring.getAccounts();
|
||||
@ -3229,7 +3227,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
const keyring = await this.keyringController.getKeyringForAccount(address);
|
||||
|
||||
switch (keyring.type) {
|
||||
case HardwareKeyringTypes.ledger: {
|
||||
case KeyringType.ledger: {
|
||||
return new Promise((_, reject) => {
|
||||
reject(
|
||||
new Error('Ledger does not support eth_getEncryptionPublicKey.'),
|
||||
@ -3237,7 +3235,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
case HardwareKeyringTypes.trezor: {
|
||||
case KeyringType.trezor: {
|
||||
return new Promise((_, reject) => {
|
||||
reject(
|
||||
new Error('Trezor does not support eth_getEncryptionPublicKey.'),
|
||||
@ -3245,7 +3243,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
case HardwareKeyringTypes.lattice: {
|
||||
case KeyringType.lattice: {
|
||||
return new Promise((_, reject) => {
|
||||
reject(
|
||||
new Error('Lattice does not support eth_getEncryptionPublicKey.'),
|
||||
@ -3253,7 +3251,7 @@ export default class MetamaskController extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
case HardwareKeyringTypes.qr: {
|
||||
case KeyringType.qr: {
|
||||
return Promise.reject(
|
||||
new Error('QR hardware does not support eth_getEncryptionPublicKey.'),
|
||||
);
|
||||
@ -4296,14 +4294,14 @@ export default class MetamaskController extends EventEmitter {
|
||||
*/
|
||||
setLocked() {
|
||||
const [trezorKeyring] = this.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.trezor,
|
||||
KeyringType.trezor,
|
||||
);
|
||||
if (trezorKeyring) {
|
||||
trezorKeyring.dispose();
|
||||
}
|
||||
|
||||
const [ledgerKeyring] = this.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.ledger,
|
||||
KeyringType.ledger,
|
||||
);
|
||||
ledgerKeyring?.destroy?.();
|
||||
|
||||
|
@ -11,10 +11,8 @@ import { TransactionStatus } from '../../shared/constants/transaction';
|
||||
import createTxMeta from '../../test/lib/createTxMeta';
|
||||
import { NETWORK_TYPES } from '../../shared/constants/network';
|
||||
import { createTestProviderTools } from '../../test/stub/provider';
|
||||
import {
|
||||
HardwareDeviceNames,
|
||||
HardwareKeyringTypes,
|
||||
} from '../../shared/constants/hardware-wallets';
|
||||
import { HardwareDeviceNames } from '../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../shared/constants/keyring';
|
||||
import { deferredPromise } from './lib/util';
|
||||
|
||||
const Ganache = require('../../test/e2e/ganache');
|
||||
@ -275,7 +273,7 @@ describe('MetaMaskController', function () {
|
||||
it('adds private key to keyrings in KeyringController', async function () {
|
||||
const simpleKeyrings =
|
||||
metamaskController.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.imported,
|
||||
KeyringType.imported,
|
||||
);
|
||||
const pubAddressHexArr = await simpleKeyrings[0].getAccounts();
|
||||
const privKeyHex = await simpleKeyrings[0].exportAccount(
|
||||
@ -555,11 +553,11 @@ describe('MetaMaskController', function () {
|
||||
.catch(() => null);
|
||||
const keyrings =
|
||||
await metamaskController.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.trezor,
|
||||
KeyringType.trezor,
|
||||
);
|
||||
assert.deepEqual(
|
||||
metamaskController.keyringController.addNewKeyring.getCall(0).args,
|
||||
[HardwareKeyringTypes.trezor],
|
||||
[KeyringType.trezor],
|
||||
);
|
||||
assert.equal(keyrings.length, 1);
|
||||
});
|
||||
@ -571,11 +569,11 @@ describe('MetaMaskController', function () {
|
||||
.catch(() => null);
|
||||
const keyrings =
|
||||
await metamaskController.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.ledger,
|
||||
KeyringType.ledger,
|
||||
);
|
||||
assert.deepEqual(
|
||||
metamaskController.keyringController.addNewKeyring.getCall(0).args,
|
||||
[HardwareKeyringTypes.ledger],
|
||||
[KeyringType.ledger],
|
||||
);
|
||||
assert.equal(keyrings.length, 1);
|
||||
});
|
||||
@ -651,7 +649,7 @@ describe('MetaMaskController', function () {
|
||||
await metamaskController.forgetDevice(HardwareDeviceNames.trezor);
|
||||
const keyrings =
|
||||
await metamaskController.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.trezor,
|
||||
KeyringType.trezor,
|
||||
);
|
||||
|
||||
assert.deepEqual(keyrings[0].accounts, []);
|
||||
@ -711,7 +709,7 @@ describe('MetaMaskController', function () {
|
||||
it('should set unlockedAccount in the keyring', async function () {
|
||||
const keyrings =
|
||||
await metamaskController.keyringController.getKeyringsByType(
|
||||
HardwareKeyringTypes.trezor,
|
||||
KeyringType.trezor,
|
||||
);
|
||||
assert.equal(keyrings[0].unlockedAccount, accountToUnlock);
|
||||
});
|
||||
|
@ -1,15 +1,11 @@
|
||||
/**
|
||||
* 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.
|
||||
* Hardware wallets supported by MetaMask.
|
||||
*/
|
||||
export enum HardwareKeyringTypes {
|
||||
export enum HardwareKeyringType {
|
||||
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 {
|
||||
|
17
shared/constants/keyring.ts
Normal file
17
shared/constants/keyring.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { HardwareKeyringType } from './hardware-wallets';
|
||||
|
||||
/**
|
||||
* These are the keyrings that are managed entirely by MetaMask.
|
||||
*/
|
||||
export enum InternalKeyringType {
|
||||
hdKeyTree = 'HD Key Tree',
|
||||
imported = 'Simple Key Pair',
|
||||
}
|
||||
|
||||
/**
|
||||
* All keyrings supported by MetaMask.
|
||||
*/
|
||||
export const KeyringType = {
|
||||
...HardwareKeyringType,
|
||||
...InternalKeyringType,
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
import { CHAIN_IDS } from '../../shared/constants/network';
|
||||
import { HardwareKeyringTypes } from '../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../shared/constants/keyring';
|
||||
|
||||
const createGetSmartTransactionFeesApiResponse = () => {
|
||||
return {
|
||||
@ -252,13 +252,10 @@ export const createSwapsMockStore = () => {
|
||||
},
|
||||
},
|
||||
selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||||
keyringTypes: [
|
||||
HardwareKeyringTypes.imported,
|
||||
HardwareKeyringTypes.hdKeyTree,
|
||||
],
|
||||
keyringTypes: [KeyringType.imported, KeyringType.hdKeyTree],
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: [
|
||||
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||||
'c5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||||
@ -266,7 +263,7 @@ export const createSwapsMockStore = () => {
|
||||
],
|
||||
},
|
||||
{
|
||||
type: HardwareKeyringTypes.imported,
|
||||
type: KeyringType.imported,
|
||||
accounts: ['0xd85a4b6a394794842887b8284293d69163007bbb'],
|
||||
},
|
||||
],
|
||||
|
@ -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 { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../../shared/constants/keyring';
|
||||
import AccountMenu from '.';
|
||||
|
||||
describe('Account Menu', () => {
|
||||
@ -37,11 +37,11 @@ describe('Account Menu', () => {
|
||||
],
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: ['0xAdress'],
|
||||
},
|
||||
{
|
||||
type: HardwareKeyringTypes.imported,
|
||||
type: KeyringType.imported,
|
||||
accounts: ['0x1'],
|
||||
},
|
||||
],
|
||||
|
@ -2,10 +2,8 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import { useI18nContext } from '../../../hooks/useI18nContext';
|
||||
import {
|
||||
HardwareKeyringNames,
|
||||
HardwareKeyringTypes,
|
||||
} from '../../../../shared/constants/hardware-wallets';
|
||||
import { HardwareKeyringNames } from '../../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../../shared/constants/keyring';
|
||||
|
||||
export default function KeyRingLabel({ keyring }) {
|
||||
const t = useI18nContext();
|
||||
@ -19,19 +17,19 @@ export default function KeyRingLabel({ keyring }) {
|
||||
const { type } = keyring;
|
||||
|
||||
switch (type) {
|
||||
case HardwareKeyringTypes.qr:
|
||||
case KeyringType.qr:
|
||||
label = HardwareKeyringNames.qr;
|
||||
break;
|
||||
case HardwareKeyringTypes.imported:
|
||||
case KeyringType.imported:
|
||||
label = t('imported');
|
||||
break;
|
||||
case HardwareKeyringTypes.trezor:
|
||||
case KeyringType.trezor:
|
||||
label = HardwareKeyringNames.trezor;
|
||||
break;
|
||||
case HardwareKeyringTypes.ledger:
|
||||
case KeyringType.ledger:
|
||||
label = HardwareKeyringNames.ledger;
|
||||
break;
|
||||
case HardwareKeyringTypes.lattice:
|
||||
case KeyringType.lattice:
|
||||
label = HardwareKeyringNames.lattice;
|
||||
break;
|
||||
default:
|
||||
|
@ -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 { HardwareKeyringTypes } from '../../../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../../../shared/constants/keyring';
|
||||
|
||||
import UnconnectedAccountAlert from '.';
|
||||
|
||||
@ -49,7 +49,7 @@ describe('Unconnected Account Alert', () => {
|
||||
|
||||
const keyrings = [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: [
|
||||
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||||
'0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b',
|
||||
|
@ -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 { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../../shared/constants/keyring';
|
||||
import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics';
|
||||
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
||||
import { ICON_NAMES } from '../../component-library';
|
||||
@ -42,7 +42,7 @@ export default function AccountOptionsMenu({ anchorElement, onClose }) {
|
||||
const trackEvent = useContext(MetaMetricsContext);
|
||||
const blockExplorerLinkText = useSelector(getBlockExplorerLinkText);
|
||||
|
||||
const isRemovable = keyring.type !== HardwareKeyringTypes.hdKeyTree;
|
||||
const isRemovable = keyring.type !== KeyringType.hdKeyTree;
|
||||
|
||||
const routeToAddBlockExplorerUrl = () => {
|
||||
history.push(`${NETWORKS_ROUTE}#blockExplorerUrl`);
|
||||
|
@ -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 { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../../shared/constants/keyring';
|
||||
import MenuBar from './menu-bar';
|
||||
|
||||
const initState = {
|
||||
@ -21,7 +21,7 @@ const initState = {
|
||||
},
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
||||
},
|
||||
],
|
||||
|
@ -4,7 +4,7 @@ import thunk from 'redux-thunk';
|
||||
import { fireEvent, waitFor } from '@testing-library/react';
|
||||
import { CHAIN_IDS } from '../../../../shared/constants/network';
|
||||
import { renderWithProvider } from '../../../../test/jest/rendering';
|
||||
import { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../../shared/constants/keyring';
|
||||
import EthOverview from './eth-overview';
|
||||
|
||||
// Mock BUYABLE_CHAINS_MAP
|
||||
@ -56,11 +56,11 @@ describe('EthOverview', () => {
|
||||
selectedAddress: '0x1',
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.imported,
|
||||
type: KeyringType.imported,
|
||||
accounts: ['0x1', '0x2'],
|
||||
},
|
||||
{
|
||||
type: HardwareKeyringTypes.ledger,
|
||||
type: KeyringType.ledger,
|
||||
accounts: [],
|
||||
},
|
||||
],
|
||||
|
@ -4,7 +4,7 @@ import thunk from 'redux-thunk';
|
||||
import { fireEvent, waitFor } from '@testing-library/react';
|
||||
import { CHAIN_IDS } from '../../../../shared/constants/network';
|
||||
import { renderWithProvider } from '../../../../test/jest/rendering';
|
||||
import { HardwareKeyringTypes } from '../../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../../shared/constants/keyring';
|
||||
import TokenOverview from './token-overview';
|
||||
|
||||
// Mock BUYABLE_CHAINS_MAP
|
||||
@ -42,11 +42,11 @@ describe('TokenOverview', () => {
|
||||
selectedAddress: '0x1',
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: ['0x1', '0x2'],
|
||||
},
|
||||
{
|
||||
type: HardwareKeyringTypes.ledger,
|
||||
type: KeyringType.ledger,
|
||||
accounts: [],
|
||||
},
|
||||
],
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
import { updateTransactionGasFees } from '../../store/actions';
|
||||
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
|
||||
|
||||
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
|
||||
import { stripHexPrefix } from '../../../shared/modules/hexstring-utils';
|
||||
import {
|
||||
@ -407,7 +407,7 @@ export function getLedgerTransportType(state) {
|
||||
export function isAddressLedger(state, address) {
|
||||
const keyring = findKeyringForAddress(state, address);
|
||||
|
||||
return keyring?.type === HardwareKeyringTypes.ledger;
|
||||
return keyring?.type === KeyringType.ledger;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -419,6 +419,6 @@ export function isAddressLedger(state, address) {
|
||||
*/
|
||||
export function doesUserHaveALedgerAccount(state) {
|
||||
return state.metamask.keyrings.some((kr) => {
|
||||
return kr.type === HardwareKeyringTypes.ledger;
|
||||
return kr.type === KeyringType.ledger;
|
||||
});
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
} from '../../pages/send/send.constants';
|
||||
import { CHAIN_IDS } from '../../../shared/constants/network';
|
||||
import { GasEstimateTypes, GAS_LIMITS } from '../../../shared/constants/gas';
|
||||
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
import {
|
||||
AssetType,
|
||||
TokenStandard,
|
||||
@ -1278,7 +1278,7 @@ describe('Send Slice', () => {
|
||||
identities: { '0xAddress': { address: '0xAddress' } },
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: ['0xAddress'],
|
||||
},
|
||||
],
|
||||
|
@ -6,7 +6,7 @@ import { renderWithProvider } from '../../../test/lib/render-helpers';
|
||||
import { setBackgroundConnection } from '../../../test/jest';
|
||||
import { INITIAL_SEND_STATE_FOR_EXISTING_DRAFT } from '../../../test/jest/mocks';
|
||||
import { GasEstimateTypes } from '../../../shared/constants/gas';
|
||||
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
import { CHAIN_IDS } from '../../../shared/constants/network';
|
||||
import { domainInitialState } from '../../ducks/domains';
|
||||
|
||||
@ -54,7 +54,7 @@ const baseStore = {
|
||||
selectedAddress: '0x0',
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: ['0x0'],
|
||||
},
|
||||
],
|
||||
|
@ -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 { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
|
||||
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 === HardwareKeyringTypes.imported) {
|
||||
if (keyring.type === KeyringType.imported) {
|
||||
addresses.push(keyring.accounts[0]);
|
||||
}
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
setBackgroundConnection,
|
||||
} from '../../../test/jest';
|
||||
import { GasEstimateTypes } from '../../../shared/constants/gas';
|
||||
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
import { INITIAL_SEND_STATE_FOR_EXISTING_DRAFT } from '../../../test/jest/mocks';
|
||||
import Send from './send';
|
||||
|
||||
@ -81,7 +81,7 @@ const baseStore = {
|
||||
selectedAddress: '0x0',
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.hdKeyTree,
|
||||
type: KeyringType.hdKeyTree,
|
||||
accounts: ['0x0'],
|
||||
},
|
||||
],
|
||||
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||
import configureMockStore from 'redux-mock-store';
|
||||
import { fireEvent } from '@testing-library/react';
|
||||
import { renderWithProvider } from '../../../test/lib/render-helpers';
|
||||
import { HardwareKeyringTypes } from '../../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../../shared/constants/keyring';
|
||||
import TokenAllowance from './token-allowance';
|
||||
|
||||
const testTokenAddress = '0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F';
|
||||
@ -65,10 +65,10 @@ const state = {
|
||||
},
|
||||
],
|
||||
unapprovedTxs: {},
|
||||
keyringTypes: [HardwareKeyringTypes.ledger],
|
||||
keyringTypes: [KeyringType.ledger],
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.ledger,
|
||||
type: KeyringType.ledger,
|
||||
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
||||
},
|
||||
],
|
||||
|
@ -26,11 +26,11 @@ import {
|
||||
NETWORK_TYPES,
|
||||
} from '../../shared/constants/network';
|
||||
import {
|
||||
HardwareKeyringTypes,
|
||||
WebHIDConnectedStatuses,
|
||||
LedgerTransportTypes,
|
||||
HardwareTransportStates,
|
||||
} from '../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../shared/constants/keyring';
|
||||
import { MESSAGE_TYPE } from '../../shared/constants/app';
|
||||
|
||||
import { TRUNCATED_NAME_CHAR_LIMIT } from '../../shared/constants/labels';
|
||||
@ -127,7 +127,7 @@ export function hasUnsignedQRHardwareTransaction(state) {
|
||||
}
|
||||
const { from } = txParams;
|
||||
const { keyrings } = state.metamask;
|
||||
const qrKeyring = keyrings.find((kr) => kr.type === HardwareKeyringTypes.qr);
|
||||
const qrKeyring = keyrings.find((kr) => kr.type === KeyringType.qr);
|
||||
if (!qrKeyring) {
|
||||
return false;
|
||||
}
|
||||
@ -145,7 +145,7 @@ export function hasUnsignedQRHardwareMessage(state) {
|
||||
}
|
||||
const { from } = msgParams;
|
||||
const { keyrings } = state.metamask;
|
||||
const qrKeyring = keyrings.find((kr) => kr.type === HardwareKeyringTypes.qr);
|
||||
const qrKeyring = keyrings.find((kr) => kr.type === KeyringType.qr);
|
||||
if (!qrKeyring) {
|
||||
return false;
|
||||
}
|
||||
@ -232,11 +232,11 @@ export function getAccountType(state) {
|
||||
const type = currentKeyring && currentKeyring.type;
|
||||
|
||||
switch (type) {
|
||||
case HardwareKeyringTypes.trezor:
|
||||
case HardwareKeyringTypes.ledger:
|
||||
case HardwareKeyringTypes.lattice:
|
||||
case KeyringType.trezor:
|
||||
case KeyringType.ledger:
|
||||
case KeyringType.lattice:
|
||||
return 'hardware';
|
||||
case HardwareKeyringTypes.imported:
|
||||
case KeyringType.imported:
|
||||
return 'imported';
|
||||
default:
|
||||
return 'default';
|
||||
@ -934,8 +934,7 @@ export const getUnreadNotificationsCount = createSelector(
|
||||
*/
|
||||
function getAllowedAnnouncementIds(state) {
|
||||
const currentKeyring = getCurrentKeyring(state);
|
||||
const currentKeyringIsLedger =
|
||||
currentKeyring?.type === HardwareKeyringTypes.ledger;
|
||||
const currentKeyringIsLedger = currentKeyring?.type === KeyringType.ledger;
|
||||
const supportsWebHid = window.navigator.hid !== undefined;
|
||||
const currentlyUsingLedgerLive =
|
||||
getLedgerTransportType(state) === LedgerTransportTypes.live;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import mockState from '../../test/data/mock-state.json';
|
||||
import { HardwareKeyringTypes } from '../../shared/constants/hardware-wallets';
|
||||
import { KeyringType } from '../../shared/constants/keyring';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
describe('Selectors', () => {
|
||||
@ -105,38 +105,38 @@ describe('Selectors', () => {
|
||||
|
||||
describe('#isHardwareWallet', () => {
|
||||
it('returns false if it is not a HW wallet', () => {
|
||||
mockState.metamask.keyrings[0].type = HardwareKeyringTypes.imported;
|
||||
mockState.metamask.keyrings[0].type = KeyringType.imported;
|
||||
expect(selectors.isHardwareWallet(mockState)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true if it is a Ledger HW wallet', () => {
|
||||
mockState.metamask.keyrings[0].type = HardwareKeyringTypes.ledger;
|
||||
mockState.metamask.keyrings[0].type = KeyringType.ledger;
|
||||
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true if it is a Trezor HW wallet', () => {
|
||||
mockState.metamask.keyrings[0].type = HardwareKeyringTypes.trezor;
|
||||
mockState.metamask.keyrings[0].type = KeyringType.trezor;
|
||||
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getHardwareWalletType', () => {
|
||||
it('returns undefined if it is not a HW wallet', () => {
|
||||
mockState.metamask.keyrings[0].type = HardwareKeyringTypes.imported;
|
||||
mockState.metamask.keyrings[0].type = KeyringType.imported;
|
||||
expect(selectors.getHardwareWalletType(mockState)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns "Ledger Hardware" if it is a Ledger HW wallet', () => {
|
||||
mockState.metamask.keyrings[0].type = HardwareKeyringTypes.ledger;
|
||||
mockState.metamask.keyrings[0].type = KeyringType.ledger;
|
||||
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
||||
HardwareKeyringTypes.ledger,
|
||||
KeyringType.ledger,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns "Trezor Hardware" if it is a Trezor HW wallet', () => {
|
||||
mockState.metamask.keyrings[0].type = HardwareKeyringTypes.trezor;
|
||||
mockState.metamask.keyrings[0].type = KeyringType.trezor;
|
||||
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
||||
HardwareKeyringTypes.trezor,
|
||||
KeyringType.trezor,
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -174,7 +174,7 @@ describe('Selectors', () => {
|
||||
...mockState.metamask,
|
||||
keyrings: [
|
||||
{
|
||||
type: HardwareKeyringTypes.ledger,
|
||||
type: KeyringType.ledger,
|
||||
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
||||
},
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user