@@ -7,6 +7,7 @@ import {
8 LinkButton,
8 LinkButton,
10} from 'indigo-react';
11} from 'indigo-react';
11import { toBN } from 'web3-utils';
12import { toBN } from 'web3-utils';
@@ -26,6 +27,7 @@ import FeeDropdown from './L2/Dropdowns/FeeDropdown';
26import CopyButton from './copiable/CopyButton';
27import CopyButton from './copiable/CopyButton';
28import './InlineEthereumTransaction.scss';
29import './InlineEthereumTransaction.scss';
30+import { useRollerStore } from 'store/rollerStore';
30export default function InlineEthereumTransaction({
32export default function InlineEthereumTransaction({
31 // from useEthereumTransaction.bind
33 // from useEthereumTransaction.bind
@@ -58,6 +60,7 @@ export default function InlineEthereumTransaction({
58 className,
60 className,
63+ const { ethBalance } = useRollerStore();
61 // show receipt after successful broadcast
64 // show receipt after successful broadcast
62 const [showReceipt, setShowReceipt] = useState(false);
65 const [showReceipt, setShowReceipt] = useState(false);
63 const toggleShowReceipt = useCallback(() => setShowReceipt(!showReceipt), [
66 const toggleShowReceipt = useCallback(() => setShowReceipt(!showReceipt), [
@@ -91,6 +94,35 @@ export default function InlineEthereumTransaction({
91 [resetGasPrice]
94 [resetGasPrice]
97+ const serializedTxsHex = useMemo(
99+ signedTransactions &&
100+ signedTransactions.map(stx => hexify(stx.serialize())),
101+ [signedTransactions]
104+ const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
105+ unsignedTransactions,
107+ const maxCost = useMemo(
112+ .mul(toBN(gasPrice))
118+ [gasLimit, gasPrice, numTxs]
121+ const insufficientEth = useMemo(
122+ () => Number(maxCost) > Number(ethBalance.toString()),
123+ [maxCost, ethBalance]
94 const renderPrimarySection = () => {
126 const renderPrimarySection = () => {
95 if (error) {
127 if (error) {
@@ -135,6 +167,18 @@ export default function InlineEthereumTransaction({
170+ } else if (insufficientEth) {
173+ className="ph4 eth-tx-button insufficient-eth"
138 } else if (showBroadcastButton) {
182 } else if (showBroadcastButton) {
140 <Grid.Item
184 <Grid.Item
@@ -178,30 +222,6 @@ export default function InlineEthereumTransaction({
181− const serializedTxsHex = useMemo(
183− signedTransactions &&
184− signedTransactions.map(stx => hexify(stx.serialize())),
185− [signedTransactions]
188− const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
189− unsignedTransactions,
191− const maxCost = useMemo(
196− .mul(toBN(gasPrice))
202− [gasLimit, gasPrice, numTxs]
206 <Grid className={cn(className, 'mt1', 'inline-ethereum-tx')}>
226 <Grid className={cn(className, 'mt1', 'inline-ethereum-tx')}>
207 <BridgeForm validate={validate} onValues={onValues}>
227 <BridgeForm validate={validate} onValues={onValues}>