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 } = 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(networkType);
33 console.log(suggestedGasPrices);
36 setSuggestedGasPrices(suggestedGasPrices);
37 setGasPrice(suggestedGasPrices.average);
38 }, [mounted, networkType]);
43 return () => setMounted(false);
44 }, [mounted, networkType, fetchPrices]);
46 const resetGasPrice = useCallback(
47 () => 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