mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Use hardware constants everywhere (#12329)
This commit is contained in:
parent
77f8ec4d3a
commit
72a3db7c0c
@ -9,6 +9,7 @@ import proxyquire from 'proxyquire';
|
|||||||
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_TYPE_RPC } from '../../shared/constants/network';
|
import { NETWORK_TYPE_RPC } from '../../shared/constants/network';
|
||||||
|
import { KEYRING_TYPES } 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');
|
||||||
@ -506,11 +507,11 @@ describe('MetaMaskController', function () {
|
|||||||
sinon.spy(metamaskController.keyringController, 'addNewKeyring');
|
sinon.spy(metamaskController.keyringController, 'addNewKeyring');
|
||||||
await metamaskController.connectHardware('trezor', 0).catch(() => null);
|
await metamaskController.connectHardware('trezor', 0).catch(() => null);
|
||||||
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
||||||
'Trezor Hardware',
|
KEYRING_TYPES.TREZOR,
|
||||||
);
|
);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
metamaskController.keyringController.addNewKeyring.getCall(0).args,
|
metamaskController.keyringController.addNewKeyring.getCall(0).args,
|
||||||
['Trezor Hardware'],
|
[KEYRING_TYPES.TREZOR],
|
||||||
);
|
);
|
||||||
assert.equal(keyrings.length, 1);
|
assert.equal(keyrings.length, 1);
|
||||||
});
|
});
|
||||||
@ -519,11 +520,11 @@ describe('MetaMaskController', function () {
|
|||||||
sinon.spy(metamaskController.keyringController, 'addNewKeyring');
|
sinon.spy(metamaskController.keyringController, 'addNewKeyring');
|
||||||
await metamaskController.connectHardware('ledger', 0).catch(() => null);
|
await metamaskController.connectHardware('ledger', 0).catch(() => null);
|
||||||
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
||||||
'Ledger Hardware',
|
KEYRING_TYPES.LEDGER,
|
||||||
);
|
);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
metamaskController.keyringController.addNewKeyring.getCall(0).args,
|
metamaskController.keyringController.addNewKeyring.getCall(0).args,
|
||||||
['Ledger Hardware'],
|
[KEYRING_TYPES.LEDGER],
|
||||||
);
|
);
|
||||||
assert.equal(keyrings.length, 1);
|
assert.equal(keyrings.length, 1);
|
||||||
});
|
});
|
||||||
@ -567,7 +568,7 @@ describe('MetaMaskController', function () {
|
|||||||
await metamaskController.connectHardware('trezor', 0).catch(() => null);
|
await metamaskController.connectHardware('trezor', 0).catch(() => null);
|
||||||
await metamaskController.forgetDevice('trezor');
|
await metamaskController.forgetDevice('trezor');
|
||||||
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
||||||
'Trezor Hardware',
|
KEYRING_TYPES.TREZOR,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.deepEqual(keyrings[0].accounts, []);
|
assert.deepEqual(keyrings[0].accounts, []);
|
||||||
@ -626,7 +627,7 @@ describe('MetaMaskController', function () {
|
|||||||
|
|
||||||
it('should set unlockedAccount in the keyring', async function () {
|
it('should set unlockedAccount in the keyring', async function () {
|
||||||
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
const keyrings = await metamaskController.keyringController.getKeyringsByType(
|
||||||
'Trezor Hardware',
|
KEYRING_TYPES.TREZOR,
|
||||||
);
|
);
|
||||||
assert.equal(keyrings[0].unlockedAccount, accountToUnlock);
|
assert.equal(keyrings[0].unlockedAccount, accountToUnlock);
|
||||||
});
|
});
|
||||||
|
@ -10,6 +10,7 @@ import Identicon from '../../ui/identicon';
|
|||||||
import SiteIcon from '../../ui/site-icon';
|
import SiteIcon from '../../ui/site-icon';
|
||||||
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display';
|
||||||
import { PRIMARY } from '../../../helpers/constants/common';
|
import { PRIMARY } from '../../../helpers/constants/common';
|
||||||
|
import { KEYRING_TYPES } from '../../../../shared/constants/hardware-wallets';
|
||||||
import {
|
import {
|
||||||
SETTINGS_ROUTE,
|
SETTINGS_ROUTE,
|
||||||
NEW_ACCOUNT_ROUTE,
|
NEW_ACCOUNT_ROUTE,
|
||||||
@ -233,8 +234,8 @@ export default class AccountMenu extends Component {
|
|||||||
let label;
|
let label;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'Trezor Hardware':
|
case KEYRING_TYPES.TREZOR:
|
||||||
case 'Ledger Hardware':
|
case KEYRING_TYPES.LEDGER:
|
||||||
label = t('hardware');
|
label = t('hardware');
|
||||||
break;
|
break;
|
||||||
case 'Simple Key Pair':
|
case 'Simple Key Pair':
|
||||||
|
@ -140,8 +140,8 @@ export function getAccountType(state) {
|
|||||||
const type = currentKeyring && currentKeyring.type;
|
const type = currentKeyring && currentKeyring.type;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'Trezor Hardware':
|
case KEYRING_TYPES.TREZOR:
|
||||||
case 'Ledger Hardware':
|
case KEYRING_TYPES.LEDGER:
|
||||||
return 'hardware';
|
return 'hardware';
|
||||||
case 'Simple Key Pair':
|
case 'Simple Key Pair':
|
||||||
return 'imported';
|
return 'imported';
|
||||||
|
@ -1,4 +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 * as selectors from './selectors';
|
import * as selectors from './selectors';
|
||||||
|
|
||||||
describe('Selectors', () => {
|
describe('Selectors', () => {
|
||||||
@ -22,12 +23,12 @@ describe('Selectors', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns true if it is a Ledger HW wallet', () => {
|
it('returns true if it is a Ledger HW wallet', () => {
|
||||||
mockState.metamask.keyrings[0].type = 'Ledger Hardware';
|
mockState.metamask.keyrings[0].type = KEYRING_TYPES.LEDGER;
|
||||||
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns true if it is a Trezor HW wallet', () => {
|
it('returns true if it is a Trezor HW wallet', () => {
|
||||||
mockState.metamask.keyrings[0].type = 'Trezor Hardware';
|
mockState.metamask.keyrings[0].type = KEYRING_TYPES.TREZOR;
|
||||||
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -39,16 +40,16 @@ describe('Selectors', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns "Ledger Hardware" if it is a Ledger HW wallet', () => {
|
it('returns "Ledger Hardware" if it is a Ledger HW wallet', () => {
|
||||||
mockState.metamask.keyrings[0].type = 'Ledger Hardware';
|
mockState.metamask.keyrings[0].type = KEYRING_TYPES.LEDGER;
|
||||||
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
||||||
'Ledger Hardware',
|
KEYRING_TYPES.LEDGER,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns "Trezor Hardware" if it is a Trezor HW wallet', () => {
|
it('returns "Trezor Hardware" if it is a Trezor HW wallet', () => {
|
||||||
mockState.metamask.keyrings[0].type = 'Trezor Hardware';
|
mockState.metamask.keyrings[0].type = KEYRING_TYPES.TREZOR;
|
||||||
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
||||||
'Trezor Hardware',
|
KEYRING_TYPES.TREZOR,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -86,7 +87,7 @@ describe('Selectors', () => {
|
|||||||
...mockState.metamask,
|
...mockState.metamask,
|
||||||
keyrings: [
|
keyrings: [
|
||||||
{
|
{
|
||||||
type: 'Ledger Hardware',
|
type: KEYRING_TYPES.LEDGER,
|
||||||
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -126,7 +127,7 @@ describe('Selectors', () => {
|
|||||||
...mockState.metamask,
|
...mockState.metamask,
|
||||||
keyrings: [
|
keyrings: [
|
||||||
{
|
{
|
||||||
type: 'Trezor Hardware',
|
type: KEYRING_TYPES.TREZOR,
|
||||||
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
accounts: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user