1import React, { useMemo, useCallback } from 'react';
2import cn from 'classnames';
13import { useExploreTxUrl, useExploreTxUrls } from 'lib/explorer';
14import { hexify } from 'lib/txn';
15import pluralize from 'lib/pluralize';
17import { composeValidator, buildCheckboxValidator } from 'form/validators';
18import BridgeForm from 'form/BridgeForm';
19import Condition from 'form/Condition';
21import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
22import CopyButton from './CopyButton';
23import ProgressButton from './ProgressButton';
24import convertToInt from 'lib/convertToInt';
25import NeedFundsNotice from './NeedFundsNotice';
27export default function InlineEthereumTransaction({
28 // from useEthereumTransaction.bind
49 // additional from parent
50 label = 'Generate & Sign Transaction',
54 // show receipt after successful broadcast
55 const showReceipt = broadcasted || confirmed || completed;
56 // show configure controls pre-broadcast
57 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
58 // show the send/loading button while signed, broadcasting, or confirme
59 const showBroadcastButton = signed;
60 const showLoadingButton = broadcasted || confirmed;
61 const canBroadcast = signed && !needFunds;
62 // show signed tx only when signing (for offline usage)
63 const showSignedTx = signed;
65 const validate = useMemo(
68 useAdvanced: buildCheckboxValidator(),
69 viewSigned: buildCheckboxValidator(),
74 const onValues = useCallback(
75 ({ valid, values, form }) => {
76 if (!values.useAdvanced) {
83 const renderPrimarySection = () => {
86 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
90 } else if (completed) {
92 <Grid.Item full className="pv4 black f5">
96 } else if (showBroadcastButton) {
103 disabled={!canBroadcast}
104 onClick={() => broadcast()}>
108 } else if (showLoadingButton) {
115 progress={confirmationProgress}>
124 onClick={generateAndSign}
126 loading={!canSign && initializing}>
133 const serializedTxsHex = useMemo(
135 signedTransactions &&
136 signedTransactions.map(stx => hexify(stx.serialize())),
141 <Grid className={cn(className, 'mt1')}>
142 <BridgeForm validate={validate} onValues={onValues}>
145 {renderPrimarySection()}
148 <Grid.Item full as={ErrorText} className="mv1">
162 {showConfigureInput && (
169 inverseLabel="Back to Defaults"
171 disabled={!showConfigureInput || initializing}
174 <Condition when="useAdvanced" is={true}>
182 <Flex.Item as={H5}>Gas Price</Flex.Item>
183 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
185 {/* TODO(shrugs): move to indigo/RangeInput */}
194 setGasPrice(convertToInt(e.target.value, 10))
203 <Flex.Item as={Text}>Cheap</Flex.Item>
204 <Flex.Item as={Text}>Fast</Flex.Item>
206 <Grid.Divider className="mt4" />
217 label="Signed Transaction"
219 disabled={!showSignedTx}
221 <Condition when="viewSigned" is={true}>
222 <SignedTransactionList
223 serializedTxsHex={serializedTxsHex}
234 <HashReceiptList txHashes={txHashes} />
242 <Grid.Item full as={RestartButton} onClick={onReturn}>
255function SignedTransactionList({ serializedTxsHex, nonce, gasPrice }) {
256 return serializedTxsHex.map((serializedTxHex, i) => (
257 <React.Fragment key="i">
259 <Grid.Item full as={Flex} justify="between" className="pv4 black f5">
260 <Flex.Item>Nonce</Flex.Item>
261 <Flex.Item>{nonce + i}</Flex.Item>
264 <Grid.Item full as={Flex} justify="between" className="pv4 black f5">
265 <Flex.Item>Gas Price</Flex.Item>
266 <Flex.Item>{gasPrice.toFixed()} Gwei</Flex.Item>
269 <Grid.Item full as={Flex} justify="between" className="mt3 mb2">
270 <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
271 <Flex.Item as={CopyButton} text={serializedTxHex} />
273 <Grid.Item full as="code" className="mb4 f6 mono gray4 wrap">
281function HashReceiptList({ txHashes }) {
282 const txUrls = useExploreTxUrls(txHashes);
283 const header = pluralize(txHashes.length, 'Hash', 'Hashes');
287 <Grid.Item full as={Flex} col className="pv4">
288 <Flex.Item as={H5}>Transaction {header}</Flex.Item>
291 txHashes.map((txHash, i) => (
292 <Flex.Item as={Flex}>
298 className="f6 mono gray4 wrap">
301 <Flex.Item as={LinkButton} href={txUrls[i]}>
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