import React from 'react'; import { connect } from 'react-redux'; import { Icon } from 'antd'; import { Link } from 'react-router-dom'; import Result from 'ant-design-pro/lib/Result'; import Loader from 'components/Loader'; import { createActions } from 'modules/create'; import { AppState } from 'store/reducers'; import { getProposalStakingContribution } from 'api/api'; import './Final.less'; import PaymentInfo from 'components/ContributionModal/PaymentInfo'; import { ContributionWithAddresses } from 'types'; interface OwnProps { goBack(): void; } interface StateProps { form: AppState['create']['form']; submittedProposal: AppState['create']['submittedProposal']; submitError: AppState['create']['submitError']; } interface DispatchProps { submitProposal: typeof createActions['submitProposal']; } type Props = OwnProps & StateProps & DispatchProps; const STATE = { contribution: null as null | ContributionWithAddresses, contributionError: null as null | Error, }; type State = typeof STATE; class CreateFinal extends React.Component { state = STATE; componentDidMount() { this.submit(); } componentDidUpdate(prev: Props) { const { submittedProposal } = this.props; if (!prev.submittedProposal && submittedProposal) { if (!submittedProposal.isStaked) { this.getStakingContribution(); } } } render() { const { submittedProposal, submitError, goBack } = this.props; const { contribution, contributionError } = this.state; const ready = submittedProposal && (submittedProposal.isStaked || contribution); const staked = submittedProposal && submittedProposal.isStaked; let content; if (submitError) { content = (

Something went wrong during creation

{submitError}
Click here to go back to the form and try again.
); } else if (ready) { content = ( <>
{staked && (
Your proposal has been staked and submitted! Check your{' '} profile's pending proposals tab{' '} to check its status.
)} {!staked && (
Your proposal has been submitted! Please send the staking contribution of{' '} {contribution && contribution.amount} ZEC using the instructions below.
)}
{!staked && ( <>

If you cannot send the payment now, you may bring up these instructions again by visiting your{' '} profile's funded tab.

Once your payment has been sent and processed with 6 confirmations, you will receive an email. Visit your{' '} profile's pending proposals tab {' '} at any time to check its status.

} contribution={contribution} />

I'm finished, take me to{' '} my pending proposals!

)} ); } else if (contributionError) { content = ( We were unable to get your staking contribution started. You can finish staking from your profile, please try again from there soon. } /> ); } else { content = ; } return
{content}
; } private submit = () => { if (this.props.form) { this.props.submitProposal(this.props.form); } }; private getStakingContribution = async () => { const { submittedProposal } = this.props; if (submittedProposal) { try { const res = await getProposalStakingContribution(submittedProposal.proposalId); this.setState({ contribution: res.data }); } catch (err) { this.setState({ contributionError: err }); } } }; } export default connect( (state: AppState) => ({ form: state.create.form, submittedProposal: state.create.submittedProposal, submitError: state.create.submitError, }), { submitProposal: createActions.submitProposal, }, )(CreateFinal);