1import React, { useEffect } from 'react';
2import cn from 'classnames';
13import { fromWei } from 'web3-utils';
15import { useCheckboxInput } from 'lib/useInputs';
16import { useExploreTxUrl } from 'lib/explorer';
17import { hexify } from 'lib/txn';
19import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
20import WarningBox from './WarningBox';
22export default function InlineEthereumTransaction({
23 // from useEthereumTransaction.bind
43 // additional from parent
44 label = 'Generate & Sign Transaction',
48 // show receipt after successful broadcast
49 const showReceipt = broadcasted || confirmed || completed;
50 // show configure controls pre-broadcast
51 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
52 // show the send/loading button while signed, broadcasting, or confirme
53 const showBroadcastButton = signed || broadcasted || confirmed;
54 const canBroadcast = signed;
55 const isLoading = broadcasted || confirmed;
56 // show signed tx only when signing (for offline usage)
57 const showSignedTx = signed;
59 const exploreTxUrl = useExploreTxUrl(txHash);
60 const [advancedInput, { data: advancedOpen }] = useCheckboxInput({
62 label: 'Advanced Configuration',
63 inverseLabel: 'Cancel Advanced Configuration',
64 disabled: !showConfigureInput,
68 viewSignedTransaction,
69 { data: signedTransactionOpen },
70 ] = useCheckboxInput({
72 label: 'View Signed Transaction',
73 inverseLabel: 'Hide Signed Transaction',
74 disabled: !showSignedTx,
77 // reset gas price when closing advanced configuration
82 }, [advancedOpen, resetGasPrice]);
84 const renderPrimaryButton = () => {
87 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
91 } else if (completed) {
95 <Grid.Item full as={RestartButton} onClick={onReturn}>
100 } else if (showBroadcastButton) {
107 disabled={!canBroadcast}
109 onClick={() => broadcast()}>
118 onClick={generateAndSign}
120 loading={!canSign && initializing}>
128 <Grid className={cn(className, 'mt1')}>
129 {renderPrimaryButton()}
132 <Grid.Item full as={ErrorText} className="mt1">
138 <Grid.Item full as={WarningBox} className="mt3">
139 The address {needFunds.address} needs at least{' '}
140 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
141 {fromWei(needFunds.balance)} ETH. Waiting until the account has enough
146 {showConfigureInput && (
148 <Grid.Item full as={ToggleInput} {...advancedInput} />
151 <Grid.Item full as={Flex} row justify="between" className="mt2">
152 <Flex.Item as={H5}>Gas Price</Flex.Item>
153 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
155 {/* TODO(shrugs): move to indigo/RangeInput */}
163 onChange={e => setGasPrice(parseInt(e.target.value, 10))}
171 <Flex.Item as={Text}>Cheap</Flex.Item>
172 <Flex.Item as={Text}>Fast</Flex.Item>
174 <Grid.Item full as={HelpText} className="mt3">
177 <Grid.Item full as={HelpText} className="mt1">
180 <Grid.Divider className="mt3" />
188 <Grid.Item full as={ToggleInput} {...viewSignedTransaction} />
189 {signedTransactionOpen && (
190 <Grid.Item full as="code" className="f6 mono gray4 wrap">
191 {hexify(signedTransaction.serialize())}
200 <Grid.Item full as={Flex} col className="pv4">
201 <Flex.Item as={Flex} row justify="between">
202 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
203 <Flex.Item as={LinkButton} href={exploreTxUrl}>
207 <Flex.Item as={Flex}>
208 <Flex.Item flex as="code" className="f6 mono gray4 wrap">
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