gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: towards the improved confirmP


From: gnunet
Subject: [taler-wallet-core] branch master updated: towards the improved confirmPay API
Date: Tue, 11 Aug 2020 14:02:17 +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 ff3f9656 towards the improved confirmPay API
ff3f9656 is described below

commit ff3f96566151d390462931574184ed9e6b84db5b
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Tue Aug 11 17:32:11 2020 +0530

    towards the improved confirmPay API
---
 packages/taler-wallet-core/src/operations/pay.ts     |  9 ++++++++-
 packages/taler-wallet-core/src/types/transactions.ts |  2 +-
 packages/taler-wallet-core/src/types/walletTypes.ts  | 20 +++++++++++++++++++-
 packages/taler-wallet-webextension/src/pages/pay.tsx |  3 +++
 4 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/pay.ts 
b/packages/taler-wallet-core/src/operations/pay.ts
index fd997fb1..db5a56d1 100644
--- a/packages/taler-wallet-core/src/operations/pay.ts
+++ b/packages/taler-wallet-core/src/operations/pay.ts
@@ -49,6 +49,7 @@ import {
   PreparePayResult,
   RefreshReason,
   PreparePayResultType,
+  ConfirmPayResultType,
 } from "../types/walletTypes";
 import * as Amounts from "../util/amounts";
 import { AmountJson } from "../util/amounts";
@@ -853,7 +854,10 @@ export async function submitPay(
     lastSessionId: sessionId,
   };
 
-  return { nextUrl };
+  return {
+    type: ConfirmPayResultType.Done,
+    nextUrl,
+  };
 }
 
 /**
@@ -957,6 +961,9 @@ export async function preparePayForUri(
       await tx.put(Stores.purchases, p);
     });
     const r = await submitPay(ws, proposalId);
+    if (r.type !== ConfirmPayResultType.Done) {
+      throw Error("submitting pay failed");
+    }
     return {
       status: PreparePayResultType.AlreadyConfirmed,
       contractTerms: JSON.parse(purchase.contractTermsRaw),
diff --git a/packages/taler-wallet-core/src/types/transactions.ts 
b/packages/taler-wallet-core/src/types/transactions.ts
index fe5580f8..47e3e7d5 100644
--- a/packages/taler-wallet-core/src/types/transactions.ts
+++ b/packages/taler-wallet-core/src/types/transactions.ts
@@ -53,7 +53,7 @@ export interface TransactionsResponse {
   transactions: Transaction[];
 }
 
-interface TransactionError {
+export interface TransactionError {
   /**
    * TALER_EC_* unique error code.
    * The action(s) offered and message displayed on the transaction item 
depend on this code.
diff --git a/packages/taler-wallet-core/src/types/walletTypes.ts 
b/packages/taler-wallet-core/src/types/walletTypes.ts
index 6175c40e..26d7e8e0 100644
--- a/packages/taler-wallet-core/src/types/walletTypes.ts
+++ b/packages/taler-wallet-core/src/types/walletTypes.ts
@@ -45,6 +45,7 @@ import {
 } from "../util/codec";
 import { AmountString } from "./talerTypes";
 import { codec } from "..";
+import { TransactionError } from "./transactions";
 
 /**
  * Response for the create reserve request to the wallet.
@@ -192,13 +193,30 @@ export function mkAmount(
   return { value, fraction, currency };
 }
 
+export const enum ConfirmPayResultType {
+  Done = "done",
+  Pending = "pending",
+}
+
 /**
  * Result for confirmPay
  */
-export interface ConfirmPayResult {
+export interface ConfirmPayResultDone {
+  type: ConfirmPayResultType.Done,
+
   nextUrl: string;
 }
 
+export interface ConfirmPayResultPending {
+  type: ConfirmPayResultType.Pending,
+
+  lastError: TransactionError;
+}
+
+export type ConfirmPayResult =
+  | ConfirmPayResultDone
+  | ConfirmPayResultPending
+
 /**
  * Information about all sender wire details known to the wallet,
  * as well as exchanges that accept these wire types.
diff --git a/packages/taler-wallet-webextension/src/pages/pay.tsx 
b/packages/taler-wallet-webextension/src/pages/pay.tsx
index 2abd423b..b876a9c5 100644
--- a/packages/taler-wallet-webextension/src/pages/pay.tsx
+++ b/packages/taler-wallet-webextension/src/pages/pay.tsx
@@ -109,6 +109,9 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }): JSX.Element {
     try {
       setLoading(true);
       const res = await wxApi.confirmPay(proposalId, undefined);
+      if (res.type !== walletTypes.ConfirmPayResultType.Done) {
+        throw Error("payment pending");
+      }
       document.location.href = res.nextUrl;
     } catch (e) {
       console.error(e);

-- 
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]