diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-01-29 22:58:47 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-01-29 22:58:47 +0100 |
commit | 97f6e68ce3a515938228b9a4d3e41b5f4b25a015 (patch) | |
tree | 371331acc56b7c56abec502126c2a40cdb23a95f /src/webex/pages | |
parent | 9fe6dc596573f38b13f0b15c946b8bc16013fdd9 (diff) | |
download | wallet-core-97f6e68ce3a515938228b9a4d3e41b5f4b25a015.tar.xz |
change protocol to string amount network format
Diffstat (limited to 'src/webex/pages')
-rw-r--r-- | src/webex/pages/confirm-contract.tsx | 4 | ||||
-rw-r--r-- | src/webex/pages/confirm-create-reserve.tsx | 2 | ||||
-rw-r--r-- | src/webex/pages/refund.tsx | 21 |
3 files changed, 19 insertions, 8 deletions
diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index 21f05d5d6..78e90ee0e 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -42,6 +42,8 @@ import * as ReactDOM from "react-dom"; import URI = require("urijs"); import { WalletApiError } from "../wxApi"; +import * as Amounts from "../../amounts"; + interface DetailState { collapsed: boolean; @@ -294,7 +296,7 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt } else { merchantName = <strong>(pub: {c.merchant_pub})</strong>; } - const amount = <strong>{renderAmount(c.amount)}</strong>; + const amount = <strong>{renderAmount(Amounts.parseOrThrow(c.amount))}</strong>; console.log("payStatus", this.state.payStatus); let products = null; diff --git a/src/webex/pages/confirm-create-reserve.tsx b/src/webex/pages/confirm-create-reserve.tsx index bd21280c3..d83c56665 100644 --- a/src/webex/pages/confirm-create-reserve.tsx +++ b/src/webex/pages/confirm-create-reserve.tsx @@ -38,11 +38,11 @@ import { import { ImplicitStateComponent, StateHolder } from "../components"; import { + WalletApiError, createReserve, getCurrency, getExchangeInfo, getReserveCreationInfo, - WalletApiError, } from "../wxApi"; import { 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 <p>Waiting for refunds ...</p>; + } + 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<RefundStatusViewProps, RefundStat 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> + <p>Total amount: <AmountDisplay amount={Amounts.parseOrThrow(purchase.contractTerms.amount)} /></p> {purchase.finished ? <RefundDetail purchase={purchase} fullRefundFees={this.state.refundFees!} /> : <p>Purchase not completed.</p>} @@ -147,12 +153,15 @@ class RefundStatusView extends React.Component<RefundStatusViewProps, RefundStat return; } contractTermsHash = await wxApi.acceptRefund(refundUrl); + this.setState({ contractTermsHash }); } const purchase = await wxApi.getPurchase(contractTermsHash); console.log("got purchase", purchase); const refundsDone = Object.keys(purchase.refundsDone).map((x) => 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 }); + } } } |