From 008926b18470e7f394cd640302957b29728a9803 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 30 Aug 2017 17:08:54 +0200 Subject: compute full fees for refresh and spending --- src/webex/messages.ts | 6 ++++- src/webex/pages/confirm-contract.html | 1 + src/webex/pages/confirm-contract.tsx | 43 +++++++++++++++++++++++++++-------- src/webex/pages/refund.tsx | 17 +++++++------- src/webex/renderHtml.tsx | 32 -------------------------- src/webex/wxApi.ts | 5 ++++ src/webex/wxBackend.ts | 2 ++ 7 files changed, 54 insertions(+), 52 deletions(-) (limited to 'src/webex') diff --git a/src/webex/messages.ts b/src/webex/messages.ts index 7de28b9e9..122bd8fe2 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -191,7 +191,11 @@ export interface MessageMap { "get-purchase": { request: any; response: void; - } + }; + "get-full-refund-fees": { + request: { refundPermissions: types.RefundPermission[] }; + response: void; + }; } /** diff --git a/src/webex/pages/confirm-contract.html b/src/webex/pages/confirm-contract.html index 394de582a..223d413d8 100644 --- a/src/webex/pages/confirm-contract.html +++ b/src/webex/pages/confirm-contract.html @@ -5,6 +5,7 @@ Taler Wallet: Confirm Reserve Creation + diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index fa71b1028..5436cb5a6 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -25,12 +25,13 @@ */ import * as i18n from "../../i18n"; import { + CheckPayResult, ContractTerms, ExchangeRecord, ProposalRecord, } from "../../types"; -import { renderContractTerms } from "../renderHtml"; +import { renderAmount } from "../renderHtml"; import * as wxApi from "../wxApi"; import * as React from "react"; @@ -113,6 +114,7 @@ interface ContractPromptState { * when pressing pay. */ holdCheck: boolean; + payStatus?: CheckPayResult; } class ContractPrompt extends React.Component { @@ -150,7 +152,7 @@ class ContractPrompt extends React.Component...; } const c = this.state.proposal.contractTerms; + let merchantName; + if (c.merchant && c.merchant.name) { + merchantName = {c.merchant.name}; + } else { + merchantName = (pub: {c.merchant_pub}); + } + const amount = {renderAmount(c.amount)}; + console.log("payStatus", this.state.payStatus); return (
- {renderContractTerms(c)} + + The merchant {merchantName} {" "} + offers you to purchase: + +
    + {c.products.map( + (p: any, i: number) => (
  • {p.description}: {renderAmount(p.price)}
  • )) + } +
+ {(this.state.payStatus && this.state.payStatus.coinSelection) ? +

The total price is {amount} (plus {renderAmount(this.state.payStatus.coinSelection.totalFees)} fees).

+ : +

The total price is {amount}.

+ }
-
{(this.state.alreadyPaid ?

You already paid for this, clicking "Confirm payment" will not cost money again.

:

)} 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 (

-

Refund fully received: (refund fees: )

-

Refund incoming: (refund fees: )

+

Refund fully received: (refund fees: )

+

Refund incoming:

); }; @@ -108,7 +105,7 @@ class RefundStatusView extends React.ComponentRefund Status

Status of purchase {summary} from merchant {merchantName} (order id {purchase.contractTerms.order_id}).

Total amount:

- {purchase.finished ? :

Purchase not completed.

} + {purchase.finished ? :

Purchase not completed.

}
); } @@ -116,7 +113,9 @@ class RefundStatusView extends React.Component purchase.refundsDone[x]); + const refundFees = await wxApi.getFullRefundFees( {refundPermissions: refundsDone }); + this.setState({ purchase, gotResult: true, refundFees }); } } diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx index 2a5b50533..d26f726af 100644 --- a/src/webex/renderHtml.tsx +++ b/src/webex/renderHtml.tsx @@ -24,45 +24,13 @@ /** * Imports. */ -import { amountToPretty } from "../helpers"; -import * as i18n from "../i18n"; import { AmountJson, Amounts, - ContractTerms, } from "../types"; import * as React from "react"; -/** - * Render contract terms for the end user to view. - */ -export function renderContractTerms(contractTerms: ContractTerms): JSX.Element { - let merchantName; - if (contractTerms.merchant && contractTerms.merchant.name) { - merchantName = {contractTerms.merchant.name}; - } else { - merchantName = (pub: {contractTerms.merchant_pub}); - } - const amount = {amountToPretty(contractTerms.amount)}; - - return ( -
- - The merchant {merchantName} - wants to enter a contract over {amount}{" "} - with you. - -

{i18n.str`You are about to purchase:`}

-
    - {contractTerms.products.map( - (p: any, i: number) => (
  • {`${p.description}: ${amountToPretty(p.price)}`}
  • )) - } -
-
- ); -} - /** * Render amount as HTML, which non-breaking space between diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index 1423da53b..096d855e0 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -33,6 +33,7 @@ import { PreCoinRecord, PurchaseRecord, QueryPaymentResult, + RefundPermission, ReserveCreationInfo, ReserveRecord, SenderWireInfos, @@ -345,3 +346,7 @@ export function acceptRefund(refundData: any): Promise { export function getPurchase(contractTermsHash: string): Promise { return callBackend("get-purchase", { contractTermsHash }); } + +export function getFullRefundFees(args: { refundPermissions: RefundPermission[] }): Promise { + return callBackend("get-full-refund-fees", { refundPermissions: args.refundPermissions }); +} diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index db2ffbfbd..16da3d97d 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -323,6 +323,8 @@ function handleMessage(sender: MessageSender, throw Error("contractTermsHash missing"); } return needsWallet().getPurchase(contractTermsHash); + case "get-full-refund-fees": + return needsWallet().getFullRefundFees(detail.refundPermissions); default: // Exhaustiveness check. // See https://www.typescriptlang.org/docs/handbook/advanced-types.html -- cgit v1.2.3