@@ -1,34 +1,21 @@
11import React, { useMemo, useCallback, useState } from 'react';
22import cn from 'classnames';
3−import {
4− Grid,
5− ToggleInput,
6− ErrorText,
7− Flex,
8− LinkButton,
9− H5,
10− Text,
11−} from 'indigo-react';
3+import { Grid, ErrorText, Flex, LinkButton, H5, Text } from 'indigo-react';
124import { toBN } from 'web3-utils';
135
14−import { ReactComponent as InfoIcon } from 'assets/info.svg';
15−
166import { useExploreTxUrls } from 'lib/explorer';
17−import { hexify } from 'lib/txn';
187import { safeFromWei, safeToWei } from 'lib/lib';
198
209import { composeValidator, buildCheckboxValidator } from 'form/validators';
2110import BridgeForm from 'form/BridgeForm';
22−import Condition from 'form/Condition';
2311
2412import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
25−import CopyButton from './copiable/CopyButton';
2613import ProgressButton from './ProgressButton';
27−import { convertToInt } from 'lib/convertToInt';
2814import NeedFundsNotice from './NeedFundsNotice';
2915import NoticeBox from './NoticeBox';
3016
3117import './InlineEthereumTransaction.scss';
18+import FeeDropdown from './L2/Dropdowns/FeeDropdown';
3219
3320export default function InlineEthereumTransaction({
3421 // from useEthereumTransaction.bind
@@ -47,10 +34,7 @@ export default function InlineEthereumTransaction({
4734 setGasPrice,
4835 resetGasPrice,
4936 txHashes,
50− nonce,
51− chainId,
5237 needFunds,
53− signedTransactions,
5438 confirmationProgress,
5539 gasLimit,
5640 unsignedTransactions,
@@ -76,12 +60,6 @@ export default function InlineEthereumTransaction({
7660 // show signed tx only when signing (for offline usage)
7761 const showSignedTx = signed;
7862
79− const [showGasDetails, _setShowGasDetails] = useState(false);
80− const toggleGasDetails = useCallback(
81− () => _setShowGasDetails(!showGasDetails),
82− [_setShowGasDetails, showGasDetails]
83− );
84−
8563 const validate = useMemo(
8664 () =>
8765 composeValidator({
@@ -182,13 +160,6 @@ export default function InlineEthereumTransaction({
182160 }
183161 };
184162
185− const serializedTxsHex = useMemo(
186− () =>
187− signedTransactions &&
188− signedTransactions.map(stx => hexify(stx.serialize())),
189− [signedTransactions]
190− );
191−
192163 const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
193164 unsignedTransactions,
194165 ]);
@@ -206,18 +177,36 @@ export default function InlineEthereumTransaction({
206177 [gasLimit, gasPrice, numTxs]
207178 );
208179
209− const gasInfo = useMemo(() => {
210− const extra = numTxs === 1 ? '' : `* ${numTxs} txs`;
211− return showGasDetails
212− ? `${gasPrice} Gwei * ${gasLimit} ${extra} = ${maxCost} ETH`
213− : `${maxCost} ETH`;
214− }, [showGasDetails, maxCost, gasPrice, gasLimit, numTxs]);
215−
216180 return (
217181 <Grid className={cn(className, 'mt1')}>
218182 <BridgeForm validate={validate} onValues={onValues}>
219183 {() => (
220184 <>
185+ {showConfigureInput && (
186+ <>
187+ <Grid.Item
188+ className="mt2 text eth-tx-button"
189+ full
190+ as={Flex}
191+ row
192+ justify="between">
193+ <Flex.Item as={H5}>Gas Fee</Flex.Item>
194+ <FeeDropdown setGasPrice={setGasPrice} />
195+ </Grid.Item>
196+
197+ <Grid.Item
198+ className="mt2 text eth-tx-button"
199+ full
200+ as={Flex}
201+ row
202+ justify="between">
203+ <Flex.Item as={H5}>Max Transaction Cost</Flex.Item>
204+ <Flex.Item as={H5}>{maxCost} ETH</Flex.Item>
205+ </Grid.Item>
206+ <Grid.Divider className="mt4" />
207+ </>
208+ )}
209+
221210 {renderPrimarySection()}
222211
223212 {error && (
@@ -235,66 +224,6 @@ export default function InlineEthereumTransaction({
235224 />
236225 )}
237226
238− {showConfigureInput && (
239− <>
240− <Grid.Item
241− className="eth-tx-button"
242− full
243− as={ToggleInput}
244− name="useAdvanced"
245− label="Advanced"
246− inverseLabel="Back to Defaults"
247− inverseColor="red3"
248− disabled={!showConfigureInput || initializing}
249− />
250−
251− <Condition when="useAdvanced" is={true}>
252− <Grid.Item className="mb2 eth-tx-button" full></Grid.Item>
253− <Grid.Divider />
254− <Grid.Item
255− className="mt2 eth-tx-button"
256− full
257− as={Flex}
258− row
259− justify="between">
260− <Flex.Item as={H5}>Transaction Fee</Flex.Item>
261−
262− <Flex.Item as={H5}>
263− {gasInfo}{' '}
264− <InfoIcon
265− className="pointer"
266− onClick={toggleGasDetails}
267− />
268− </Flex.Item>
269− </Grid.Item>
270−
271− {/* TODO(shrugs): move to indigo/RangeInput */}
272− <Grid.Item
273− className="eth-tx-button"
274− full
275− as="input"
276− type="range"
277− min="1"
278− max="400"
279− value={gasPrice}
280− onChange={e =>
281− setGasPrice(convertToInt(e.target.value, 10))
282− }
283− />
284− <Grid.Item
285− className="f6 mt1 eth-tx-button"
286− full
287− as={Flex}
288− row
289− justify="between">
290− <Flex.Item as={Text}>Cheap</Flex.Item>
291− <Flex.Item as={Text}>Fast</Flex.Item>
292− </Grid.Item>
293− <Grid.Divider className="mt4" />
294− </Condition>
295− </>
296− )}
297−
298227 {showSignedTx && fakeSigned && (
299228 <>
300229 <Grid.Item className="mt2 eth-tx-button" full as={NoticeBox}>
@@ -302,27 +231,6 @@ export default function InlineEthereumTransaction({
302231 </Grid.Item>
303232 </>
304233 )}
305−
306− {showSignedTx && !fakeSigned && (
307− <>
308− <Grid.Item
309− className="eth-tx-button"
310− full
311− as={ToggleInput}
312− name="viewSigned"
313− label="Signed Transaction"
314− inverseLabel="Hide"
315− disabled={!showSignedTx}
316− />
317− <Condition when="viewSigned" is={true}>
318− <SignedTransactionList
319− serializedTxsHex={serializedTxsHex}
320− maxCost={maxCost}
321− nonce={nonce}
322− />
323− </Condition>
324− </>
325− )}
326234 </>
327235 )}
328236 </BridgeForm>
@@ -330,47 +238,6 @@ export default function InlineEthereumTransaction({
330238 );
331239}
332240
333−function SignedTransactionList({ serializedTxsHex, nonce, maxCost }) {
334− return serializedTxsHex.map((serializedTxHex, i) => (
335− <React.Fragment key={i}>
336− <Grid.Divider />
337− <Grid.Item
338− className="pv4 black f5 eth-tx-button"
339− full
340− as={Flex}
341− justify="between">
342− <Flex.Item>Nonce</Flex.Item>
343− <Flex.Item>{nonce + i}</Flex.Item>
344− </Grid.Item>
345− <Grid.Divider />
346− <Grid.Item
347− className="pv4 black f5 eth-tx-button"
348− full
349− as={Flex}
350− justify="between">
351− <Flex.Item>Transaction Cost</Flex.Item>
352− <Flex.Item>{maxCost} ETH</Flex.Item>
353− </Grid.Item>
354− <Grid.Divider />
355− <Grid.Item
356− className="mt3 mb2 eth-tx-button"
357− full
358− as={Flex}
359− justify="between">
360− <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
361− <Flex.Item as={CopyButton} text={serializedTxHex} />
362− </Grid.Item>
363− <Grid.Item
364− className="mb4 f6 mono gray4 wrap eth-tx-button"
365− full
366− as="code">
367− {serializedTxHex}
368− </Grid.Item>
369− <Grid.Divider />
370− </React.Fragment>
371− ));
372−}
373−
374241function TransactionReceipt({ txHashes, finalCost, onClose }) {
375242 const txUrls = useExploreTxUrls(txHashes);
376243 return (