Merge pull request #391 from poanetwork/vb-gas-price-oracles-package-integration

Gas price oracles npm package integration
This commit is contained in:
Victor Baranov 2020-06-15 13:19:55 +03:00 committed by GitHub
commit 205c101ff8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 12 deletions

View File

@ -2,6 +2,7 @@
## Current Master
- [#391](https://github.com/poanetwork/nifty-wallet/pull/391) - (Feature) Gas price oracles npm package integration
- [#389](https://github.com/poanetwork/nifty-wallet/pull/389) - (Feature) Support 24 words mnemonic phrase
- [#388](https://github.com/poanetwork/nifty-wallet/pull/388) - (Feature) "Send all" option for simple coin transfers
- [#385](https://github.com/poanetwork/nifty-wallet/pull/385) - (Feature) Display value of current pending tx's nonce on send tx screen

View File

@ -61,6 +61,7 @@ import nanoid from 'nanoid'
const { importTypes } = require('../../old-ui/app/accounts/import/enums')
const { LEDGER, TREZOR } = require('../../old-ui/app/components/connect-hardware/enum')
const { ifPOA, ifRSK, getNetworkID, getDPath, setDPath } = require('../../old-ui/app/util')
const { GasPriceOracle } = require('gas-price-oracle')
import {
PhishingController,
@ -1967,23 +1968,30 @@ module.exports = class MetamaskController extends EventEmitter {
*/
getGasPriceFromOracles (networkId) {
return new Promise(async (resolve, reject) => {
const gasPriceOracleETC = 'https://gasprice-etc.poa.network'
const gasPriceOracleETH = 'https://gasprice.poa.network'
const gasPriceOracle = networkId === CLASSIC_CODE ?
gasPriceOracleETC : networkId === MAINNET_CODE ? gasPriceOracleETH : null
try {
if (gasPriceOracle) {
const response = await fetch(gasPriceOracle)
if (networkId === MAINNET_CODE) {
const oracle = new GasPriceOracle()
// optional fallbackGasPrices
const fallbackGasPrices = {
instant: 70, fast: 31, standard: 20, low: 7,
}
oracle.gasPrices(fallbackGasPrices).then((gasPrices) => {
gasPrices && (gasPrices.standard || gasPrices.fast) ? resolve(gasPrices.standard || gasPrices.fast) : reject()
})
} else if (networkId === CLASSIC_CODE) {
const gasPriceOracleETC = 'https://gasprice-etc.poa.network'
try {
const response = await fetch(gasPriceOracleETC)
const parsedResponse = await response.json()
if (parsedResponse && (parsedResponse.standard || parsedResponse.fast)) {
resolve(parsedResponse.standard || parsedResponse.fast)
} else {
reject()
reject('Empty response from gas price oracle')
}
} catch (error) {
reject(error)
}
} catch (error) {
reject(error)
} else {
reject(`No gas price oracles for ${networkId}`)
}
})
}

24
package-lock.json generated
View File

@ -37924,6 +37924,30 @@
}
}
},
"gas-price-oracle": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/gas-price-oracle/-/gas-price-oracle-0.1.4.tgz",
"integrity": "sha512-lIxzxu5LtkdUewaFl6MlBU2Me6rWL58ENeAOD2AM/KZYB0Os7EcIBq87ixTced4UF2zb9bzPcVPoEVuH7icOJQ==",
"requires": {
"axios": "^0.19.2",
"bignumber.js": "^9.0.0"
},
"dependencies": {
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"requires": {
"follow-redirects": "1.5.10"
}
},
"bignumber.js": {
"version": "9.0.0",
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
"integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A=="
}
}
},
"gather-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/gather-stream/-/gather-stream-1.0.0.tgz",

View File

@ -143,6 +143,7 @@
"fast-levenshtein": "^2.0.6",
"fuse.js": "^3.2.0",
"gaba": "^1.9.3",
"gas-price-oracle": "^0.1.4",
"human-standard-token-abi": "^2.0.0",
"idb-global": "^2.1.0",
"iframe-stream": "^3.0.0",

View File

@ -137,7 +137,7 @@ describe('MetaMaskController', function () {
},
}
const gasPrice = await metamaskController.getGasPrice()
const gasPrice = await metamaskController.getGasPriceFromBlocks(1)
assert.equal(gasPrice, '0x174876e800', 'accurately estimates 65th percentile accepted gas price')
metamaskController.recentBlocksController = realRecentBlocksController