diff options
author | Hsuan Lee <boczeratul@gmail.com> | 2019-04-06 12:25:33 +0800 |
---|---|---|
committer | Hsuan Lee <boczeratul@gmail.com> | 2019-04-06 12:26:13 +0800 |
commit | ba92ec6104175c8324e55e241d77e415ba7b1791 (patch) | |
tree | d0a3664f01a43d838c981c4dd5711c2e8c17d4d4 | |
parent | b6e7279eeaddc3171a87686c894af54e4dc66492 (diff) | |
download | dexon-wallet-ba92ec6104175c8324e55e241d77e415ba7b1791.tar.gz dexon-wallet-ba92ec6104175c8324e55e241d77e415ba7b1791.tar.zst dexon-wallet-ba92ec6104175c8324e55e241d77e415ba7b1791.zip |
Fix gas estimation
-rw-r--r-- | ui/app/ducks/gas.duck.js | 87 | ||||
-rw-r--r-- | ui/app/selectors/custom-gas.js | 32 |
2 files changed, 49 insertions, 70 deletions
diff --git a/ui/app/ducks/gas.duck.js b/ui/app/ducks/gas.duck.js index 83c236d8..a1186f63 100644 --- a/ui/app/ducks/gas.duck.js +++ b/ui/app/ducks/gas.duck.js @@ -1,5 +1,6 @@ import { clone, uniqBy, flatten } from 'ramda' import BigNumber from 'bignumber.js' +import { hexToNumberString } from 'web3-utils' import { loadLocalStorageData, saveLocalStorageData, @@ -170,31 +171,29 @@ export function fetchBasicGasEstimates () { return (dispatch) => { dispatch(basicGasEstimatesLoadingStarted()) - return fetch('https://dev.blockscale.net/api/gasexpress.json', { - 'headers': {}, - 'referrer': 'https://dev.blockscale.net/api/', - 'referrerPolicy': 'no-referrer-when-downgrade', - 'body': null, - 'method': 'GET', + // TODO: switch to Mainnet + return fetch('https://testnet-rpc.dexon.org', { + 'headers': { + 'Content-Type': 'application/json', + }, + 'body': '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":67}', + 'method': 'POST', 'mode': 'cors'} ) .then(r => r.json()) .then(({ - safeLow, - standard: average, - fast, - fastest, - block_time: blockTime, - blockNum, + result, }) => { + const gasEstimate = parseInt(hexToNumberString(result).slice(0, -9)) + const basicEstimates = { - safeLow, - average, - fast, - fastest, - blockTime, - blockNum, + blockTime: 1, + safeLow: gasEstimate, + average: gasEstimate, + fast: gasEstimate, + fastest: gasEstimate * 2, } + dispatch(setBasicGasEstimateData(basicEstimates)) dispatch(basicGasEstimatesLoadingFinished()) return basicEstimates @@ -212,48 +211,28 @@ export function fetchBasicGasAndTimeEstimates () { dispatch(basicGasEstimatesLoadingStarted()) + // TODO: switch to Mainnet const promiseToFetch = Date.now() - timeLastRetrieved > 75000 - ? fetch('https://ethgasstation.info/json/ethgasAPI.json', { - 'headers': {}, - 'referrer': 'http://ethgasstation.info/json/', - 'referrerPolicy': 'no-referrer-when-downgrade', - 'body': null, - 'method': 'GET', - 'mode': 'cors'} - ) + ? fetch('https://testnet-rpc.dexon.org', { + 'headers': { + 'Content-Type': 'application/json', + }, + 'body': '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":67}', + 'method': 'POST', + 'mode': 'cors', + }) .then(r => r.json()) .then(({ - average: averageTimes10, - avgWait, - block_time: blockTime, - blockNum, - fast: fastTimes10, - fastest: fastestTimes10, - fastestWait, - fastWait, - safeLow: safeLowTimes10, - safeLowWait, - speed, + result, }) => { - const [average, fast, fastest, safeLow] = [ - averageTimes10, - fastTimes10, - fastestTimes10, - safeLowTimes10, - ].map(price => (new BigNumber(price)).div(10).toNumber()) + const gasEstimate = parseInt(hexToNumberString(result).slice(0, -9)) const basicEstimates = { - average, - avgWait, - blockTime, - blockNum, - fast, - fastest, - fastestWait, - fastWait, - safeLow, - safeLowWait, - speed, + blockTime: 1, + safeLow: gasEstimate, + average: gasEstimate, + fast: gasEstimate, + fastest: gasEstimate * 2, } const timeRetrieved = Date.now() diff --git a/ui/app/selectors/custom-gas.js b/ui/app/selectors/custom-gas.js index e98df53f..b0dfece2 100644 --- a/ui/app/selectors/custom-gas.js +++ b/ui/app/selectors/custom-gas.js @@ -195,10 +195,10 @@ function getRenderableBasicEstimateData (state) { const { gas: { basicEstimates: { - safeLow, + // safeLow, fast, fastest, - safeLowWait, + // safeLowWait, fastestWait, fastWait, }, @@ -220,13 +220,13 @@ function getRenderableBasicEstimateData (state) { timeEstimate: fastWait && getRenderableTimeEstimate(fastWait), priceInHexWei: getGasPriceInHexWei(fast), }, - { - labelKey: 'slow', - feeInPrimaryCurrency: getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate), - feeInSecondaryCurrency: getRenderableEthFee(safeLow, gasLimit), - timeEstimate: safeLowWait && getRenderableTimeEstimate(safeLowWait), - priceInHexWei: getGasPriceInHexWei(safeLow), - }, + // { + // labelKey: 'slow', + // feeInPrimaryCurrency: getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate), + // feeInSecondaryCurrency: getRenderableEthFee(safeLow, gasLimit), + // timeEstimate: safeLowWait && getRenderableTimeEstimate(safeLowWait), + // priceInHexWei: getGasPriceInHexWei(safeLow), + // }, ] } @@ -240,7 +240,7 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) { const { gas: { basicEstimates: { - safeLow, + // safeLow, fast, fastest, }, @@ -260,11 +260,11 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) { feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), priceInHexWei: getGasPriceInHexWei(fast, true), }, - { - labelKey: 'slow', - feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate), - feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), - priceInHexWei: getGasPriceInHexWei(safeLow, true), - }, + // { + // labelKey: 'slow', + // feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate), + // feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), + // priceInHexWei: getGasPriceInHexWei(safeLow, true), + // }, ] } |