From a4c0133bc5e8e9d38b0aba875775d083c758c8eb Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Wed, 1 Sep 2021 13:55:06 -0230 Subject: [PATCH] 1559 ledger (#11951) * EIP-1559 - Provide support for Ledger * Update ui/selectors/selectors.js Co-authored-by: Mark Stacey * Add shared constants for hw types * bump eth-ledger-bridge-keyring to v0.7.0 Co-authored-by: David Walsh Co-authored-by: Mark Stacey Co-authored-by: Alex --- app/scripts/metamask-controller.js | 16 ++-------------- package.json | 2 +- shared/constants/hardware-wallets.js | 9 +++++++++ ui/selectors/selectors.js | 6 ++++-- yarn.lock | 14 ++++++-------- 5 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 shared/constants/hardware-wallets.js diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b094e8836..804a73542 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -29,6 +29,7 @@ import { } from '@metamask/controllers'; import { TRANSACTION_STATUSES } from '../../shared/constants/transaction'; import { MAINNET_CHAIN_ID } from '../../shared/constants/network'; +import { KEYRING_TYPES } from '../../shared/constants/hardware-wallets'; import { UI_NOTIFICATIONS } from '../../shared/notifications'; import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils'; import { MILLISECOND } from '../../shared/constants/time'; @@ -79,16 +80,6 @@ export const METAMASK_CONTROLLER_EVENTS = { APPROVAL_STATE_CHANGE: 'ApprovalController:stateChange', }; -/** - * Accounts can be instantiated from simple, HD or the two hardware wallet - * keyring types. Both simple and HD are treated as default but we do special - * case accounts managed by a hardware wallet. - */ -const KEYRING_TYPES = { - LEDGER: 'Ledger Hardware', - TREZOR: 'Trezor Hardware', -}; - export default class MetamaskController extends EventEmitter { /** * @constructor @@ -2083,10 +2074,7 @@ export default class MetamaskController extends EventEmitter { const address = fromAddress || this.preferencesController.getSelectedAddress(); const keyring = await this.keyringController.getKeyringForAccount(address); - return ( - keyring.type !== KEYRING_TYPES.LEDGER && - keyring.type !== KEYRING_TYPES.TREZOR - ); + return keyring.type !== KEYRING_TYPES.TREZOR; } //============================================================================= diff --git a/package.json b/package.json index e9c8d43f9..20459f35b 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,7 @@ "@material-ui/core": "^4.11.0", "@metamask/contract-metadata": "^1.28.0", "@metamask/controllers": "^15.0.0", - "@metamask/eth-ledger-bridge-keyring": "^0.6.0", + "@metamask/eth-ledger-bridge-keyring": "^0.7.0", "@metamask/eth-token-tracker": "^3.0.1", "@metamask/etherscan-link": "^2.1.0", "@metamask/jazzicon": "^2.0.0", diff --git a/shared/constants/hardware-wallets.js b/shared/constants/hardware-wallets.js new file mode 100644 index 000000000..880efb5b2 --- /dev/null +++ b/shared/constants/hardware-wallets.js @@ -0,0 +1,9 @@ +/** + * Accounts can be instantiated from simple, HD or the two 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 KEYRING_TYPES = { + LEDGER: 'Ledger Hardware', + TREZOR: 'Trezor Hardware', +}; diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index a7c3fbed7..48e1ab2f5 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -8,6 +8,7 @@ import { NETWORK_TYPE_RPC, NATIVE_CURRENCY_TOKEN_IMAGE_MAP, } from '../../shared/constants/network'; +import { KEYRING_TYPES } from '../../shared/constants/hardware-wallets'; import { SWAPS_CHAINID_DEFAULT_TOKEN_MAP, @@ -82,8 +83,9 @@ export function getCurrentKeyring(state) { } export function isEIP1559Account(state) { - // Neither hardware wallet supports 1559 at this time - return !isHardwareWallet(state); + // Trezor does not support 1559 at this time + const currentKeyring = getCurrentKeyring(state); + return currentKeyring && currentKeyring.type !== KEYRING_TYPES.TREZOR; } export function checkNetworkAndAccountSupports1559(state) { diff --git a/yarn.lock b/yarn.lock index a2f2d2cb2..12d5abe0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1564,7 +1564,7 @@ crc-32 "^1.2.0" ethereumjs-util "^7.1.0" -"@ethereumjs/tx@^3.1.1", "@ethereumjs/tx@^3.1.4", "@ethereumjs/tx@^3.2.1", "@ethereumjs/tx@^3.3.0": +"@ethereumjs/tx@^3.1.4", "@ethereumjs/tx@^3.2.0", "@ethereumjs/tx@^3.2.1", "@ethereumjs/tx@^3.3.0": version "3.3.0" resolved "https://registry.yarnpkg.com/@ethereumjs/tx/-/tx-3.3.0.tgz#14ed1b7fa0f28e1cd61e3ecbdab824205f6a4378" integrity sha512-yTwEj2lVzSMgE6Hjw9Oa1DZks/nKTWM8Wn4ykDNapBPua2f4nXO3qKnni86O6lgDj5fVNRqbDsD0yy7/XNGDEA== @@ -2814,16 +2814,14 @@ resolved "https://registry.yarnpkg.com/@metamask/eslint-config/-/eslint-config-6.0.0.tgz#ec53e8ab278073e882411ed89705bc7d06b78c81" integrity sha512-LyakGYGwM8UQOGhwWa+5erAI1hXuiTgf/y7USzOomX6H9KiuY09IAUYnPh7ToPG2sedD2F48UF1bUm8yvCoZOw== -"@metamask/eth-ledger-bridge-keyring@^0.6.0": - version "0.6.0" - resolved "https://registry.yarnpkg.com/@metamask/eth-ledger-bridge-keyring/-/eth-ledger-bridge-keyring-0.6.0.tgz#2f1344eb76bf880c8cfbb92b9b64510920c7e335" - integrity sha512-eP0f8Q7o5K35wVinK2EjEw/gVY/pvzkAcbk49CwQEzGPKm6d+AAURJZ0o33/8gYGIrpq4bmWZhZzgyAbphgVLw== +"@metamask/eth-ledger-bridge-keyring@^0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@metamask/eth-ledger-bridge-keyring/-/eth-ledger-bridge-keyring-0.7.0.tgz#7d80e1e3dfab91ba2b6a1a2a5e352320e948b568" + integrity sha512-0UOEb/c3/fkatDK+se3gOHaGQ0RTRLbG5DqsoeowZ/JcO4wcMxBhOiIgOY4domOqUTekKKVPNC7Pc0mHpM9sAQ== dependencies: - "@ethereumjs/tx" "^3.1.1" + "@ethereumjs/tx" "^3.2.0" eth-sig-util "^2.0.0" - ethereumjs-tx "^1.3.4" ethereumjs-util "^7.0.9" - events "^2.0.0" hdkey "0.8.0" "@metamask/eth-token-tracker@^3.0.1":