From 97f6e68ce3a515938228b9a4d3e41b5f4b25a015 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 29 Jan 2018 22:58:47 +0100 Subject: change protocol to string amount network format --- src/webex/pages/refund.tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/webex/pages/refund.tsx') diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx index 8164eb664..b2f5948d7 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -59,18 +59,24 @@ const RefundDetail = ({purchase, fullRefundFees}: RefundDetailProps) => { } const firstRefundKey = [...pendingKeys, ...doneKeys][0]; - const currency = { ...purchase.refundsDone, ...purchase.refundsPending }[firstRefundKey].refund_amount.currency; + if (!firstRefundKey) { + return

Waiting for refunds ...

; + } + const allRefunds = { ...purchase.refundsDone, ...purchase.refundsPending }; + const currency = Amounts.parseOrThrow(allRefunds[firstRefundKey].refund_amount).currency; if (!currency) { throw Error("invariant"); } let amountPending = Amounts.getZero(currency); for (const k of pendingKeys) { - amountPending = Amounts.add(amountPending, purchase.refundsPending[k].refund_amount).amount; + const refundAmount = Amounts.parseOrThrow(purchase.refundsPending[k].refund_amount); + amountPending = Amounts.add(amountPending, refundAmount).amount; } let amountDone = Amounts.getZero(currency); for (const k of doneKeys) { - amountDone = Amounts.add(amountDone, purchase.refundsDone[k].refund_amount).amount; + const refundAmount = Amounts.parseOrThrow(purchase.refundsDone[k].refund_amount); + amountDone = Amounts.add(amountDone, refundAmount).amount; } const hasPending = amountPending.fraction !== 0 || amountPending.value !== 0; @@ -130,7 +136,7 @@ class RefundStatusView extends React.Component{summary} from merchant {merchantName}{" "} (order id {purchase.contractTerms.order_id}).

-

Total amount:

+

Total amount:

{purchase.finished ? :

Purchase not completed.

} @@ -147,12 +153,15 @@ class RefundStatusView extends React.Component purchase.refundsDone[x]); - const refundFees = await wxApi.getFullRefundFees( {refundPermissions: refundsDone }); - this.setState({ purchase, gotResult: true, refundFees }); + if (refundsDone.length) { + const refundFees = await wxApi.getFullRefundFees({ refundPermissions: refundsDone }); + this.setState({ purchase, gotResult: true, refundFees }); + } } } -- cgit v1.2.3