aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-05-30 23:26:42 +0800
committerDan <danjm.com@gmail.com>2018-05-31 09:13:49 +0800
commit1bde2892ec222cec1ba3265d50ed59f665afbf83 (patch)
treea75c78fc2b6a6693e002ed0753da745281478b53 /ui
parent64aa56b5a6f753d198ceadc9cf2c79929046fc19 (diff)
downloadtangerine-wallet-browser-1bde2892ec222cec1ba3265d50ed59f665afbf83.tar
tangerine-wallet-browser-1bde2892ec222cec1ba3265d50ed59f665afbf83.tar.gz
tangerine-wallet-browser-1bde2892ec222cec1ba3265d50ed59f665afbf83.tar.bz2
tangerine-wallet-browser-1bde2892ec222cec1ba3265d50ed59f665afbf83.tar.lz
tangerine-wallet-browser-1bde2892ec222cec1ba3265d50ed59f665afbf83.tar.xz
tangerine-wallet-browser-1bde2892ec222cec1ba3265d50ed59f665afbf83.tar.zst
tangerine-wallet-browser-1bde2892ec222cec1ba3265d50ed59f665afbf83.zip
Improve efficiency of estimateGasPriceFromRecentBlocks
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/send_/send.utils.js15
1 files changed, 5 insertions, 10 deletions
diff --git a/ui/app/components/send_/send.utils.js b/ui/app/components/send_/send.utils.js
index 9b8f1d118..e685cc274 100644
--- a/ui/app/components/send_/send.utils.js
+++ b/ui/app/components/send_/send.utils.js
@@ -221,26 +221,21 @@ function generateTokenTransferData (selectedAddress, selectedToken) {
).join('')
}
-function hexComparator (a, b) {
- return conversionGreaterThan(
- { value: a, fromNumericBase: 'hex' },
- { value: b, fromNumericBase: 'hex' },
- ) ? 1 : -1
-}
-
function estimateGasPriceFromRecentBlocks (recentBlocks) {
// Return 1 gwei if no blocks have been observed:
if (!recentBlocks || recentBlocks.length === 0) {
return ONE_GWEI_IN_WEI_HEX
}
+
const lowestPrices = recentBlocks.map((block) => {
if (!block.gasPrices || block.gasPrices.length < 1) {
return ONE_GWEI_IN_WEI_HEX
}
- return block.gasPrices
- .sort(hexComparator)[0]
+ return block.gasPrices.reduce((currentLowest, next) => {
+ return parseInt(next, 16) < parseInt(currentLowest, 16) ? next : currentLowest
+ })
})
- .sort(hexComparator)
+ .sort((a, b) => parseInt(a, 16) > parseInt(b, 16) ? 1 : -1)
return lowestPrices[Math.floor(lowestPrices.length / 2)]
}