1import React, { useMemo, useCallback } from 'react';
2import cn from 'classnames';
13import { fromWei } from 'web3-utils';
15import { useExploreTxUrl } from 'lib/explorer';
16import { hexify } from 'lib/txn';
18import { GenerateButton, ForwardButton, RestartButton } from './Buttons';
19import WarningBox from './WarningBox';
20import { composeValidator, buildCheckboxValidator } from 'form/validators';
21import BridgeForm from 'form/BridgeForm';
22import Condition from 'form/Condition';
24export default function InlineEthereumTransaction({
25 // from useEthereumTransaction.bind
45 // additional from parent
46 label = 'Generate & Sign Transaction',
50 // show receipt after successful broadcast
51 const showReceipt = broadcasted || confirmed || completed;
52 // show configure controls pre-broadcast
53 const showConfigureInput = !(signed || broadcasted || confirmed || completed);
54 // show the send/loading button while signed, broadcasting, or confirme
55 const showBroadcastButton = signed || broadcasted || confirmed;
56 const canBroadcast = signed && !needFunds;
57 const isLoading = broadcasted || confirmed;
58 // show signed tx only when signing (for offline usage)
59 const showSignedTx = signed;
61 const exploreTxUrl = useExploreTxUrl(txHash);
63 const validate = useMemo(
66 useAdvanced: buildCheckboxValidator(),
67 viewSigned: buildCheckboxValidator(),
72 const onValues = useCallback(
73 ({ valid, values, form }) => {
74 if (!values.useAdvanced) {
81 const renderPrimaryButton = () => {
84 <Grid.Item full as={RestartButton} solid onClick={() => reset()}>
88 } else if (completed) {
92 <Grid.Item full as={RestartButton} onClick={onReturn}>
97 } else if (showBroadcastButton) {
104 disabled={!canBroadcast}
106 onClick={() => broadcast()}>
115 onClick={generateAndSign}
117 loading={!canSign && initializing}>
125 <Grid className={cn(className, 'mt1')}>
126 <BridgeForm validate={validate} onValues={onValues}>
127 {({ handleSubmit }) => (
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
146 {showConfigureInput && (
152 label="Advanced Configuration"
153 inverseLabel="Cancel Advanced Configuration"
154 disabled={!showConfigureInput || initializing}
157 <Condition when="useAdvanced" is={true}>
164 <Flex.Item as={H5}>Gas Price</Flex.Item>
165 <Flex.Item as={H5}>{gasPrice} Gwei</Flex.Item>
167 {/* TODO(shrugs): move to indigo/RangeInput */}
175 onChange={e => setGasPrice(parseInt(e.target.value, 10))}
183 <Flex.Item as={Text}>Cheap</Flex.Item>
184 <Flex.Item as={Text}>Fast</Flex.Item>
186 <Grid.Item full as={HelpText} className="mt3">
189 <Grid.Item full as={HelpText} className="mt1">
192 <Grid.Divider className="mt3" />
203 label="View Signed Transaction"
204 inverseLabel="Hide Signed Transaction"
205 disabled={!showSignedTx}
207 <Condition when="viewSigned" is={true}>
208 <Grid.Item full as="code" className="f6 mono gray4 wrap">
209 {hexify(signedTransaction.serialize())}
218 <Grid.Item full as={Flex} col className="pv4">
219 <Flex.Item as={Flex} row justify="between">
220 <Flex.Item as={H5}>Transaction Hash</Flex.Item>
221 <Flex.Item as={LinkButton} href={exploreTxUrl}>
225 <Flex.Item as={Flex}>
226 <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