gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: tweaks to pay API


From: gnunet
Subject: [taler-wallet-core] branch master updated: tweaks to pay API
Date: Wed, 29 Jul 2020 19:40:46 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new c8553f3b tweaks to pay API
c8553f3b is described below

commit c8553f3bc53064d157b56220e9d2333b8931e7a5
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Wed Jul 29 23:10:41 2020 +0530

    tweaks to pay API
---
 src/headless/taler-wallet-cli.ts |  7 ++++---
 src/operations/pay.ts            | 20 ++++++++++----------
 src/types/walletTypes.ts         |  9 +++++----
 src/webex/pages/pay.tsx          | 12 ++++++------
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index ed6146a6..ba629537 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -60,7 +60,7 @@ async function doPay(
 ): Promise<void> {
   const result = await wallet.preparePayForUri(payUrl);
   if (result.status === PreparePayResultType.InsufficientBalance) {
-    console.log("contract", result.contractTermsRaw);
+    console.log("contract", result.contractTerms);
     console.error("insufficient balance");
     process.exit(1);
     return;
@@ -80,8 +80,9 @@ async function doPay(
   } else {
     throw Error("not reached");
   }
-  console.log("contract", result.contractTermsRaw);
-  console.log("total fees:", Amounts.stringify(result.totalFees));
+  console.log("contract", result.contractTerms);
+  console.log("raw amount:", result.amountRaw);
+  console.log("effective amount:", result.amountEffective);
   let pay;
   if (options.alwaysYes) {
     pay = true;
diff --git a/src/operations/pay.ts b/src/operations/pay.ts
index 08bbe43a..c2877da6 100644
--- a/src/operations/pay.ts
+++ b/src/operations/pay.ts
@@ -915,26 +915,26 @@ export async function preparePayForUri(
       console.log("not confirming payment, insufficient coins");
       return {
         status: PreparePayResultType.InsufficientBalance,
-        contractTermsRaw: d.contractTermsRaw,
+        contractTerms: d.contractTermsRaw,
         proposalId: proposal.proposalId,
       };
     }
 
     const costInfo = await getTotalPaymentCost(ws, res);
-    console.log("costInfo", costInfo);
-    console.log("coinsForPayment", res);
-    const totalFees = Amounts.sub(costInfo.totalCost, 
res.paymentAmount).amount;
+    logger.trace("costInfo", costInfo);
+    logger.trace("coinsForPayment", res);
 
     return {
       status: PreparePayResultType.PaymentPossible,
-      contractTermsRaw: d.contractTermsRaw,
+      contractTerms: d.contractTermsRaw,
       proposalId: proposal.proposalId,
-      totalFees,
+      amountEffective: Amounts.stringify(costInfo.totalCost),
+      amountRaw: Amounts.stringify(res.paymentAmount),
     };
   }
 
   if (purchase.lastSessionId !== uriResult.sessionId) {
-    console.log(
+    logger.trace(
       "automatically re-submitting payment with different session ID",
     );
     await ws.db.runWithWriteTransaction([Stores.purchases], async (tx) => {
@@ -948,20 +948,20 @@ export async function preparePayForUri(
     const r = await submitPay(ws, proposalId);
     return {
       status: PreparePayResultType.AlreadyConfirmed,
-      contractTermsRaw: purchase.contractTermsRaw,
+      contractTerms: purchase.contractTermsRaw,
       paid: true,
       nextUrl: r.nextUrl,
     };
   } else if (!purchase.timestampFirstSuccessfulPay) {
     return {
       status: PreparePayResultType.AlreadyConfirmed,
-      contractTermsRaw: purchase.contractTermsRaw,
+      contractTerms: purchase.contractTermsRaw,
       paid: false,
     };    
   } else if (purchase.paymentSubmitPending) {
     return {
       status: PreparePayResultType.AlreadyConfirmed,
-      contractTermsRaw: purchase.contractTermsRaw,
+      contractTerms: purchase.contractTermsRaw,
       paid: false,
     };
   }
diff --git a/src/types/walletTypes.ts b/src/types/walletTypes.ts
index a6bc26d8..9f0bfaf3 100644
--- a/src/types/walletTypes.ts
+++ b/src/types/walletTypes.ts
@@ -329,19 +329,20 @@ export type PreparePayResult =
 export interface PreparePayResultPaymentPossible {
   status: PreparePayResultType.PaymentPossible;
   proposalId: string;
-  contractTermsRaw: string;
-  totalFees: AmountJson;
+  contractTerms: string;
+  amountRaw: string;
+  amountEffective: string;
 }
 
 export interface PreparePayResultInsufficientBalance {
   status: PreparePayResultType.InsufficientBalance;
   proposalId: string;
-  contractTermsRaw: any;
+  contractTerms: any;
 }
 
 export interface PreparePayResultAlreadyConfirmed {
   status: PreparePayResultType.AlreadyConfirmed;
-  contractTermsRaw: any;
+  contractTerms: any;
   paid: boolean;
   // Only specified if paid.
   nextUrl?: string;
diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx
index 87f3c83d..d255ab6e 100644
--- a/src/webex/pages/pay.tsx
+++ b/src/webex/pages/pay.tsx
@@ -39,7 +39,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }): JSX.Element {
   const [payErrMsg, setPayErrMsg] = useState<string | undefined>("");
   const [numTries, setNumTries] = useState(0);
   const [loading, setLoading] = useState(false);
-  let totalFees: Amounts.AmountJson | undefined = undefined;
+  let amountEffective: Amounts.AmountJson | undefined = undefined;
 
   useEffect(() => {
     const doFetch = async (): Promise<void> => {
@@ -59,7 +59,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }): JSX.Element {
   }
 
   if (payStatus.status === "payment-possible") {
-    totalFees = payStatus.totalFees;
+    amountEffective = Amounts.parseOrThrow(payStatus.amountEffective);
   }
 
   if (payStatus.status === PreparePayResultType.AlreadyConfirmed && numTries 
=== 0) {
@@ -75,13 +75,13 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }): JSX.Element {
 
   try {
     contractTerms = codecForContractTerms().decode(
-      JSON.parse(payStatus.contractTermsRaw),
+      JSON.parse(payStatus.contractTerms),
     );
   } catch (e) {
     // This should never happen, as the wallet is supposed to check the 
contract terms
     // before storing them.
     console.error(e);
-    console.log("raw contract terms were", payStatus.contractTermsRaw);
+    console.log("raw contract terms were", payStatus.contractTerms);
     return <span>Invalid contract terms.</span>;
   }
 
@@ -129,10 +129,10 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }): JSX.Element {
         <div style={{ textAlign: "center" }}>
           <strong>{contractTerms.summary}</strong>
         </div>
-        {totalFees ? (
+        {amountEffective ? (
           <i18n.Translate wrap="p">
             The total price is <span>{amount} </span>
-            (plus <span>{renderAmount(totalFees)}</span> fees).
+            (plus <span>{renderAmount(amountEffective)}</span> fees).
           </i18n.Translate>
         ) : (
           <i18n.Translate wrap="p">

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]