diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-30 17:08:54 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-30 17:08:54 +0200 |
commit | 008926b18470e7f394cd640302957b29728a9803 (patch) | |
tree | 45f914f5117116bb3af5010f9e7570e99b015952 /src/webex/pages/refund.tsx | |
parent | 24e021fef360448caf11ab5a489b570102e66f6f (diff) | |
download | wallet-core-008926b18470e7f394cd640302957b29728a9803.tar.xz |
compute full fees for refresh and spending
Diffstat (limited to 'src/webex/pages/refund.tsx')
-rw-r--r-- | src/webex/pages/refund.tsx | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx index b9506bf29..d2c21c2f4 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -37,11 +37,12 @@ interface RefundStatusViewProps { interface RefundStatusViewState { purchase?: types.PurchaseRecord; + refundFees?: types.AmountJson; gotResult: boolean; } -const RefundDetail = ({purchase}: {purchase: types.PurchaseRecord}) => { +const RefundDetail = ({purchase, fullRefundFees}: {purchase: types.PurchaseRecord, fullRefundFees: types.AmountJson}) => { const pendingKeys = Object.keys(purchase.refundsPending); const doneKeys = Object.keys(purchase.refundsDone); if (pendingKeys.length == 0 && doneKeys.length == 0) { @@ -54,22 +55,18 @@ const RefundDetail = ({purchase}: {purchase: types.PurchaseRecord}) => { } let amountPending = types.Amounts.getZero(currency); - let feesPending = types.Amounts.getZero(currency) for (let k of pendingKeys) { amountPending = types.Amounts.add(amountPending, purchase.refundsPending[k].refund_amount).amount; - feesPending = types.Amounts.add(feesPending, purchase.refundsPending[k].refund_fee).amount; } let amountDone = types.Amounts.getZero(currency); - let feesDone = types.Amounts.getZero(currency); for (let k of doneKeys) { amountDone = types.Amounts.add(amountDone, purchase.refundsDone[k].refund_amount).amount; - feesDone = types.Amounts.add(feesDone, purchase.refundsDone[k].refund_fee).amount; } return ( <div> - <p>Refund fully received: <AmountDisplay amount={amountDone} /> (refund fees: <AmountDisplay amount={feesDone} />)</p> - <p>Refund incoming: <AmountDisplay amount={amountPending} /> (refund fees: <AmountDisplay amount={feesPending} />)</p> + <p>Refund fully received: <AmountDisplay amount={amountDone} /> (refund fees: <AmountDisplay amount={fullRefundFees} />)</p> + <p>Refund incoming: <AmountDisplay amount={amountPending} /></p> </div> ); }; @@ -108,7 +105,7 @@ class RefundStatusView extends React.Component<RefundStatusViewProps, RefundStat <h1>Refund Status</h1> <p>Status of purchase <strong>{summary}</strong> from merchant <strong>{merchantName}</strong> (order id {purchase.contractTerms.order_id}).</p> <p>Total amount: <AmountDisplay amount={purchase.contractTerms.amount} /></p> - {purchase.finished ? <RefundDetail purchase={purchase} /> : <p>Purchase not completed.</p>} + {purchase.finished ? <RefundDetail purchase={purchase} fullRefundFees={this.state.refundFees!} /> : <p>Purchase not completed.</p>} </div> ); } @@ -116,7 +113,9 @@ class RefundStatusView extends React.Component<RefundStatusViewProps, RefundStat async update() { const purchase = await wxApi.getPurchase(this.props.contractTermsHash); console.log("got purchase", purchase); - this.setState({ purchase, gotResult: true }); + const refundsDone = Object.keys(purchase.refundsDone).map((x) => purchase.refundsDone[x]); + const refundFees = await wxApi.getFullRefundFees( {refundPermissions: refundsDone }); + this.setState({ purchase, gotResult: true, refundFees }); } } |