gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: fix issues in the webextensio


From: gnunet
Subject: [taler-wallet-core] branch master updated: fix issues in the webextension refund UI
Date: Fri, 15 May 2020 09:23:41 +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 35c83414 fix issues in the webextension refund UI
35c83414 is described below

commit 35c83414f9e0af11012c1a2e00672d2a7c1856ae
Author: Florian Dold <address@hidden>
AuthorDate: Fri May 15 12:53:35 2020 +0530

    fix issues in the webextension refund UI
---
 src/operations/refund.ts    | 12 ++++++------
 src/wallet.ts               | 33 +++++++++++++++++++--------------
 src/webex/messages.ts       |  6 +++---
 src/webex/pageEntryPoint.ts |  4 ++++
 src/webex/pages/refund.tsx  |  4 ++--
 src/webex/wxApi.ts          | 15 +++++++++------
 src/webex/wxBackend.ts      | 11 +++++++----
 7 files changed, 50 insertions(+), 35 deletions(-)

diff --git a/src/operations/refund.ts b/src/operations/refund.ts
index 1ffcd2da..cbcb9644 100644
--- a/src/operations/refund.ts
+++ b/src/operations/refund.ts
@@ -252,10 +252,7 @@ async function acceptRefundResponse(
       let queryDone = true;
 
       if (numNewRefunds === 0) {
-        if (
-          p.autoRefundDeadline &&
-          p.autoRefundDeadline.t_ms > now.t_ms
-        ) {
+        if (p.autoRefundDeadline && p.autoRefundDeadline.t_ms > now.t_ms) {
           queryDone = false;
         }
       } else {
@@ -361,7 +358,7 @@ async function startRefundQuery(
 export async function applyRefund(
   ws: InternalWalletState,
   talerRefundUri: string,
-): Promise<{ contractTermsHash: string }> {
+): Promise<{ contractTermsHash: string; proposalId: string }> {
   const parseResult = parseRefundUri(talerRefundUri);
 
   console.log("applying refund", parseResult);
@@ -384,7 +381,10 @@ export async function applyRefund(
   logger.info("processing purchase for refund");
   await startRefundQuery(ws, purchase.proposalId);
 
-  return { contractTermsHash: purchase.contractData.contractTermsHash };
+  return {
+    contractTermsHash: purchase.contractData.contractTermsHash,
+    proposalId: purchase.proposalId,
+  };
 }
 
 export async function processPurchaseQueryRefund(
diff --git a/src/wallet.ts b/src/wallet.ts
index 2d63e229..31f9af8c 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -112,7 +112,10 @@ import {
 import { durationMin, Duration } from "./util/time";
 import { processRecoupGroup } from "./operations/recoup";
 import { OperationFailedAndReportedError } from "./operations/errors";
-import { TransactionsRequest, TransactionsResponse } from 
"./types/transactions";
+import {
+  TransactionsRequest,
+  TransactionsResponse,
+} from "./types/transactions";
 import { getTransactions } from "./operations/transactions";
 
 const builtinCurrencies: CurrencyRecord[] = [
@@ -631,7 +634,7 @@ export class Wallet {
    */
   async applyRefund(
     talerRefundUri: string,
-  ): Promise<{ contractTermsHash: string }> {
+  ): Promise<{ contractTermsHash: string; proposalId: string }> {
     return applyRefund(this.ws, talerRefundUri);
   }
 
@@ -719,14 +722,14 @@ export class Wallet {
     return refuseProposal(this.ws, proposalId);
   }
 
-  async getPurchaseDetails(hc: string): Promise<PurchaseDetails> {
-    const purchase = await this.db.get(Stores.purchases, hc);
+  async getPurchaseDetails(proposalId: string): Promise<PurchaseDetails> {
+    const purchase = await this.db.get(Stores.purchases, proposalId);
     if (!purchase) {
       throw Error("unknown purchase");
     }
-    const refundsDoneAmounts = Object.values(
-      purchase.refundsDone,
-    ).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
+    const refundsDoneAmounts = Object.values(purchase.refundsDone).map((x) =>
+      Amounts.parseOrThrow(x.perm.refund_amount),
+    );
     const refundsPendingAmounts = Object.values(
       purchase.refundsPending,
     ).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
@@ -734,12 +737,12 @@ export class Wallet {
       ...refundsDoneAmounts,
       ...refundsPendingAmounts,
     ]).amount;
-    const refundsDoneFees = Object.values(
-      purchase.refundsDone,
-    ).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
-    const refundsPendingFees = Object.values(
-      purchase.refundsPending,
-    ).map((x) => Amounts.parseOrThrow(x.perm.refund_amount));
+    const refundsDoneFees = Object.values(purchase.refundsDone).map((x) =>
+      Amounts.parseOrThrow(x.perm.refund_amount),
+    );
+    const refundsPendingFees = Object.values(purchase.refundsPending).map((x) 
=>
+      Amounts.parseOrThrow(x.perm.refund_amount),
+    );
     const totalRefundFees = Amounts.sum([
       ...refundsDoneFees,
       ...refundsPendingFees,
@@ -818,7 +821,9 @@ export class Wallet {
     return coinsJson;
   }
 
-  async getTransactions(request: TransactionsRequest): 
Promise<TransactionsResponse> {
+  async getTransactions(
+    request: TransactionsRequest,
+  ): Promise<TransactionsResponse> {
     return getTransactions(this.ws, request);
   }
 }
diff --git a/src/webex/messages.ts b/src/webex/messages.ts
index 179eec88..932636f1 100644
--- a/src/webex/messages.ts
+++ b/src/webex/messages.ts
@@ -122,7 +122,7 @@ export interface MessageMap {
     response: void;
   };
   "get-purchase-details": {
-    request: { contractTermsHash: string };
+    request: { proposalId: string };
     response: walletTypes.PurchaseDetails;
   };
   "accept-tip": {
@@ -135,7 +135,7 @@ export interface MessageMap {
   };
   "accept-refund": {
     request: { refundUrl: string };
-    response: string;
+    response: { contractTermsHash: string; proposalId: string };
   };
   "abort-failed-payment": {
     request: { contractTermsHash: string };
@@ -169,7 +169,7 @@ export interface MessageMap {
     response: walletTypes.ExtendedPermissionsResponse;
   };
   "get-extended-permissions": {
-    request: { };
+    request: {};
     response: walletTypes.ExtendedPermissionsResponse;
   };
 }
diff --git a/src/webex/pageEntryPoint.ts b/src/webex/pageEntryPoint.ts
index b9bdba06..9fd1d36f 100644
--- a/src/webex/pageEntryPoint.ts
+++ b/src/webex/pageEntryPoint.ts
@@ -25,6 +25,7 @@ import { createPopup } from "./pages/popup";
 import { createWithdrawPage } from "./pages/withdraw";
 import { createWelcomePage } from "./pages/welcome";
 import { createPayPage } from "./pages/pay";
+import { createRefundPage } from "./pages/refund";
 
 function main(): void {
   try {
@@ -47,6 +48,9 @@ function main(): void {
       case "pay.html":
         mainElement = createPayPage();
         break;
+      case "refund.html":
+        mainElement = createRefundPage();
+        break;
       default:
         throw Error(`page '${page}' not implemented`);
     }
diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx
index 621a286b..c5d6a00d 100644
--- a/src/webex/pages/refund.tsx
+++ b/src/webex/pages/refund.tsx
@@ -36,9 +36,9 @@ function RefundStatusView(props: { talerRefundUri: string }): 
JSX.Element {
   useEffect(() => {
     const doFetch = async (): Promise<void> => {
       try {
-        const hc = await wxApi.applyRefund(props.talerRefundUri);
+        const result = await wxApi.applyRefund(props.talerRefundUri);
         setApplied(true);
-        const r = await wxApi.getPurchaseDetails(hc);
+        const r = await wxApi.getPurchaseDetails(result.proposalId);
         setPurchaseDetails(r);
       } catch (e) {
         console.error(e);
diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts
index 0bd44485..1823f662 100644
--- a/src/webex/wxApi.ts
+++ b/src/webex/wxApi.ts
@@ -246,9 +246,9 @@ export function returnCoins(args: {
  * the contract terms hash.
  */
 export function getPurchaseDetails(
-  contractTermsHash: string,
+  proposalId: string,
 ): Promise<PurchaseDetails> {
-  return callBackend("get-purchase-details", { contractTermsHash });
+  return callBackend("get-purchase-details", { proposalId });
 }
 
 /**
@@ -268,7 +268,9 @@ export function acceptTip(talerTipUri: string): 
Promise<void> {
 /**
  * Download a refund and accept it.
  */
-export function applyRefund(refundUrl: string): Promise<string> {
+export function applyRefund(
+  refundUrl: string,
+): Promise<{ contractTermsHash: string; proposalId: string }> {
   return callBackend("accept-refund", { refundUrl });
 }
 
@@ -329,7 +331,9 @@ export function getDiagnostics(): 
Promise<WalletDiagnostics> {
 /**
  * Get diagnostics information
  */
-export function setExtendedPermissions(value: boolean): 
Promise<ExtendedPermissionsResponse> {
+export function setExtendedPermissions(
+  value: boolean,
+): Promise<ExtendedPermissionsResponse> {
   return callBackend("set-extended-permissions", { value });
 }
 
@@ -340,7 +344,6 @@ export function getExtendedPermissions(): 
Promise<ExtendedPermissionsResponse> {
   return callBackend("get-extended-permissions", {});
 }
 
-
 export function onUpdateNotification(f: () => void): () => void {
   const port = chrome.runtime.connect({ name: "notifications" });
   const listener = (): void => {
@@ -350,4 +353,4 @@ export function onUpdateNotification(f: () => void): () => 
void {
   return () => {
     port.onMessage.removeListener(listener);
   };
-}
\ No newline at end of file
+}
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts
index f56cba17..0e8b5307 100644
--- a/src/webex/wxBackend.ts
+++ b/src/webex/wxBackend.ts
@@ -212,11 +212,14 @@ async function handleMessage(
       return resp;
     }
     case "get-purchase-details": {
-      const contractTermsHash = detail.contractTermsHash;
-      if (!contractTermsHash) {
-        throw Error("contractTermsHash missing");
+      const proposalId = detail.proposalId;
+      if (!proposalId) {
+        throw Error("proposalId missing");
       }
-      return needsWallet().getPurchaseDetails(contractTermsHash);
+      if (typeof proposalId !== "string")  {
+        throw Error("proposalId must be a string");
+      }
+      return needsWallet().getPurchaseDetails(proposalId);
     }
     case "accept-refund":
       return needsWallet().applyRefund(detail.refundUrl);

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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