gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (b3b3c21a -> 0bfd4523)


From: gnunet
Subject: [taler-wallet-core] branch master updated (b3b3c21a -> 0bfd4523)
Date: Wed, 24 Nov 2021 12:58:58 +0100

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

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

    from b3b3c21a webextension: bump version
     new f07436aa new exchange-added notifiaction and including tos information 
in the wxApi.listExchange api
     new 0bfd4523 adding tos information in settings and return to manual 
withdraw when adding an exchange

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:
 packages/taler-util/src/notifications.ts           |   6 +
 packages/taler-util/src/walletTypes.ts             |  15 ++
 .../taler-wallet-core/src/operations/exchanges.ts  |  13 +-
 .../taler-wallet-core/src/operations/withdraw.ts   |  13 +-
 packages/taler-wallet-core/src/wallet.ts           |   9 +-
 .../src/components/styled/index.tsx                |   8 +
 .../src/cta/TermsOfServiceSection.tsx              |  21 ++-
 .../src/cta/Withdraw.stories.tsx                   | 170 +++++----------------
 .../taler-wallet-webextension/src/cta/Withdraw.tsx |  30 ++--
 .../src/popup/Settings.tsx                         |  16 --
 .../taler-wallet-webextension/src/utils/index.ts   |  14 +-
 .../src/wallet/CreateManualWithdraw.tsx            |  11 +-
 .../src/wallet/ExchangeAddConfirm.tsx              |   9 --
 .../src/wallet/ExchangeAddPage.tsx                 |   2 +-
 .../src/wallet/ExchangeAddSetUrl.stories.tsx       |   6 +
 .../src/wallet/ManualWithdrawPage.tsx              |  13 +-
 .../src/wallet/Settings.stories.tsx                |  46 ++++++
 .../src/wallet/Settings.tsx                        |  91 ++++++-----
 packages/taler-wallet-webextension/src/wxApi.ts    |   6 +-
 19 files changed, 259 insertions(+), 240 deletions(-)

diff --git a/packages/taler-util/src/notifications.ts 
b/packages/taler-util/src/notifications.ts
index 289dcb68..e8f27062 100644
--- a/packages/taler-util/src/notifications.ts
+++ b/packages/taler-util/src/notifications.ts
@@ -45,6 +45,7 @@ export enum NotificationType {
   RefundQueried = "refund-queried",
   RefundFinished = "refund-finished",
   ExchangeOperationError = "exchange-operation-error",
+  ExchangeAdded = "exchange-added",
   RefreshOperationError = "refresh-operation-error",
   RecoupOperationError = "recoup-operation-error",
   RefundApplyOperationError = "refund-apply-error",
@@ -150,6 +151,10 @@ export interface RefundFinishedNotification {
   type: NotificationType.RefundFinished;
 }
 
+export interface ExchangeAddedNotification {
+  type: NotificationType.ExchangeAdded;
+}
+
 export interface ExchangeOperationErrorNotification {
   type: NotificationType.ExchangeOperationError;
   error: TalerErrorDetails;
@@ -243,6 +248,7 @@ export type WalletNotification =
   | BackupOperationErrorNotification
   | WithdrawOperationErrorNotification
   | ReserveOperationErrorNotification
+  | ExchangeAddedNotification
   | ExchangeOperationErrorNotification
   | RefreshOperationErrorNotification
   | RefundStatusOperationErrorNotification
diff --git a/packages/taler-util/src/walletTypes.ts 
b/packages/taler-util/src/walletTypes.ts
index 879640e8..f00e2907 100644
--- a/packages/taler-util/src/walletTypes.ts
+++ b/packages/taler-util/src/walletTypes.ts
@@ -523,17 +523,32 @@ export interface ExchangesListRespose {
   exchanges: ExchangeListItem[];
 }
 
+export interface ExchangeTos {
+  acceptedVersion?: string;
+  currentVersion?: string;
+  contentType?: string;
+  content?: string;
+}
 export interface ExchangeListItem {
   exchangeBaseUrl: string;
   currency: string;
   paytoUris: string[];
+  tos: ExchangeTos;
 }
 
+const codecForExchangeTos = (): Codec<ExchangeTos> => 
buildCodecForObject<ExchangeTos>()
+  .property("acceptedVersion", codecOptional(codecForString()))
+  .property("currentVersion", codecOptional(codecForString()))
+  .property("contentType", codecOptional(codecForString()))
+  .property("content", codecOptional(codecForString()))
+  .build("ExchangeTos")
+
 export const codecForExchangeListItem = (): Codec<ExchangeListItem> =>
   buildCodecForObject<ExchangeListItem>()
     .property("currency", codecForString())
     .property("exchangeBaseUrl", codecForString())
     .property("paytoUris", codecForList(codecForString()))
+    .property("tos", codecForExchangeTos())
     .build("ExchangeListItem");
 
 export const codecForExchangesListResponse = (): Codec<ExchangesListRespose> =>
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts 
b/packages/taler-wallet-core/src/operations/exchanges.ts
index 638af813..a10378a8 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -494,11 +494,11 @@ async function updateExchangeFromUrlImpl(
     tosFound !== undefined
       ? tosFound
       : await downloadExchangeWithTermsOfService(
-          baseUrl,
-          ws.http,
-          timeout,
-          "text/plain",
-        );
+        baseUrl,
+        ws.http,
+        timeout,
+        "text/plain",
+      );
 
   let recoupGroupId: string | undefined = undefined;
 
@@ -657,6 +657,9 @@ async function updateExchangeFromUrlImpl(
 
   logger.trace("done updating exchange info in database");
 
+  ws.notify({
+    type: NotificationType.ExchangeAdded,
+  });
   return {
     exchange: updated.exchange,
     exchangeDetails: updated.exchangeDetails,
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts 
b/packages/taler-wallet-core/src/operations/withdraw.ts
index a5a8653c..979bd0e5 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -218,7 +218,7 @@ export function selectWithdrawalDenominations(
   for (const d of denoms) {
     let count = 0;
     const cost = Amounts.add(d.value, d.feeWithdraw).amount;
-    for (;;) {
+    for (; ;) {
       if (Amounts.cmp(remaining, cost) < 0) {
         break;
       }
@@ -746,8 +746,7 @@ export async function updateWithdrawalDenoms(
         denom.verificationStatus === DenominationVerificationStatus.Unverified
       ) {
         logger.trace(
-          `Validating denomination (${current + 1}/${
-            denominations.length
+          `Validating denomination (${current + 1}/${denominations.length
           }) signature of ${denom.denomPubHash}`,
         );
         const valid = await ws.cryptoApi.isValidDenom(
@@ -997,7 +996,7 @@ export async function getExchangeWithdrawalInfo(
     ) {
       console.warn(
         `wallet's support for exchange protocol version 
${WALLET_EXCHANGE_PROTOCOL_VERSION} might be outdated ` +
-          `(exchange has ${exchangeDetails.protocolVersion}), checking for 
updates`,
+        `(exchange has ${exchangeDetails.protocolVersion}), checking for 
updates`,
       );
     }
   }
@@ -1075,6 +1074,12 @@ export async function getWithdrawalDetailsForUri(
           exchanges.push({
             exchangeBaseUrl: details.exchangeBaseUrl,
             currency: details.currency,
+            tos: {
+              acceptedVersion: details.termsOfServiceAcceptedEtag,
+              currentVersion: details.termsOfServiceLastEtag,
+              contentType: details.termsOfServiceContentType,
+              content: details.termsOfServiceText,
+            },
             paytoUris: details.wireInfo.accounts.map((x) => x.payto_uri),
           });
         }
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 44591a26..576a4459 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -513,9 +513,16 @@ async function getExchanges(
         if (!exchangeDetails) {
           continue;
         }
+
         exchanges.push({
           exchangeBaseUrl: r.baseUrl,
           currency,
+          tos: {
+            acceptedVersion: exchangeDetails.termsOfServiceAcceptedEtag,
+            currentVersion: exchangeDetails.termsOfServiceLastEtag,
+            contentType: exchangeDetails.termsOfServiceContentType,
+            content: exchangeDetails.termsOfServiceText,
+          },
           paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
         });
       }
@@ -988,7 +995,7 @@ export async function handleCoreApiRequest(
       try {
         logger.error("Caught unexpected exception:");
         logger.error(e.stack);
-      } catch (e) {}
+      } catch (e) { }
       return {
         type: "error",
         operation,
diff --git a/packages/taler-wallet-webextension/src/components/styled/index.tsx 
b/packages/taler-wallet-webextension/src/components/styled/index.tsx
index 7cef8789..4c236700 100644
--- a/packages/taler-wallet-webextension/src/components/styled/index.tsx
+++ b/packages/taler-wallet-webextension/src/components/styled/index.tsx
@@ -613,6 +613,14 @@ export const LightText = styled.div`
   color: gray;
 `;
 
+export const SuccessText = styled.div`
+  color: #388e3c;
+`;
+
+export const DestructiveText = styled.div`
+  color: rgb(202, 60, 60);
+`;
+
 export const WarningText = styled.div`
   color: rgb(223, 117, 20);
 `;
diff --git 
a/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.tsx 
b/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.tsx
index 5eddde64..5109055e 100644
--- a/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.tsx
+++ b/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.tsx
@@ -8,6 +8,7 @@ import {
   LinkSuccess,
   TermsOfService,
   WarningBox,
+  WarningText,
 } from "../components/styled";
 import { TermsState } from "../utils";
 
@@ -28,10 +29,27 @@ export function TermsOfServiceSection({
   if (!reviewing) {
     if (!reviewed) {
       if (!onReview) {
-        return <section>Terms of service status: {terms.status}</section>;
+        return (
+          <Fragment>
+            {terms.status === "notfound" && (
+              <section>
+                <WarningText>
+                  {i18n.str`Exchange doesn't have terms of service`}
+                </WarningText>
+              </section>
+            )}
+          </Fragment>
+        );
       }
       return (
         <Fragment>
+          {terms.status === "notfound" && (
+            <section>
+              <WarningText>
+                {i18n.str`Exchange doesn't have terms of service`}
+              </WarningText>
+            </section>
+          )}
           {terms.status === "new" && (
             <section>
               <ButtonSuccess upperCased onClick={() => onReview(true)}>
@@ -64,7 +82,6 @@ export function TermsOfServiceSection({
             enabled={reviewed}
             label={i18n.str`I accept the exchange terms of service`}
             onToggle={() => {
-              console.log("asdasd", reviewed);
               onAccept(!reviewed);
               if (onReview) onReview(false);
             }}
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx 
b/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx
index fbbecd6f..3915dc12 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx
@@ -19,7 +19,7 @@
  * @author Sebastian Javier Marchano (sebasjm)
  */
 
-import { amountFractionalBase } from "@gnu-taler/taler-util";
+import { amountFractionalBase, ExchangeListItem } from "@gnu-taler/taler-util";
 import { createExample } from "../test-utils";
 import { termsHtml, termsPdf, termsPlain, termsXml } from "./termsExample";
 import { View as TestedComponent } from "./Withdraw";
@@ -32,24 +32,38 @@ export default {
   },
 };
 
-export const NewTerms = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
+const exchangeList: ExchangeListItem[] = [
+  {
+    currency: "USD",
+    exchangeBaseUrl: "exchange.demo.taler.net",
+    tos: {
+      currentVersion: "1",
+      acceptedVersion: "1",
+      content: "terms of service content",
+      contentType: "text/plain",
     },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
+    paytoUris: ["asd"],
+  },
+  {
+    currency: "USD",
+    exchangeBaseUrl: "exchange.test.taler.net",
+    tos: {
+      currentVersion: "1",
+      acceptedVersion: "1",
+      content: "terms of service content",
+      contentType: "text/plain",
     },
-  ],
+    paytoUris: ["asd"],
+  },
+];
+
+export const NewTerms = createExample(TestedComponent, {
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
     fraction: 0,
-    value: 0,
+    value: 1,
   },
   amount: {
     currency: "USD",
@@ -71,18 +85,7 @@ export const NewTerms = createExample(TestedComponent, {
 });
 
 export const TermsReviewingPLAIN = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -110,18 +113,7 @@ export const TermsReviewingPLAIN = 
createExample(TestedComponent, {
 });
 
 export const TermsReviewingHTML = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -151,18 +143,7 @@ export const TermsReviewingHTML = 
createExample(TestedComponent, {
 });
 
 export const TermsReviewingPDF = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -192,18 +173,7 @@ export const TermsReviewingPDF = 
createExample(TestedComponent, {
 });
 
 export const TermsReviewingXML = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -231,18 +201,7 @@ export const TermsReviewingXML = 
createExample(TestedComponent, {
 });
 
 export const NewTermsAccepted = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -269,18 +228,7 @@ export const NewTermsAccepted = 
createExample(TestedComponent, {
 });
 
 export const TermsShowAgainXML = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -309,18 +257,7 @@ export const TermsShowAgainXML = 
createExample(TestedComponent, {
 });
 
 export const TermsChanged = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -347,18 +284,7 @@ export const TermsChanged = createExample(TestedComponent, 
{
 });
 
 export const TermsNotFound = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -382,18 +308,7 @@ export const TermsNotFound = 
createExample(TestedComponent, {
 });
 
 export const TermsAlreadyAccepted = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
@@ -417,18 +332,7 @@ export const TermsAlreadyAccepted = 
createExample(TestedComponent, {
 });
 
 export const WithoutFee = createExample(TestedComponent, {
-  knownExchanges: [
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.demo.taler.net",
-      paytoUris: ["asd"],
-    },
-    {
-      currency: "USD",
-      exchangeBaseUrl: "exchange.test.taler.net",
-      paytoUris: ["asd"],
-    },
-  ],
+  knownExchanges: exchangeList,
   exchangeBaseUrl: "exchange.demo.taler.net",
   withdrawalFee: {
     currency: "USD",
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx 
b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
index 4ebbe11c..eead5169 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
@@ -38,7 +38,6 @@ import {
   ButtonWarning,
   LinkSuccess,
   WalletAction,
-  WarningText,
 } from "../components/styled";
 import { useAsyncAsHook } from "../hooks/useAsyncAsHook";
 import { amountToString, buildTermsOfServiceState, TermsState } from 
"../utils";
@@ -98,17 +97,19 @@ export function View({
           text={amountToString(Amounts.sub(amount, withdrawalFee).amount)}
           kind="positive"
         />
-        <Part
-          title="Chosen amount"
-          text={amountToString(amount)}
-          kind="neutral"
-        />
         {Amounts.isNonZero(withdrawalFee) && (
-          <Part
-            title="Exchange fee"
-            text={amountToString(withdrawalFee)}
-            kind="negative"
-          />
+          <Fragment>
+            <Part
+              title="Chosen amount"
+              text={amountToString(amount)}
+              kind="neutral"
+            />
+            <Part
+              title="Exchange fee"
+              text={amountToString(withdrawalFee)}
+              kind="negative"
+            />
+          </Fragment>
         )}
         {exchangeBaseUrl && (
           <Part title="Exchange" text={exchangeBaseUrl} kind="neutral" big />
@@ -140,13 +141,6 @@ export function View({
           )}
         </section>
       )}
-      {terms.status === "notfound" && (
-        <section>
-          <WarningText>
-            {i18n.str`Exchange doesn't have terms of service`}
-          </WarningText>
-        </section>
-      )}
       <TermsOfServiceSection
         reviewed={reviewed}
         reviewing={reviewing}
diff --git a/packages/taler-wallet-webextension/src/popup/Settings.tsx 
b/packages/taler-wallet-webextension/src/popup/Settings.tsx
index 84ecea4f..3732cf7b 100644
--- a/packages/taler-wallet-webextension/src/popup/Settings.tsx
+++ b/packages/taler-wallet-webextension/src/popup/Settings.tsx
@@ -17,19 +17,15 @@
 import { i18n } from "@gnu-taler/taler-util";
 import { Fragment, h, VNode } from "preact";
 import { Checkbox } from "../components/Checkbox";
-import { useDevContext } from "../context/devContext";
 import { useExtendedPermissions } from "../hooks/useExtendedPermissions";
 
 export function SettingsPage(): VNode {
   const [permissionsEnabled, togglePermissions] = useExtendedPermissions();
-  const { devMode, toggleDevMode } = useDevContext();
 
   return (
     <SettingsView
       permissionsEnabled={permissionsEnabled}
       togglePermissions={togglePermissions}
-      developerMode={devMode}
-      toggleDeveloperMode={toggleDevMode}
     />
   );
 }
@@ -37,15 +33,11 @@ export function SettingsPage(): VNode {
 export interface ViewProps {
   permissionsEnabled: boolean;
   togglePermissions: () => void;
-  developerMode: boolean;
-  toggleDeveloperMode: () => void;
 }
 
 export function SettingsView({
   permissionsEnabled,
   togglePermissions,
-  developerMode,
-  toggleDeveloperMode,
 }: ViewProps): VNode {
   return (
     <Fragment>
@@ -60,14 +52,6 @@ export function SettingsView({
           enabled={permissionsEnabled}
           onToggle={togglePermissions}
         />
-        <h2>Config</h2>
-        <Checkbox
-          label="Developer mode"
-          name="devMode"
-          description="(More options and information useful for debugging)"
-          enabled={developerMode}
-          onToggle={toggleDeveloperMode}
-        />
       </section>
       <footer style={{ justifyContent: "space-around" }}>
         <a
diff --git a/packages/taler-wallet-webextension/src/utils/index.ts 
b/packages/taler-wallet-webextension/src/utils/index.ts
index 47781852..15081f92 100644
--- a/packages/taler-wallet-webextension/src/utils/index.ts
+++ b/packages/taler-wallet-webextension/src/utils/index.ts
@@ -60,15 +60,19 @@ export function buildTermsOfServiceState(tos: 
GetExchangeTosResult): TermsState
     tos.content,
   );
 
-  const status: TermsStatus = !content
+  const status: TermsStatus = buildTermsOfServiceStatus(tos.content, 
tos.acceptedEtag, tos.currentEtag);
+
+  return { content, status, version: tos.currentEtag }
+
+}
+export function buildTermsOfServiceStatus(content: string | undefined, 
acceptedVersion: string | undefined, currentVersion: string | undefined): 
TermsStatus {
+  return !content
     ? "notfound"
-    : !tos.acceptedEtag
+    : !acceptedVersion
       ? "new"
-      : tos.acceptedEtag !== tos.currentEtag
+      : acceptedVersion !== currentVersion
         ? "changed"
         : "accepted";
-
-  return { content, status, version: tos.currentEtag }
 }
 
 function parseTermsOfServiceContent(
diff --git 
a/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx 
b/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx
index 55495279..36feeb76 100644
--- a/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/CreateManualWithdraw.tsx
@@ -21,7 +21,6 @@
 
 import { AmountJson, Amounts, i18n } from "@gnu-taler/taler-util";
 import { Fragment, h, VNode } from "preact";
-import { route } from "preact-router";
 import { useState } from "preact/hooks";
 import { ErrorMessage } from "../components/ErrorMessage";
 import { SelectList } from "../components/SelectList";
@@ -35,13 +34,13 @@ import {
   LightText,
   LinkPrimary,
 } from "../components/styled";
-import { Pages } from "../NavigationBar";
 
 export interface Props {
   error: string | undefined;
   initialAmount?: string;
   exchangeList: Record<string, string>;
   onCreate: (exchangeBaseUrl: string, amount: AmountJson) => Promise<void>;
+  onAddExchange: () => void;
 }
 
 export function CreateManualWithdraw({
@@ -49,6 +48,7 @@ export function CreateManualWithdraw({
   exchangeList,
   error,
   onCreate,
+  onAddExchange,
 }: Props): VNode {
   const exchangeSelectList = Object.keys(exchangeList);
   const currencySelectList = Object.values(exchangeList);
@@ -90,7 +90,7 @@ export function CreateManualWithdraw({
     return (
       <Centered style={{ marginTop: 100 }}>
         <BoldLight>No exchange configured</BoldLight>
-        <ButtonSuccess onClick={() => route(Pages.exchange_add)}>
+        <ButtonSuccess onClick={onAddExchange}>
           <i18n.Translate>Add exchange</i18n.Translate>
         </ButtonSuccess>
       </Centered>
@@ -130,10 +130,7 @@ export function CreateManualWithdraw({
             />
           </Input>
           <div style={{ display: "flex", justifyContent: "space-between" }}>
-            <LinkPrimary
-              onClick={() => route(Pages.exchange_add)}
-              style={{ marginLeft: "auto" }}
-            >
+            <LinkPrimary onClick={onAddExchange} style={{ marginLeft: "auto" 
}}>
               <i18n.Translate>Add exchange</i18n.Translate>
             </LinkPrimary>
           </div>
diff --git 
a/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx 
b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx
index 5c7f94ec..409e0b49 100644
--- a/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx
@@ -5,7 +5,6 @@ import {
   Button,
   ButtonSuccess,
   ButtonWarning,
-  WarningBox,
 } from "../components/styled/index";
 import { TermsOfServiceSection } from "../cta/TermsOfServiceSection";
 import { useAsyncAsHook } from "../hooks/useAsyncAsHook";
@@ -97,14 +96,6 @@ export function View({
           </a>
         </div>
       </section>
-      {terms && terms.status === "notfound" && (
-        <section>
-          <WarningBox>
-            {i18n.str`Exchange doesn't have terms of service`}
-          </WarningBox>
-        </section>
-      )}
-
       {terms && (
         <TermsOfServiceSection
           reviewed={reviewed}
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx 
b/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx
index 10449c10..0c8336e6 100644
--- a/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx
@@ -27,7 +27,7 @@ import { ExchangeAddConfirmPage } from "./ExchangeAddConfirm";
 import { ExchangeSetUrlPage } from "./ExchangeSetUrl";
 
 interface Props {
-  currency: string;
+  currency?: string;
   onBack: () => void;
 }
 
diff --git 
a/packages/taler-wallet-webextension/src/wallet/ExchangeAddSetUrl.stories.tsx 
b/packages/taler-wallet-webextension/src/wallet/ExchangeAddSetUrl.stories.tsx
index bc182cb7..9ea800fe 100644
--- 
a/packages/taler-wallet-webextension/src/wallet/ExchangeAddSetUrl.stories.tsx
+++ 
b/packages/taler-wallet-webextension/src/wallet/ExchangeAddSetUrl.stories.tsx
@@ -55,6 +55,12 @@ export const WithDemoAsKnownExchange = 
createExample(TestedComponent, {
     {
       currency: "TESTKUDOS",
       exchangeBaseUrl: "https://exchange.demo.taler.net/";,
+      tos: {
+        currentVersion: "1",
+        acceptedVersion: "1",
+        content: "content of tos",
+        contentType: "text/plain",
+      },
       paytoUris: [],
     },
   ],
diff --git 
a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx 
b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
index 88d5f172..b3e8a2c2 100644
--- a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
@@ -22,11 +22,13 @@ import {
   AcceptManualWithdrawalResult,
   AmountJson,
   Amounts,
+  NotificationType,
 } from "@gnu-taler/taler-util";
 import { ReserveCreated } from "./ReserveCreated";
 import { route } from "preact-router";
 import { Pages } from "../NavigationBar";
 import { useAsyncAsHook } from "../hooks/useAsyncAsHook";
+import { ExchangeAddPage } from "./ExchangeAddPage";
 
 export function ManualWithdrawPage(): VNode {
   const [success, setSuccess] = useState<
@@ -39,7 +41,9 @@ export function ManualWithdrawPage(): VNode {
   >(undefined);
   const [error, setError] = useState<string | undefined>(undefined);
 
-  const state = useAsyncAsHook(() => wxApi.listExchanges());
+  const state = useAsyncAsHook(wxApi.listExchanges, [
+    NotificationType.ExchangeAdded,
+  ]);
 
   async function doCreate(
     exchangeBaseUrl: string,
@@ -61,6 +65,12 @@ export function ManualWithdrawPage(): VNode {
     }
   }
 
+  const [addingExchange, setAddingExchange] = useState(false);
+
+  if (addingExchange) {
+    return <ExchangeAddPage onBack={() => setAddingExchange(false)} />;
+  }
+
   if (success) {
     return (
       <ReserveCreated
@@ -91,6 +101,7 @@ export function ManualWithdrawPage(): VNode {
 
   return (
     <CreateManualWithdraw
+      onAddExchange={() => setAddingExchange(true)}
       error={error}
       exchangeList={exchangeList}
       onCreate={doCreate}
diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx 
b/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx
index 6cc1368d..8acf9d21 100644
--- a/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/Settings.stories.tsx
@@ -49,6 +49,52 @@ export const WithOneExchange = 
createExample(TestedComponent, {
     {
       currency: "USD",
       exchangeBaseUrl: "http://exchange.taler";,
+      tos: {
+        currentVersion: "1",
+        acceptedVersion: "1",
+        content: "content of tos",
+        contentType: "text/plain",
+      },
+      paytoUris: ["payto://x-taler-bank/bank.rpi.sebasjm.com/exchangeminator"],
+    },
+  ],
+});
+
+export const WithExchangeInDifferentState = createExample(TestedComponent, {
+  deviceName: "this-is-the-device-name",
+  permissionsEnabled: true,
+  setDeviceName: () => Promise.resolve(),
+  knownExchanges: [
+    {
+      currency: "USD",
+      exchangeBaseUrl: "http://exchange1.taler";,
+      tos: {
+        currentVersion: "1",
+        acceptedVersion: "1",
+        content: "content of tos",
+        contentType: "text/plain",
+      },
+      paytoUris: ["payto://x-taler-bank/bank.rpi.sebasjm.com/exchangeminator"],
+    },
+    {
+      currency: "USD",
+      exchangeBaseUrl: "http://exchange2.taler";,
+      tos: {
+        currentVersion: "2",
+        acceptedVersion: "1",
+        content: "content of tos",
+        contentType: "text/plain",
+      },
+      paytoUris: ["payto://x-taler-bank/bank.rpi.sebasjm.com/exchangeminator"],
+    },
+    {
+      currency: "USD",
+      exchangeBaseUrl: "http://exchange3.taler";,
+      tos: {
+        currentVersion: "1",
+        content: "content of tos",
+        contentType: "text/plain",
+      },
       paytoUris: ["payto://x-taler-bank/bank.rpi.sebasjm.com/exchangeminator"],
     },
   ],
diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.tsx 
b/packages/taler-wallet-webextension/src/wallet/Settings.tsx
index 5f1cd89d..04656acc 100644
--- a/packages/taler-wallet-webextension/src/wallet/Settings.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/Settings.tsx
@@ -17,14 +17,19 @@
 import { ExchangeListItem, i18n } from "@gnu-taler/taler-util";
 import { Fragment, h, VNode } from "preact";
 import { Checkbox } from "../components/Checkbox";
-import { LinkPrimary } from "../components/styled";
+import {
+  DestructiveText,
+  LinkPrimary,
+  SuccessText,
+  WarningText,
+} from "../components/styled";
 import { useDevContext } from "../context/devContext";
 import { useAsyncAsHook } from "../hooks/useAsyncAsHook";
 import { useBackupDeviceName } from "../hooks/useBackupDeviceName";
 import { useExtendedPermissions } from "../hooks/useExtendedPermissions";
 import { useLang } from "../hooks/useLang";
 import { Pages } from "../NavigationBar";
-// import { strings as messages } from "../i18n/strings";
+import { buildTermsOfServiceStatus } from "../utils";
 import * as wxApi from "../wxApi";
 
 export function SettingsPage(): VNode {
@@ -65,25 +70,8 @@ export interface ViewProps {
   knownExchanges: Array<ExchangeListItem>;
 }
 
-// type LangsNames = {
-//   [P in keyof typeof messages]: string;
-// };
-
-// const names: LangsNames = {
-//   es: "Español [es]",
-//   en: "English [en]",
-//   fr: "Français [fr]",
-//   de: "Deutsch [de]",
-//   sv: "Svenska [sv]",
-//   it: "Italiano [it]",
-// };
-
 export function SettingsView({
   knownExchanges,
-  // lang,
-  // changeLang,
-  // deviceName,
-  // setDeviceName,
   permissionsEnabled,
   togglePermissions,
   developerMode,
@@ -92,6 +80,17 @@ export function SettingsView({
   return (
     <Fragment>
       <section>
+        <h2>
+          <i18n.Translate>Permissions</i18n.Translate>
+        </h2>
+        <Checkbox
+          label="Automatically open wallet based on page content"
+          name="perm"
+          description="(Enabling this option below will make using the wallet 
faster, but requires more permissions from your browser.)"
+          enabled={permissionsEnabled}
+          onToggle={togglePermissions}
+        />
+
         <h2>
           <i18n.Translate>Known exchanges</i18n.Translate>
         </h2>
@@ -100,14 +99,44 @@ export function SettingsView({
         ) : (
           <Fragment>
             <table>
-              {knownExchanges.map((e, idx) => (
-                <tr key={idx}>
-                  <td>{e.currency}</td>
-                  <td>
-                    <a href={e.exchangeBaseUrl}>{e.exchangeBaseUrl}</a>
-                  </td>
+              <thead>
+                <tr>
+                  <th>currency</th>
+                  <th>url</th>
+                  <th>term of service</th>
                 </tr>
-              ))}
+              </thead>
+              <tbody>
+                {knownExchanges.map((e, idx) => {
+                  function Status(): VNode {
+                    const status = buildTermsOfServiceStatus(
+                      e.tos.content,
+                      e.tos.acceptedVersion,
+                      e.tos.currentVersion,
+                    );
+                    switch (status) {
+                      case "accepted":
+                        return <SuccessText>ok</SuccessText>;
+                      case "changed":
+                        return <WarningText>changed!</WarningText>;
+                      case "new":
+                      case "notfound":
+                        return <DestructiveText>not accepted</DestructiveText>;
+                    }
+                  }
+                  return (
+                    <tr key={idx}>
+                      <td>{e.currency}</td>
+                      <td>
+                        <a href={e.exchangeBaseUrl}>{e.exchangeBaseUrl}</a>
+                      </td>
+                      <td>
+                        <Status />
+                      </td>
+                    </tr>
+                  );
+                })}
+              </tbody>
             </table>
           </Fragment>
         )}
@@ -116,16 +145,6 @@ export function SettingsView({
           <LinkPrimary href={Pages.exchange_add}>Add an exchange</LinkPrimary>
         </div>
 
-        <h2>
-          <i18n.Translate>Permissions</i18n.Translate>
-        </h2>
-        <Checkbox
-          label="Automatically open wallet based on page content"
-          name="perm"
-          description="(Enabling this option below will make using the wallet 
faster, but requires more permissions from your browser.)"
-          enabled={permissionsEnabled}
-          onToggle={togglePermissions}
-        />
         <h2>Config</h2>
         <Checkbox
           label="Developer mode"
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts 
b/packages/taler-wallet-webextension/src/wxApi.ts
index be0fed88..31fbd5b4 100644
--- a/packages/taler-wallet-webextension/src/wxApi.ts
+++ b/packages/taler-wallet-webextension/src/wxApi.ts
@@ -350,11 +350,13 @@ export function acceptTip(req: AcceptTipRequest): 
Promise<void> {
   return callBackend("acceptTip", req);
 }
 
-export function onUpdateNotification(messageType: Array<NotificationType>, 
doCallback: () => void): () => void {
+export function onUpdateNotification(messageTypes: Array<NotificationType>, 
doCallback: () => void): () => void {
   // eslint-disable-next-line no-undef
   const port = chrome.runtime.connect({ name: "notifications" });
   const listener = (message: MessageFromBackend): void => {
-    if (messageType.includes(message.type)) {
+    const shouldNotify = messageTypes.includes(message.type)
+    console.log("Notification arrived, should notify?", shouldNotify, 
message.type, messageTypes)
+    if (shouldNotify) {
       doCallback();
     }
   };

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