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';
15import NoticeBox from './NoticeBox';
17import './InlineEthereumTransaction.scss';
18import FeeDropdown from './L2/Dropdowns/FeeDropdown';
20export default function InlineEthereumTransaction({
21 // from useEthereumTransaction.bind
43 // additional from parent
44 label = 'Generate & Sign Transaction',
48 // show receipt after successful broadcast
49 const [showReceipt, setShowReceipt] = useState(false);
50 const toggleShowReceipt = useCallback(() => setShowReceipt(!showReceipt), [
54 // show configure controls pre-broadcast
55 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
56 // show the send/loading button while signed, broadcasting, or confirme
57 const showBroadcastButton = signed;
58 const showLoadingButton = broadcasted || confirmed;
59 const canBroadcast = signed && !needFunds;
60 // show signed tx only when signing (for offline usage)
61 const showSignedTx = signed;
63 const validate = useMemo(
66 useAdvanced: buildCheckboxValidator(),
67 viewSigned: buildCheckboxValidator(),
72 const onValues = useCallback(
73 ({ valid, values, form }) => {
74 if (!values.useAdvanced) {
81 const renderPrimarySection = () => {
85 className="eth-tx-button"
89 onClick={() => reset()}>
93 } else if (completed) {
98 className="eth-tx-button"
108 finalCost={finalCost}
109 onClose={toggleShowReceipt}
115 className="underline mv2 pointer"
117 onClick={toggleShowReceipt}>
123 } else if (showBroadcastButton) {
126 className="eth-tx-button"
131 disabled={!canBroadcast}
132 onClick={() => broadcast()}>
136 } else if (showLoadingButton) {
139 className="eth-tx-button"
144 progress={confirmationProgress}>
151 className="eth-tx-button"
154 onClick={generateAndSign}
156 loading={!canSign && initializing}>
163 const numTxs = useMemo(() => (unsignedTransactions || []).length || 1, [
164 unsignedTransactions,
166 const maxCost = useMemo(
177 [gasLimit, gasPrice, numTxs]
181 <Grid className={cn(className, 'mt1')}>
182 <BridgeForm validate={validate} onValues={onValues}>
185 {showConfigureInput && (
188 className="mt2 text eth-tx-button"
193 <Flex.Item as={H5}>Gas Fee</Flex.Item>
194 <FeeDropdown setGasPrice={setGasPrice} />
198 className="mt2 text eth-tx-button"
203 <Flex.Item as={H5}>Max Transaction Cost</Flex.Item>
204 <Flex.Item as={H5}>{maxCost} ETH</Flex.Item>
206 <Grid.Divider className="mt4" />
210 {renderPrimarySection()}
213 <Grid.Item className="mv1 eth-tx-button" full as={ErrorText}>
220 className="mt3 eth-tx-button"
227 {showSignedTx && fakeSigned && (
229 <Grid.Item className="mt2 eth-tx-button" full as={NoticeBox}>
230 Your wallet will sign the transaction upon sending it.
241function TransactionReceipt({ txHashes, finalCost, onClose }) {
242 const txUrls = useExploreTxUrls(txHashes);
246 className="pv2 black f5 eth-tx-button"
250 <Flex.Item>Receipt</Flex.Item>
251 <Flex.Item onClick={onClose} className="underline pointer">
256 className="pv2 black f5 eth-tx-button"
260 <Flex.Item>Transaction Cost</Flex.Item>
261 <Flex.Item className="mono">{finalCost} ETH</Flex.Item>
264 <Grid.Item className="pv4 eth-tx-button" full as={Flex} col>
265 <Flex.Item as={H5}>Receipt</Flex.Item>
268 txHashes.map((txHash, i) => (
269 <Flex.Item as={Flex} className="mv3">
275 className="f6 mono gray4 wrap ">
278 <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