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 { networkType } = useNetwork();
19 const [suggestedGasPrices, setSuggestedGasPrices] = useState(
20 defaultGasValues(initialGasPrice)
21 ); // fast, average, low. In gwei
22 const [gasPrice, setGasPrice] = useState(initialGasPrice); // gwei
28 const suggestedGasPrices = await getSuggestedGasPrices(networkType);
35 setSuggestedGasPrices(suggestedGasPrices);
36 setGasPrice(suggestedGasPrices.average.price);
39 return () => (mounted = true);
42 const resetGasPrice = useCallback(
43 () => setGasPrice(suggestedGasPrices.average.price),
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