import Maybe from 'folktale/maybe'; import React from 'react'; import * as need from '../lib/need'; import { H1, H3, P, Warning, Anchor } from '../components/old/Base'; import { Button } from '../components/old/Base'; import { ROUTE_NAMES } from '../lib/routeNames'; import { useHistory } from '../store/history'; import { BRIDGE_ERROR, renderTxnError } from '../lib/error'; import { NETWORK_TYPES } from '../lib/network'; import { useTxnConfirmations } from '../store/txnConfirmations'; import { useNetwork } from '../store/network'; import { useTxnCursor } from '../store/txnCursor'; import View from 'components/View'; import { Grid } from 'indigo-react'; class Success extends React.Component { constructor(props) { super(props); this.state = { pending: '.', interval: null, }; } componentDidMount() { const nextDot = { '.': '..', '..': '...', '...': '.' }; const interval = setInterval(() => { this.setState(({ pending }) => ({ pending: nextDot[pending] })); }, 1000); this.setState({ interval: interval }); } componentWillUnmount() { clearInterval(this.state.interval); } render() { const { props, state } = this; const { networkType, hash, txnConfirmations } = props; const { pending } = state; const esvisible = networkType === NETWORK_TYPES.ROPSTEN || networkType === NETWORK_TYPES.MAINNET; const esdomain = networkType === NETWORK_TYPES.ROPSTEN ? 'ropsten.etherscan.io' : 'etherscan.io'; const esmessage = esvisible === true ? 'If you’d like to keep track of it, click the Etherscan link below.' : ''; const esanchor = esvisible === false ? null : ( {'View on Etherscan ↗'} ); const confirmations = Maybe.fromNullable(txnConfirmations[hash]).getOrElse( 0 ); const requiredConfirmations = 1; const status = confirmations < requiredConfirmations ? `Pending${pending}` : `Confirmed! (x${confirmations} confirmations)!`; return ( {'Your Transaction was Sent'} {`We sent your transaction to the chain. It can take some time to execute, especially if the network is busy. ${esmessage}`} {'Transaction Hash'} {hash} {'Transaction Status'} {status} {esanchor} ); } } const Failure = props => ( {'Error!'} {'There was an error sending your transaction.'} {renderTxnError(props.web3, props.message)} ); function SentTransaction(props) { const history = useHistory(); const { txnConfirmations } = useTxnConfirmations(); const { web3, networkType } = useNetwork(); const { txnCursor } = useTxnCursor(); const promptKeyfile = history.data && history.data.promptKeyfile; const w3 = need.web3(web3); const result = txnCursor.matchWith({ Nothing: _ => { throw BRIDGE_ERROR.MISSING_TXN; }, Just: res => res.value, }); const body = result.matchWith({ Error: message => , Ok: hash => ( ), }); const ok = ( { history.pop(); }}> {'Ok →'} ); let keyfile; if (promptKeyfile) { keyfile = ( history.popAndPush(ROUTE_NAMES.GEN_KEYFILE)}> {'Download Keyfile →'} ); } return ( {body} {ok} {keyfile} ); } export default SentTransaction;
{`We sent your transaction to the chain. It can take some time to execute, especially if the network is busy. ${esmessage}`}
{hash}
{status}
{esanchor}