1import React, { useMemo, useCallback } from 'react';
2import cn from 'classnames';
13import { useExploreTxUrl } from 'lib/explorer';
14import { hexify } from 'lib/txn';
16import { composeValidator, buildCheckboxValidator } from 'form/validators';
17import BridgeForm from 'form/BridgeForm';
18import Condition from 'form/Condition';
20import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
21import CopyButton from './CopyButton';
22import ProgressButton from './ProgressButton';
23import convertToInt from 'lib/convertToInt';
24import NeedFundsNotice from './NeedFundsNotice';
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}>
144 {renderPrimarySection()}
147 <Grid.Item full as={ErrorText} className="mv1">
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 */}
193 setGasPrice(convertToInt(e.target.value, 10))
202 <Flex.Item as={Text}>Cheap</Flex.Item>
203 <Flex.Item as={Text}>Fast</Flex.Item>
205 <Grid.Divider className="mt4" />
216 label="Signed Transaction"
218 disabled={!showSignedTx}
220 <Condition when="viewSigned" is={true}>
226 className="pv4 black f5">
227 <Flex.Item>Nonce</Flex.Item>
228 <Flex.Item>{nonce}</Flex.Item>
235 className="pv4 black f5">
236 <Flex.Item>Gas Price</Flex.Item>
237 <Flex.Item>{gasPrice.toFixed()} Gwei</Flex.Item>
245 <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
246 <Flex.Item as={CopyButton} text={serializedTxHex} />
248 <Grid.Item full as="code" className="mb4 f6 mono gray4 wrap">
259 <Grid.Item full as={Flex} col className="pv4">
260 <Flex.Item as={Flex} row justify="between">
261 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
262 <Flex.Item as={LinkButton} href={exploreTxUrl}>
266 <Flex.Item as={Flex}>
267 <Flex.Item flex as="code" className="f6 mono gray4 wrap">
279 <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