1import { NETWORK_TYPES } from './network';
2import { DEFAULT_GAS_PRICE_GWEI, MAX_GAS_PRICE_GWEI } from './constants';
3import { formatWait } from 'components/L2/Dropdowns/FeeDropdown';
5// ethgasstation returns values in floating point, one order of magitude
6// more than gwei. see: https://docs.ethgasstation.info
7// we don't want to charge users more than the gas tank funds
8const minGas = gas => Math.min(Math.ceil(gas), MAX_GAS_PRICE_GWEI);
10export const defaultGasValues = value => ({
25export default async function getSuggestedGasPrice(networkType) {
26 switch (networkType) {
27 case NETWORK_TYPES.ROPSTEN:
28 return defaultGasValues(10);
29 case NETWORK_TYPES.OFFLINE:
30 return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
31 case NETWORK_TYPES.LOCAL:
34 const etherscanGas = await fetch(
35 'https://api.etherscan.io/api' +
36 '?module=gastracker' +
38 '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
45 const ethgasstationGas = await fetch(
46 'https://ethgasstation.info/json/ethgasAPI.json',
53 const etherscanGasJson = await etherscanGas.json();
55 const ethgasstationGasJson = await ethgasstationGas.json();
59 price: minGas(etherscanGasJson.result.FastGasPrice),
60 wait: formatWait(ethgasstationGasJson.fastWait),
63 price: minGas(etherscanGasJson.result.ProposeGasPrice),
64 wait: formatWait(ethgasstationGasJson.avgWait),
67 price: minGas(etherscanGasJson.result.SafeGasPrice),
68 wait: formatWait(ethgasstationGasJson.safeLowWait),
72 return defaultGasValues(DEFAULT_GAS_PRICE_GWEI);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list