1import React, { useMemo, useCallback, useState } from 'react';
2import cn from 'classnames';
3import { Grid, ErrorText, Flex, LinkButton, H5 } from 'indigo-react';
4import { toBN } from 'web3-utils';
6import { useExploreTxUrls } from 'lib/explorer';
7import { safeFromWei, safeToWei } from 'lib/lib';
9import { composeValidator, buildCheckboxValidator } from 'form/validators';
10import BridgeForm from 'form/BridgeForm';
12import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
13import ProgressButton from './ProgressButton';
14import NeedFundsNotice from './NeedFundsNotice';
16import './InlineEthereumTransaction.scss';
17import FeeDropdown from './L2/Dropdowns/FeeDropdown';
19export default function InlineEthereumTransaction({
20 // from useEthereumTransaction.bind
42 // additional from parent
43 label = 'Generate & Sign Transaction',
47 // show receipt after successful broadcast
48 const [showReceipt, setShowReceipt] = useState(false);
49 const toggleShowReceipt = useCallback(() => setShowReceipt(!showReceipt), [
53 // show configure controls pre-broadcast
54 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
55 // show the send/loading button while signed, broadcasting, or confirme
56 const showBroadcastButton = signed;
57 const showLoadingButton = broadcasted || confirmed;
58 const canBroadcast = signed && !needFunds;
59 // show signed tx only when signing (for offline usage)
61 const validate = useMemo(
64 useAdvanced: buildCheckboxValidator(),
65 viewSigned: buildCheckboxValidator(),
70 const onValues = useCallback(
71 ({ valid, values, form }) => {
72 if (!values.useAdvanced) {
79 const renderPrimarySection = () => {
83 className="eth-tx-button"
87 onClick={() => reset()}>
91 } else if (completed) {
96 className="eth-tx-button"
106 finalCost={finalCost}
107 onClose={toggleShowReceipt}
113 className="underline mv2 pointer"
115 onClick={toggleShowReceipt}>
121 } else if (showBroadcastButton) {
124 className="eth-tx-button"
129 disabled={!canBroadcast}
130 onClick={() => broadcast()}>
134 } else if (showLoadingButton) {
137 className="eth-tx-button"
142 progress={confirmationProgress}>
149 className="eth-tx-button"
152 onClick={generateAndSign}
154 loading={!canSign && initializing}>
161 const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
162 unsignedTransactions,
164 const maxCost = useMemo(
175 [gasLimit, gasPrice, numTxs]
179 <Grid className={cn(className, 'mt1')}>
180 <BridgeForm validate={validate} onValues={onValues}>
183 {showConfigureInput && (
186 className="mt2 text eth-tx-button"
191 <Flex.Item as={H5}>Gas Fee</Flex.Item>
192 <FeeDropdown setGasPrice={setGasPrice} />
196 className="mt2 text eth-tx-button"
201 <Flex.Item as={H5}>Max Transaction Cost</Flex.Item>
202 <Flex.Item as={H5}>{maxCost} ETH</Flex.Item>
204 <Grid.Divider className="mt4" />
208 {renderPrimarySection()}
211 <Grid.Item className="mv1 eth-tx-button" full as={ErrorText}>
218 className="mt3 eth-tx-button"
231function TransactionReceipt({ txHashes, finalCost, onClose }) {
232 const txUrls = useExploreTxUrls(txHashes);
236 className="pv2 black f5 eth-tx-button"
240 <Flex.Item>Receipt</Flex.Item>
241 <Flex.Item onClick={onClose} className="underline pointer">
246 className="pv2 black f5 eth-tx-button"
250 <Flex.Item>Transaction Cost</Flex.Item>
251 <Flex.Item className="mono">{finalCost} ETH</Flex.Item>
254 <Grid.Item className="pv4 eth-tx-button" full as={Flex} col>
255 <Flex.Item as={H5}>Receipt</Flex.Item>
258 txHashes.map((txHash, i) => (
259 <Flex.Item as={Flex} className="mv3">
265 className="f6 mono gray4 wrap ">
268 <Flex.Item className="ml8" as={LinkButton} href={txUrls[i]}>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list