1import { useCallback, useEffect, useState } from 'react';
3import { useNetwork } from 'store/network';
5import getSuggestedGasPrices, {
7} from 'lib/getSuggestedGasPrice';
8import { DEFAULT_GAS_PRICE_GWEI } from './constants';
11 * handles all of the state of components that manage gas prices
13 * + lazy fetching optimal gas from oracle
14 * + resetting to oracle (or sync) default
15 * @param {Number} initialGasPrice the initial gas price available instantly
17export default function useGasPrice(initialGasPrice = DEFAULT_GAS_PRICE_GWEI) {
18 const [mounted, setMounted] = useState(false);
19 const { networkType, web3 } = useNetwork();
20 const [suggestedGasPrices, setSuggestedGasPrices] = useState(
21 defaultGasValues(initialGasPrice)
22 ); // fast, average, low. In gwei
23 const [gasPrice, setGasPrice] = useState(
24 defaultGasValues(initialGasPrice).average
27 const fetchPrices = useCallback(async () => {
32 const suggestedGasPrices = await getSuggestedGasPrices(
36 console.log(suggestedGasPrices);
39 setSuggestedGasPrices(suggestedGasPrices);
40 setGasPrice(suggestedGasPrices.average);
41 }, [mounted, networkType, web3]);
46 return () => setMounted(false);
47 }, [mounted, networkType, web3, fetchPrices]);
49 const resetGasPrice = useCallback(
50 () => setGasPrice(suggestedGasPrices.average),
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