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';
25export default function InlineEthereumTransaction({
26 // from useEthereumTransaction.bind
46 // additional from parent
47 label = 'Generate & Sign Transaction',
51 // show receipt after successful broadcast
52 const showReceipt = broadcasted || confirmed || completed;
53 // show configure controls pre-broadcast
54 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
55 // show the send/loading button while signed, broadcasting, or confirme
56 const showBroadcastButton = signed || broadcasted || confirmed;
57 const canBroadcast = signed && !needFunds;
58 const isLoading = broadcasted || confirmed;
59 // show signed tx only when signing (for offline usage)
60 const showSignedTx = signed;
62 const exploreTxUrl = useExploreTxUrl(txHash);
64 const validate = useMemo(
67 useAdvanced: buildCheckboxValidator(),
68 viewSigned: buildCheckboxValidator(),
73 const onValues = useCallback(
74 ({ valid, values, form }) => {
75 if (!values.useAdvanced) {
82 const renderPrimarySection = () => {
85 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
89 } else if (completed) {
91 <Grid.Item full className="pv4 black f5">
95 } else if (showBroadcastButton) {
102 disabled={!canBroadcast}
104 onClick={() => broadcast()}>
113 onClick={generateAndSign}
115 loading={!canSign && initializing}>
122 const serializedTxHex = useMemo(
123 () => signedTransaction && hexify(signedTransaction.serialize()),
128 <Grid className={cn(className, 'mt1')}>
129 <BridgeForm validate={validate} onValues={onValues}>
130 {({ handleSubmit }) => (
132 {renderPrimarySection()}
135 <Grid.Item full as={ErrorText} className="mt1">
141 <Grid.Item full as={WarningBox} className="mt3">
142 The address {needFunds.address} needs at least{' '}
143 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
144 {fromWei(needFunds.balance)} ETH. Waiting until the account has
149 {showConfigureInput && (
156 inverseLabel="Back to Defaults"
158 disabled={!showConfigureInput || initializing}
161 <Condition when="useAdvanced" is={true}>
169 <Flex.Item as={H5}>Gas Price</Flex.Item>
170 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
172 {/* TODO(shrugs): move to indigo/RangeInput */}
180 onChange={e => setGasPrice(parseInt(e.target.value, 10))}
188 <Flex.Item as={Text}>Cheap</Flex.Item>
189 <Flex.Item as={Text}>Fast</Flex.Item>
191 <Grid.Divider className="mt4" />
202 label="Signed Transaction"
204 disabled={!showSignedTx}
206 <Condition when="viewSigned" is={true}>
212 className="pv4 black f5">
213 <Flex.Item>Nonce</Flex.Item>
214 <Flex.Item>{nonce}</Flex.Item>
221 className="pv4 black f5">
222 <Flex.Item>Gas Price</Flex.Item>
223 <Flex.Item>{gasPrice.toFixed()} Gwei</Flex.Item>
231 <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
232 <Flex.Item as={CopyButton} text={serializedTxHex} />
234 <Grid.Item full as="code" className="mb4 f6 mono gray4 wrap">
245 <Grid.Item full as={Flex} col className="pv4">
246 <Flex.Item as={Flex} row justify="between">
247 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
248 <Flex.Item as={LinkButton} href={exploreTxUrl}>
252 <Flex.Item as={Flex}>
253 <Flex.Item flex as="code" className="f6 mono gray4 wrap">
265 <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