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 / 10), 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 response = await fetch(
35 'https://api.etherscan.io/api' +
36 '?module=gastracker' +
38 '&apikey=CG52E4R96W56GIKUI4IJ8CH9EZIXPUW1W8',
45 const json = await response.json();
49 price: minGas(json.fast),
50 wait: formatWait(json.fastWait),
53 price: minGas(json.average),
54 wait: formatWait(json.avgWait),
57 price: minGas(json.safeLow),
58 wait: formatWait(json.safeLowWait),
62 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