gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (b3b1329a -> dc2c2b36)


From: gnunet
Subject: [taler-wallet-core] branch master updated (b3b1329a -> dc2c2b36)
Date: Mon, 18 Apr 2022 21:21:02 +0200

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

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

    from b3b1329a show an error message when the input has more than 21 chars
     new 9d997280 missing tests
     new c3e65fb4 urgent fix: take currency from amount, dont assume BTC
     new dc2c2b36 show btc wire details in withdraw details transaction

The 3 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/bitcoin.ts                 | 12 ++--
 .../src/components/BankDetailsByPaytoType.tsx      | 71 ++++++++++++++++++++--
 .../src/components/ExchangeToS.tsx                 |  4 ++
 .../src/cta/TermsOfServiceSection.stories.tsx      | 14 ++++-
 .../src/cta/return-coins.tsx                       | 35 -----------
 .../taler-wallet-webextension/src/stories.test.ts  |  4 +-
 .../src/wallet/ReserveCreated.tsx                  | 61 +------------------
 .../src/wallet/Transaction.tsx                     |  2 +-
 8 files changed, 94 insertions(+), 109 deletions(-)
 delete mode 100644 packages/taler-wallet-webextension/src/cta/return-coins.tsx

diff --git a/packages/taler-util/src/bitcoin.ts 
b/packages/taler-util/src/bitcoin.ts
index cf9d52c4..b5cafbba 100644
--- a/packages/taler-util/src/bitcoin.ts
+++ b/packages/taler-util/src/bitcoin.ts
@@ -64,10 +64,10 @@ export function generateFakeSegwitAddress(
     addr[0] === "t" && addr[1] == "b"
       ? "tb"
       : addr[0] === "b" && addr[1] == "c" && addr[2] === "r" && addr[3] == "t"
-      ? "bcrt"
-      : addr[0] === "b" && addr[1] == "c"
-      ? "bc"
-      : undefined;
+        ? "bcrt"
+        : addr[0] === "b" && addr[1] == "c"
+          ? "bc"
+          : undefined;
   if (prefix === undefined) throw new Error("unknown bitcoin net");
 
   return {
@@ -77,6 +77,6 @@ export function generateFakeSegwitAddress(
 }
 
 // https://github.com/bitcoin/bitcoin/blob/master/src/policy/policy.cpp
-export function segwitMinAmount(): AmountJson {
-  return Amounts.parseOrThrow("BTC:0.00000294");
+export function segwitMinAmount(currency: string): AmountJson {
+  return Amounts.parseOrThrow(`${currency}:0.00000294`);
 }
diff --git 
a/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx 
b/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx
index 182e82a3..ac6f8541 100644
--- 
a/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx
+++ 
b/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx
@@ -14,18 +14,24 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-import { PaytoUri } from "@gnu-taler/taler-util";
+import {
+  AmountJson,
+  Amounts,
+  PaytoUri,
+  segwitMinAmount,
+} from "@gnu-taler/taler-util";
 import { Fragment, h, VNode } from "preact";
 import { useEffect, useRef, useState } from "preact/hooks";
 import { useTranslationContext } from "../context/translation.js";
 import { CopiedIcon, CopyIcon } from "../svg/index.js";
+import { Amount } from "./Amount.js";
 import { ButtonBox, TooltipRight } from "./styled/index.js";
 
 export interface BankDetailsProps {
   payto: PaytoUri | undefined;
   exchangeBaseUrl: string;
   subject: string;
-  amount: string | VNode;
+  amount: AmountJson;
 }
 
 export function BankDetailsByPaytoType({
@@ -35,8 +41,65 @@ export function BankDetailsByPaytoType({
   amount,
 }: BankDetailsProps): VNode {
   const { i18n } = useTranslationContext();
+  if (!payto) return <Fragment />;
 
-  const firstPart = !payto ? undefined : !payto.isKnown ? (
+  if (payto.isKnown && payto.targetType === "bitcoin") {
+    const min = segwitMinAmount(amount.currency);
+    if (typeof window !== "undefined") {
+      //FIXME: generate (and possibly save in db?) in wallet-core
+      payto.generateSegwitAddress(subject);
+    }
+    return (
+      <section style={{ textAlign: "left" }}>
+        <p>
+          <i18n.Translate>
+            Bitcoin exchange need a transaction with 3 output, one output is 
the
+            exchange account and the other two are segwit fake address for
+            metadata with an minimum amount. Reserve pub : {subject}
+          </i18n.Translate>
+        </p>
+        <p>
+          <i18n.Translate>
+            In bitcoincore wallet use &apos;Add Recipient&apos; button to add
+            two additional recipient and copy addresses and amounts
+          </i18n.Translate>
+          <ul>
+            <li>
+              {payto.targetPath} {Amounts.stringifyValue(amount)} BTC
+            </li>
+            <li>
+              {payto.addr1} {Amounts.stringifyValue(min)} BTC
+            </li>
+            <li>
+              {payto.addr2} {Amounts.stringifyValue(min)} BTC
+            </li>
+          </ul>
+          <i18n.Translate>
+            In Electrum wallet paste the following three lines in &apos;Pay
+            to&apos; field :
+          </i18n.Translate>
+          <ul>
+            <li>
+              {payto.targetPath},{Amounts.stringifyValue(amount)}
+            </li>
+            <li>
+              {payto.addr1},{Amounts.stringifyValue(min)}
+            </li>
+            <li>
+              {payto.addr2},{Amounts.stringifyValue(min)}
+            </li>
+          </ul>
+          <i18n.Translate>
+            Make sure the amount show{" "}
+            {Amounts.stringifyValue(Amounts.sum([amount, min, min]).amount)}{" 
"}
+            BTC, else you have to change the base unit to BTC
+          </i18n.Translate>
+        </p>
+      </section>
+    );
+  }
+
+  const firstPart = !payto.isKnown ? (
     <Row
       name={<i18n.Translate>Account</i18n.Translate>}
       value={payto.targetPath}
@@ -66,7 +129,7 @@ export function BankDetailsByPaytoType({
         />
         <Row
           name={<i18n.Translate>Chosen amount</i18n.Translate>}
-          value={amount}
+          value={<Amount value={amount} />}
         />
         <Row
           name={<i18n.Translate>Subject</i18n.Translate>}
diff --git a/packages/taler-wallet-webextension/src/components/ExchangeToS.tsx 
b/packages/taler-wallet-webextension/src/components/ExchangeToS.tsx
index 6aee838a..d54d66dc 100644
--- a/packages/taler-wallet-webextension/src/components/ExchangeToS.tsx
+++ b/packages/taler-wallet-webextension/src/components/ExchangeToS.tsx
@@ -17,6 +17,10 @@ import { Fragment, VNode, h } from "preact";
 import { useState } from "preact/hooks";
 
 export function ExchangeXmlTos({ doc }: { doc: Document }): VNode {
+  if (typeof window === "undefined") {
+    // in nodejs env we don't have xml api
+    return <div />;
+  }
   const termsNode = doc.querySelector("[ids=terms-of-service]");
   if (!termsNode) {
     return (
diff --git 
a/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.stories.tsx 
b/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.stories.tsx
index f24da1e1..4a0296ba 100644
--- 
a/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.stories.tsx
+++ 
b/packages/taler-wallet-webextension/src/cta/TermsOfServiceSection.stories.tsx
@@ -60,11 +60,19 @@ export const ReviewingHTML = createExample(TestedComponent, 
{
 });
 
 function toBase64(str: string): string {
-  return btoa(
-    encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
+  const encoded = encodeURIComponent(str).replace(
+    /%([0-9A-F]{2})/g,
+    function (match, p1) {
       return String.fromCharCode(parseInt(p1, 16));
-    }),
+    },
   );
+  if (typeof btoa === "undefined") {
+    //nodejs
+    return Buffer.from(encoded).toString("base64");
+  } else {
+    //browser
+    return btoa(encoded);
+  }
 }
 
 export const ReviewingPDF = createExample(TestedComponent, {
diff --git a/packages/taler-wallet-webextension/src/cta/return-coins.tsx 
b/packages/taler-wallet-webextension/src/cta/return-coins.tsx
deleted file mode 100644
index ae2bb07b..00000000
--- a/packages/taler-wallet-webextension/src/cta/return-coins.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- This file is part of TALER
- (C) 2017 Inria
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
- */
-
-import { h, VNode } from "preact";
-import { useTranslationContext } from "../context/translation.js";
-/**
- * Return coins to own bank account.
- *
- * @author sebasjm
- */
-
-/**
- * Imports.
- */
-export function CreateReturnCoinsPage(): VNode {
-  const { i18n } = useTranslationContext();
-  return (
-    <span>
-      <i18n.Translate>Not implemented yet.</i18n.Translate>
-    </span>
-  );
-}
diff --git a/packages/taler-wallet-webextension/src/stories.test.ts 
b/packages/taler-wallet-webextension/src/stories.test.ts
index cd6f8813..7e6be428 100644
--- a/packages/taler-wallet-webextension/src/stories.test.ts
+++ b/packages/taler-wallet-webextension/src/stories.test.ts
@@ -21,6 +21,8 @@
 import * as popup from "./popup/index.stories.js";
 import * as wallet from "./wallet/index.stories.js";
 import * as mui from "./mui/index.stories.js";
+import * as cta from "./cta/index.stories.js";
+import * as components from "./components/index.stories.js";
 
 import { setupI18n } from "@gnu-taler/taler-util";
 import { renderNodeOrBrowser } from "./test-utils.js";
@@ -40,7 +42,7 @@ function testThisStory(st: any): any {
 }
 
 describe("render every storybook example", () => {
-  [popup, wallet, mui].forEach(function testAll(st: any) {
+  [popup, wallet, cta, mui, components].forEach(function testAll(st: any) {
     if (Array.isArray(st.default)) {
       st.default.forEach(testAll)
     } else {
diff --git a/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx 
b/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx
index e656393c..02d8fe6a 100644
--- a/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx
@@ -1,10 +1,4 @@
-import {
-  AmountJson,
-  Amounts,
-  PaytoUri,
-  segwitMinAmount,
-  stringifyPaytoUri,
-} from "@gnu-taler/taler-util";
+import { AmountJson, PaytoUri, stringifyPaytoUri } from 
"@gnu-taler/taler-util";
 import { Fragment, h, VNode } from "preact";
 import { Amount } from "../components/Amount.js";
 import { BankDetailsByPaytoType } from 
"../components/BankDetailsByPaytoType.js";
@@ -42,61 +36,10 @@ export function ReserveCreated({
   }
   function TransferDetails(): VNode {
     if (!paytoURI) return <Fragment />;
-    if (paytoURI.isKnown && paytoURI.targetType === "bitcoin") {
-      const min = segwitMinAmount();
-      return (
-        <section>
-          <p>
-            <i18n.Translate>
-              Bitcoin exchange need a transaction with 3 output, one output is
-              the exchange account and the other two are segwit fake address 
for
-              metadata with an minimum amount. Reserve pub : {reservePub}
-            </i18n.Translate>
-          </p>
-          <p>
-            <i18n.Translate>
-              In bitcoincore wallet use &apos;Add Recipient&apos; button to add
-              two additional recipient and copy addresses and amounts
-            </i18n.Translate>
-            <ul>
-              <li>
-                {paytoURI.targetPath} {Amounts.stringifyValue(amount)} BTC
-              </li>
-              <li>
-                {paytoURI.addr1} {Amounts.stringifyValue(min)} BTC
-              </li>
-              <li>
-                {paytoURI.addr2} {Amounts.stringifyValue(min)} BTC
-              </li>
-            </ul>
-            <i18n.Translate>
-              In Electrum wallet paste the following three lines in &apos;Pay
-              to&apos; field :
-            </i18n.Translate>
-            <ul>
-              <li>
-                {paytoURI.targetPath},{Amounts.stringifyValue(amount)}
-              </li>
-              <li>
-                {paytoURI.addr1},{Amounts.stringifyValue(min)}
-              </li>
-              <li>
-                {paytoURI.addr2},{Amounts.stringifyValue(min)}
-              </li>
-            </ul>
-            <i18n.Translate>
-              Make sure the amount show{" "}
-              {Amounts.stringifyValue(Amounts.sum([amount, min, 
min]).amount)}{" "}
-              BTC, else you have to change the base unit to BTC
-            </i18n.Translate>
-          </p>
-        </section>
-      );
-    }
     return (
       <section>
         <BankDetailsByPaytoType
-          amount={<Amount value={amount} />}
+          amount={amount}
           exchangeBaseUrl={exchangeBaseUrl}
           payto={paytoURI}
           subject={reservePub}
diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx 
b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx
index 62e40d02..4a6c218c 100644
--- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx
@@ -224,7 +224,7 @@ export function TransactionView({
           WithdrawalType.ManualTransfer ? (
             <Fragment>
               <BankDetailsByPaytoType
-                amount={<Amount value={transaction.amountRaw} />}
+                amount={Amounts.parseOrThrow(transaction.amountRaw)}
                 exchangeBaseUrl={transaction.exchangeBaseUrl}
                 payto={parsePaytoUri(
                   transaction.withdrawalDetails.exchangePaytoUris[0],

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