1import React, { useEffect } from 'react';
2import cn from 'classnames';
14import { useCheckboxInput } from 'lib/useInputs';
15import { hexify } from 'lib/txn';
16import { useExploreTxUrl } from 'lib/explorer';
18import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
20export default function InlineEthereumTransaction({
21 // from useEthereumTransaction.bind
39 // additional from parent
40 label = 'Generate & Sign Transaction',
44 // show receipt after successful broadcast
45 const showReceipt = broadcasted || confirmed;
46 // show configure controls pre-broadcast
47 const showConfigureInput = !(signed || broadcasted || confirmed);
48 // show signed tx only when signing (for offline usage)
49 const showSignedTx = signed;
51 const exploreTxUrl = useExploreTxUrl(txHash);
52 const [advancedInput, { data: advancedOpen }] = useCheckboxInput({
54 label: 'Advanced Configuration',
55 inverseLabel: 'Cancel Advanced Configuration',
56 disabled: !showConfigureInput,
60 viewSignedTransaction,
61 { data: signedTransactionOpen },
62 ] = useCheckboxInput({
64 label: 'View Signed Transaction',
65 inverseLabel: 'Hide Signed Transaction',
66 disabled: !showSignedTx,
69 // reset gas price when closing advanced configuration
74 }, [advancedOpen, resetGasPrice]);
76 const renderPrimaryButton = () => {
79 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
83 } else if (confirmed) {
87 <Grid.Item full as={RestartButton} onClick={onReturn}>
92 } else if (signed || broadcasted) {
99 disabled={broadcasted}
100 loading={broadcasted}
101 onClick={() => broadcast()}>
110 onClick={generateAndSign}
112 loading={!canSign && initializing}>
120 <Grid className={cn(className, 'mt1')}>
121 {renderPrimaryButton()}
124 <Grid.Item full as={ErrorText} className="mt1">
129 {showConfigureInput && (
131 <Grid.Item full as={ToggleInput} {...advancedInput} />
134 <Grid.Item full as={Flex} row justify="between" className="mt2">
135 <Flex.Item as={H5}>Gas Price</Flex.Item>
136 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
138 {/* TODO(shrugs): move to indigo/RangeInput */}
146 onChange={e => setGasPrice(parseInt(e.target.value, 10))}
154 <Flex.Item as={Text}>Cheap</Flex.Item>
155 <Flex.Item as={Text}>Fast</Flex.Item>
157 <Grid.Item full as={HelpText} className="mt3">
160 <Grid.Item full as={HelpText} className="mt1">
163 <Grid.Divider className="mt3" />
171 <Grid.Item full as={ToggleInput} {...viewSignedTransaction} />
172 {signedTransactionOpen && (
173 <Grid.Item full as="code" className="f6 mono gray4 wrap">
174 {hexify(signedTransaction.serialize())}
183 <Grid.Item full as={Flex} col className="pv4">
184 <Flex.Item as={Flex} row justify="between">
185 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
186 <Flex.Item as={LinkButton} href={exploreTxUrl}>
190 <Flex.Item as={Flex}>
191 <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