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';
25import CopiableAddress from './CopiableAddress';
26import convertToInt from 'lib/convertToInt';
28export default function InlineEthereumTransaction({
29 // from useEthereumTransaction.bind
50 // additional from parent
51 label = 'Generate & Sign Transaction',
55 // show receipt after successful broadcast
56 const showReceipt = broadcasted || confirmed || completed;
57 // show configure controls pre-broadcast
58 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
59 // show the send/loading button while signed, broadcasting, or confirme
60 const showBroadcastButton = signed;
61 const showLoadingButton = broadcasted || confirmed;
62 const canBroadcast = signed && !needFunds;
63 // show signed tx only when signing (for offline usage)
64 const showSignedTx = signed;
66 const exploreTxUrl = useExploreTxUrl(txHash);
68 const validate = useMemo(
71 useAdvanced: buildCheckboxValidator(),
72 viewSigned: buildCheckboxValidator(),
77 const onValues = useCallback(
78 ({ valid, values, form }) => {
79 if (!values.useAdvanced) {
86 const renderPrimarySection = () => {
89 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
93 } else if (completed) {
95 <Grid.Item full className="pv4 black f5">
99 } else if (showBroadcastButton) {
106 disabled={!canBroadcast}
107 onClick={() => broadcast()}>
111 } else if (showLoadingButton) {
118 progress={confirmationProgress}>
127 onClick={generateAndSign}
129 loading={!canSign && initializing}>
136 const serializedTxHex = useMemo(
137 () => signedTransaction && hexify(signedTransaction.serialize()),
142 <Grid className={cn(className, 'mt1')}>
143 <BridgeForm validate={validate} onValues={onValues}>
146 {renderPrimarySection()}
149 <Grid.Item full as={ErrorText} className="mv1">
155 <Grid.Item full as={WarningBox} className="mt3">
157 <CopiableAddress>{needFunds.address}</CopiableAddress> needs at
158 least {fromWei(needFunds.minBalance)} ETH and currently has{' '}
159 {fromWei(needFunds.balance)} ETH. Waiting until the account has
164 {showConfigureInput && (
171 inverseLabel="Back to Defaults"
173 disabled={!showConfigureInput || initializing}
176 <Condition when="useAdvanced" is={true}>
184 <Flex.Item as={H5}>Gas Price</Flex.Item>
185 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
187 {/* TODO(shrugs): move to indigo/RangeInput */}
196 setGasPrice(convertToInt(e.target.value, 10))
205 <Flex.Item as={Text}>Cheap</Flex.Item>
206 <Flex.Item as={Text}>Fast</Flex.Item>
208 <Grid.Divider className="mt4" />
219 label="Signed Transaction"
221 disabled={!showSignedTx}
223 <Condition when="viewSigned" is={true}>
229 className="pv4 black f5">
230 <Flex.Item>Nonce</Flex.Item>
231 <Flex.Item>{nonce}</Flex.Item>
238 className="pv4 black f5">
239 <Flex.Item>Gas Price</Flex.Item>
240 <Flex.Item>{gasPrice.toFixed()} Gwei</Flex.Item>
248 <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
249 <Flex.Item as={CopyButton} text={serializedTxHex} />
251 <Grid.Item full as="code" className="mb4 f6 mono gray4 wrap">
262 <Grid.Item full as={Flex} col className="pv4">
263 <Flex.Item as={Flex} row justify="between">
264 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
265 <Flex.Item as={LinkButton} href={exploreTxUrl}>
269 <Flex.Item as={Flex}>
270 <Flex.Item flex as="code" className="f6 mono gray4 wrap">
282 <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