gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-wallet-core] branch master updated (5ec34429 -> c3f4


From: gnunet
Subject: [GNUnet-SVN] [taler-wallet-core] branch master updated (5ec34429 -> c3f47e8f)
Date: Sat, 31 Aug 2019 12:00:08 +0200

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

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

    from 5ec34429 support for tipping protocol changes
     new 5a7269b2 cli refunds
     new c3f47e8f api simplication

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/dbTypes.ts                   |   4 --
 src/headless/taler-wallet-cli.ts |  14 ++++++
 src/taleruri.ts                  |  53 ++++++++++++++++++++
 src/wallet.ts                    |  37 +++++---------
 src/walletTypes.ts               |  20 --------
 src/webex/messages.ts            |  16 -------
 src/webex/pages/pay.tsx          |  13 ++---
 src/webex/pages/refund.tsx       |   8 +++-
 src/webex/pages/tip.tsx          |  29 ++---------
 src/webex/renderHtml.tsx         |  25 ++++++++++
 src/webex/wxApi.ts               |  28 -----------
 src/webex/wxBackend.ts           | 101 +--------------------------------------
 12 files changed, 121 insertions(+), 227 deletions(-)

diff --git a/src/dbTypes.ts b/src/dbTypes.ts
index 17e7a89b..0ca2b626 100644
--- a/src/dbTypes.ts
+++ b/src/dbTypes.ts
@@ -817,10 +817,6 @@ export interface PurchaseRecord {
    */
   timestamp_refund: number;
 
-  /**
-   * Last session id that we submitted to /pay (if any).
-   */
-  lastSessionSig: string | undefined;
 
   /**
    * Last session signature that we submitted to /pay (if any).
diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts
index 86eaec64..bfa1ac4b 100644
--- a/src/headless/taler-wallet-cli.ts
+++ b/src/headless/taler-wallet-cli.ts
@@ -179,6 +179,20 @@ program
     wallet.stop();
   });
 
+
+
+  program
+  .command("refund-uri <refund-uri>")
+  .action(async (refundUri, cmdObj) => {
+    applyVerbose(program.verbose);
+    console.log("getting refund", refundUri);
+    const wallet = await getDefaultNodeWallet({
+      persistentStoragePath: walletDbPath,
+    });
+    await wallet.applyRefund(refundUri);
+    wallet.stop();
+  });
+
 program
   .command("pay-uri <pay-uri")
   .option("-y, --yes", "automatically answer yes to prompts")
diff --git a/src/taleruri.ts b/src/taleruri.ts
index f5fc7742..bd01abb6 100644
--- a/src/taleruri.ts
+++ b/src/taleruri.ts
@@ -26,6 +26,10 @@ export interface WithdrawUriResult {
   statusUrl: string;
 }
 
+export interface RefundUriResult {
+  refundUrl: string;
+}
+
 export interface TipUriResult {
   tipPickupUrl: string;
   tipId: string;
@@ -155,3 +159,52 @@ export function parseTipUri(s: string): TipUriResult | 
undefined {
     merchantOrigin: new URI(tipPickupUrl).origin(),
   };
 }
+
+export function parseRefundUri(s: string): RefundUriResult | undefined {
+  const parsedUri = new URI(s);
+  if (parsedUri.scheme() != "taler") {
+    return undefined;
+  }
+  if (parsedUri.authority() != "refund") {
+    return undefined;
+  }
+
+  let [
+    _,
+    host,
+    maybePath,
+    maybeInstance,
+    orderId,
+  ] = parsedUri.path().split("/");
+
+  if (!host) {
+    return undefined;
+  }
+
+  if (!maybePath) {
+    return undefined;
+  }
+
+  if (!orderId) {
+    return undefined;
+  }
+
+  if (maybePath === "-") {
+    maybePath = "public/refund";
+  } else {
+    maybePath = decodeURIComponent(maybePath);
+  }
+  if (maybeInstance === "-") {
+    maybeInstance = "default";
+  }
+
+  const refundUrl = new URI(
+    "https://"; + host + "/" + decodeURIComponent(maybePath),
+  )
+    .addQuery({ instance: maybeInstance, order_id: orderId })
+    .href();
+
+  return {
+    refundUrl,
+  };
+}
\ No newline at end of file
diff --git a/src/wallet.ts b/src/wallet.ts
index fd1be529..e90a6e3d 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -109,7 +109,7 @@ import {
   AcceptWithdrawalResponse,
 } from "./walletTypes";
 import { openPromise } from "./promiseUtils";
-import { parsePayUri, parseWithdrawUri, parseTipUri } from "./taleruri";
+import { parsePayUri, parseWithdrawUri, parseTipUri, parseRefundUri } from 
"./taleruri";
 
 interface SpeculativePayData {
   payCoinInfo: PayCoinInfo;
@@ -701,7 +701,6 @@ export class Wallet {
       contractTermsHash: proposal.contractTermsHash,
       finished: false,
       lastSessionId: undefined,
-      lastSessionSig: undefined,
       merchantSig: proposal.merchantSig,
       payReq,
       refundsDone: {},
@@ -1134,25 +1133,6 @@ export class Wallet {
     return { status: "payment-possible", coinSelection: res };
   }
 
-  /**
-   * Retrieve information required to pay for a contract, where the
-   * contract is identified via the fulfillment url.
-   */
-  async queryPaymentByFulfillmentUrl(
-    url: string,
-  ): Promise<PurchaseRecord | undefined> {
-    const t = await this.q().getIndexed(
-      Stores.purchases.fulfillmentUrlIndex,
-      url,
-    );
-
-    if (!t) {
-      console.log("query for payment failed");
-      return undefined;
-    }
-    return t;
-  }
-
   private async sendReserveInfoToBank(reservePub: string) {
     const reserve = await this.q().get<ReserveRecord>(
       Stores.reserves,
@@ -3109,7 +3089,7 @@ export class Wallet {
     }
   }
 
-  async acceptRefundResponse(
+  private async acceptRefundResponse(
     refundResponse: MerchantRefundResponse,
   ): Promise<string> {
     const refundPermissions = refundResponse.refund_permissions;
@@ -3149,8 +3129,7 @@ export class Wallet {
       .finish();
     this.notifier.notify();
 
-    // Start submitting it but don't wait for it here.
-    this.submitRefunds(hc);
+    await this.submitRefunds(hc);
 
     return hc;
   }
@@ -3159,7 +3138,15 @@ export class Wallet {
    * Accept a refund, return the contract hash for the contract
    * that was involved in the refund.
    */
-  async acceptRefund(refundUrl: string): Promise<string> {
+  async applyRefund(talerRefundUri: string): Promise<string> {
+    const parseResult = parseRefundUri(talerRefundUri);
+
+    if (!parseResult) {
+      throw Error("invalid refund URI");
+    }
+
+    const refundUrl = parseResult.refundUrl;
+
     Wallet.enableTracing && console.log("processing refund");
     let resp;
     try {
diff --git a/src/walletTypes.ts b/src/walletTypes.ts
index aec02937..060401c2 100644
--- a/src/walletTypes.ts
+++ b/src/walletTypes.ts
@@ -262,26 +262,6 @@ export interface HistoryRecord {
 }
 
 /**
- * Query payment response when the payment was found.
- */
-export interface QueryPaymentNotFound {
-  found: false;
-}
-
-/**
- * Query payment response when the payment wasn't found.
- */
-export interface QueryPaymentFound {
-  found: true;
-  contractTermsHash: string;
-  contractTerms: ContractTerms;
-  lastSessionSig?: string;
-  lastSessionId?: string;
-  payReq: PayReq;
-  proposalId: number;
-}
-
-/**
  * Information about all sender wire details known to the wallet,
  * as well as exchanges that accept these wire types.
  */
diff --git a/src/webex/messages.ts b/src/webex/messages.ts
index f1046d5c..7b3041ac 100644
--- a/src/webex/messages.ts
+++ b/src/webex/messages.ts
@@ -73,10 +73,6 @@ export interface MessageMap {
     request: { proposalId: number };
     response: walletTypes.CheckPayResult;
   };
-  "query-payment": {
-    request: {};
-    response: dbTypes.PurchaseRecord;
-  };
   "exchange-info": {
     request: { baseUrl: string };
     response: dbTypes.ExchangeRecord;
@@ -97,10 +93,6 @@ export interface MessageMap {
     request: {};
     response: walletTypes.HistoryRecord[];
   };
-  "get-proposal": {
-    request: { proposalId: number };
-    response: dbTypes.ProposalDownloadRecord | undefined;
-  };
   "get-coins": {
     request: { exchangeBaseUrl: string };
     response: any;
@@ -169,10 +161,6 @@ export interface MessageMap {
     request: { contractTermsHash: string };
     response: dbTypes.PurchaseRecord;
   };
-  "get-full-refund-fees": {
-    request: { refundPermissions: talerTypes.MerchantRefundPermission[] };
-    response: AmountJson;
-  };
   "accept-tip": {
     request: { talerTipUri: string };
     response: void;
@@ -185,10 +173,6 @@ export interface MessageMap {
     request: {};
     response: void;
   };
-  "taler-pay": {
-    request: any;
-    response: void;
-  };
   "download-proposal": {
     request: { url: string };
     response: number;
diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx
index d929426c..1561dd95 100644
--- a/src/webex/pages/pay.tsx
+++ b/src/webex/pages/pay.tsx
@@ -30,7 +30,7 @@ import { ExchangeRecord, ProposalDownloadRecord } from 
"../../dbTypes";
 import { ContractTerms } from "../../talerTypes";
 import { CheckPayResult, PreparePayResult } from "../../walletTypes";
 
-import { renderAmount } from "../renderHtml";
+import { renderAmount, ProgressButton } from "../renderHtml";
 import * as wxApi from "../wxApi";
 
 import React, { useState, useEffect } from "react";
@@ -44,6 +44,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }) {
   const [payStatus, setPayStatus] = useState<PreparePayResult | undefined>();
   const [payErrMsg, setPayErrMsg] = useState<string | undefined>("");
   const [numTries, setNumTries] = useState(0);
+  const [loading, setLoading] = useState(false);
   let totalFees: Amounts.AmountJson | undefined = undefined;
 
   useEffect(() => {
@@ -99,6 +100,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }) {
   const doPayment = async () => {
     setNumTries(numTries + 1);
     try {
+      setLoading(true);
       const res = await wxApi.confirmPay(payStatus!.proposalId!, undefined);
       document.location.href = res.nextUrl;
     } catch (e) {
@@ -140,12 +142,11 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: 
string }) {
         </div>
       ) : (
         <div>
-          <button
-            className="pure-button button-success"
-            onClick={() => doPayment()}
-          >
+          <ProgressButton
+            loading={loading}
+            onClick={() => doPayment()}>
             {i18n.str`Confirm payment`}
-          </button>
+          </ProgressButton>
         </div>
       )}
     </div>
diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx
index 6bc1a136..57d74048 100644
--- a/src/webex/pages/refund.tsx
+++ b/src/webex/pages/refund.tsx
@@ -188,8 +188,12 @@ async function main() {
     return;
   }
 
-  const contractTermsHash = query.contractTermsHash;
-  const refundUrl = query.refundUrl;
+  const talerRefundUri = query.talerRefundUri;
+  if (!talerRefundUri) {
+    console.error("taler refund URI requred");
+    return;
+  }
+
   ReactDOM.render(<RefundStatusView contractTermsHash={contractTermsHash} 
refundUrl={refundUrl} />, container);
 }
 
diff --git a/src/webex/pages/tip.tsx b/src/webex/pages/tip.tsx
index a3f5c38c..0a066053 100644
--- a/src/webex/pages/tip.tsx
+++ b/src/webex/pages/tip.tsx
@@ -29,35 +29,12 @@ import * as i18n from "../../i18n";
 
 import { acceptTip, getReserveCreationInfo, getTipStatus } from "../wxApi";
 
-import { WithdrawDetailView, renderAmount } from "../renderHtml";
+import { WithdrawDetailView, renderAmount, ProgressButton } from 
"../renderHtml";
 
 import * as Amounts from "../../amounts";
 import { useState, useEffect } from "react";
 import { TipStatus } from "../../walletTypes";
 
-interface LoadingButtonProps {
-  loading: boolean;
-}
-
-function LoadingButton(
-  props:
-    & React.PropsWithChildren<LoadingButtonProps>
-    & React.DetailedHTMLProps<
-        React.ButtonHTMLAttributes<HTMLButtonElement>,
-        HTMLButtonElement
-      >,
-) {
-  return (
-    <button
-      className="pure-button pure-button-primary"
-      type="button"
-      {...props}
-    >
-      {props.loading ? <span><object className="svg-icon svg-baseline" 
data="/img/spinner-bars.svg" /></span> : null}
-      {props.children}
-    </button>
-  );
-}
 
 function TipDisplay(props: { talerTipUri: string }) {
   const [tipStatus, setTipStatus] = useState<TipStatus | undefined>(undefined);
@@ -110,9 +87,9 @@ function TipDisplay(props: { talerTipUri: string }) {
         operation.
       </p>
       <form className="pure-form">
-        <LoadingButton loading={loading} onClick={() => accept()}>
+        <ProgressButton loading={loading} onClick={() => accept()}>
           AcceptTip
-        </LoadingButton>
+        </ProgressButton>
         {" "}
         <button className="pure-button" type="button" onClick={() => 
discard()}>
           Discard tip
diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx
index e4686ade..867fb440 100644
--- a/src/webex/renderHtml.tsx
+++ b/src/webex/renderHtml.tsx
@@ -316,3 +316,28 @@ export class ExpanderText extends 
ImplicitStateComponent<ExpanderTextProps> {
   }
 }
 
+
+export interface LoadingButtonProps {
+  loading: boolean;
+}
+
+export function ProgressButton(
+  props:
+    & React.PropsWithChildren<LoadingButtonProps>
+    & React.DetailedHTMLProps<
+        React.ButtonHTMLAttributes<HTMLButtonElement>,
+        HTMLButtonElement
+      >,
+) {
+  return (
+    <button
+      className="pure-button pure-button-primary"
+      type="button"
+      {...props}
+    >
+      {props.loading ? <span><object className="svg-icon svg-baseline" 
data="/img/spinner-bars.svg" /></span> : null}
+      {" "}
+      {props.children}
+    </button>
+  );
+}
\ No newline at end of file
diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts
index fd01aed3..d2e8c94f 100644
--- a/src/webex/wxApi.ts
+++ b/src/webex/wxApi.ts
@@ -216,13 +216,6 @@ export function payback(coinPub: string): Promise<void> {
 }
 
 /**
- * Get a proposal stored in the wallet by its proposal id.
- */
-export function getProposal(proposalId: number): 
Promise<ProposalDownloadRecord | undefined> {
-  return callBackend("get-proposal", { proposalId });
-}
-
-/**
  * Check if payment is possible or already done.
  */
 export function checkPay(proposalId: number): Promise<CheckPayResult> {
@@ -258,13 +251,6 @@ export function confirmReserve(reservePub: string): 
Promise<void> {
 }
 
 /**
- * Query for a payment by fulfillment URL.
- */
-export function queryPaymentByFulfillmentUrl(url: string): 
Promise<PurchaseRecord> {
-  return callBackend("query-payment", { url });
-}
-
-/**
  * Check upgrade information
  */
 export function checkUpgrade(): Promise<UpgradeResponse> {
@@ -336,14 +322,6 @@ export function getPurchase(contractTermsHash: string): 
Promise<PurchaseRecord>
   return callBackend("get-purchase", { contractTermsHash });
 }
 
-/**
- * Get the refund fees for a refund permission, including
- * subsequent refresh and unrefreshable coins.
- */
-export function getFullRefundFees(args: { refundPermissions: 
MerchantRefundPermission[] }): Promise<AmountJson> {
-  return callBackend("get-full-refund-fees", { refundPermissions: 
args.refundPermissions });
-}
-
 
 /**
  * Get the status of processing a tip.
@@ -367,12 +345,6 @@ export function clearNotification(): Promise<void> {
   return callBackend("clear-notification", { });
 }
 
-/**
- * Trigger taler payment processing (for payment, tipping and refunds).
- */
-export function talerPay(msg: any): Promise<void> {
-  return callBackend("taler-pay", msg);
-}
 
 /**
  * Download a contract.
diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts
index 5bff4fe0..570a3758 100644
--- a/src/webex/wxBackend.ts
+++ b/src/webex/wxBackend.ts
@@ -139,21 +139,6 @@ function handleMessage(
       }
       return needsWallet().checkPay(detail.proposalId);
     }
-    case "query-payment": {
-      if (sender.tab && sender.tab.id) {
-        rateLimitCache[sender.tab.id]++;
-        if (rateLimitCache[sender.tab.id] > 10) {
-          console.warn("rate limit for query-payment exceeded");
-          const msg = {
-            error: "rate limit exceeded for query-payment",
-            hint: "Check for redirect loops",
-            rateLimitExceeded: true,
-          };
-          return Promise.resolve(msg);
-        }
-      }
-      return needsWallet().queryPaymentByFulfillmentUrl(detail.url);
-    }
     case "exchange-info": {
       if (!detail.baseUrl) {
         return Promise.resolve({ error: "bad url" });
@@ -187,9 +172,6 @@ function handleMessage(
       // TODO: limit history length
       return needsWallet().getHistory();
     }
-    case "get-proposal": {
-      return needsWallet().getProposal(detail.proposalId);
-    }
     case "get-exchanges": {
       return needsWallet().getExchanges();
     }
@@ -289,10 +271,8 @@ function handleMessage(
       }
       return needsWallet().getPurchase(contractTermsHash);
     }
-    case "get-full-refund-fees":
-      return needsWallet().getFullRefundFees(detail.refundPermissions);
     case "accept-refund":
-      return needsWallet().acceptRefund(detail.refundUrl);
+      return needsWallet().applyRefund(detail.refundUrl);
     case "get-tip-status": {
       return needsWallet().getTipStatus(detail.talerTipUri);
     }
@@ -311,25 +291,6 @@ function handleMessage(
       }
       return needsWallet().abortFailedPayment(detail.contractTermsHash);
     }
-    case "taler-pay": {
-      const senderUrl = sender.url;
-      if (!senderUrl) {
-        console.log("can't trigger payment, no sender URL");
-        return;
-      }
-      const tab = sender.tab;
-      if (!tab) {
-        console.log("can't trigger payment, no sender tab");
-        return;
-      }
-      const tabId = tab.id;
-      if (typeof tabId !== "string") {
-        console.log("can't trigger payment, no sender tab id");
-        return;
-      }
-      talerPay(detail, senderUrl, tabId);
-      return;
-    }
     case "benchmark-crypto": {
       if (!detail.repetitions) {
         throw Error("repetitions not given");
@@ -418,66 +379,6 @@ class ChromeNotifier implements Notifier {
   }
 }
 
-async function talerPay(
-  fields: any,
-  url: string,
-  tabId: number,
-): Promise<string | undefined> {
-  if (!currentWallet) {
-    console.log("can't handle payment, no wallet");
-    return undefined;
-  }
-
-  const w = currentWallet;
-
-  const goToPayment = (p: PurchaseRecord): string => {
-    const nextUrl = new URI(p.contractTerms.fulfillment_url);
-    nextUrl.addSearch("order_id", p.contractTerms.order_id);
-    if (p.lastSessionSig) {
-      nextUrl.addSearch("session_sig", p.lastSessionSig);
-    }
-    return nextUrl.href();
-  };
-
-  if (fields.resource_url) {
-    const p = await w.queryPaymentByFulfillmentUrl(fields.resource_url);
-    console.log("query for resource url", fields.resource_url, "result", p);
-    if (
-      p &&
-      (fields.session_id === undefined || fields.session_id === 
p.lastSessionId)
-    ) {
-      return goToPayment(p);
-    }
-  }
-  if (fields.contract_url) {
-    const proposalId = await w.downloadProposal(fields.contract_url);
-    const uri = new URI(
-      chrome.extension.getURL("/src/webex/pages/confirm-contract.html"),
-    );
-    if (fields.session_id) {
-      uri.addSearch("sessionId", fields.session_id);
-    }
-    uri.addSearch("proposalId", proposalId);
-    const redirectUrl = uri.href();
-    return redirectUrl;
-  }
-  if (fields.offer_url) {
-    return fields.offer_url;
-  }
-  if (fields.refund_url) {
-    console.log("processing refund");
-    const uri = new URI(
-      chrome.extension.getURL("/src/webex/pages/refund.html"),
-    );
-    return uri.query({ refundUrl: fields.refund_url }).href();
-  }
-  if (fields.tip) {
-    const uri = new URI(chrome.extension.getURL("/src/webex/pages/tip.html"));
-    return uri.query({ tip_token: fields.tip }).href();
-  }
-  return undefined;
-}
-
 function getTab(tabId: number): Promise<chrome.tabs.Tab> {
   return new Promise((resolve, reject) => {
     chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) => resolve(tab));

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



reply via email to

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