@@ -22,7 +22,7 @@ import { ensureFundsFor } from 'lib/tank';
2222import useDeepEqualReference from 'lib/useDeepEqualReference';
2323import useGasPrice from 'lib/useGasPrice';
2424import timeout from 'lib/timeout';
25−import { safeToWei } from 'lib/lib';
25+import { safeToWei, safeFromWei } from 'lib/lib';
2626
2727const STATE = {
2828 NONE: 'NONE',
@@ -73,6 +73,8 @@ export default function useEthereumTransaction(
7373 const [needFunds, setNeedFunds] = useState();
7474 const [confirmationProgress, setConfirmationProgress] = useState(0.0);
7575
76+ const [finalCost, setFinalCost] = useState();
77+
7678 const initializing = nonce === undefined || chainId === undefined;
7779 const constructed = !!unsignedTransactions;
7880 const isDefaultState = state === STATE.NONE;
@@ -186,10 +188,26 @@ export default function useEthereumTransaction(
186188
187189 setConfirmationProgress(0.2);
188190
189− await Promise.all(
191+ const receipts = await Promise.all(
190192 txHashes.map(txHash => waitForTransactionConfirm(_web3, txHash))
191193 );
192194
195+ setFinalCost(
196+ safeFromWei(
197+ safeToWei(
198+ receipts.reduce(
199+ (acc, receipt) =>
200+ toBN(receipt.gasUsed)
201+ .mul(toBN(gasPrice))
202+ .add(acc),
203+ toBN(0)
204+ ),
205+ 'gwei'
206+ ),
207+ 'ether'
208+ )
209+ );
210+
193211 setConfirmationProgress(0.9);
194212
195213 setState(STATE.CONFIRMED);
@@ -217,6 +235,7 @@ export default function useEthereumTransaction(
217235 setError(undefined);
218236 setNeedFunds(undefined);
219237 setConfirmationProgress(0.0);
238+ setFinalCost(undefined);
220239 }, [resetGasPrice, setError]);
221240
222241 useEffect(() => {
@@ -314,6 +333,7 @@ export default function useEthereumTransaction(
314333 needFunds,
315334 gasLimit,
316335 unsignedTransactions,
336+ finalCost,
317337 });
318338
319339 return { ...values, bind: values };