From 1a66e232a55dff8c889e5554f637f4d4e475179c Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 29 Jan 2018 16:41:17 +0100 Subject: implement aborting and getting refunds from failed payments --- src/webex/pages/confirm-contract.tsx | 129 +++++++++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 28 deletions(-) (limited to 'src/webex/pages/confirm-contract.tsx') diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index 7fe6b9600..f41dba069 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -40,6 +40,7 @@ import * as wxApi from "../wxApi"; import * as React from "react"; import * as ReactDOM from "react-dom"; import URI = require("urijs"); +import { WalletApiError } from "../wxApi"; interface DetailState { @@ -111,7 +112,8 @@ interface ContractPromptProps { interface ContractPromptState { proposalId: number | undefined; proposal: ProposalDownloadRecord | undefined; - error: string | null; + checkPayError: string | undefined; + confirmPayError: object | undefined; payDisabled: boolean; alreadyPaid: boolean; exchanges: ExchangeRecord[] | undefined; @@ -124,21 +126,30 @@ interface ContractPromptState { payStatus?: CheckPayResult; replaying: boolean; payInProgress: boolean; + payAttempt: number; + working: boolean; + abortDone: boolean; + abortStarted: boolean; } class ContractPrompt extends React.Component { constructor(props: ContractPromptProps) { super(props); this.state = { + abortDone: false, + abortStarted: false, alreadyPaid: false, - error: null, + checkPayError: undefined, + confirmPayError: undefined, exchanges: undefined, holdCheck: false, + payAttempt: 0, payDisabled: true, payInProgress: false, proposal: undefined, proposalId: props.proposalId, replaying: false, + working: false, }; } @@ -154,7 +165,7 @@ class ContractPrompt extends React.Component e.master_pub); const ex = this.state.exchanges.find((e) => acceptedExchangePubs.indexOf(e.masterPublicKey) >= 0); if (ex) { - this.setState({ error: msgInsufficient }); + this.setState({ checkPayError: msgInsufficient }); } else { - this.setState({ error: msgNoMatch }); + this.setState({ checkPayError: msgNoMatch }); } } else { - this.setState({ error: msgInsufficient }); + this.setState({ checkPayError: msgInsufficient }); } this.setState({ payDisabled: true }); } else if (payStatus.status === "paid") { - this.setState({ alreadyPaid: true, payDisabled: false, error: null, payStatus }); + this.setState({ alreadyPaid: true, payDisabled: false, checkPayError: undefined, payStatus }); } else { - this.setState({ payDisabled: false, error: null, payStatus }); + this.setState({ payDisabled: false, checkPayError: undefined, payStatus }); } } async doPayment() { const proposal = this.state.proposal; - this.setState({holdCheck: true}); + this.setState({ holdCheck: true, payAttempt: this.state.payAttempt + 1}); if (!proposal) { return; } @@ -234,11 +247,17 @@ class ContractPrompt extends React.ComponentError: either contractUrl or proposalId must be given; @@ -272,18 +302,72 @@ class ContractPrompt extends React.Component +
The following items are included:
    {c.products.map( (p: any, i: number) => (
  • {p.description}: {renderAmount(p.price)}
  • )) }
- +
); } + + const ConfirmButton = () => ( + + ); + + const WorkingButton = () => ( +
+