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
42 // additional from parent
43 label = 'Generate & Sign Transaction',
47 // show receipt after successful broadcast
48 const showReceipt = broadcasted || confirmed;
49 // show configure controls pre-broadcast
50 const showConfigureInput = !(signed || broadcasted || confirmed);
51 // show signed tx only when signing (for offline usage)
52 const showSignedTx = signed;
54 const exploreTxUrl = useExploreTxUrl(txHash);
55 const [advancedInput, { data: advancedOpen }] = useCheckboxInput({
57 label: 'Advanced Configuration',
58 inverseLabel: 'Cancel Advanced Configuration',
59 disabled: !showConfigureInput,
63 viewSignedTransaction,
64 { data: signedTransactionOpen },
65 ] = useCheckboxInput({
67 label: 'View Signed Transaction',
68 inverseLabel: 'Hide Signed Transaction',
69 disabled: !showSignedTx,
72 // reset gas price when closing advanced configuration
77 }, [advancedOpen, resetGasPrice]);
79 const renderPrimaryButton = () => {
82 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
86 } else if (confirmed) {
90 <Grid.Item full as={RestartButton} onClick={onReturn}>
95 } else if (signed || broadcasted) {
102 disabled={broadcasted || needFunds}
103 loading={broadcasted || needFunds}
104 onClick={() => broadcast()}>
113 onClick={generateAndSign}
115 loading={!canSign && initializing}>
123 <Grid className={cn(className, 'mt1')}>
124 {renderPrimaryButton()}
127 <Grid.Item full as={ErrorText} className="mt1">
133 <Grid.Item full as={WarningBox} className="mt3">
134 The address {needFunds.address} needs at least{' '}
135 {fromWei(needFunds.minBalance)} ETH and currently has{' '}
136 {fromWei(needFunds.balance)} ETH. Waiting until the account has enough
141 {showConfigureInput && (
143 <Grid.Item full as={ToggleInput} {...advancedInput} />
146 <Grid.Item full as={Flex} row justify="between" className="mt2">
147 <Flex.Item as={H5}>Gas Price</Flex.Item>
148 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
150 {/* TODO(shrugs): move to indigo/RangeInput */}
158 onChange={e => setGasPrice(parseInt(e.target.value, 10))}
166 <Flex.Item as={Text}>Cheap</Flex.Item>
167 <Flex.Item as={Text}>Fast</Flex.Item>
169 <Grid.Item full as={HelpText} className="mt3">
172 <Grid.Item full as={HelpText} className="mt1">
175 <Grid.Divider className="mt3" />
183 <Grid.Item full as={ToggleInput} {...viewSignedTransaction} />
184 {signedTransactionOpen && (
185 <Grid.Item full as="code" className="f6 mono gray4 wrap">
186 {hexify(signedTransaction.serialize())}
195 <Grid.Item full as={Flex} col className="pv4">
196 <Flex.Item as={Flex} row justify="between">
197 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
198 <Flex.Item as={LinkButton} href={exploreTxUrl}>
202 <Flex.Item as={Flex}>
203 <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