aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/ducks
diff options
context:
space:
mode:
authorChen Wei <chenwei@byzantine-lab.io>2019-07-01 18:36:31 +0800
committerChen Wei <chenwei@byzantine-lab.io>2019-07-01 18:36:31 +0800
commit4af785859d508445228dba9c3d5163ac842b4b53 (patch)
tree087693fc2b9ccc32f068c7dfa4bdd90286afcaed /ui/app/ducks
parent629ec182fe69a8ee81abc2a03ba26dd1a1f76a24 (diff)
downloadtangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar.gz
tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.tar.zst
tangerine-wallet-browser-4af785859d508445228dba9c3d5163ac842b4b53.zip
estimated gas should come from RPC
Diffstat (limited to 'ui/app/ducks')
-rw-r--r--ui/app/ducks/gas/gas.duck.js122
1 files changed, 50 insertions, 72 deletions
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')