gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: make diagnostics, welcome pag


From: gnunet
Subject: [taler-wallet-core] branch master updated: make diagnostics, welcome page and permissions work again
Date: Fri, 21 Aug 2020 17:26:30 +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 1548086f make diagnostics, welcome page and permissions work again
1548086f is described below

commit 1548086f50a7e33f17c5a5218fa0fc3383a8a2d5
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Fri Aug 21 20:56:25 2020 +0530

    make diagnostics, welcome page and permissions work again
---
 .../src/operations/transactions.ts                 |   1 +
 .../taler-wallet-core/src/types/transactions.ts    |   5 +
 .../taler-wallet-webextension/src/pages/refund.tsx |   4 +-
 .../taler-wallet-webextension/src/pages/tip.tsx    |  74 +------------
 packages/taler-wallet-webextension/src/wxApi.ts    |  59 +----------
 .../taler-wallet-webextension/src/wxBackend.ts     | 114 ++++++++++++++++++---
 .../taler-wallet-webextension/static/welcome.html  |   8 +-
 7 files changed, 118 insertions(+), 147 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/transactions.ts 
b/packages/taler-wallet-core/src/operations/transactions.ts
index b79ac3b2..8300864b 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -241,6 +241,7 @@ export async function getTransactions(
           products: pr.contractData.products,
           summary: pr.contractData.summary,
           summary_i18n: pr.contractData.summaryI18n,
+          contractTermsHash: pr.contractData.contractTermsHash,
         };
         const paymentTransactionId = makeEventId(
           TransactionType.Payment,
diff --git a/packages/taler-wallet-core/src/types/transactions.ts 
b/packages/taler-wallet-core/src/types/transactions.ts
index e4003149..5ee09384 100644
--- a/packages/taler-wallet-core/src/types/transactions.ts
+++ b/packages/taler-wallet-core/src/types/transactions.ts
@@ -226,6 +226,11 @@ export interface PaymentShortInfo {
    */
   orderId: string;
 
+  /**
+   * Hash of the contract terms.
+   */
+  contractTermsHash: string;
+
   /**
    * More information about the merchant
    */
diff --git a/packages/taler-wallet-webextension/src/pages/refund.tsx 
b/packages/taler-wallet-webextension/src/pages/refund.tsx
index b34b98f6..1ace5022 100644
--- a/packages/taler-wallet-webextension/src/pages/refund.tsx
+++ b/packages/taler-wallet-webextension/src/pages/refund.tsx
@@ -37,8 +37,8 @@ function RefundStatusView(props: { talerRefundUri: string }): 
JSX.Element {
       try {
         const result = await wxApi.applyRefund(props.talerRefundUri);
         setApplied(true);
-        const r = await wxApi.getPurchaseDetails(result.proposalId);
-        setPurchaseDetails(r);
+        // const r = await wxApi.getPurchaseDetails(result.proposalId);
+        // setPurchaseDetails(r);
       } catch (e) {
         console.error(e);
         setErrMsg(e.message);
diff --git a/packages/taler-wallet-webextension/src/pages/tip.tsx 
b/packages/taler-wallet-webextension/src/pages/tip.tsx
index 1f164ad1..1290037e 100644
--- a/packages/taler-wallet-webextension/src/pages/tip.tsx
+++ b/packages/taler-wallet-webextension/src/pages/tip.tsx
@@ -22,79 +22,7 @@
  */
 
 import * as React from "react";
-import { acceptTip, getTipStatus } from "../wxApi";
-import { renderAmount, ProgressButton } from "../renderHtml";
-import { useState, useEffect } from "react";
-import { TipStatus } from "taler-wallet-core";
-
-function TipDisplay(props: { talerTipUri: string }): JSX.Element {
-  const [tipStatus, setTipStatus] = useState<TipStatus | undefined>(undefined);
-  const [discarded, setDiscarded] = useState(false);
-  const [loading, setLoading] = useState(false);
-  const [finished, setFinished] = useState(false);
-
-  useEffect(() => {
-    const doFetch = async (): Promise<void> => {
-      const ts = await getTipStatus(props.talerTipUri);
-      setTipStatus(ts);
-    };
-    doFetch();
-  }, [props.talerTipUri]);
-
-  if (discarded) {
-    return <span>You&apos;ve discarded the tip.</span>;
-  }
-
-  if (finished) {
-    return <span>Tip has been accepted!</span>;
-  }
-
-  if (!tipStatus) {
-    return <span>Loading ...</span>;
-  }
-
-  const discard = (): void => {
-    setDiscarded(true);
-  };
-
-  const accept = async (): Promise<void> => {
-    setLoading(true);
-    await acceptTip(tipStatus.tipId);
-    setFinished(true);
-  };
-
-  return (
-    <div>
-      <h2>Tip Received!</h2>
-      <p>
-        You received a tip of 
<strong>{renderAmount(tipStatus.amount)}</strong>{" "}
-        from <span> </span>
-        <strong>{tipStatus.merchantOrigin}</strong>.
-      </p>
-      <p>
-        The tip is handled by the exchange{" "}
-        <strong>{tipStatus.exchangeUrl}</strong>. This exchange will charge 
fees
-        of <strong>{renderAmount(tipStatus.totalFees)}</strong> for this
-        operation.
-      </p>
-      <form className="pure-form">
-        <ProgressButton loading={loading} onClick={() => accept()}>
-          Accept Tip
-        </ProgressButton>{" "}
-        <button className="pure-button" type="button" onClick={() => 
discard()}>
-          Discard tip
-        </button>
-      </form>
-    </div>
-  );
-}
 
 export function createTipPage(): JSX.Element {
-  const url = new URL(document.location.href);
-  const talerTipUri = url.searchParams.get("talerTipUri");
-  if (typeof talerTipUri !== "string") {
-    throw Error("talerTipUri must be a string");
-  }
-
-  return <TipDisplay talerTipUri={talerTipUri} />;
+  return <span>not implemented</span>;
 }
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts 
b/packages/taler-wallet-webextension/src/wxApi.ts
index 455d0b8a..947b63ce 100644
--- a/packages/taler-wallet-webextension/src/wxApi.ts
+++ b/packages/taler-wallet-webextension/src/wxApi.ts
@@ -130,62 +130,13 @@ export function getTransactions(): 
Promise<TransactionsResponse> {
   return callBackend("getTransactions", {});
 }
 
-/**
- * Return coins to a bank account.
- */
-export function returnCoins(args: {
-  amount: AmountJson;
-  exchange: string;
-  senderWire: string;
-}): Promise<void> {
-  return callBackend("return-coins", args);
-}
-
-/**
- * Look up a purchase in the wallet database from
- * the contract terms hash.
- */
-export function getPurchaseDetails(
-  proposalId: string,
-): Promise<PurchaseDetails> {
-  return callBackend("get-purchase-details", { proposalId });
-}
-
-/**
- * Get the status of processing a tip.
- */
-export function getTipStatus(talerTipUri: string): Promise<TipStatus> {
-  return callBackend("get-tip-status", { talerTipUri });
-}
-
-/**
- * Mark a tip as accepted by the user.
- */
-export function acceptTip(talerTipUri: string): Promise<void> {
-  return callBackend("accept-tip", { talerTipUri });
-}
-
 /**
  * Download a refund and accept it.
  */
 export function applyRefund(
-  refundUrl: string,
+  talerRefundUri: string,
 ): Promise<{ contractTermsHash: string; proposalId: string }> {
-  return callBackend("accept-refund", { refundUrl });
-}
-
-/**
- * Abort a failed payment and try to get a refund.
- */
-export function abortFailedPayment(contractTermsHash: string): Promise<void> {
-  return callBackend("abort-failed-payment", { contractTermsHash });
-}
-
-/**
- * Abort a failed payment and try to get a refund.
- */
-export function benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> 
{
-  return callBackend("benchmark-crypto", { repetitions });
+  return callBackend("applyRefund", { talerRefundUri });
 }
 
 /**
@@ -212,7 +163,7 @@ export function acceptWithdrawal(
  * Get diagnostics information
  */
 export function getDiagnostics(): Promise<WalletDiagnostics> {
-  return callBackend("get-diagnostics", {});
+  return callBackend("wxGetDiagnostics", {});
 }
 
 /**
@@ -221,14 +172,14 @@ export function getDiagnostics(): 
Promise<WalletDiagnostics> {
 export function setExtendedPermissions(
   value: boolean,
 ): Promise<ExtendedPermissionsResponse> {
-  return callBackend("set-extended-permissions", { value });
+  return callBackend("wxSetExtendedPermissions", { value });
 }
 
 /**
  * Get diagnostics information
  */
 export function getExtendedPermissions(): Promise<ExtendedPermissionsResponse> 
{
-  return callBackend("get-extended-permissions", {});
+  return callBackend("wxGetExtendedPermissions", {});
 }
 
 /**
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts 
b/packages/taler-wallet-webextension/src/wxBackend.ts
index 60d0b6d4..a77b173f 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -37,12 +37,13 @@ import {
   TalerUriType,
   makeErrorDetails,
   TalerErrorCode,
+  CoreApiResponse,
+  WalletDiagnostics,
+  CoreApiResponseSuccess,
 } from "taler-wallet-core";
 import { BrowserHttpLib } from "./browserHttpLib";
 import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
 
-const NeedsWallet = Symbol("NeedsWallet");
-
 /**
  * Currently active wallet instance.  Might be unloaded and
  * re-instantiated when the database is reset.
@@ -60,24 +61,109 @@ const walletInit: OpenedPromise<void> = 
openPromise<void>();
 
 const notificationPorts: chrome.runtime.Port[] = [];
 
+async function getDiagnostics(): Promise<WalletDiagnostics> {
+  const manifestData = chrome.runtime.getManifest();
+  const errors: string[] = [];
+  let firefoxIdbProblem = false;
+  let dbOutdated = false;
+  try {
+    await walletInit.promise;
+  } catch (e) {
+    errors.push("Error during wallet initialization: " + e);
+    if (
+      currentDatabase === undefined &&
+      outdatedDbVersion === undefined &&
+      isFirefox()
+    ) {
+      firefoxIdbProblem = true;
+    }
+  }
+  if (!currentWallet) {
+    errors.push("Could not create wallet backend.");
+  }
+  if (!currentDatabase) {
+    errors.push("Could not open database");
+  }
+  if (outdatedDbVersion !== undefined) {
+    errors.push(`Outdated DB version: ${outdatedDbVersion}`);
+    dbOutdated = true;
+  }
+  const diagnostics: WalletDiagnostics = {
+    walletManifestDisplayVersion: manifestData.version_name || "(undefined)",
+    walletManifestVersion: manifestData.version,
+    errors,
+    firefoxIdbProblem,
+    dbOutdated,
+  };
+  return diagnostics;
+}
+
 async function dispatch(
   req: any,
   sender: any,
   sendResponse: any,
 ): Promise<void> {
-  const w = currentWallet;
-  if (!w) {
-    sendResponse(
-      makeErrorDetails(
-        TalerErrorCode.WALLET_CORE_NOT_AVAILABLE,
-        "wallet core not available",
-        {},
-      ),
-    );
-    return;
+  let r: CoreApiResponse;
+
+  const wrapResponse = (result: unknown): CoreApiResponseSuccess => {
+    return {
+      type: "response",
+      id: req.id,
+      operation: req.operation,
+      result,
+    };
+  };
+
+  switch (req.operation) {
+    case "wxGetDiagnostics": {
+      r = wrapResponse(await getDiagnostics());
+      break;
+    }
+    case "wxGetExtendedPermissions": {
+      const res = await new Promise((resolve, reject) => {
+        getPermissionsApi().contains(extendedPermissions, (result: boolean) => 
{
+          resolve(result);
+        });
+      });
+      r = wrapResponse({ newValue: res });
+      break;
+    }
+    case "wxSetExtendedPermissions": {
+      const newVal = req.payload.value;
+      console.log("new extended permissions value", newVal);
+      if (newVal) {
+        setupHeaderListener();
+        r = wrapResponse({ newValue: true });
+      } else {
+        await new Promise((resolve, reject) => {
+          getPermissionsApi().remove(extendedPermissions, (rem) => {
+            console.log("permissions removed:", rem);
+            resolve();
+          });
+        });
+        r = wrapResponse({ newVal: false });
+      }
+      break;
+    }
+    default:
+      const w = currentWallet;
+      if (!w) {
+        r = {
+          type: "error",
+          id: req.id,
+          operation: req.operation,
+          error: makeErrorDetails(
+            TalerErrorCode.WALLET_CORE_NOT_AVAILABLE,
+            "wallet core not available",
+            {},
+          ),
+        };
+        break;
+      }
+      r = await w.handleCoreApiRequest(req.operation, req.id, req.payload);
+      break;
   }
 
-  const r = await w.handleCoreApiRequest(req.operation, req.id, req.payload);
   try {
     sendResponse(r);
   } catch (e) {
@@ -188,7 +274,7 @@ try {
   chrome.runtime.onInstalled.addListener((details) => {
     console.log("onInstalled with reason", details.reason);
     if (details.reason === "install") {
-      const url = chrome.extension.getURL("/welcome.html");
+      const url = chrome.extension.getURL("/static/welcome.html");
       chrome.tabs.create({ active: true, url: url });
     }
   });
diff --git a/packages/taler-wallet-webextension/static/welcome.html 
b/packages/taler-wallet-webextension/static/welcome.html
index 07ecac70..e0b429f4 100644
--- a/packages/taler-wallet-webextension/static/welcome.html
+++ b/packages/taler-wallet-webextension/static/welcome.html
@@ -4,10 +4,10 @@
     <meta charset="UTF-8" />
     <title>Taler Wallet Installed</title>
 
-    <link rel="icon" href="/img/icon.png" />
-    <link rel="stylesheet" type="text/css" href="/style/pure.css" />
-    <link rel="stylesheet" type="text/css" href="/style/wallet.css" />
-    <script src="/pageEntryPoint.js"></script>
+    <link rel="icon" href="/static/img/icon.png" />
+    <link rel="stylesheet" type="text/css" href="/static/style/pure.css" />
+    <link rel="stylesheet" type="text/css" href="/static/style/wallet.css" />
+    <script src="/dist/pageEntryPoint.js"></script>
   </head>
 
   <body>

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