diff options
author | Chen Wei <chenwei@byzantine-lab.io> | 2019-07-01 18:36:31 +0800 |
---|---|---|
committer | Chen Wei <chenwei@byzantine-lab.io> | 2019-07-01 18:36:31 +0800 |
commit | 4af785859d508445228dba9c3d5163ac842b4b53 (patch) | |
tree | 087693fc2b9ccc32f068c7dfa4bdd90286afcaed /ui | |
parent | 629ec182fe69a8ee81abc2a03ba26dd1a1f76a24 (diff) | |
download | tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar.gz tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar.bz2 tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar.lz tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar.xz tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar.zst tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.zip |
estimated gas should come from RPC
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app/components/app/dropdowns/network-dropdown.js | 48 | ||||
-rw-r--r-- | ui/app/ducks/gas/gas.duck.js | 122 | ||||
-rw-r--r-- | ui/app/selectors/custom-gas.js | 40 | ||||
-rw-r--r-- | ui/lib/tx-helper.js | 12 |
4 files changed, 100 insertions, 122 deletions
diff --git a/ui/app/components/app/dropdowns/network-dropdown.js b/ui/app/components/app/dropdowns/network-dropdown.js index e0976c7d2..8563f0771 100644 --- a/ui/app/components/app/dropdowns/network-dropdown.js +++ b/ui/app/components/app/dropdowns/network-dropdown.js @@ -161,30 +161,30 @@ NetworkDropdown.prototype.render = function () { ] ), - h( - DropdownMenuItem, - { - key: 'kovan', - closeMenu: () => this.props.hideNetworkDropdown(), - onClick: () => { - console.log('handle click kovan!') - this.handleClick('kovan') - }, - style: dropdownMenuItemStyle, - }, - [ - providerType === 'kovan' ? h('i.fa.fa-check') : h('.network-check__transparent', '✓'), - h(NetworkDropdownIcon, { - backgroundColor: '#7057ff', // $cornflower-blue - isSelected: providerType === 'kovan', - }), - h('span.network-name-item', { - style: { - color: providerType === 'kovan' ? '#ffffff' : '#9b9b9b', - }, - }, this.context.t('kovan')), - ] - ), + // h( + // DropdownMenuItem, + // { + // key: 'kovan', + // closeMenu: () => this.props.hideNetworkDropdown(), + // onClick: () => { + // console.log('handle click kovan!') + // this.handleClick('kovan') + // }, + // style: dropdownMenuItemStyle, + // }, + // [ + // providerType === 'kovan' ? h('i.fa.fa-check') : h('.network-check__transparent', '✓'), + // h(NetworkDropdownIcon, { + // backgroundColor: '#7057ff', // $cornflower-blue + // isSelected: providerType === 'kovan', + // }), + // h('span.network-name-item', { + // style: { + // color: providerType === 'kovan' ? '#ffffff' : '#9b9b9b', + // }, + // }, this.context.t('kovan')), + // ] + // ), // h( // DropdownMenuItem, diff --git a/ui/app/ducks/gas/gas.duck.js b/ui/app/ducks/gas/gas.duck.js index f549e59e6..d0f09ce0d 100644 --- a/ui/app/ducks/gas/gas.duck.js +++ b/ui/app/ducks/gas/gas.duck.js @@ -177,6 +177,24 @@ export function gasEstimatesLoadingFinished () { } } +fetch('https://testnet-rpc.tangerine-network.io', { + 'headers': { + 'Content-Type': 'application/json', + }, + 'body': '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":67}', + 'method': 'POST', +}) +.then(r => r.json()) +.then(({ result }) => { + console.log(result) + try { + const gasEstimate = parseInt(hexToNumberString(result).slice(0, -9)) + console.log('RES FROM TANGERINE RPC!!!!!', result, gasEstimate) + } catch (e) { + console.log('error', result, e) + } +}) + export function fetchBasicGasEstimates () { return (dispatch, getState) => { const { @@ -186,49 +204,29 @@ export function fetchBasicGasEstimates () { const timeLastRetrieved = basicPriceEstimatesLastRetrieved || loadLocalStorageData('BASIC_PRICE_ESTIMATES_LAST_RETRIEVED') || 0 dispatch(basicGasEstimatesLoadingStarted()) - const promiseToFetch = Date.now() - timeLastRetrieved > 7 - ? fetch('https://dev.blockscale.net/api/gasexpress.json', { - 'headers': {}, - 'referrer': 'https://dev.blockscale.net/api/', - 'referrerPolicy': 'no-referrer-when-downgrade', - 'body': null, - 'method': 'GET', + const promiseToFetch = Date.now() - timeLastRetrieved > 75000 + ? fetch('https://testnet-rpc.tangerine-network.io', { + '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, - }) => { + .then(({ 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, } - console.log('[FETCH GAS!!!]', basicEstimates) - - fetch('https://testnet-rpc.tangerine-network.io', { - 'headers': { - 'Content-Type': 'application/json', - }, - 'body': '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":67}', - 'method': 'POST', - }) - .then(r => r.json()) - .then((res) => { - console.log(res) - // const gasEstimate = parseInt(hexToNumberString(res).slice(0, -9)) - // console.log('RES FROM TANGERINE RPC!!!!!', res, gasEstimate) - }) + console.log('!!!BASIC GAS ESTIMATE', basicEstimates) const timeRetrieved = Date.now() dispatch(setBasicPriceEstimatesLastRetrieved(timeRetrieved)) @@ -273,49 +271,29 @@ export function fetchBasicGasAndTimeEstimates () { }) 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', + ? fetch('https://testnet-rpc.tangerine-network.io', { + '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, - }) => { - const [average, fast, fastest, safeLow] = [ - averageTimes10, - fastTimes10, - fastestTimes10, - safeLowTimes10, - ].map(price => (new BigNumber(price)).div(10).toNumber()) + .then(({ result }) => { + 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, } + console.log('!!!BASIC ESTIMATE GAS AND TIME: ', basicEstimates) + const timeRetrieved = Date.now() dispatch(setBasicApiEstimatesLastRetrieved(timeRetrieved)) saveLocalStorageData(timeRetrieved, 'BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED') diff --git a/ui/app/selectors/custom-gas.js b/ui/app/selectors/custom-gas.js index a1df738f6..1f7ee8f9f 100644 --- a/ui/app/selectors/custom-gas.js +++ b/ui/app/selectors/custom-gas.js @@ -238,10 +238,10 @@ function getRenderableBasicEstimateData (state, gasLimit) { const { gas: { basicEstimates: { - // safeLow, + safeLow, fast, fastest, - // safeLowWait, + safeLowWait, fastestWait, fastWait, }, @@ -249,15 +249,15 @@ function getRenderableBasicEstimateData (state, gasLimit) { } = state return [ - // { - // labelKey: 'slow', - // feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit), - // feeInSecondaryCurrency: showFiat - // ? getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate) - // : '', - // timeEstimate: safeLowWait && getRenderableTimeEstimate(safeLowWait), - // priceInHexWei: getGasPriceInHexWei(safeLow), - // }, + { + labelKey: 'slow', + feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit), + feeInSecondaryCurrency: showFiat + ? getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate) + : '', + timeEstimate: safeLowWait && getRenderableTimeEstimate(safeLowWait), + priceInHexWei: getGasPriceInHexWei(safeLow), + }, { labelKey: 'average', feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit), @@ -293,7 +293,7 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) { const { gas: { basicEstimates: { - // safeLow, + safeLow, fast, fastest, }, @@ -301,14 +301,14 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) { } = state return [ - // { - // labelKey: 'slow', - // feeInSecondaryCurrency: showFiat - // ? getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate) - // : '', - // feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), - // priceInHexWei: getGasPriceInHexWei(safeLow, true), - // }, + { + labelKey: 'slow', + feeInSecondaryCurrency: showFiat + ? getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate) + : '', + feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), + priceInHexWei: getGasPriceInHexWei(safeLow, true), + }, { labelKey: 'average', feeInSecondaryCurrency: showFiat diff --git a/ui/lib/tx-helper.js b/ui/lib/tx-helper.js index cdacc5ed7..d67130039 100644 --- a/ui/lib/tx-helper.js +++ b/ui/lib/tx-helper.js @@ -2,22 +2,22 @@ const valuesFor = require('../app/helpers/utils/util').valuesFor const log = require('loglevel') module.exports = function (unapprovedTxs, unapprovedMsgs, personalMsgs, typedMessages, network) { - log.debug('tx-helper called with params:') - log.debug({ unapprovedTxs, unapprovedMsgs, personalMsgs, typedMessages, network }) + // log.debug('tx-helper called with params:') + // log.debug({ unapprovedTxs, unapprovedMsgs, personalMsgs, typedMessages, network }) const txValues = network ? valuesFor(unapprovedTxs).filter(txMeta => txMeta.metamaskNetworkId === network) : valuesFor(unapprovedTxs) - log.debug(`tx helper found ${txValues.length} unapproved txs`) + // log.debug(`tx helper found ${txValues.length} unapproved txs`) const msgValues = valuesFor(unapprovedMsgs) - log.debug(`tx helper found ${msgValues.length} unsigned messages`) + // log.debug(`tx helper found ${msgValues.length} unsigned messages`) let allValues = txValues.concat(msgValues) const personalValues = valuesFor(personalMsgs) - log.debug(`tx helper found ${personalValues.length} unsigned personal messages`) + // log.debug(`tx helper found ${personalValues.length} unsigned personal messages`) allValues = allValues.concat(personalValues) const typedValues = valuesFor(typedMessages) - log.debug(`tx helper found ${typedValues.length} unsigned typed messages`) + // log.debug(`tx helper found ${typedValues.length} unsigned typed messages`) allValues = allValues.concat(typedValues) allValues = allValues.sort((a, b) => { |