1import React, { useMemo, useCallback } from 'react';
2import cn from 'classnames';
12import { fromWei } from 'web3-utils';
14import { useExploreTxUrl } from 'lib/explorer';
15import { hexify } from 'lib/txn';
17import { composeValidator, buildCheckboxValidator } from 'form/validators';
18import BridgeForm from 'form/BridgeForm';
19import Condition from 'form/Condition';
21import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
22import WarningBox from './WarningBox';
23import CopyButton from './CopyButton';
24import ProgressButton from './ProgressButton';
26export default function InlineEthereumTransaction({
27 // from useEthereumTransaction.bind
48 // additional from parent
49 label = 'Generate & Sign Transaction',
53 // show receipt after successful broadcast
54 const showReceipt = broadcasted || confirmed || completed;
55 // show configure controls pre-broadcast
56 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
57 // show the send/loading button while signed, broadcasting, or confirme
58 const showBroadcastButton = signed;
59 const showLoadingButton = broadcasted || confirmed;
60 const canBroadcast = signed && !needFunds;
61 // show signed tx only when signing (for offline usage)
62 const showSignedTx = signed;
64 const exploreTxUrl = useExploreTxUrl(txHash);
66 const validate = useMemo(
69 useAdvanced: buildCheckboxValidator(),
70 viewSigned: buildCheckboxValidator(),
75 const onValues = useCallback(
76 ({ valid, values, form }) => {
77 if (!values.useAdvanced) {
84 const renderPrimarySection = () => {
87 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
91 } else if (completed) {
93 <Grid.Item full className="pv4 black f5">
97 } else if (showBroadcastButton) {
104 disabled={!canBroadcast}
105 onClick={() => broadcast()}>
109 } else if (showLoadingButton) {
115 progress={confirmationProgress}>
124 onClick={generateAndSign}
126 loading={!canSign && initializing}>
133 const serializedTxHex = useMemo(
134 () => signedTransaction && hexify(signedTransaction.serialize()),
139 <Grid className={cn(className, 'mt1')}>
140 <BridgeForm validate={validate} onValues={onValues}>
141 {({ handleSubmit }) => (
143 {renderPrimarySection()}
146 <Grid.Item full as={ErrorText} className="mt1">
152 <Grid.Item full as={WarningBox} className="mt3">
153 The address {needFunds.address} needs at least{' '}
154 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
155 {fromWei(needFunds.balance)} ETH. Waiting until the account has
160 {showConfigureInput && (
167 inverseLabel="Back to Defaults"
169 disabled={!showConfigureInput || initializing}
172 <Condition when="useAdvanced" is={true}>
180 <Flex.Item as={H5}>Gas Price</Flex.Item>
181 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
183 {/* TODO(shrugs): move to indigo/RangeInput */}
191 onChange={e => setGasPrice(parseInt(e.target.value, 10))}
199 <Flex.Item as={Text}>Cheap</Flex.Item>
200 <Flex.Item as={Text}>Fast</Flex.Item>
202 <Grid.Divider className="mt4" />
213 label="Signed Transaction"
215 disabled={!showSignedTx}
217 <Condition when="viewSigned" is={true}>
223 className="pv4 black f5">
224 <Flex.Item>Nonce</Flex.Item>
225 <Flex.Item>{nonce}</Flex.Item>
232 className="pv4 black f5">
233 <Flex.Item>Gas Price</Flex.Item>
234 <Flex.Item>{gasPrice.toFixed()} Gwei</Flex.Item>
242 <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
243 <Flex.Item as={CopyButton} text={serializedTxHex} />
245 <Grid.Item full as="code" className="mb4 f6 mono gray4 wrap">
256 <Grid.Item full as={Flex} col className="pv4">
257 <Flex.Item as={Flex} row justify="between">
258 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
259 <Flex.Item as={LinkButton} href={exploreTxUrl}>
263 <Flex.Item as={Flex}>
264 <Flex.Item flex as="code" className="f6 mono gray4 wrap">
276 <Grid.Item full as={RestartButton} onClick={onReturn}>
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