gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated (77849fdf5 -> 34e2fd51e)


From: gnunet
Subject: [taler-wallet-core] branch master updated (77849fdf5 -> 34e2fd51e)
Date: Tue, 20 Jun 2023 22:51:16 +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 77849fdf5 -minor rename
     new 5c5586df9 more real cases
     new 34e2fd51e add select max amount

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:
 .../taler-wallet-core/src/operations/deposits.ts   |   7 +-
 .../src/util/coinSelection.test.ts                 | 138 +++++++++++++++++++++
 .../src/components/AmountField.tsx                 |   5 +-
 .../src/wallet/DestinationSelection/index.ts       |   2 +-
 .../src/wallet/DestinationSelection/state.ts       |  33 +++--
 .../src/wallet/DestinationSelection/views.tsx      |   6 +-
 6 files changed, 173 insertions(+), 18 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/deposits.ts 
b/packages/taler-wallet-core/src/operations/deposits.ts
index 6781696cf..0bc3caec4 100644
--- a/packages/taler-wallet-core/src/operations/deposits.ts
+++ b/packages/taler-wallet-core/src/operations/deposits.ts
@@ -79,7 +79,12 @@ import {
 } from "../index.js";
 import { InternalWalletState } from "../internal-wallet-state.js";
 import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http";
-import { constructTaskIdentifier, OperationAttemptResult, spendCoins, 
TombstoneTag } from "./common.js";
+import {
+  constructTaskIdentifier,
+  OperationAttemptResult,
+  spendCoins,
+  TombstoneTag,
+} from "./common.js";
 import { getExchangeDetails } from "./exchanges.js";
 import {
   extractContractData,
diff --git a/packages/taler-wallet-core/src/util/coinSelection.test.ts 
b/packages/taler-wallet-core/src/util/coinSelection.test.ts
index 3073b69c7..fddd217ea 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.test.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.test.ts
@@ -627,3 +627,141 @@ function asCoinList(v: { info: CoinInfo; size: number 
}[]): any {
     return [c.info.value, c.size];
   });
 }
+
+/**
+ * regression tests
+ */
+
+test("demo: withdraw raw 25", (t) => {
+  const coinList: Coin[] = [
+    [kudos`0.1`, 0],
+    [kudos`1`, 0],
+    [kudos`2`, 0],
+    [kudos`5`, 0],
+    [kudos`10`, 0],
+  ];
+  const result = convertWithdrawalAmountFromAvailableCoins(
+    {
+      list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
+      exchanges: {},
+    },
+    kudos`25`,
+    TransactionAmountMode.Raw,
+  );
+  t.is(Amounts.stringifyValue(result.effective), "24.8");
+  t.is(Amounts.stringifyValue(result.raw), "24.92");
+  // coins received
+  // 8 x  0.1
+  // 2 x  0.2
+  // 2 x 10.0
+  // total effective 24.8
+  // fee 12 x 0.01 = 0.12
+  // total raw 24.92
+  // left in reserve 25 - 24.92 == 0.08
+
+  //current wallet impl: hides the left in reserve fee
+  //shows fee = 0.2
+});
+
+test("demo: deposit max after withdraw raw 25", (t) => {
+  const coinList: Coin[] = [
+    [kudos`0.1`, 8],
+    [kudos`1`, 0],
+    [kudos`2`, 2],
+    [kudos`5`, 0],
+    [kudos`10`, 2],
+  ];
+  const result = getMaxDepositAmountForAvailableCoins(
+    {
+      list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
+      exchanges: {
+        one: {
+          wireFee: kudos`0.01`,
+          purseFee: kudos`0.00`,
+          creditDeadline: AbsoluteTime.never(),
+          debitDeadline: AbsoluteTime.never(),
+        },
+      },
+    },
+    "KUDOS",
+  );
+  t.is(Amounts.stringifyValue(result.effective), "24.8");
+  t.is(Amounts.stringifyValue(result.raw), "24.67");
+
+  // 8 x  0.1
+  // 2 x  0.2
+  // 2 x 10.0
+  // total effective 24.8
+  // deposit fee 12 x 0.01 = 0.12
+  // wire fee 0.01
+  // total raw: 24.8 - 0.13 = 24.67
+
+  // current wallet impl fee 0.14
+});
+
+test("demo: withdraw raw 13", (t) => {
+  const coinList: Coin[] = [
+    [kudos`0.1`, 0],
+    [kudos`1`, 0],
+    [kudos`2`, 0],
+    [kudos`5`, 0],
+    [kudos`10`, 0],
+  ];
+  const result = convertWithdrawalAmountFromAvailableCoins(
+    {
+      list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
+      exchanges: {},
+    },
+    kudos`13`,
+    TransactionAmountMode.Raw,
+  );
+  t.is(Amounts.stringifyValue(result.effective), "12.8");
+  t.is(Amounts.stringifyValue(result.raw), "12.9");
+  // coins received
+  // 8 x  0.1
+  // 1 x  0.2
+  // 1 x 10.0
+  // total effective 12.8
+  // fee 10 x 0.01 = 0.10
+  // total raw 12.9
+  // left in reserve 13 - 12.9 == 0.1
+
+  //current wallet impl: hides the left in reserve fee
+  //shows fee = 0.2
+});
+
+test("demo: deposit max after withdraw raw 13", (t) => {
+  const coinList: Coin[] = [
+    [kudos`0.1`, 8],
+    [kudos`1`, 0],
+    [kudos`2`, 1],
+    [kudos`5`, 0],
+    [kudos`10`, 1],
+  ];
+  const result = getMaxDepositAmountForAvailableCoins(
+    {
+      list: coinList.map(([v, t]) => defaultFeeConfig(v, t)),
+      exchanges: {
+        one: {
+          wireFee: kudos`0.01`,
+          purseFee: kudos`0.00`,
+          creditDeadline: AbsoluteTime.never(),
+          debitDeadline: AbsoluteTime.never(),
+        },
+      },
+    },
+    "KUDOS",
+  );
+  t.is(Amounts.stringifyValue(result.effective), "12.8");
+  t.is(Amounts.stringifyValue(result.raw), "12.69");
+
+  // 8 x  0.1
+  // 1 x  0.2
+  // 1 x 10.0
+  // total effective 12.8
+  // deposit fee 10 x 0.01 = 0.10
+  // wire fee 0.01
+  // total raw: 12.8 - 0.11 = 12.69
+
+  // current wallet impl fee 0.14
+});
diff --git a/packages/taler-wallet-webextension/src/components/AmountField.tsx 
b/packages/taler-wallet-webextension/src/components/AmountField.tsx
index 432aa6af1..c330c72b5 100644
--- a/packages/taler-wallet-webextension/src/components/AmountField.tsx
+++ b/packages/taler-wallet-webextension/src/components/AmountField.tsx
@@ -24,7 +24,7 @@ import {
   TranslatedString,
 } from "@gnu-taler/taler-util";
 import { Fragment, h, VNode } from "preact";
-import { useState } from "preact/hooks";
+import { useEffect, useState } from "preact/hooks";
 import { useTranslationContext } from "@gnu-taler/web-util/browser";
 import { AmountFieldHandler } from "../mui/handlers.js";
 import { TextField } from "../mui/TextField.js";
@@ -56,6 +56,9 @@ export function AmountField({
   const previousValue = Amounts.stringifyValue(normal);
 
   const [textValue, setTextValue] = useState<string>(previousValue);
+  useEffect(() => {
+    setTextValue(previousValue);
+  }, [previousValue]);
 
   function updateUnit(newUnit: number) {
     setUnit(newUnit);
diff --git 
a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts 
b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts
index 7724ec2be..b56fe5523 100644
--- 
a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts
+++ 
b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/index.ts
@@ -70,7 +70,7 @@ export namespace State {
     error: undefined;
     type: Props["type"];
     selectCurrency: ButtonHandler;
-    sendAll: ButtonHandler;
+    selectMax: ButtonHandler;
     previous: Contact[];
     goToBank: ButtonHandler;
     goToWallet: ButtonHandler;
diff --git 
a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts 
b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
index e42b1dbf9..a5d44e872 100644
--- 
a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
+++ 
b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
@@ -14,14 +14,14 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-import { Amounts, TransactionType } from "@gnu-taler/taler-util";
+import { Amounts } from "@gnu-taler/taler-util";
 import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { useEffect, useState } from "preact/hooks";
+import { useTranslationContext } from "@gnu-taler/web-util/browser";
+import { useState } from "preact/hooks";
 import { alertFromError, useAlertContext } from "../../context/alert.js";
 import { useBackendContext } from "../../context/backend.js";
-import { useTranslationContext } from "@gnu-taler/web-util/browser";
 import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js";
-import { assertUnreachable, RecursiveState } from "../../utils/index.js";
+import { RecursiveState, assertUnreachable } from "../../utils/index.js";
 import { Contact, Props, State } from "./index.js";
 
 export function useComponentState(props: Props): RecursiveState<State> {
@@ -130,13 +130,16 @@ export function useComponentState(props: Props): 
RecursiveState<State> {
                 props.goToWalletBankDeposit(currencyAndAmount);
               }),
         },
-        sendAll: {
-          onClick:
-            info === undefined
-              ? undefined
-              : pushAlertOnError(async () => {
-                  setAmount(info.balance.balanceMerchantDepositable);
-                }),
+        selectMax: {
+          onClick: pushAlertOnError(async () => {
+            const resp = await api.wallet.call(
+              WalletApiOperation.GetMaxDepositAmount,
+              {
+                currency: amount.currency,
+              },
+            );
+            setAmount(Amounts.parseOrThrow(resp.effectiveAmount));
+          }),
         },
         goToWallet: {
           onClick: invalid
@@ -161,7 +164,13 @@ export function useComponentState(props: Props): 
RecursiveState<State> {
             setAmount(undefined);
           }),
         },
-        sendAll: {},
+        selectMax: {
+          onClick: invalid
+            ? undefined
+            : pushAlertOnError(async () => {
+                props.goToWalletManualWithdraw(currencyAndAmount);
+              }),
+        },
         goToBank: {
           onClick: invalid
             ? undefined
diff --git 
a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx 
b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx
index c230c1490..f8e2c6707 100644
--- 
a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx
+++ 
b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx
@@ -203,7 +203,7 @@ export function ReadyGetView({
   return (
     <Container>
       <h1>
-        <i18n.Translate>Specify the amount and the origin2</i18n.Translate>
+        <i18n.Translate>Specify the amount and the origin</i18n.Translate>
       </h1>
       <Grid container columns={2} justifyContent="space-between">
         <AmountField
@@ -287,7 +287,7 @@ export function ReadySendView({
   goToBank,
   goToWallet,
   previous,
-  sendAll,
+  selectMax,
 }: State.Ready): VNode {
   const { i18n } = useTranslationContext();
 
@@ -304,7 +304,7 @@ export function ReadySendView({
           handler={amountHandler}
         />
         <EnabledBySettings name="advanceMode">
-          <Button onClick={sendAll.onClick}>
+          <Button onClick={selectMax.onClick}>
             <i18n.Translate>Send all</i18n.Translate>
           </Button>
         </EnabledBySettings>

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