Skip to content

Commit

Permalink
Merge pull request #375 from Conflux-Chain/Version-v0.6.12
Browse files Browse the repository at this point in the history
  • Loading branch information
yqrashawn committed Dec 21, 2021
2 parents 0e0a5fa + 8b96102 commit 7c2f895
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 68 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## Current Develop Branch

## 0.6.12 Tue Dec 21 2021

This comment has been minimized.

Copy link
@Sarkar44

Sarkar44 Dec 28, 2021

CHANGELOG.md


## 0.6.11 Sat Nov 06 2021

## 0.6.10 Mon Aug 02 2021
Expand Down
2 changes: 1 addition & 1 deletion app/manifest.json
@@ -1,7 +1,7 @@
{
"name": "ConfluxPortal",
"short_name": "ConfluxPortal",
"version": "0.6.11",
"version": "0.6.12",
"manifest_version": 2,
"author": "https://confluxnetwork.org",
"description": "__MSG_appDescription__",
Expand Down
25 changes: 23 additions & 2 deletions app/scripts/controllers/transactions/index.js
Expand Up @@ -303,8 +303,29 @@ class TransactionController extends EventEmitter {
: '0x0'
txMeta.gasPriceSpecified = Boolean(txParams.gasPrice)
let gasPrice = txParams.gasPrice
if (!gasPrice) {
gasPrice = 30000
const isMainnet = txMeta.metamaskNetworkId === '1029'
if (isMainnet) {
const res = await fetch('https://main.confluxrpc.com/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'gasstation_price',
params: [],
}),
}).then(res => res.json())
if (res && res.result && res.result.fastest) {
if (!gasPrice || res.result.fastest > gasPrice) {
gasPrice = res.result.fastest
}
} else {
gasPrice = 1000000000
}
} else {
if (!gasPrice) {
gasPrice = 1
}
}
txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16))
// set gasLimit
Expand Down
132 changes: 67 additions & 65 deletions ui/app/ducks/gas/gas.duck.js
Expand Up @@ -183,6 +183,7 @@ export function gasEstimatesLoadingFinished() {
export function fetchBasicGasEstimates() {
return async (dispatch, getState) => {
const { basicPriceEstimatesLastRetrieved } = getState().gas
const isMainnet = getState().metamask.settings.network === 1029
const timeLastRetrieved =
basicPriceEstimatesLastRetrieved ||
loadLocalStorageData('BASIC_PRICE_ESTIMATES_LAST_RETRIEVED') ||
Expand All @@ -193,11 +194,12 @@ export function fetchBasicGasEstimates() {

let basicEstimates
if (Date.now() - timeLastRetrieved > 75000) {
basicEstimates = await fetchExternalBasicGasEstimates(dispatch)
basicEstimates = await fetchExternalBasicGasEstimates(dispatch, isMainnet)
} else {
const cachedBasicEstimates = loadLocalStorageData('BASIC_PRICE_ESTIMATES')
basicEstimates =
cachedBasicEstimates || (await fetchExternalBasicGasEstimates(dispatch))
cachedBasicEstimates ||
(await fetchExternalBasicGasEstimates(dispatch, isMainnet))
}

dispatch(setBasicGasEstimateData(basicEstimates))
Expand All @@ -208,36 +210,37 @@ export function fetchBasicGasEstimates() {
}
}

async function fetchExternalBasicGasEstimates(dispatch) {
// const [response /* estimateGasDrip */] = await Promise.all([
// fetch('https://ethgasstation.info/json/ethgasAPI.json', {
// headers: {},
// referrer: 'http://ethgasstation.info/json/',
// referrerPolicy: 'no-referrer-when-downgrade',
// body: null,
// method: 'GET',
// mode: 'cors',
// }),
// // (function() {
// // return new Promise((resolve, reject) => {
// // global.ethQuery.gasPrice((err, gasPrice) => {
// // if (err) {
// // reject(err)
// // }
// // resolve(gasPrice)
// // })
// // })
// // })(),
// ])

// const { result: estimateGasDrip } = await estimateGasResult.json()
// TODO change this back later, use 1 drip as default gas price for now
const estimateGasGdripTimes10 =
// new BigNumber(estimateGasDrip, 16)
new BigNumber('0x7530', 16)
.times(10)
.div(1e9)
.toNumber()
async function fetchExternalBasicGasEstimates(dispatch, isMainnet) {
let estimateGasGdripTimes10 = new BigNumber('0x3b9aca00', 16)
.times(10)
.div(1e9)
.toNumber()

if (isMainnet) {
const res = await fetch('https://main.confluxrpc.com/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'gasstation_price',
params: [],
}),
}).then(res => res.json())
if (res && res.result && res.result.fastest) {
estimateGasGdripTimes10 = new BigNumber(res.result.fastest, 16)
.times(10)
.div(1e9)
.toNumber()
}
} else {
estimateGasGdripTimes10 =
// new BigNumber(estimateGasDrip, 16)
new BigNumber('0x1', 16)
.times(10)
.div(1e9)
.toNumber()
}

// const {
// safeLow: safeLowTimes10,
Expand Down Expand Up @@ -291,6 +294,7 @@ async function fetchExternalBasicGasEstimates(dispatch) {
export function fetchBasicGasAndTimeEstimates() {
return async (dispatch, getState) => {
const { basicPriceAndTimeEstimatesLastRetrieved } = getState().gas
const isMainnet = getState().metamask.settings.network === 1029
const timeLastRetrieved =
basicPriceAndTimeEstimatesLastRetrieved ||
loadLocalStorageData('BASIC_GAS_AND_TIME_API_ESTIMATES_LAST_RETRIEVED') ||
Expand All @@ -301,14 +305,17 @@ export function fetchBasicGasAndTimeEstimates() {

let basicEstimates
if (Date.now() - timeLastRetrieved > 75000) {
basicEstimates = await fetchExternalBasicGasAndTimeEstimates(dispatch)
basicEstimates = await fetchExternalBasicGasAndTimeEstimates(
dispatch,
isMainnet
)
} else {
const cachedBasicEstimates = loadLocalStorageData(
'BASIC_GAS_AND_TIME_API_ESTIMATES'
)
basicEstimates =
cachedBasicEstimates ||
(await fetchExternalBasicGasAndTimeEstimates(dispatch))
(await fetchExternalBasicGasAndTimeEstimates(dispatch, isMainnet))
}

dispatch(setBasicGasEstimateData(basicEstimates))
Expand All @@ -318,40 +325,35 @@ export function fetchBasicGasAndTimeEstimates() {
}
}

async function fetchExternalBasicGasAndTimeEstimates(dispatch) {
// const [response /* estimateGasDrip */] = await Promise.all([
// fetch('https://ethgasstation.info/json/ethgasAPI.json', {
// headers: {},
// referrer: 'http://ethgasstation.info/json/',
// referrerPolicy: 'no-referrer-when-downgrade',
// body: null,
// method: 'GET',
// mode: 'cors',
// }),
// // (function() {
// // return new Promise((resolve, reject) => {
// // global.ethQuery.gasPrice((err, gasPrice) => {
// // if (err) {
// // reject(err)
// // }
// // resolve(gasPrice)
// // })
// // })
// // })(),
// ])

// const { result: estimateGasDrip } = await estimateGasResult.json()
// TODO change this back later, use 1 drip as default gas price for now
const estimateGasGdripTimes10 =
// new BigNumber(estimateGasDrip, 16)
new BigNumber('0x7530', 16)
.times(10)
.div(1e9)
.toNumber() ||
new BigNumber('0x7530', 16)
async function fetchExternalBasicGasAndTimeEstimates(dispatch, isMainnet) {
let estimateGasGdripTimes10 = new BigNumber('0x3b9aca00', 16)
.times(10)
.div(1e9)
.toNumber()

if (isMainnet) {
const res = await fetch('https://main.confluxrpc.com/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'gasstation_price',
params: [],
}),
}).then(res => res.json())
if (res && res.result && res.result.fastest) {
estimateGasGdripTimes10 = new BigNumber(res.result.fastest, 16)
.times(10)
.div(1e9)
.toNumber()
}
} else {
estimateGasGdripTimes10 = new BigNumber('0x1', 16)
.times(10)
.div(1e9)
.toNumber()
}

const {
// average: averageTimes10,
Expand Down

0 comments on commit 7c2f895

Please sign in to comment.