From 6dbb2c4ded2f3098ce03031bf48cbad49f822f75 Mon Sep 17 00:00:00 2001
From: Daniel <80175477+dan437@users.noreply.github.com>
Date: Thu, 26 May 2022 19:56:28 +0200
Subject: [PATCH] Migrate the "estimateGas" API call to "getFees" for STX
(#14767)
---
app/scripts/metamask-controller.js | 3 -
lavamoat/browserify/beta/policy.json | 206 +---------------
lavamoat/browserify/flask/policy.json | 206 +---------------
lavamoat/browserify/main/policy.json | 244 +------------------
package.json | 2 +-
test/jest/mock-store.js | 146 +++++++----
ui/ducks/swaps/swaps.js | 62 ++---
ui/pages/swaps/view-quote/view-quote.js | 34 ++-
ui/pages/swaps/view-quote/view-quote.test.js | 3 +-
ui/store/actions.js | 30 +--
yarn.lock | 97 +-------
11 files changed, 191 insertions(+), 842 deletions(-)
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 8c9956f26..d416c6aea 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -1819,9 +1819,6 @@ export default class MetamaskController extends EventEmitter {
fetchSmartTransactionFees: smartTransactionsController.getFees.bind(
smartTransactionsController,
),
- estimateSmartTransactionsGas: smartTransactionsController.estimateGas.bind(
- smartTransactionsController,
- ),
submitSignedTransactions: smartTransactionsController.submitSignedTransactions.bind(
smartTransactionsController,
),
diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json
index 88685c3a7..ce2bde5e4 100644
--- a/lavamoat/browserify/beta/policy.json
+++ b/lavamoat/browserify/beta/policy.json
@@ -3216,6 +3216,10 @@
}
},
"@metamask/rpc-methods": {
+ "globals": {
+ "caveats": true,
+ "params": true
+ },
"packages": {
"@metamask/controllers": true,
"@metamask/rpc-methods>@metamask/key-tree": true,
@@ -3275,207 +3279,17 @@
"console.error": true,
"console.log": true,
"fetch": true,
- "setInterval": true,
- "setTimeout": true
+ "setInterval": true
},
"packages": {
+ "@metamask/controllers": true,
"@metamask/controllers>isomorphic-fetch": true,
- "@metamask/smart-transactions-controller>@metamask/controllers": true,
"@metamask/smart-transactions-controller>bignumber.js": true,
"@metamask/smart-transactions-controller>fast-json-patch": true,
"ethers": true,
"lodash": true
}
},
- "@metamask/smart-transactions-controller>@metamask/controllers": {
- "globals": {
- "Headers": true,
- "URL": true,
- "clearInterval": true,
- "clearTimeout": true,
- "console.error": true,
- "console.log": true,
- "fetch": true,
- "setInterval": true,
- "setTimeout": true
- },
- "packages": {
- "@ethereumjs/common": true,
- "@ethereumjs/tx": true,
- "@metamask/contract-metadata": true,
- "@metamask/controllers>abort-controller": true,
- "@metamask/controllers>async-mutex": true,
- "@metamask/controllers>eth-phishing-detect": true,
- "@metamask/controllers>isomorphic-fetch": true,
- "@metamask/controllers>multiformats": true,
- "@metamask/controllers>web3-provider-engine": true,
- "@metamask/metamask-eth-abis": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>nanoid": true,
- "@storybook/api>fast-deep-equal": true,
- "browserify>buffer": true,
- "browserify>events": true,
- "deep-freeze-strict": true,
- "eth-ens-namehash": true,
- "eth-json-rpc-infura": true,
- "eth-query": true,
- "eth-rpc-errors": true,
- "eth-sig-util": true,
- "ethereumjs-util": true,
- "ethers": true,
- "ethjs>ethjs-unit": true,
- "immer": true,
- "json-rpc-engine": true,
- "jsonschema": true,
- "punycode": true,
- "single-call-balance-checker-abi": true,
- "uuid": true,
- "web3": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring": true,
- "browserify>events": true,
- "eth-keyring-controller>browser-passworder": true,
- "eth-keyring-controller>eth-simple-keyring": true,
- "eth-keyring-controller>obs-store": true,
- "eth-sig-util": true,
- "ethereumjs-util": true,
- "loglevel": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39>unorm": true,
- "browserify>crypto-browserify>pbkdf2": true,
- "ethereumjs-util>create-hash": true,
- "ethereumjs-wallet>randombytes": true,
- "ethereumjs-wallet>safe-buffer": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39>unorm": {
- "globals": {
- "define": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet": true,
- "eth-keyring-controller>eth-simple-keyring": true,
- "eth-sig-util": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet>uuid": true,
- "@truffle/codec>utf8": true,
- "browserify>buffer": true,
- "browserify>crypto-browserify": true,
- "ethereumjs-util": true,
- "ethereumjs-util>ethereum-cryptography": true,
- "ethereumjs-wallet>aes-js": true,
- "ethereumjs-wallet>bs58check": true,
- "ethereumjs-wallet>randombytes": true,
- "ethers>@ethersproject/json-wallets>scrypt-js": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet>uuid": {
- "globals": {
- "crypto": true,
- "msCrypto": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs": {
- "globals": {
- "clearInterval": true,
- "setInterval": true
- },
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-abi": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-query": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>ethjs-filter": true,
- "ethjs>ethjs-provider-http": true,
- "ethjs>ethjs-unit": true,
- "ethjs>ethjs-util": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-abi": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract>ethjs-abi": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "ethjs-query>babel-runtime": true,
- "ethjs>ethjs-filter": true,
- "ethjs>ethjs-util": true,
- "promise-to-callback": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract>ethjs-abi": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-query": {
- "globals": {
- "console": true
- },
- "packages": {
- "ethjs-query>babel-runtime": true,
- "ethjs-query>ethjs-format": true,
- "ethjs-query>ethjs-rpc": true,
- "promise-to-callback": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": {
- "packages": {
- "browserify>process": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet>uuid": true,
- "@truffle/codec>utf8": true,
- "browserify>buffer": true,
- "browserify>crypto-browserify": true,
- "ethereumjs-util": true,
- "ethereumjs-util>ethereum-cryptography": true,
- "ethereumjs-wallet>aes-js": true,
- "ethereumjs-wallet>bs58check": true,
- "ethereumjs-wallet>randombytes": true,
- "ethers>@ethersproject/json-wallets>scrypt-js": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet>uuid": {
- "globals": {
- "crypto": true,
- "msCrypto": true
- }
- },
"@metamask/smart-transactions-controller>@metamask/controllers>nanoid": {
"globals": {
"crypto.getRandomValues": true
@@ -3504,11 +3318,17 @@
"console.info": true,
"console.log": true,
"console.warn": true,
+ "dist": true,
"document.body.appendChild": true,
"document.createElement": true,
"document.getElementById": true,
"fetch": true,
- "setTimeout": true
+ "location": true,
+ "npm": true,
+ "remove": true,
+ "setTimeout": true,
+ "tarball": true,
+ "versions": true
},
"packages": {
"@metamask/controllers": true,
diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json
index 88685c3a7..ce2bde5e4 100644
--- a/lavamoat/browserify/flask/policy.json
+++ b/lavamoat/browserify/flask/policy.json
@@ -3216,6 +3216,10 @@
}
},
"@metamask/rpc-methods": {
+ "globals": {
+ "caveats": true,
+ "params": true
+ },
"packages": {
"@metamask/controllers": true,
"@metamask/rpc-methods>@metamask/key-tree": true,
@@ -3275,207 +3279,17 @@
"console.error": true,
"console.log": true,
"fetch": true,
- "setInterval": true,
- "setTimeout": true
+ "setInterval": true
},
"packages": {
+ "@metamask/controllers": true,
"@metamask/controllers>isomorphic-fetch": true,
- "@metamask/smart-transactions-controller>@metamask/controllers": true,
"@metamask/smart-transactions-controller>bignumber.js": true,
"@metamask/smart-transactions-controller>fast-json-patch": true,
"ethers": true,
"lodash": true
}
},
- "@metamask/smart-transactions-controller>@metamask/controllers": {
- "globals": {
- "Headers": true,
- "URL": true,
- "clearInterval": true,
- "clearTimeout": true,
- "console.error": true,
- "console.log": true,
- "fetch": true,
- "setInterval": true,
- "setTimeout": true
- },
- "packages": {
- "@ethereumjs/common": true,
- "@ethereumjs/tx": true,
- "@metamask/contract-metadata": true,
- "@metamask/controllers>abort-controller": true,
- "@metamask/controllers>async-mutex": true,
- "@metamask/controllers>eth-phishing-detect": true,
- "@metamask/controllers>isomorphic-fetch": true,
- "@metamask/controllers>multiformats": true,
- "@metamask/controllers>web3-provider-engine": true,
- "@metamask/metamask-eth-abis": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>nanoid": true,
- "@storybook/api>fast-deep-equal": true,
- "browserify>buffer": true,
- "browserify>events": true,
- "deep-freeze-strict": true,
- "eth-ens-namehash": true,
- "eth-json-rpc-infura": true,
- "eth-query": true,
- "eth-rpc-errors": true,
- "eth-sig-util": true,
- "ethereumjs-util": true,
- "ethers": true,
- "ethjs>ethjs-unit": true,
- "immer": true,
- "json-rpc-engine": true,
- "jsonschema": true,
- "punycode": true,
- "single-call-balance-checker-abi": true,
- "uuid": true,
- "web3": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring": true,
- "browserify>events": true,
- "eth-keyring-controller>browser-passworder": true,
- "eth-keyring-controller>eth-simple-keyring": true,
- "eth-keyring-controller>obs-store": true,
- "eth-sig-util": true,
- "ethereumjs-util": true,
- "loglevel": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39>unorm": true,
- "browserify>crypto-browserify>pbkdf2": true,
- "ethereumjs-util>create-hash": true,
- "ethereumjs-wallet>randombytes": true,
- "ethereumjs-wallet>safe-buffer": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39>unorm": {
- "globals": {
- "define": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet": true,
- "eth-keyring-controller>eth-simple-keyring": true,
- "eth-sig-util": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet>uuid": true,
- "@truffle/codec>utf8": true,
- "browserify>buffer": true,
- "browserify>crypto-browserify": true,
- "ethereumjs-util": true,
- "ethereumjs-util>ethereum-cryptography": true,
- "ethereumjs-wallet>aes-js": true,
- "ethereumjs-wallet>bs58check": true,
- "ethereumjs-wallet>randombytes": true,
- "ethers>@ethersproject/json-wallets>scrypt-js": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet>uuid": {
- "globals": {
- "crypto": true,
- "msCrypto": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs": {
- "globals": {
- "clearInterval": true,
- "setInterval": true
- },
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-abi": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-query": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>ethjs-filter": true,
- "ethjs>ethjs-provider-http": true,
- "ethjs>ethjs-unit": true,
- "ethjs>ethjs-util": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-abi": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract>ethjs-abi": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "ethjs-query>babel-runtime": true,
- "ethjs>ethjs-filter": true,
- "ethjs>ethjs-util": true,
- "promise-to-callback": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract>ethjs-abi": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-query": {
- "globals": {
- "console": true
- },
- "packages": {
- "ethjs-query>babel-runtime": true,
- "ethjs-query>ethjs-format": true,
- "ethjs-query>ethjs-rpc": true,
- "promise-to-callback": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": {
- "packages": {
- "browserify>process": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet>uuid": true,
- "@truffle/codec>utf8": true,
- "browserify>buffer": true,
- "browserify>crypto-browserify": true,
- "ethereumjs-util": true,
- "ethereumjs-util>ethereum-cryptography": true,
- "ethereumjs-wallet>aes-js": true,
- "ethereumjs-wallet>bs58check": true,
- "ethereumjs-wallet>randombytes": true,
- "ethers>@ethersproject/json-wallets>scrypt-js": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet>uuid": {
- "globals": {
- "crypto": true,
- "msCrypto": true
- }
- },
"@metamask/smart-transactions-controller>@metamask/controllers>nanoid": {
"globals": {
"crypto.getRandomValues": true
@@ -3504,11 +3318,17 @@
"console.info": true,
"console.log": true,
"console.warn": true,
+ "dist": true,
"document.body.appendChild": true,
"document.createElement": true,
"document.getElementById": true,
"fetch": true,
- "setTimeout": true
+ "location": true,
+ "npm": true,
+ "remove": true,
+ "setTimeout": true,
+ "tarball": true,
+ "versions": true
},
"packages": {
"@metamask/controllers": true,
diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json
index bc3e11725..ce2bde5e4 100644
--- a/lavamoat/browserify/main/policy.json
+++ b/lavamoat/browserify/main/policy.json
@@ -3216,6 +3216,10 @@
}
},
"@metamask/rpc-methods": {
+ "globals": {
+ "caveats": true,
+ "params": true
+ },
"packages": {
"@metamask/controllers": true,
"@metamask/rpc-methods>@metamask/key-tree": true,
@@ -3275,207 +3279,17 @@
"console.error": true,
"console.log": true,
"fetch": true,
- "setInterval": true,
- "setTimeout": true
+ "setInterval": true
},
"packages": {
+ "@metamask/controllers": true,
"@metamask/controllers>isomorphic-fetch": true,
- "@metamask/smart-transactions-controller>@metamask/controllers": true,
"@metamask/smart-transactions-controller>bignumber.js": true,
"@metamask/smart-transactions-controller>fast-json-patch": true,
"ethers": true,
"lodash": true
}
},
- "@metamask/smart-transactions-controller>@metamask/controllers": {
- "globals": {
- "Headers": true,
- "URL": true,
- "clearInterval": true,
- "clearTimeout": true,
- "console.error": true,
- "console.log": true,
- "fetch": true,
- "setInterval": true,
- "setTimeout": true
- },
- "packages": {
- "@ethereumjs/common": true,
- "@ethereumjs/tx": true,
- "@metamask/contract-metadata": true,
- "@metamask/controllers>abort-controller": true,
- "@metamask/controllers>async-mutex": true,
- "@metamask/controllers>eth-phishing-detect": true,
- "@metamask/controllers>isomorphic-fetch": true,
- "@metamask/controllers>multiformats": true,
- "@metamask/controllers>web3-provider-engine": true,
- "@metamask/metamask-eth-abis": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>nanoid": true,
- "@storybook/api>fast-deep-equal": true,
- "browserify>buffer": true,
- "browserify>events": true,
- "deep-freeze-strict": true,
- "eth-ens-namehash": true,
- "eth-json-rpc-infura": true,
- "eth-query": true,
- "eth-rpc-errors": true,
- "eth-sig-util": true,
- "ethereumjs-util": true,
- "ethers": true,
- "ethjs>ethjs-unit": true,
- "immer": true,
- "json-rpc-engine": true,
- "jsonschema": true,
- "punycode": true,
- "single-call-balance-checker-abi": true,
- "uuid": true,
- "web3": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring": true,
- "browserify>events": true,
- "eth-keyring-controller>browser-passworder": true,
- "eth-keyring-controller>eth-simple-keyring": true,
- "eth-keyring-controller>obs-store": true,
- "eth-sig-util": true,
- "ethereumjs-util": true,
- "loglevel": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39>unorm": true,
- "browserify>crypto-browserify>pbkdf2": true,
- "ethereumjs-util>create-hash": true,
- "ethereumjs-wallet>randombytes": true,
- "ethereumjs-wallet>safe-buffer": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39>unorm": {
- "globals": {
- "define": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>bip39": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet": true,
- "eth-keyring-controller>eth-simple-keyring": true,
- "eth-sig-util": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet>uuid": true,
- "@truffle/codec>utf8": true,
- "browserify>buffer": true,
- "browserify>crypto-browserify": true,
- "ethereumjs-util": true,
- "ethereumjs-util>ethereum-cryptography": true,
- "ethereumjs-wallet>aes-js": true,
- "ethereumjs-wallet>bs58check": true,
- "ethereumjs-wallet>randombytes": true,
- "ethers>@ethersproject/json-wallets>scrypt-js": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-keyring-controller>eth-hd-keyring>ethereumjs-wallet>uuid": {
- "globals": {
- "crypto": true,
- "msCrypto": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs": {
- "globals": {
- "clearInterval": true,
- "setInterval": true
- },
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-abi": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-query": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>ethjs-filter": true,
- "ethjs>ethjs-provider-http": true,
- "ethjs>ethjs-unit": true,
- "ethjs>ethjs-util": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-abi": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract>ethjs-abi": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "ethjs-query>babel-runtime": true,
- "ethjs>ethjs-filter": true,
- "ethjs>ethjs-util": true,
- "promise-to-callback": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-contract>ethjs-abi": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>bn.js": true,
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": true,
- "browserify>buffer": true,
- "ethjs>number-to-bn": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>ethjs-query": {
- "globals": {
- "console": true
- },
- "packages": {
- "ethjs-query>babel-runtime": true,
- "ethjs-query>ethjs-format": true,
- "ethjs-query>ethjs-rpc": true,
- "promise-to-callback": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>eth-method-registry>ethjs>js-sha3": {
- "packages": {
- "browserify>process": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet": {
- "packages": {
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet>uuid": true,
- "@truffle/codec>utf8": true,
- "browserify>buffer": true,
- "browserify>crypto-browserify": true,
- "ethereumjs-util": true,
- "ethereumjs-util>ethereum-cryptography": true,
- "ethereumjs-wallet>aes-js": true,
- "ethereumjs-wallet>bs58check": true,
- "ethereumjs-wallet>randombytes": true,
- "ethers>@ethersproject/json-wallets>scrypt-js": true
- }
- },
- "@metamask/smart-transactions-controller>@metamask/controllers>ethereumjs-wallet>uuid": {
- "globals": {
- "crypto": true,
- "msCrypto": true
- }
- },
"@metamask/smart-transactions-controller>@metamask/controllers>nanoid": {
"globals": {
"crypto.getRandomValues": true
@@ -3504,14 +3318,19 @@
"console.info": true,
"console.log": true,
"console.warn": true,
+ "dist": true,
"document.body.appendChild": true,
"document.createElement": true,
"document.getElementById": true,
"fetch": true,
- "setTimeout": true
+ "location": true,
+ "npm": true,
+ "remove": true,
+ "setTimeout": true,
+ "tarball": true,
+ "versions": true
},
"packages": {
- "@metamask/snap-controllers>@metamask/controllers": true,
"@metamask/controllers": true,
"@metamask/post-message-stream": true,
"@metamask/providers>@metamask/object-multiplex": true,
@@ -3534,43 +3353,6 @@
"semver": true
}
},
- "@metamask/snap-controllers>@metamask/controllers": {
- "packages": {
- "@metamask/controllers>isomorphic-fetch": true,
- "browserify>buffer": true,
- "ethereumjs-util": true,
- "ethjs>ethjs-unit": true,
- "eth-rpc-errors": true,
- "eth-ens-namehash": true,
- "eth-sig-util": true,
- "jsonschema": true,
- "@metamask/controllers>multiformats": true,
- "@storybook/api>fast-deep-equal": true,
- "eth-query": true,
- "@metamask/controllers>async-mutex": true,
- "@metamask/snap-controllers>nanoid": true,
- "immer": true,
- "web3": true,
- "single-call-balance-checker-abi": true,
- "@metamask/metamask-eth-abis": true,
- "ethereumjs-wallet": true,
- "eth-keyring-controller": true,
- "uuid": true,
- "browserify>events": true,
- "@metamask/controllers>web3-provider-engine": true,
- "eth-json-rpc-infura": true,
- "punycode": true,
- "@metamask/controllers>eth-phishing-detect": true,
- "eth-method-registry": true,
- "@ethereumjs/common": true,
- "@ethereumjs/tx": true,
- "@metamask/contract-metadata": true,
- "@metamask/controllers>abort-controller": true,
- "ethers": true,
- "deep-freeze-strict": true,
- "json-rpc-engine": true
- }
- },
"@metamask/snap-controllers>@metamask/obs-store": {
"packages": {
"@metamask/snap-controllers>@metamask/obs-store>through2": true,
diff --git a/package.json b/package.json
index 2a6666b9d..ce039664d 100644
--- a/package.json
+++ b/package.json
@@ -129,7 +129,7 @@
"@metamask/providers": "^8.1.1",
"@metamask/rpc-methods": "^0.14.0",
"@metamask/slip44": "^2.1.0",
- "@metamask/smart-transactions-controller": "^1.10.0",
+ "@metamask/smart-transactions-controller": "^2.0.1",
"@metamask/snap-controllers": "^0.14.0",
"@ngraveio/bc-ur": "^1.1.6",
"@popperjs/core": "^2.4.0",
diff --git a/test/jest/mock-store.js b/test/jest/mock-store.js
index 73f4892b3..2595746c0 100644
--- a/test/jest/mock-store.js
+++ b/test/jest/mock-store.js
@@ -2,51 +2,102 @@ import { MAINNET_CHAIN_ID } from '../../shared/constants/network';
const createGetSmartTransactionFeesApiResponse = () => {
return {
- cancelFees: [
- { maxFeePerGas: 2100001000, maxPriorityFeePerGas: 466503987 },
- { maxFeePerGas: 2310003200, maxPriorityFeePerGas: 513154852 },
- { maxFeePerGas: 2541005830, maxPriorityFeePerGas: 564470851 },
- { maxFeePerGas: 2795108954, maxPriorityFeePerGas: 620918500 },
- { maxFeePerGas: 3074622644, maxPriorityFeePerGas: 683010971 },
- { maxFeePerGas: 3382087983, maxPriorityFeePerGas: 751312751 },
- { maxFeePerGas: 3720300164, maxPriorityFeePerGas: 826444778 },
- { maxFeePerGas: 4092333900, maxPriorityFeePerGas: 909090082 },
- { maxFeePerGas: 4501571383, maxPriorityFeePerGas: 1000000000 },
- { maxFeePerGas: 4951733023, maxPriorityFeePerGas: 1100001000 },
- { maxFeePerGas: 5446911277, maxPriorityFeePerGas: 1210002200 },
- { maxFeePerGas: 5991607851, maxPriorityFeePerGas: 1331003630 },
- { maxFeePerGas: 6590774628, maxPriorityFeePerGas: 1464105324 },
- { maxFeePerGas: 7249858682, maxPriorityFeePerGas: 1610517320 },
- { maxFeePerGas: 7974851800, maxPriorityFeePerGas: 1771570663 },
- { maxFeePerGas: 8772344955, maxPriorityFeePerGas: 1948729500 },
- { maxFeePerGas: 9649588222, maxPriorityFeePerGas: 2143604399 },
- { maxFeePerGas: 10614556694, maxPriorityFeePerGas: 2357966983 },
- { maxFeePerGas: 11676022978, maxPriorityFeePerGas: 2593766039 },
- ],
- feeEstimate: 42000000000000,
- fees: [
- { maxFeePerGas: 2310003200, maxPriorityFeePerGas: 513154852 },
- { maxFeePerGas: 2541005830, maxPriorityFeePerGas: 564470850 },
- { maxFeePerGas: 2795108954, maxPriorityFeePerGas: 620918500 },
- { maxFeePerGas: 3074622644, maxPriorityFeePerGas: 683010970 },
- { maxFeePerGas: 3382087983, maxPriorityFeePerGas: 751312751 },
- { maxFeePerGas: 3720300163, maxPriorityFeePerGas: 826444777 },
- { maxFeePerGas: 4092333900, maxPriorityFeePerGas: 909090082 },
- { maxFeePerGas: 4501571382, maxPriorityFeePerGas: 999999999 },
- { maxFeePerGas: 4951733022, maxPriorityFeePerGas: 1100001000 },
- { maxFeePerGas: 5446911277, maxPriorityFeePerGas: 1210002200 },
- { maxFeePerGas: 5991607851, maxPriorityFeePerGas: 1331003630 },
- { maxFeePerGas: 6590774627, maxPriorityFeePerGas: 1464105324 },
- { maxFeePerGas: 7249858681, maxPriorityFeePerGas: 1610517320 },
- { maxFeePerGas: 7974851800, maxPriorityFeePerGas: 1771570662 },
- { maxFeePerGas: 8772344954, maxPriorityFeePerGas: 1948729500 },
- { maxFeePerGas: 9649588222, maxPriorityFeePerGas: 2143604398 },
- { maxFeePerGas: 10614556693, maxPriorityFeePerGas: 2357966982 },
- { maxFeePerGas: 11676022977, maxPriorityFeePerGas: 2593766039 },
- { maxFeePerGas: 12843636951, maxPriorityFeePerGas: 2853145236 },
- ],
- gasLimit: 21000,
- gasUsed: 21000,
+ tradeTxFees: {
+ // Approval tx.
+ cancelFees: [
+ { maxFeePerGas: 2100001000, maxPriorityFeePerGas: 466503987 },
+ { maxFeePerGas: 2310003200, maxPriorityFeePerGas: 513154852 },
+ { maxFeePerGas: 2541005830, maxPriorityFeePerGas: 564470851 },
+ { maxFeePerGas: 2795108954, maxPriorityFeePerGas: 620918500 },
+ { maxFeePerGas: 3074622644, maxPriorityFeePerGas: 683010971 },
+ { maxFeePerGas: 3382087983, maxPriorityFeePerGas: 751312751 },
+ { maxFeePerGas: 3720300164, maxPriorityFeePerGas: 826444778 },
+ { maxFeePerGas: 4092333900, maxPriorityFeePerGas: 909090082 },
+ { maxFeePerGas: 4501571383, maxPriorityFeePerGas: 1000000000 },
+ { maxFeePerGas: 4951733023, maxPriorityFeePerGas: 1100001000 },
+ { maxFeePerGas: 5446911277, maxPriorityFeePerGas: 1210002200 },
+ { maxFeePerGas: 5991607851, maxPriorityFeePerGas: 1331003630 },
+ { maxFeePerGas: 6590774628, maxPriorityFeePerGas: 1464105324 },
+ { maxFeePerGas: 7249858682, maxPriorityFeePerGas: 1610517320 },
+ { maxFeePerGas: 7974851800, maxPriorityFeePerGas: 1771570663 },
+ { maxFeePerGas: 8772344955, maxPriorityFeePerGas: 1948729500 },
+ { maxFeePerGas: 9649588222, maxPriorityFeePerGas: 2143604399 },
+ { maxFeePerGas: 10614556694, maxPriorityFeePerGas: 2357966983 },
+ { maxFeePerGas: 11676022978, maxPriorityFeePerGas: 2593766039 },
+ ],
+ feeEstimate: 42000000000000,
+ fees: [
+ { maxFeePerGas: 2310003200, maxPriorityFeePerGas: 513154852 },
+ { maxFeePerGas: 2541005830, maxPriorityFeePerGas: 564470850 },
+ { maxFeePerGas: 2795108954, maxPriorityFeePerGas: 620918500 },
+ { maxFeePerGas: 3074622644, maxPriorityFeePerGas: 683010970 },
+ { maxFeePerGas: 3382087983, maxPriorityFeePerGas: 751312751 },
+ { maxFeePerGas: 3720300163, maxPriorityFeePerGas: 826444777 },
+ { maxFeePerGas: 4092333900, maxPriorityFeePerGas: 909090082 },
+ { maxFeePerGas: 4501571382, maxPriorityFeePerGas: 999999999 },
+ { maxFeePerGas: 4951733022, maxPriorityFeePerGas: 1100001000 },
+ { maxFeePerGas: 5446911277, maxPriorityFeePerGas: 1210002200 },
+ { maxFeePerGas: 5991607851, maxPriorityFeePerGas: 1331003630 },
+ { maxFeePerGas: 6590774627, maxPriorityFeePerGas: 1464105324 },
+ { maxFeePerGas: 7249858681, maxPriorityFeePerGas: 1610517320 },
+ { maxFeePerGas: 7974851800, maxPriorityFeePerGas: 1771570662 },
+ { maxFeePerGas: 8772344954, maxPriorityFeePerGas: 1948729500 },
+ { maxFeePerGas: 9649588222, maxPriorityFeePerGas: 2143604398 },
+ { maxFeePerGas: 10614556693, maxPriorityFeePerGas: 2357966982 },
+ { maxFeePerGas: 11676022977, maxPriorityFeePerGas: 2593766039 },
+ { maxFeePerGas: 12843636951, maxPriorityFeePerGas: 2853145236 },
+ ],
+ gasLimit: 21000,
+ gasUsed: 21000,
+ },
+ approvalTxFees: {
+ // Trade tx.
+ cancelFees: [
+ { maxFeePerGas: 2100001000, maxPriorityFeePerGas: 466503987 },
+ { maxFeePerGas: 2310003200, maxPriorityFeePerGas: 513154852 },
+ { maxFeePerGas: 2541005830, maxPriorityFeePerGas: 564470851 },
+ { maxFeePerGas: 2795108954, maxPriorityFeePerGas: 620918500 },
+ { maxFeePerGas: 3074622644, maxPriorityFeePerGas: 683010971 },
+ { maxFeePerGas: 3382087983, maxPriorityFeePerGas: 751312751 },
+ { maxFeePerGas: 3720300164, maxPriorityFeePerGas: 826444778 },
+ { maxFeePerGas: 4092333900, maxPriorityFeePerGas: 909090082 },
+ { maxFeePerGas: 4501571383, maxPriorityFeePerGas: 1000000000 },
+ { maxFeePerGas: 4951733023, maxPriorityFeePerGas: 1100001000 },
+ { maxFeePerGas: 5446911277, maxPriorityFeePerGas: 1210002200 },
+ { maxFeePerGas: 5991607851, maxPriorityFeePerGas: 1331003630 },
+ { maxFeePerGas: 6590774628, maxPriorityFeePerGas: 1464105324 },
+ { maxFeePerGas: 7249858682, maxPriorityFeePerGas: 1610517320 },
+ { maxFeePerGas: 7974851800, maxPriorityFeePerGas: 1771570663 },
+ { maxFeePerGas: 8772344955, maxPriorityFeePerGas: 1948729500 },
+ { maxFeePerGas: 9649588222, maxPriorityFeePerGas: 2143604399 },
+ { maxFeePerGas: 10614556694, maxPriorityFeePerGas: 2357966983 },
+ { maxFeePerGas: 11676022978, maxPriorityFeePerGas: 2593766039 },
+ ],
+ feeEstimate: 42000000000000,
+ fees: [
+ { maxFeePerGas: 2310003200, maxPriorityFeePerGas: 513154852 },
+ { maxFeePerGas: 2541005830, maxPriorityFeePerGas: 564470850 },
+ { maxFeePerGas: 2795108954, maxPriorityFeePerGas: 620918500 },
+ { maxFeePerGas: 3074622644, maxPriorityFeePerGas: 683010970 },
+ { maxFeePerGas: 3382087983, maxPriorityFeePerGas: 751312751 },
+ { maxFeePerGas: 3720300163, maxPriorityFeePerGas: 826444777 },
+ { maxFeePerGas: 4092333900, maxPriorityFeePerGas: 909090082 },
+ { maxFeePerGas: 4501571382, maxPriorityFeePerGas: 999999999 },
+ { maxFeePerGas: 4951733022, maxPriorityFeePerGas: 1100001000 },
+ { maxFeePerGas: 5446911277, maxPriorityFeePerGas: 1210002200 },
+ { maxFeePerGas: 5991607851, maxPriorityFeePerGas: 1331003630 },
+ { maxFeePerGas: 6590774627, maxPriorityFeePerGas: 1464105324 },
+ { maxFeePerGas: 7249858681, maxPriorityFeePerGas: 1610517320 },
+ { maxFeePerGas: 7974851800, maxPriorityFeePerGas: 1771570662 },
+ { maxFeePerGas: 8772344954, maxPriorityFeePerGas: 1948729500 },
+ { maxFeePerGas: 9649588222, maxPriorityFeePerGas: 2143604398 },
+ { maxFeePerGas: 10614556693, maxPriorityFeePerGas: 2357966982 },
+ { maxFeePerGas: 11676022977, maxPriorityFeePerGas: 2593766039 },
+ { maxFeePerGas: 12843636951, maxPriorityFeePerGas: 2853145236 },
+ ],
+ gasLimit: 21000,
+ gasUsed: 21000,
+ },
};
};
@@ -384,11 +435,6 @@ export const createSwapsMockStore = () => {
},
],
},
- estimatedGas: {
- txData: {
- feeEstimate: 5435000587128155,
- },
- },
},
},
appState: {
diff --git a/ui/ducks/swaps/swaps.js b/ui/ducks/swaps/swaps.js
index fc75375ba..a2fe1b53c 100644
--- a/ui/ducks/swaps/swaps.js
+++ b/ui/ducks/swaps/swaps.js
@@ -31,7 +31,6 @@ import {
updateSmartTransaction,
setSmartTransactionsRefreshInterval,
fetchSmartTransactionFees,
- estimateSmartTransactionsGas,
cancelSmartTransaction,
getTransactions,
} from '../../store/actions';
@@ -923,36 +922,44 @@ export const signAndSendSwapsSmartTransaction = ({
const approveTxParams = getApproveTxParams(state);
let approvalTxUuid;
+ let updatedApproveTxParams;
try {
if (approveTxParams) {
- const updatedApproveTxParams = {
+ updatedApproveTxParams = {
...approveTxParams,
value: '0x0',
};
- const smartTransactionApprovalFees = await dispatch(
- fetchSwapsSmartTransactionFees(updatedApproveTxParams),
- );
+ }
+ const fees = await dispatch(
+ fetchSwapsSmartTransactionFees(
+ unsignedTransaction,
+ updatedApproveTxParams,
+ ),
+ );
+ if (!fees) {
+ log.error('"fetchSwapsSmartTransactionFees" failed');
+ dispatch(setSwapsSTXSubmitLoading(false));
+ dispatch(setCurrentSmartTransactionsError(stxErrorTypes.UNAVAILABLE));
+ return;
+ }
+ if (approveTxParams) {
updatedApproveTxParams.gas = `0x${decimalToHex(
- smartTransactionApprovalFees?.gasLimit || 0,
+ fees.approvalTxFees?.gasLimit || 0,
)}`;
approvalTxUuid = await dispatch(
signAndSendSmartTransaction({
unsignedTransaction: updatedApproveTxParams,
- smartTransactionFees: smartTransactionApprovalFees,
+ smartTransactionFees: fees.approvalTxFees,
}),
);
}
-
- const smartTransactionFees = await dispatch(
- fetchSwapsSmartTransactionFees(unsignedTransaction),
- );
unsignedTransaction.gas = `0x${decimalToHex(
- smartTransactionFees?.gasLimit || 0,
+ fees.tradeTxFees?.gasLimit || 0,
)}`;
const uuid = await dispatch(
signAndSendSmartTransaction({
unsignedTransaction,
- smartTransactionFees,
+ smartTransactionFees: fees.tradeTxFees,
}),
);
@@ -1304,37 +1311,17 @@ export function fetchMetaSwapsGasPriceEstimates() {
};
}
-export function fetchSwapsSmartTransactionFees(unsignedTransaction) {
- return async (dispatch, getState) => {
- const {
- swaps: { isFeatureFlagLoaded },
- } = getState();
- try {
- return await dispatch(fetchSmartTransactionFees(unsignedTransaction));
- } catch (e) {
- if (e.message.startsWith('Fetch error:') && isFeatureFlagLoaded) {
- const errorObj = parseSmartTransactionsError(e.message);
- dispatch(setCurrentSmartTransactionsError(errorObj?.type));
- }
- }
- return null;
- };
-}
-
-export function estimateSwapsSmartTransactionsGas(
+export function fetchSwapsSmartTransactionFees(
unsignedTransaction,
approveTxParams,
) {
return async (dispatch, getState) => {
const {
- swaps: { isFeatureFlagLoaded, swapsSTXLoading },
+ swaps: { isFeatureFlagLoaded },
} = getState();
- if (swapsSTXLoading) {
- return;
- }
try {
- await dispatch(
- estimateSmartTransactionsGas(unsignedTransaction, approveTxParams),
+ return await dispatch(
+ fetchSmartTransactionFees(unsignedTransaction, approveTxParams),
);
} catch (e) {
if (e.message.startsWith('Fetch error:') && isFeatureFlagLoaded) {
@@ -1342,6 +1329,7 @@ export function estimateSwapsSmartTransactionsGas(
dispatch(setCurrentSmartTransactionsError(errorObj?.type));
}
}
+ return null;
};
}
diff --git a/ui/pages/swaps/view-quote/view-quote.js b/ui/pages/swaps/view-quote/view-quote.js
index e1a098b2b..3e42fb9e8 100644
--- a/ui/pages/swaps/view-quote/view-quote.js
+++ b/ui/pages/swaps/view-quote/view-quote.js
@@ -47,8 +47,8 @@ import {
getCurrentSmartTransactionsError,
getCurrentSmartTransactionsErrorMessageDismissed,
getSwapsSTXLoading,
- estimateSwapsSmartTransactionsGas,
- getSmartTransactionEstimatedGas,
+ fetchSwapsSmartTransactionFees,
+ getSmartTransactionFees,
} from '../../../ducks/swaps/swaps';
import {
conversionRateSelector,
@@ -202,9 +202,7 @@ export default function ViewQuote() {
(currentSmartTransactionsError !== 'not_enough_funds' ||
currentSmartTransactionsErrorMessageDismissed)
);
- const smartTransactionEstimatedGas = useSelector(
- getSmartTransactionEstimatedGas,
- );
+ const smartTransactionFees = useSelector(getSmartTransactionFees);
const swapsNetworkConfig = useSelector(getSwapsNetworkConfig);
const unsignedTransaction = usedQuote.trade;
@@ -308,7 +306,7 @@ export default function ViewQuote() {
chainId,
smartTransactionsEnabled &&
smartTransactionsOptInStatus &&
- smartTransactionEstimatedGas?.txData,
+ smartTransactionFees?.tradeTxFees,
nativeCurrencySymbol,
);
}, [
@@ -321,7 +319,7 @@ export default function ViewQuote() {
approveGas,
memoizedTokenConversionRates,
chainId,
- smartTransactionEstimatedGas?.txData,
+ smartTransactionFees?.tradeTxFees,
nativeCurrencySymbol,
smartTransactionsEnabled,
smartTransactionsOptInStatus,
@@ -391,11 +389,11 @@ export default function ViewQuote() {
if (
currentSmartTransactionsEnabled &&
smartTransactionsOptInStatus &&
- smartTransactionEstimatedGas?.txData
+ smartTransactionFees?.tradeTxFees
) {
const stxEstimatedFeeInWeiDec =
- smartTransactionEstimatedGas.txData.feeEstimate +
- (smartTransactionEstimatedGas.approvalTxData?.feeEstimate || 0);
+ smartTransactionFees?.tradeTxFees.feeEstimate +
+ (smartTransactionFees?.approvalTxFees?.feeEstimate || 0);
const stxMaxFeeInWeiDec =
stxEstimatedFeeInWeiDec * swapsNetworkConfig.stxMaxFeeMultiplier;
({ feeInFiat, feeInEth, rawEthFee, feeInUsd } = getFeeForSmartTransaction({
@@ -409,7 +407,7 @@ export default function ViewQuote() {
additionalTrackingParams.stx_fee_in_usd = Number(feeInUsd);
additionalTrackingParams.stx_fee_in_eth = Number(rawEthFee);
additionalTrackingParams.estimated_gas =
- smartTransactionEstimatedGas.txData.gasLimit;
+ smartTransactionFees?.tradeTxFees.gasLimit;
({
feeInFiat: maxFeeInFiat,
feeInEth: maxFeeInEth,
@@ -785,11 +783,11 @@ export default function ViewQuote() {
chainId,
};
intervalId = setInterval(() => {
- dispatch(
- estimateSwapsSmartTransactionsGas(unsignedTx, approveTxParams),
- );
+ if (!swapsSTXLoading) {
+ dispatch(fetchSwapsSmartTransactionFees(unsignedTx, approveTxParams));
+ }
}, swapsNetworkConfig.stxGetTransactionsRefreshTime);
- dispatch(estimateSwapsSmartTransactionsGas(unsignedTx, approveTxParams));
+ dispatch(fetchSwapsSmartTransactionFees(unsignedTx, approveTxParams));
} else if (intervalId) {
clearInterval(intervalId);
}
@@ -908,14 +906,14 @@ export default function ViewQuote() {
/>
{currentSmartTransactionsEnabled &&
smartTransactionsOptInStatus &&
- !smartTransactionEstimatedGas?.txData && (
+ !smartTransactionFees?.tradeTxFees && (