2018-09-20 11:58:47 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2019-01-23 07:15:59 -08:00
|
|
|
import { Icon } from 'antd';
|
2018-09-20 11:58:47 -07:00
|
|
|
import { Link } from 'react-router-dom';
|
2019-03-12 10:10:56 -07:00
|
|
|
import Result from 'ant-design-pro/lib/Result';
|
2019-01-23 07:15:59 -08:00
|
|
|
import Loader from 'components/Loader';
|
2018-09-20 11:58:47 -07:00
|
|
|
import { createActions } from 'modules/create';
|
|
|
|
import { AppState } from 'store/reducers';
|
2019-01-31 14:56:16 -08:00
|
|
|
import { getProposalStakingContribution } from 'api/api';
|
2018-09-20 11:58:47 -07:00
|
|
|
import './Final.less';
|
2019-01-31 14:56:16 -08:00
|
|
|
import PaymentInfo from 'components/ContributionModal/PaymentInfo';
|
|
|
|
import { ContributionWithAddresses } from 'types';
|
2018-09-20 11:58:47 -07:00
|
|
|
|
2019-02-05 12:26:37 -08:00
|
|
|
interface OwnProps {
|
|
|
|
goBack(): void;
|
|
|
|
}
|
|
|
|
|
2018-09-20 11:58:47 -07:00
|
|
|
interface StateProps {
|
|
|
|
form: AppState['create']['form'];
|
2018-12-28 15:05:34 -08:00
|
|
|
submittedProposal: AppState['create']['submittedProposal'];
|
|
|
|
submitError: AppState['create']['submitError'];
|
2018-09-20 11:58:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
interface DispatchProps {
|
2018-12-28 15:05:34 -08:00
|
|
|
submitProposal: typeof createActions['submitProposal'];
|
2018-09-20 11:58:47 -07:00
|
|
|
}
|
|
|
|
|
2019-02-05 12:26:37 -08:00
|
|
|
type Props = OwnProps & StateProps & DispatchProps;
|
2018-09-20 11:58:47 -07:00
|
|
|
|
2019-01-31 14:56:16 -08:00
|
|
|
const STATE = {
|
|
|
|
contribution: null as null | ContributionWithAddresses,
|
2019-03-12 10:10:56 -07:00
|
|
|
contributionError: null as null | Error,
|
2019-01-31 14:56:16 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = typeof STATE;
|
|
|
|
|
|
|
|
class CreateFinal extends React.Component<Props, State> {
|
|
|
|
state = STATE;
|
2018-09-20 11:58:47 -07:00
|
|
|
componentDidMount() {
|
2018-12-28 15:05:34 -08:00
|
|
|
this.submit();
|
2018-09-20 11:58:47 -07:00
|
|
|
}
|
|
|
|
|
2019-01-31 14:56:16 -08:00
|
|
|
componentDidUpdate(prev: Props) {
|
|
|
|
const { submittedProposal } = this.props;
|
|
|
|
if (!prev.submittedProposal && submittedProposal) {
|
|
|
|
if (!submittedProposal.isStaked) {
|
|
|
|
this.getStakingContribution();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 11:58:47 -07:00
|
|
|
render() {
|
2019-02-05 12:26:37 -08:00
|
|
|
const { submittedProposal, submitError, goBack } = this.props;
|
2019-03-12 10:10:56 -07:00
|
|
|
const { contribution, contributionError } = this.state;
|
2019-01-31 14:56:16 -08:00
|
|
|
|
|
|
|
const ready = submittedProposal && (submittedProposal.isStaked || contribution);
|
|
|
|
const staked = submittedProposal && submittedProposal.isStaked;
|
|
|
|
|
2018-09-20 11:58:47 -07:00
|
|
|
let content;
|
2018-12-28 15:05:34 -08:00
|
|
|
if (submitError) {
|
|
|
|
content = (
|
|
|
|
<div className="CreateFinal-message is-error">
|
|
|
|
<Icon type="close-circle" />
|
|
|
|
<div className="CreateFinal-message-text">
|
2019-01-27 19:16:04 -08:00
|
|
|
<h3>
|
|
|
|
<b>Something went wrong during creation</b>
|
|
|
|
</h3>
|
|
|
|
<h5>{submitError}</h5>
|
2019-02-05 12:26:37 -08:00
|
|
|
<a onClick={goBack}>Click here</a> to go back to the form and try again.
|
2018-12-28 15:05:34 -08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2019-01-31 14:56:16 -08:00
|
|
|
} else if (ready) {
|
2018-09-20 11:58:47 -07:00
|
|
|
content = (
|
2019-01-31 14:56:16 -08:00
|
|
|
<>
|
|
|
|
<div className="CreateFinal-message is-success">
|
|
|
|
<Icon type="check-circle" />
|
|
|
|
{staked && (
|
|
|
|
<div className="CreateFinal-message-text">
|
|
|
|
Your proposal has been staked and submitted! Check your{' '}
|
|
|
|
<Link to={`/profile?tab=pending`}>profile's pending proposals tab</Link>{' '}
|
|
|
|
to check its status.
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{!staked && (
|
|
|
|
<div className="CreateFinal-message-text">
|
|
|
|
Your proposal has been submitted! Please send the staking contribution of{' '}
|
|
|
|
<b>{contribution && contribution.amount} ZEC</b> using the instructions
|
|
|
|
below.
|
|
|
|
</div>
|
|
|
|
)}
|
2019-01-09 10:23:08 -08:00
|
|
|
</div>
|
2019-01-31 14:56:16 -08:00
|
|
|
{!staked && (
|
|
|
|
<>
|
|
|
|
<div className="CreateFinal-contribute">
|
|
|
|
<PaymentInfo
|
|
|
|
text={
|
|
|
|
<>
|
|
|
|
<p>
|
|
|
|
If you cannot send the payment now, you may bring up these
|
|
|
|
instructions again by visiting your{' '}
|
|
|
|
<Link to={`/profile?tab=funded`}>profile's funded tab</Link>.
|
|
|
|
</p>
|
|
|
|
<p>
|
2019-03-12 16:04:32 -07:00
|
|
|
Once your payment has been sent and processed with 6 confirmations, you
|
|
|
|
will receive an email. Visit your{' '}
|
2019-01-31 14:56:16 -08:00
|
|
|
<Link to={`/profile?tab=pending`}>
|
|
|
|
profile's pending proposals tab
|
|
|
|
</Link>{' '}
|
|
|
|
at any time to check its status.
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
contribution={contribution}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<p className="CreateFinal-staked">
|
|
|
|
I'm finished, take me to{' '}
|
|
|
|
<Link to="/profile?tab=pending">my pending proposals</Link>!
|
|
|
|
</p>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
2018-09-20 11:58:47 -07:00
|
|
|
);
|
2019-03-12 10:10:56 -07:00
|
|
|
} else if (contributionError) {
|
|
|
|
content = (
|
|
|
|
<Result
|
|
|
|
type="error"
|
|
|
|
title="Something went wrong"
|
|
|
|
description={
|
|
|
|
<>
|
|
|
|
We were unable to get your staking contribution started. You can finish
|
|
|
|
staking from <Link to="/profile?tab=pending">your profile</Link>, please try
|
|
|
|
again from there soon.
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
2018-09-20 11:58:47 -07:00
|
|
|
} else {
|
2019-01-23 08:35:03 -08:00
|
|
|
content = <Loader size="large" tip="Submitting your proposal..." />;
|
2018-09-20 11:58:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="CreateFinal">{content}</div>;
|
|
|
|
}
|
|
|
|
|
2018-12-28 15:05:34 -08:00
|
|
|
private submit = () => {
|
2018-11-14 08:43:00 -08:00
|
|
|
if (this.props.form) {
|
2018-12-28 15:05:34 -08:00
|
|
|
this.props.submitProposal(this.props.form);
|
2018-11-14 08:43:00 -08:00
|
|
|
}
|
2018-09-20 11:58:47 -07:00
|
|
|
};
|
2019-01-31 14:56:16 -08:00
|
|
|
|
|
|
|
private getStakingContribution = async () => {
|
|
|
|
const { submittedProposal } = this.props;
|
|
|
|
if (submittedProposal) {
|
2019-03-12 10:10:56 -07:00
|
|
|
try {
|
|
|
|
const res = await getProposalStakingContribution(submittedProposal.proposalId);
|
|
|
|
this.setState({ contribution: res.data });
|
|
|
|
} catch (err) {
|
|
|
|
this.setState({ contributionError: err });
|
|
|
|
}
|
2019-01-31 14:56:16 -08:00
|
|
|
}
|
|
|
|
};
|
2018-09-20 11:58:47 -07:00
|
|
|
}
|
|
|
|
|
2019-02-05 12:26:37 -08:00
|
|
|
export default connect<StateProps, DispatchProps, OwnProps, AppState>(
|
2018-09-20 11:58:47 -07:00
|
|
|
(state: AppState) => ({
|
|
|
|
form: state.create.form,
|
2018-12-28 15:05:34 -08:00
|
|
|
submittedProposal: state.create.submittedProposal,
|
|
|
|
submitError: state.create.submitError,
|
2018-09-20 11:58:47 -07:00
|
|
|
}),
|
|
|
|
{
|
2018-12-28 15:05:34 -08:00
|
|
|
submitProposal: createActions.submitProposal,
|
2018-09-20 11:58:47 -07:00
|
|
|
},
|
|
|
|
)(CreateFinal);
|