@@ -1,22 +1,22 @@
11import { useCallback, useEffect, useState } from 'react';
22import { Just } from 'folktale/maybe';
3−import { fromWei, toWei } from 'web3-utils';
3+import { toWei } from 'web3-utils';
44
55import { useNetwork } from 'store/network';
66import { useWallet } from 'store/wallet';
77import { usePointCursor } from 'store/pointCursor';
8−import { useSuggestedGasPrice } from 'lib/useSuggestedGasPrice';
98
10−import { GAS_LIMITS } from './constants';
9+import { GAS_LIMITS, DEFAULT_GAS_PRICE_GWEI } from './constants';
1110import {
1211 signTransaction,
1312 sendSignedTransaction,
1413 waitForTransactionConfirm,
1514 hexify,
1615} from './txn';
17−import * as need from './need';
18−import { ensureFundsFor } from './tank';
16+import * as need from 'lib/need';
17+import { ensureFundsFor } from 'lib/tank';
1918import useDeepEqualReference from './useDeepEqualReference';
19+import useGasPrice from './useGasPrice';
2020
2121const STATE = {
2222 NONE: 'NONE',
@@ -37,7 +37,7 @@ export default function useEthereumTransaction(
3737 transactionBuilder,
3838 refetch,
3939 initialGasLimit = GAS_LIMITS.DEFAULT,
40− initialGasPrice = 20
40+ initialGasPrice = DEFAULT_GAS_PRICE_GWEI
4141) {
4242 const { wallet, walletType, walletHdPath } = useWallet();
4343 const { web3, networkType } = useNetwork();
@@ -59,9 +59,7 @@ export default function useEthereumTransaction(
5959 const [state, setState] = useState(STATE.NONE);
6060 const [chainId, setChainId] = useState();
6161 const [nonce, setNonce] = useState();
62− const [gasPrice, setGasPrice] = useState(initialGasPrice); // gwei
63− const [suggestedGasPrice, setSuggestedGasPrice] = useState(gasPrice); // gwei
64− const { gasPrice: estimatedGasPrice } = useSuggestedGasPrice();
62+ const { gasPrice, setGasPrice, resetGasPrice } = useGasPrice(initialGasPrice);
6563 const [gasLimit] = useState(initialGasLimit);
6664 const [unsignedTransaction, setUnsignedTransaction] = useState();
6765 const [signedTransaction, setSignedTransaction] = useState();
@@ -179,25 +177,11 @@ export default function useEthereumTransaction(
179177 setSignedTransaction(undefined);
180178 setNonce(undefined);
181179 setChainId(undefined);
182− setGasPrice(suggestedGasPrice);
180+ resetGasPrice();
183181 setState(STATE.NONE);
184182 setError(undefined);
185183 setNeedFunds(undefined);
186− }, [suggestedGasPrice, setError]);
187−
188− const resetGasPrice = useCallback(() => setGasPrice(suggestedGasPrice), [
189− setGasPrice,
190− suggestedGasPrice,
191− ]);
192−
193− useEffect(() => {
194− const gasPrice = parseInt(
195− fromWei(estimatedGasPrice.toString(), 'gwei'),
196− 10
197− );
198− setSuggestedGasPrice(gasPrice);
199− setGasPrice(gasPrice);
200− }, [estimatedGasPrice]);
184+ }, [resetGasPrice, setError]);
201185
202186 useEffect(() => {
203187 let mounted = true;
@@ -226,15 +210,7 @@ export default function useEthereumTransaction(
226210 })();
227211
228212 return () => (mounted = false);
229− }, [
230− _wallet,
231− _web3,
232− setError,
233− nonce,
234− chainId,
235− networkType,
236− estimatedGasPrice,
237− ]);
213+ }, [_wallet, _web3, setError, nonce, chainId, networkType, initialGasPrice]);
238214
239215 useEffect(() => {
240216 let mounted = true;