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) {
116 progress={confirmationProgress}>
125 onClick={generateAndSign}
127 loading={!canSign && initializing}>
134 const serializedTxHex = useMemo(
135 () => signedTransaction && hexify(signedTransaction.serialize()),
140 <Grid className={cn(className, 'mt1')}>
141 <BridgeForm validate={validate} onValues={onValues}>
142 {({ handleSubmit }) => (
144 {renderPrimarySection()}
147 <Grid.Item full as={ErrorText} className="mt1">
153 <Grid.Item full as={WarningBox} className="mt3">
154 The address {needFunds.address} needs at least{' '}
155 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
156 {fromWei(needFunds.balance)} ETH. Waiting until the account has
161 {showConfigureInput && (
168 inverseLabel="Back to Defaults"
170 disabled={!showConfigureInput || initializing}
173 <Condition when="useAdvanced" is={true}>
181 <Flex.Item as={H5}>Gas Price</Flex.Item>
182 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
184 {/* TODO(shrugs): move to indigo/RangeInput */}
192 onChange={e => setGasPrice(parseInt(e.target.value, 10))}
200 <Flex.Item as={Text}>Cheap</Flex.Item>
201 <Flex.Item as={Text}>Fast</Flex.Item>
203 <Grid.Divider className="mt4" />
214 label="Signed Transaction"
216 disabled={!showSignedTx}
218 <Condition when="viewSigned" is={true}>
224 className="pv4 black f5">
225 <Flex.Item>Nonce</Flex.Item>
226 <Flex.Item>{nonce}</Flex.Item>
233 className="pv4 black f5">
234 <Flex.Item>Gas Price</Flex.Item>
235 <Flex.Item>{gasPrice.toFixed()} Gwei</Flex.Item>
243 <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
244 <Flex.Item as={CopyButton} text={serializedTxHex} />
246 <Grid.Item full as="code" className="mb4 f6 mono gray4 wrap">
257 <Grid.Item full as={Flex} col className="pv4">
258 <Flex.Item as={Flex} row justify="between">
259 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
260 <Flex.Item as={LinkButton} href={exploreTxUrl}>
264 <Flex.Item as={Flex}>
265 <Flex.Item flex as="code" className="f6 mono gray4 wrap">
277 <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