diff --git a/app/scripts/lib/transaction/metrics.ts b/app/scripts/lib/transaction/metrics.ts index ee09d60259cd..7134407a1b73 100644 --- a/app/scripts/lib/transaction/metrics.ts +++ b/app/scripts/lib/transaction/metrics.ts @@ -1,4 +1,4 @@ -import EthQuery, { Provider } from '@metamask/eth-query'; +import type { Provider } from '@metamask/network-controller'; import { FetchGasFeeEstimateOptions } from '@metamask/gas-fee-controller'; import { BigNumber } from 'bignumber.js'; import { isHexString } from 'ethereumjs-util'; @@ -799,7 +799,6 @@ async function buildEventFragmentProperties({ id, userFeeLevel, } = transactionMeta; - const query = new EthQuery(transactionMetricsRequest.provider); const source = referrer === ORIGIN_METAMASK ? 'user' : 'dapp'; const gasFeeSelected = @@ -807,7 +806,7 @@ async function buildEventFragmentProperties({ const { assetType, tokenStandard } = await determineTransactionAssetType( transactionMeta, - query, + transactionMetricsRequest.provider, transactionMetricsRequest.getTokenStandardAndDetails, ); diff --git a/app/scripts/ui.js b/app/scripts/ui.js index 794037e12761..ec612e748e11 100644 --- a/app/scripts/ui.js +++ b/app/scripts/ui.js @@ -11,7 +11,6 @@ import 'react-devtools'; import PortStream from 'extension-port-stream'; import browser from 'webextension-polyfill'; -import Eth from '@metamask/ethjs'; import EthQuery from '@metamask/eth-query'; import StreamProvider from 'web3-stream-provider'; import log from 'loglevel'; @@ -363,7 +362,6 @@ function setupWeb3Connection(connectionStream) { providerStream.on('error', console.error.bind(console)); global.ethereumProvider = providerStream; global.ethQuery = new EthQuery(providerStream); - global.eth = new Eth(providerStream); } /** diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index 430b196d5a7f..60b9bea834de 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -282,7 +282,7 @@ "ethers>@ethersproject/keccak256": { "packages": { "@ethersproject/bytes": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "ethers>@ethersproject/logger": { @@ -965,7 +965,7 @@ }, "packages": { "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, + "@metamask/controller-utils>@metamask/ethjs-unit": true, "@metamask/utils": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "bn.js": true, @@ -1221,36 +1221,17 @@ "URL": true } }, - "@metamask/ethjs": { - "globals": { - "clearInterval": true, - "setInterval": true - }, - "packages": { - "@metamask/ethjs-contract": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-provider-http": true, - "@metamask/ethjs-query": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, - "bn.js": true, - "browserify>buffer": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true - } - }, "@metamask/ethjs-contract": { "packages": { "@babel/runtime": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true, + "@metamask/ethjs-contract>@metamask/ethjs-filter": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-contract>ethjs-abi": true, + "eth-ens-namehash>js-sha3": true, "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-filter": { + "@metamask/ethjs-contract>@metamask/ethjs-filter": { "globals": { "clearInterval": true, "setInterval": true @@ -1258,15 +1239,10 @@ }, "@metamask/ethjs-query>@metamask/ethjs-format": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "@metamask/ethjs-query>@metamask/ethjs-format>ethjs-schema": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true - } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http": { - "packages": { - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/ethjs-query": { @@ -1284,17 +1260,17 @@ "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-unit": { + "@metamask/controller-utils>@metamask/ethjs-unit": { "packages": { - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "bn.js": true } }, - "@metamask/ethjs>@metamask/ethjs-util": { + "@metamask/ethjs-contract>@metamask/ethjs-util": { "packages": { "browserify>buffer": true, - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true, + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/gas-fee-controller": { @@ -1486,10 +1462,10 @@ "uuid": true } }, - "@metamask/ethjs>@metamask/number-to-bn": { + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/object-multiplex": { @@ -3593,7 +3569,7 @@ "packages": { "bn.js": true, "buffer": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-ens-namehash": { @@ -3603,7 +3579,7 @@ "packages": { "browserify>buffer": true, "eth-ens-namehash>idna-uts46-hx": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-lattice-keyring": { @@ -3780,12 +3756,12 @@ "ethers>@ethersproject/wordlists": true } }, - "@metamask/ethjs>ethjs-abi": { + "@metamask/ethjs-contract>ethjs-abi": { "packages": { "bn.js": true, "browserify>buffer": true, - "@metamask/ethjs>js-sha3": true, - "@metamask/ethjs>ethjs-abi>number-to-bn": true + "eth-ens-namehash>js-sha3": true, + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": true } }, "webpack>events": { @@ -3911,7 +3887,7 @@ "eth-lattice-keyring>gridplus-sdk>elliptic": true, "eth-lattice-keyring>gridplus-sdk>eth-eip712-util-browser": true, "ethers>@ethersproject/sha2>hash.js": true, - "@metamask/ethjs>js-sha3": true, + "eth-ens-namehash>js-sha3": true, "lodash": true, "eth-lattice-keyring>rlp": true, "ganache>secp256k1": true, @@ -4132,7 +4108,7 @@ "browserify>buffer": true } }, - "@metamask/ethjs>js-sha3": { + "eth-ens-namehash>js-sha3": { "globals": { "define": true }, @@ -4474,10 +4450,10 @@ "fetch": true } }, - "@metamask/ethjs>ethjs-abi>number-to-bn": { + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "string.prototype.matchall>es-abstract>object-inspect": { @@ -5311,9 +5287,9 @@ "koa>content-disposition>safe-buffer": true } }, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": { + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true } }, "react-markdown>style-to-object": { @@ -5602,11 +5578,6 @@ "string.prototype.matchall>es-abstract>gopd": true, "koa>is-generator-function>has-tostringtag": true } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": { - "globals": { - "XMLHttpRequest": true - } } } } \ No newline at end of file diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index 430b196d5a7f..60b9bea834de 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -282,7 +282,7 @@ "ethers>@ethersproject/keccak256": { "packages": { "@ethersproject/bytes": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "ethers>@ethersproject/logger": { @@ -965,7 +965,7 @@ }, "packages": { "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, + "@metamask/controller-utils>@metamask/ethjs-unit": true, "@metamask/utils": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "bn.js": true, @@ -1221,36 +1221,17 @@ "URL": true } }, - "@metamask/ethjs": { - "globals": { - "clearInterval": true, - "setInterval": true - }, - "packages": { - "@metamask/ethjs-contract": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-provider-http": true, - "@metamask/ethjs-query": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, - "bn.js": true, - "browserify>buffer": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true - } - }, "@metamask/ethjs-contract": { "packages": { "@babel/runtime": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true, + "@metamask/ethjs-contract>@metamask/ethjs-filter": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-contract>ethjs-abi": true, + "eth-ens-namehash>js-sha3": true, "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-filter": { + "@metamask/ethjs-contract>@metamask/ethjs-filter": { "globals": { "clearInterval": true, "setInterval": true @@ -1258,15 +1239,10 @@ }, "@metamask/ethjs-query>@metamask/ethjs-format": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "@metamask/ethjs-query>@metamask/ethjs-format>ethjs-schema": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true - } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http": { - "packages": { - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/ethjs-query": { @@ -1284,17 +1260,17 @@ "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-unit": { + "@metamask/controller-utils>@metamask/ethjs-unit": { "packages": { - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "bn.js": true } }, - "@metamask/ethjs>@metamask/ethjs-util": { + "@metamask/ethjs-contract>@metamask/ethjs-util": { "packages": { "browserify>buffer": true, - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true, + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/gas-fee-controller": { @@ -1486,10 +1462,10 @@ "uuid": true } }, - "@metamask/ethjs>@metamask/number-to-bn": { + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/object-multiplex": { @@ -3593,7 +3569,7 @@ "packages": { "bn.js": true, "buffer": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-ens-namehash": { @@ -3603,7 +3579,7 @@ "packages": { "browserify>buffer": true, "eth-ens-namehash>idna-uts46-hx": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-lattice-keyring": { @@ -3780,12 +3756,12 @@ "ethers>@ethersproject/wordlists": true } }, - "@metamask/ethjs>ethjs-abi": { + "@metamask/ethjs-contract>ethjs-abi": { "packages": { "bn.js": true, "browserify>buffer": true, - "@metamask/ethjs>js-sha3": true, - "@metamask/ethjs>ethjs-abi>number-to-bn": true + "eth-ens-namehash>js-sha3": true, + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": true } }, "webpack>events": { @@ -3911,7 +3887,7 @@ "eth-lattice-keyring>gridplus-sdk>elliptic": true, "eth-lattice-keyring>gridplus-sdk>eth-eip712-util-browser": true, "ethers>@ethersproject/sha2>hash.js": true, - "@metamask/ethjs>js-sha3": true, + "eth-ens-namehash>js-sha3": true, "lodash": true, "eth-lattice-keyring>rlp": true, "ganache>secp256k1": true, @@ -4132,7 +4108,7 @@ "browserify>buffer": true } }, - "@metamask/ethjs>js-sha3": { + "eth-ens-namehash>js-sha3": { "globals": { "define": true }, @@ -4474,10 +4450,10 @@ "fetch": true } }, - "@metamask/ethjs>ethjs-abi>number-to-bn": { + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "string.prototype.matchall>es-abstract>object-inspect": { @@ -5311,9 +5287,9 @@ "koa>content-disposition>safe-buffer": true } }, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": { + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true } }, "react-markdown>style-to-object": { @@ -5602,11 +5578,6 @@ "string.prototype.matchall>es-abstract>gopd": true, "koa>is-generator-function>has-tostringtag": true } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": { - "globals": { - "XMLHttpRequest": true - } } } } \ No newline at end of file diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index 430b196d5a7f..60b9bea834de 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -282,7 +282,7 @@ "ethers>@ethersproject/keccak256": { "packages": { "@ethersproject/bytes": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "ethers>@ethersproject/logger": { @@ -965,7 +965,7 @@ }, "packages": { "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, + "@metamask/controller-utils>@metamask/ethjs-unit": true, "@metamask/utils": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "bn.js": true, @@ -1221,36 +1221,17 @@ "URL": true } }, - "@metamask/ethjs": { - "globals": { - "clearInterval": true, - "setInterval": true - }, - "packages": { - "@metamask/ethjs-contract": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-provider-http": true, - "@metamask/ethjs-query": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, - "bn.js": true, - "browserify>buffer": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true - } - }, "@metamask/ethjs-contract": { "packages": { "@babel/runtime": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true, + "@metamask/ethjs-contract>@metamask/ethjs-filter": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-contract>ethjs-abi": true, + "eth-ens-namehash>js-sha3": true, "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-filter": { + "@metamask/ethjs-contract>@metamask/ethjs-filter": { "globals": { "clearInterval": true, "setInterval": true @@ -1258,15 +1239,10 @@ }, "@metamask/ethjs-query>@metamask/ethjs-format": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "@metamask/ethjs-query>@metamask/ethjs-format>ethjs-schema": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true - } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http": { - "packages": { - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/ethjs-query": { @@ -1284,17 +1260,17 @@ "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-unit": { + "@metamask/controller-utils>@metamask/ethjs-unit": { "packages": { - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "bn.js": true } }, - "@metamask/ethjs>@metamask/ethjs-util": { + "@metamask/ethjs-contract>@metamask/ethjs-util": { "packages": { "browserify>buffer": true, - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true, + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/gas-fee-controller": { @@ -1486,10 +1462,10 @@ "uuid": true } }, - "@metamask/ethjs>@metamask/number-to-bn": { + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/object-multiplex": { @@ -3593,7 +3569,7 @@ "packages": { "bn.js": true, "buffer": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-ens-namehash": { @@ -3603,7 +3579,7 @@ "packages": { "browserify>buffer": true, "eth-ens-namehash>idna-uts46-hx": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-lattice-keyring": { @@ -3780,12 +3756,12 @@ "ethers>@ethersproject/wordlists": true } }, - "@metamask/ethjs>ethjs-abi": { + "@metamask/ethjs-contract>ethjs-abi": { "packages": { "bn.js": true, "browserify>buffer": true, - "@metamask/ethjs>js-sha3": true, - "@metamask/ethjs>ethjs-abi>number-to-bn": true + "eth-ens-namehash>js-sha3": true, + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": true } }, "webpack>events": { @@ -3911,7 +3887,7 @@ "eth-lattice-keyring>gridplus-sdk>elliptic": true, "eth-lattice-keyring>gridplus-sdk>eth-eip712-util-browser": true, "ethers>@ethersproject/sha2>hash.js": true, - "@metamask/ethjs>js-sha3": true, + "eth-ens-namehash>js-sha3": true, "lodash": true, "eth-lattice-keyring>rlp": true, "ganache>secp256k1": true, @@ -4132,7 +4108,7 @@ "browserify>buffer": true } }, - "@metamask/ethjs>js-sha3": { + "eth-ens-namehash>js-sha3": { "globals": { "define": true }, @@ -4474,10 +4450,10 @@ "fetch": true } }, - "@metamask/ethjs>ethjs-abi>number-to-bn": { + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "string.prototype.matchall>es-abstract>object-inspect": { @@ -5311,9 +5287,9 @@ "koa>content-disposition>safe-buffer": true } }, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": { + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true } }, "react-markdown>style-to-object": { @@ -5602,11 +5578,6 @@ "string.prototype.matchall>es-abstract>gopd": true, "koa>is-generator-function>has-tostringtag": true } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": { - "globals": { - "XMLHttpRequest": true - } } } } \ No newline at end of file diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index b5f88a04662a..eeeb07ad2268 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -282,7 +282,7 @@ "ethers>@ethersproject/keccak256": { "packages": { "@ethersproject/bytes": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "ethers>@ethersproject/logger": { @@ -1057,7 +1057,7 @@ }, "packages": { "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, + "@metamask/controller-utils>@metamask/ethjs-unit": true, "@metamask/utils": true, "@metamask/controller-utils>@spruceid/siwe-parser": true, "bn.js": true, @@ -1313,36 +1313,17 @@ "URL": true } }, - "@metamask/ethjs": { - "globals": { - "clearInterval": true, - "setInterval": true - }, - "packages": { - "@metamask/ethjs-contract": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-provider-http": true, - "@metamask/ethjs-query": true, - "@metamask/ethjs>@metamask/ethjs-unit": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, - "bn.js": true, - "browserify>buffer": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true - } - }, "@metamask/ethjs-contract": { "packages": { "@babel/runtime": true, - "@metamask/ethjs>@metamask/ethjs-filter": true, - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>ethjs-abi": true, - "@metamask/ethjs>js-sha3": true, + "@metamask/ethjs-contract>@metamask/ethjs-filter": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-contract>ethjs-abi": true, + "eth-ens-namehash>js-sha3": true, "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-filter": { + "@metamask/ethjs-contract>@metamask/ethjs-filter": { "globals": { "clearInterval": true, "setInterval": true @@ -1350,15 +1331,10 @@ }, "@metamask/ethjs-query>@metamask/ethjs-format": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util": true, - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-contract>@metamask/ethjs-util": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "@metamask/ethjs-query>@metamask/ethjs-format>ethjs-schema": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true - } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http": { - "packages": { - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/ethjs-query": { @@ -1376,17 +1352,17 @@ "promise-to-callback": true } }, - "@metamask/ethjs>@metamask/ethjs-unit": { + "@metamask/controller-utils>@metamask/ethjs-unit": { "packages": { - "@metamask/ethjs>@metamask/number-to-bn": true, + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": true, "bn.js": true } }, - "@metamask/ethjs>@metamask/ethjs-util": { + "@metamask/ethjs-contract>@metamask/ethjs-util": { "packages": { "browserify>buffer": true, - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true, + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/gas-fee-controller": { @@ -1578,10 +1554,10 @@ "uuid": true } }, - "@metamask/ethjs>@metamask/number-to-bn": { + "@metamask/ethjs-query>@metamask/ethjs-format>@metamask/number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "@metamask/object-multiplex": { @@ -3685,7 +3661,7 @@ "packages": { "bn.js": true, "buffer": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-ens-namehash": { @@ -3695,7 +3671,7 @@ "packages": { "browserify>buffer": true, "eth-ens-namehash>idna-uts46-hx": true, - "@metamask/ethjs>js-sha3": true + "eth-ens-namehash>js-sha3": true } }, "eth-lattice-keyring": { @@ -3872,12 +3848,12 @@ "ethers>@ethersproject/wordlists": true } }, - "@metamask/ethjs>ethjs-abi": { + "@metamask/ethjs-contract>ethjs-abi": { "packages": { "bn.js": true, "browserify>buffer": true, - "@metamask/ethjs>js-sha3": true, - "@metamask/ethjs>ethjs-abi>number-to-bn": true + "eth-ens-namehash>js-sha3": true, + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": true } }, "webpack>events": { @@ -4003,7 +3979,7 @@ "eth-lattice-keyring>gridplus-sdk>elliptic": true, "eth-lattice-keyring>gridplus-sdk>eth-eip712-util-browser": true, "ethers>@ethersproject/sha2>hash.js": true, - "@metamask/ethjs>js-sha3": true, + "eth-ens-namehash>js-sha3": true, "lodash": true, "eth-lattice-keyring>rlp": true, "ganache>secp256k1": true, @@ -4224,7 +4200,7 @@ "browserify>buffer": true } }, - "@metamask/ethjs>js-sha3": { + "eth-ens-namehash>js-sha3": { "globals": { "define": true }, @@ -4566,10 +4542,10 @@ "fetch": true } }, - "@metamask/ethjs>ethjs-abi>number-to-bn": { + "@metamask/ethjs-contract>ethjs-abi>number-to-bn": { "packages": { "bn.js": true, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": true + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": true } }, "string.prototype.matchall>es-abstract>object-inspect": { @@ -5403,9 +5379,9 @@ "koa>content-disposition>safe-buffer": true } }, - "@metamask/ethjs>@metamask/ethjs-util>strip-hex-prefix": { + "@metamask/ethjs-query>@metamask/ethjs-format>strip-hex-prefix": { "packages": { - "@metamask/ethjs>@metamask/ethjs-util>is-hex-prefixed": true + "@metamask/ethjs-query>@metamask/ethjs-format>is-hex-prefixed": true } }, "react-markdown>style-to-object": { @@ -5694,11 +5670,6 @@ "string.prototype.matchall>es-abstract>gopd": true, "koa>is-generator-function>has-tostringtag": true } - }, - "@metamask/ethjs>@metamask/ethjs-provider-http>xhr2": { - "globals": { - "XMLHttpRequest": true - } } } } \ No newline at end of file diff --git a/package.json b/package.json index 1e084dbda471..90462b6440e4 100644 --- a/package.json +++ b/package.json @@ -312,7 +312,6 @@ "@metamask/eth-token-tracker": "^9.0.0", "@metamask/eth-trezor-keyring": "^6.0.0", "@metamask/etherscan-link": "^3.0.0", - "@metamask/ethjs": "^0.6.0", "@metamask/ethjs-contract": "^0.4.1", "@metamask/ethjs-query": "^0.7.1", "@metamask/gas-fee-controller": "^22.0.1", diff --git a/shared/lib/four-byte.test.ts b/shared/lib/four-byte.test.ts index 77271c4aeba3..2909bc169279 100644 --- a/shared/lib/four-byte.test.ts +++ b/shared/lib/four-byte.test.ts @@ -1,4 +1,4 @@ -import { HttpProvider } from '@metamask/ethjs'; +import { JsonRpcProvider } from '@ethersproject/providers'; import nock from 'nock'; import { @@ -68,10 +68,10 @@ describe('Four Byte', () => { }); describe('getMethodDataAsync', () => { - global.ethereumProvider = new HttpProvider( - 'https://mainnet.infura.io/v3/341eacb578dd44a1a049cbc5f6fd4035', - ); it('returns a valid signature for setApprovalForAll when use4ByteResolution privacy setting is ON', async () => { + const provider = new JsonRpcProvider({ + url: 'https://mainnet.infura.io/v3/341eacb578dd44a1a049cbc5f6fd4035', + }); nock('https://www.4byte.directory:443', { encodedQueryParams: true }) .get('/api/v1/signatures/') .query({ hex_signature: '0xa22cb465' }) @@ -96,7 +96,9 @@ describe('Four Byte', () => { }, ], }); - expect(await getMethodDataAsync('0xa22cb465', true)).toStrictEqual({ + expect( + await getMethodDataAsync('0xa22cb465', true, provider), + ).toStrictEqual({ name: 'Set Approval For All', params: [{ type: 'address' }, { type: 'bool' }], }); diff --git a/shared/lib/index.d.ts b/shared/lib/index.d.ts deleted file mode 100644 index 03952d5a6c3d..000000000000 --- a/shared/lib/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module '@metamask/ethjs'; diff --git a/shared/modules/contract-utils.test.js b/shared/modules/contract-utils.test.js index 622f76d62948..eeac97c02dfc 100644 --- a/shared/modules/contract-utils.test.js +++ b/shared/modules/contract-utils.test.js @@ -1,27 +1,29 @@ +import { createTestProviderTools } from '../../test/stub/provider'; + const { readAddressAsContract } = require('./contract-utils'); describe('Contract Utils', () => { it('checks is an address is a contract address or not', async () => { - let mockEthQuery = { - getCode: (_, cb) => { - cb(null, '0xa'); + let mockProvider = createTestProviderTools({ + scaffold: { + eth_getCode: '0xa', }, - }; + }).provider; const { isContractAddress } = await readAddressAsContract( - mockEthQuery, + mockProvider, '0x76B4aa9Fc4d351a0062c6af8d186DF959D564A84', ); expect(isContractAddress).toStrictEqual(true); - mockEthQuery = { - getCode: (_, cb) => { - cb(null, '0x'); + mockProvider = createTestProviderTools({ + scaffold: { + eth_getCode: '0x', }, - }; + }).provider; const { isContractAddress: isNotContractAddress } = await readAddressAsContract( - mockEthQuery, + mockProvider, '0x76B4aa9Fc4d351a0062c6af8d186DF959D564A84', ); expect(isNotContractAddress).toStrictEqual(false); diff --git a/shared/modules/contract-utils.ts b/shared/modules/contract-utils.ts index 43e608150a1b..5faf6b9d1339 100644 --- a/shared/modules/contract-utils.ts +++ b/shared/modules/contract-utils.ts @@ -1,5 +1,6 @@ import pify from 'pify'; -import type EthQuery from '@metamask/eth-query'; +import type { Provider } from '@metamask/network-controller'; +import { addHexPrefix, padToEven } from 'ethereumjs-util'; export type Contract = { contractCode: string | null; @@ -7,14 +8,16 @@ export type Contract = { }; export const readAddressAsContract = async ( - ethQuery: EthQuery, + provider: Provider, address: string, ): Promise => { let contractCode: string | null = null; try { - if (ethQuery && 'getCode' in ethQuery) { - contractCode = await pify(ethQuery.getCode.bind(ethQuery))(address); - } + const { result } = await pify(provider.sendAsync.bind(provider))({ + method: 'eth_getCode', + params: [address, 'latest'], + }); + contractCode = addHexPrefix(padToEven(result.slice(2))); } catch (err) { // TODO(@dbrans): Dangerous to swallow errors here. contractCode = null; diff --git a/shared/modules/transaction.utils.test.js b/shared/modules/transaction.utils.test.js index 28bfaaa34ed7..c501491fce6f 100644 --- a/shared/modules/transaction.utils.test.js +++ b/shared/modules/transaction.utils.test.js @@ -1,4 +1,3 @@ -import EthQuery from '@metamask/ethjs-query'; import { TransactionType } from '@metamask/transaction-controller'; import { createTestProviderTools } from '../../test/stub/provider'; @@ -111,8 +110,7 @@ describe('Transaction.utils', function () { }); describe('determineTransactionType', function () { - const genericProvider = createTestProviderTools().provider; - const query = new EthQuery(genericProvider); + const { provider: genericProvider } = createTestProviderTools(); it('should return a simple send type when to is truthy and is not a contract address', async function () { const _providerResultStub = { @@ -121,16 +119,16 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0x', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { to: '0xabcabcabcabcabcabcabcabcabcabcabcabcabca', data: '', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.simpleSend, @@ -145,16 +143,16 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0xab', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.tokenMethodTransfer, @@ -172,9 +170,9 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0xab', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const resultWithEmptyValue = await determineTransactionType( { @@ -182,7 +180,7 @@ describe('Transaction.utils', function () { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a', }, - new EthQuery(_provider), + provider, ); expect(resultWithEmptyValue).toMatchObject({ type: TransactionType.tokenMethodTransfer, @@ -195,7 +193,7 @@ describe('Transaction.utils', function () { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a', }, - new EthQuery(_provider), + provider, ); expect(resultWithEmptyValue2).toMatchObject({ @@ -209,7 +207,7 @@ describe('Transaction.utils', function () { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a', }, - new EthQuery(_provider), + provider, ); expect(resultWithValue).toMatchObject({ type: TransactionType.contractInteraction, @@ -225,16 +223,16 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0x', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0xa9059cbb0000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C970000000000000000000000000000000000000000000000000000000000000000a', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.simpleSend, @@ -249,16 +247,16 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0xab', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.tokenMethodApprove, @@ -272,7 +270,7 @@ describe('Transaction.utils', function () { to: '', data: '0xabd', }, - query, + genericProvider, ); expect(result).toMatchObject({ type: TransactionType.deployContract, @@ -286,7 +284,7 @@ describe('Transaction.utils', function () { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0xabd', }, - query, + genericProvider, ); expect(result).toMatchObject({ type: TransactionType.simpleSend, @@ -301,16 +299,16 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: null, }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '0xabd', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.simpleSend, @@ -325,16 +323,16 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0xa', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: 'abd', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.contractInteraction, @@ -349,16 +347,16 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0xa', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { to: '0x9e673399f795D01116e9A8B2dD2F156705131ee9', data: '', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.contractInteraction, @@ -373,9 +371,9 @@ describe('Transaction.utils', function () { // by default, all accounts are external accounts (not contracts) eth_getCode: '0xa', }; - const _provider = createTestProviderTools({ + const { provider } = createTestProviderTools({ scaffold: _providerResultStub, - }).provider; + }); const result = await determineTransactionType( { @@ -383,7 +381,7 @@ describe('Transaction.utils', function () { value: '0x5af3107a4000', data: '0x095ea7b30000000000000000000000002f318C334780961FB129D2a6c30D0763d9a5C9700000000000000000000000000000000000000000000000000000000000000005', }, - new EthQuery(_provider), + provider, ); expect(result).toMatchObject({ type: TransactionType.contractInteraction, diff --git a/shared/modules/transaction.utils.ts b/shared/modules/transaction.utils.ts index eb7a987f360f..728edbca87c2 100644 --- a/shared/modules/transaction.utils.ts +++ b/shared/modules/transaction.utils.ts @@ -6,13 +6,13 @@ import { abiERC1155, abiFiatTokenV2, } from '@metamask/metamask-eth-abis'; -import type EthQuery from '@metamask/eth-query'; import log from 'loglevel'; import { TransactionMeta, TransactionType, } from '@metamask/transaction-controller'; import type { TransactionParams } from '@metamask/transaction-controller'; +import type { Provider } from '@metamask/network-controller'; import { Hex } from '@metamask/utils'; import { AssetType, TokenStandard } from '../constants/transaction'; @@ -141,12 +141,12 @@ export function parseStandardTokenTransactionData(data: string) { * at transaction creation. * * @param txParams - Parameters for the transaction - * @param query - EthQuery instance + * @param provider - Provider instance * @returns InferTransactionTypeResult */ export async function determineTransactionType( txParams: TransactionParams, - query: EthQuery, + provider: Provider, ): Promise { const { data, to } = txParams; let contractCode: string | null | undefined; @@ -159,7 +159,7 @@ export async function determineTransactionType( } if (to) { const { contractCode: resultCode, isContractAddress } = - await readAddressAsContract(query, to); + await readAddressAsContract(provider, to); contractCode = resultCode; @@ -211,13 +211,13 @@ type GetTokenStandardAndDetails = (to: string | undefined) => Promise<{ * is a token transaction. * * @param txMeta - transaction meta object - * @param query - EthQuery instance + * @param provider - Provider instance * @param getTokenStandardAndDetails - function to get token standards and details. * @returns assetType: AssetType, tokenStandard: TokenStandard */ export async function determineTransactionAssetType( txMeta: TransactionMeta, - query: EthQuery, + provider: Provider, getTokenStandardAndDetails: GetTokenStandardAndDetails, ): Promise<{ assetType: AssetType; @@ -230,7 +230,7 @@ export async function determineTransactionAssetType( // Because we will deal with all types of transactions (including swaps) // we want to get an inferrable type of transaction that isn't special cased // that way we can narrow the number of logic gates required. - const result = await determineTransactionType(txMeta.txParams, query); + const result = await determineTransactionType(txMeta.txParams, provider); inferrableType = result.type; } diff --git a/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js b/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js index 4420db36df80..ecf34922a59b 100644 --- a/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js +++ b/ui/ducks/confirm-transaction/confirm-transaction.duck.test.js @@ -1,6 +1,5 @@ import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; -import sinon from 'sinon'; import { TransactionStatus } from '@metamask/transaction-controller'; import { CHAIN_IDS } from '../../../shared/constants/network'; @@ -289,20 +288,6 @@ describe('Confirm Transaction Duck', () => { }); describe('Thunk actions', () => { - beforeEach(() => { - global.eth = { - getCode: sinon - .stub() - .callsFake((address) => - Promise.resolve(address?.match(/isContract/u) ? 'not-0x' : '0x'), - ), - }; - }); - - afterEach(function () { - global.eth.getCode.resetHistory(); - }); - it('updates txData and updates gas values in confirmTransaction', () => { const txData = { history: [], diff --git a/ui/ducks/send/helpers.js b/ui/ducks/send/helpers.js index 5fcee6f7c88b..e5426909ea23 100644 --- a/ui/ducks/send/helpers.js +++ b/ui/ducks/send/helpers.js @@ -1,5 +1,4 @@ import { addHexPrefix, toChecksumAddress } from 'ethereumjs-util'; -import abi from 'human-standard-token-abi'; import BigNumber from 'bignumber.js'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; import { getErrorMessage } from '../../../shared/modules/error'; @@ -90,12 +89,12 @@ export async function estimateGasLimitForSend({ paramsForGasEstimate.to = sendToken.address; } else { if (!data) { - // eth.getCode will return the compiled smart contract code at the + // eth_getCode will return the compiled smart contract code at the // address. If this returns 0x, 0x0 or a nullish value then the address // is an externally owned account (NOT a contract account). For these // types of transactions the gasLimit will always be 21,000 or 0x5208 const { isContractAddress } = to - ? await readAddressAsContract(global.eth, to) + ? await readAddressAsContract(global.ethereumProvider, to) : {}; if (!isContractAddress && !isNonStandardEthChain) { return GAS_LIMITS.SIMPLE; @@ -405,19 +404,6 @@ export function getRoundedGasPrice(gasPriceEstimate) { return getGasPriceInHexWei(gasPriceAsNumber); } -export async function getERC20Balance(token, accountAddress) { - const contract = global.eth.contract(abi).at(token.address); - const usersToken = (await contract.balanceOf(accountAddress)) ?? null; - if (!usersToken) { - return '0x0'; - } - const amount = calcTokenAmount( - usersToken.balance.toString(), - token.decimals, - ).toString(16); - return addHexPrefix(amount); -} - /** * returns if a given draft transaction is a swap and send * diff --git a/ui/ducks/send/send.test.js b/ui/ducks/send/send.test.js index cdb6e3ad7e94..04246dd76c55 100644 --- a/ui/ducks/send/send.test.js +++ b/ui/ducks/send/send.test.js @@ -1,4 +1,3 @@ -import sinon from 'sinon'; import createMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; import { BigNumber } from '@ethersproject/bignumber'; @@ -90,15 +89,6 @@ const mockStore = createMockStore([thunk]); const mockAddress1 = '0xdafea492d9c6733ae3d56b7ed1adb60692c98123'; const mockNftAddress1 = 'f4831105676a5fc024684d056390b8bc529daf51c7'; -jest.mock('./send', () => { - const actual = jest.requireActual('./send'); - return { - __esModule: true, - ...actual, - getERC20Balance: jest.fn(() => '0x0'), - }; -}); - jest.mock('lodash', () => ({ ...jest.requireActual('lodash'), debounce: (fn) => fn, @@ -2177,13 +2167,6 @@ describe('Send Slice', () => { decimals: 18, }), ); - global.eth = { - contract: sinon.stub().returns({ - at: sinon.stub().returns({ - balanceOf: sinon.stub().returns(undefined), - }), - }), - }; const store = mockStore(defaultSendAssetState); const newSendAsset = { @@ -2243,13 +2226,6 @@ describe('Send Slice', () => { [tokenAddress]: { hex: '0x0' }, }), ); - global.eth = { - contract: sinon.stub().returns({ - at: sinon.stub().returns({ - balanceOf: sinon.stub().returns(undefined), - }), - }), - }; const store = mockStore(defaultSendAssetState); const newSendAsset = { @@ -2482,10 +2458,6 @@ describe('Send Slice', () => { }; it('should create actions to update recipient and recalculate gas limit if the asset type is not set', async () => { - global.eth = { - getCode: sinon.stub(), - }; - const updateRecipientState = { metamask: { addressBook: {}, @@ -2532,10 +2504,6 @@ describe('Send Slice', () => { }); it('should update recipient nickname if the passed address exists in the addressBook state but no nickname param is provided', async () => { - global.eth = { - getCode: sinon.stub(), - }; - const TEST_RECIPIENT_ADDRESS = '0x0000000000000000000000000000000000000001'; const TEST_RECIPIENT_NAME = 'The 1 address'; @@ -3499,15 +3467,6 @@ describe('Send Slice', () => { }, }; - global.eth = { - contract: sinon.stub().returns({ - at: sinon.stub().returns({ - balanceOf: sinon.stub().returns(undefined), - }), - }), - getCode: jest.fn(() => '0xa'), - }; - const store = mockStore(editTransactionState); await store.dispatch(editExistingTransaction(AssetType.NFT, 1)); @@ -3730,15 +3689,6 @@ describe('Send Slice', () => { }, }; - global.eth = { - contract: sinon.stub().returns({ - at: sinon.stub().returns({ - balanceOf: sinon.stub().returns(undefined), - }), - }), - getCode: jest.fn(() => '0xa'), - }; - const store = mockStore(editTransactionState); await store.dispatch(editExistingTransaction(AssetType.token, 1)); @@ -3980,15 +3930,6 @@ describe('Send Slice', () => { }, }; - global.eth = { - contract: sinon.stub().returns({ - at: sinon.stub().returns({ - balanceOf: sinon.stub().returns(undefined), - }), - }), - getCode: jest.fn(() => '0xa'), - }; - const store = mockStore(editTransactionState); store.clearActions(); diff --git a/ui/helpers/utils/token-util.js b/ui/helpers/utils/token-util.js index 10beae68b39e..143cdf220ed3 100644 --- a/ui/helpers/utils/token-util.js +++ b/ui/helpers/utils/token-util.js @@ -14,8 +14,7 @@ const DEFAULT_SYMBOL = ''; async function getSymbolFromContract(tokenAddress) { const token = util.getContractAtAddress(tokenAddress); try { - const result = await token.symbol(); - return result[0]; + return await token.symbol(); } catch (error) { log.warn( `symbol() call for token at address ${tokenAddress} resulted in error:`, @@ -28,8 +27,7 @@ async function getSymbolFromContract(tokenAddress) { async function getNameFromContract(tokenAddress) { const token = util.getContractAtAddress(tokenAddress); try { - const [name] = await token.name(); - return name; + return await token.name(); } catch (error) { log.warn( `name() call for token at address ${tokenAddress} resulted in error:`, @@ -43,8 +41,7 @@ async function getDecimalsFromContract(tokenAddress) { const token = util.getContractAtAddress(tokenAddress); try { - const result = await token.decimals(); - const decimalsBN = result[0]; + const decimalsBN = await token.decimals(); return decimalsBN?.toString(); } catch (error) { log.warn( diff --git a/ui/helpers/utils/transactions.util.js b/ui/helpers/utils/transactions.util.js index 51f36523676f..cfa820135e0f 100644 --- a/ui/helpers/utils/transactions.util.js +++ b/ui/helpers/utils/transactions.util.js @@ -63,7 +63,7 @@ export function getLatestSubmittedTxWithNonce( export async function isSmartContractAddress(address) { const { isContractAddress } = await readAddressAsContract( - global.eth, + global.ethereumProvider, address, ); return isContractAddress; diff --git a/ui/helpers/utils/util.js b/ui/helpers/utils/util.js index d687d9b82338..7544e35c4cfc 100644 --- a/ui/helpers/utils/util.js +++ b/ui/helpers/utils/util.js @@ -13,6 +13,8 @@ import bowser from 'bowser'; import { WALLET_SNAP_PERMISSION_KEY } from '@metamask/snaps-rpc-methods'; import { stripSnapPrefix } from '@metamask/snaps-utils'; import { isObject, isStrictHexString } from '@metamask/utils'; +import { Web3Provider } from '@ethersproject/providers'; +import { Contract } from '@ethersproject/contracts'; import { CHAIN_IDS, NETWORK_TYPES } from '../../../shared/constants/network'; import { logErrorWithMessage } from '../../../shared/modules/error'; import { @@ -227,7 +229,11 @@ export function formatBalance( } export function getContractAtAddress(tokenAddress) { - return global.eth.contract(abi).at(tokenAddress); + return new Contract( + tokenAddress, + abi, + new Web3Provider(global.ethereumProvider), + ); } export function getRandomFileName() { diff --git a/ui/pages/confirmations/confirm-approve/confirm-approve.js b/ui/pages/confirmations/confirm-approve/confirm-approve.js index aa7cc1216393..2ab4cd5a0b7d 100644 --- a/ui/pages/confirmations/confirm-approve/confirm-approve.js +++ b/ui/pages/confirmations/confirm-approve/confirm-approve.js @@ -134,7 +134,7 @@ export default function ConfirmApprove({ const checkIfContract = useCallback(async () => { const { isContractAddress } = await readAddressAsContract( - global.eth, + global.ethereumProvider, toAddress, ); setIsContract(isContractAddress); diff --git a/yarn.lock b/yarn.lock index ccb5a1a0e260..23a6e248fef0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5521,17 +5521,6 @@ __metadata: languageName: node linkType: hard -"@metamask/ethjs-provider-http@npm:^0.3.0": - version: 0.3.0 - resolution: "@metamask/ethjs-provider-http@npm:0.3.0" - dependencies: - xhr2: "npm:0.2.1" - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: 10/cece5d20836dadbe31f0c7118f26bd5330465c28f9a39ab8ac4a3fbce25094ae53fe8b737e3d95ae0cf4c7e075c9349127cf8bd066f138278ffc9fd7f9a8a101 - languageName: node - linkType: hard - "@metamask/ethjs-query@npm:^0.7.1": version: 0.7.1 resolution: "@metamask/ethjs-query@npm:0.7.1" @@ -5580,26 +5569,6 @@ __metadata: languageName: node linkType: hard -"@metamask/ethjs@npm:^0.6.0": - version: 0.6.0 - resolution: "@metamask/ethjs@npm:0.6.0" - dependencies: - "@metamask/ethjs-contract": "npm:^0.4.1" - "@metamask/ethjs-filter": "npm:^0.3.0" - "@metamask/ethjs-provider-http": "npm:^0.3.0" - "@metamask/ethjs-query": "npm:^0.7.1" - "@metamask/ethjs-unit": "npm:^0.3.0" - "@metamask/ethjs-util": "npm:^0.3.0" - "@metamask/number-to-bn": "npm:1.7.1" - bn.js: "npm:5.2.1" - ethjs-abi: "npm:0.2.1" - js-sha3: "npm:^0.9.2" - peerDependencies: - "@babel/runtime": ^7.0.0 - checksum: 10/11379cb4a1151fc8f8e939eb38c15ea6cfce042bc10a580a3fbe87b7e0234fb5cdf5b2458a7bbc8db3502032ac42054bf393154cfe967352b129fe8115719a91 - languageName: node - linkType: hard - "@metamask/forwarder@npm:^1.1.0": version: 1.1.0 resolution: "@metamask/forwarder@npm:1.1.0" @@ -5918,7 +5887,7 @@ __metadata: languageName: node linkType: hard -"@metamask/number-to-bn@npm:1.7.1, @metamask/number-to-bn@npm:^1.7.1": +"@metamask/number-to-bn@npm:^1.7.1": version: 1.7.1 resolution: "@metamask/number-to-bn@npm:1.7.1" dependencies: @@ -19016,7 +18985,7 @@ __metadata: languageName: node linkType: hard -"ethjs-abi@npm:0.2.1, ethjs-abi@npm:^0.2.0": +"ethjs-abi@npm:^0.2.0": version: 0.2.1 resolution: "ethjs-abi@npm:0.2.1" dependencies: @@ -26634,7 +26603,6 @@ __metadata: "@metamask/eth-token-tracker": "npm:^9.0.0" "@metamask/eth-trezor-keyring": "npm:^6.0.0" "@metamask/etherscan-link": "npm:^3.0.0" - "@metamask/ethjs": "npm:^0.6.0" "@metamask/ethjs-contract": "npm:^0.4.1" "@metamask/ethjs-query": "npm:^0.7.1" "@metamask/forwarder": "npm:^1.1.0" @@ -38010,13 +37978,6 @@ __metadata: languageName: node linkType: hard -"xhr2@npm:0.2.1": - version: 0.2.1 - resolution: "xhr2@npm:0.2.1" - checksum: 10/162faae70972dc9207eb9b5f05715fa7016f7a04d90371908acaf02593c16f6d2853cd4d6917000e4c3094182697c79e0d33485aea3557bd46f2beead8150f95 - languageName: node - linkType: hard - "xml-name-validator@npm:^3.0.0": version: 3.0.0 resolution: "xml-name-validator@npm:3.0.0"