1import { useCallback, useEffect, useState } from 'react';
3import { useNetwork } from 'store/network';
5import getSuggestedGasPrice from 'lib/getSuggestedGasPrice';
6import { DEFAULT_GAS_PRICE_GWEI } from './constants';
9 * handles all of the state of components that manage gas prices
11 * + lazy fetching optimal gas from oracle
12 * + resetting to oracle (or sync) default
13 * @param {Number} initialGasPrice the initial gas price available instantly
15export default function useGasPrice(initialGasPrice = DEFAULT_GAS_PRICE_GWEI) {
16 const { networkType } = useNetwork();
17 const [suggestedGasPrice, setSuggestedGasPrice] = useState(initialGasPrice); // gwei
18 const [gasPrice, setGasPrice] = useState(initialGasPrice); // gwei
24 const suggestedGasPrice = await getSuggestedGasPrice(networkType);
31 setSuggestedGasPrice(suggestedGasPrice);
32 setGasPrice(suggestedGasPrice);
35 return () => (mounted = true);
38 const resetGasPrice = useCallback(() => setGasPrice(suggestedGasPrice), [
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