import React from 'react'; import cn from 'classnames'; import { Grid, ToggleInput, ErrorText, Flex, LinkButton, H5, } from 'indigo-react'; import { GenerateButton, ForwardButton, RestartButton } from './Buttons'; import { useCheckboxInput } from 'lib/useInputs'; import Blinky from './Blinky'; import { hexify } from 'lib/txn'; import { useExploreTxUrl } from 'lib/explorer'; export default function InlineEthereumTransaction({ // from useEthereumTransaction.bind initializing, canSign, generateAndSign, signed, broadcast, broadcasted, confirmed, reset, error, setGasPrice, txHash, signedTransaction, // additional from parent className, onReturn, }) { const exploreHashUrl = useExploreTxUrl(txHash); const [configureInput, { data: configurationOpen }] = useCheckboxInput({ name: 'configure', label: 'Configure Transaction', inverseLabel: 'Cancel Configure Transaction', disabled: signed || broadcasted || confirmed, }); const [ viewSignedTransaction, { data: signedTransactionOpen }, ] = useCheckboxInput({ name: 'viewsigned', label: 'View Signed Transaction', inverseLabel: 'Hide Signed Transaction', disabled: !signed, }); // show receipt after successful broadcast const showReceipt = broadcasted || confirmed; // show configure controls pre-broadcast const showConfigureInput = !(broadcasted || confirmed); // show signed tx after signing const showSignedTx = signed; const renderButton = () => { if (error) { return ( reset()}> Reset Transaction ); } else if (confirmed) { return ( <> Return ); } else if (broadcasted) { return ( }> Sending Transaction... ); } else if (signed) { return ( broadcast()}> Send Transaction ); } else { return ( : undefined}> Generate & Sign Transaction ); } }; return ( {renderButton()} {error && ( {error.message} )} {showConfigureInput && ( )} {showSignedTx && ( <> {signedTransactionOpen && ( {hexify(signedTransaction.serialize())} )} )} {showReceipt && ( <> Transaction Hash Etherscan↗ {txHash} )} ); }