@@ -7,6 +7,7 @@ import {
77 Flex,
88 LinkButton,
99 H5,
10+ Button,
1011} from 'indigo-react';
1112import { toBN } from 'web3-utils';
1213
@@ -26,6 +27,7 @@ import FeeDropdown from './L2/Dropdowns/FeeDropdown';
2627import CopyButton from './copiable/CopyButton';
2728
2829import './InlineEthereumTransaction.scss';
30+import { useRollerStore } from 'store/rollerStore';
2931
3032export default function InlineEthereumTransaction({
3133 // from useEthereumTransaction.bind
@@ -58,6 +60,7 @@ export default function InlineEthereumTransaction({
5860 className,
5961 onReturn,
6062}) {
63+ const { ethBalance } = useRollerStore();
6164 // show receipt after successful broadcast
6265 const [showReceipt, setShowReceipt] = useState(false);
6366 const toggleShowReceipt = useCallback(() => setShowReceipt(!showReceipt), [
@@ -91,6 +94,35 @@ export default function InlineEthereumTransaction({
9194 [resetGasPrice]
9295 );
9396
97+ const serializedTxsHex = useMemo(
98+ () =>
99+ signedTransactions &&
100+ signedTransactions.map(stx => hexify(stx.serialize())),
101+ [signedTransactions]
102+ );
103+
104+ const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
105+ unsignedTransactions,
106+ ]);
107+ const maxCost = useMemo(
108+ () =>
109+ safeFromWei(
110+ safeToWei(
111+ toBN(gasLimit)
112+ .mul(toBN(gasPrice))
113+ .mul(toBN(numTxs)),
114+ 'gwei'
115+ ),
116+ 'ether'
117+ ),
118+ [gasLimit, gasPrice, numTxs]
119+ );
120+
121+ const insufficientEth = useMemo(
122+ () => Number(maxCost) > Number(ethBalance.toString()),
123+ [maxCost, ethBalance]
124+ );
125+
94126 const renderPrimarySection = () => {
95127 if (error) {
96128 return (
@@ -135,6 +167,18 @@ export default function InlineEthereumTransaction({
135167 )}
136168 </>
137169 );
170+ } else if (insufficientEth) {
171+ return (
172+ <Grid.Item
173+ className="ph4 eth-tx-button insufficient-eth"
174+ full
175+ as={Button}
176+ solid
177+ center
178+ disabled>
179+ Insufficient ETH
180+ </Grid.Item>
181+ );
138182 } else if (showBroadcastButton) {
139183 return (
140184 <Grid.Item
@@ -178,30 +222,6 @@ export default function InlineEthereumTransaction({
178222 }
179223 };
180224
181− const serializedTxsHex = useMemo(
182− () =>
183− signedTransactions &&
184− signedTransactions.map(stx => hexify(stx.serialize())),
185− [signedTransactions]
186− );
187−
188− const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
189− unsignedTransactions,
190− ]);
191− const maxCost = useMemo(
192− () =>
193− safeFromWei(
194− safeToWei(
195− toBN(gasLimit)
196− .mul(toBN(gasPrice))
197− .mul(toBN(numTxs)),
198− 'gwei'
199− ),
200− 'ether'
201− ),
202− [gasLimit, gasPrice, numTxs]
203− );
204−
205225 return (
206226 <Grid className={cn(className, 'mt1', 'inline-ethereum-tx')}>
207227 <BridgeForm validate={validate} onValues={onValues}>