gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] branch master updated: fix more error cases


From: gnunet
Subject: [taler-wallet-core] branch master updated: fix more error cases
Date: Mon, 23 Oct 2023 21:05:06 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 58c0b1151 fix more error cases
58c0b1151 is described below

commit 58c0b115175ffc963e394258ec888b2be7ad3d74
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Oct 23 16:02:58 2023 -0300

    fix more error cases
---
 packages/demobank-ui/src/hooks/circuit.ts          | 38 ++++---------------
 .../demobank-ui/src/pages/AccountPage/state.ts     | 11 ++++--
 .../demobank-ui/src/pages/ShowAccountDetails.tsx   |  7 ++++
 .../src/pages/UpdateAccountPassword.tsx            |  2 +-
 packages/demobank-ui/src/pages/admin/Account.tsx   |  1 +
 .../demobank-ui/src/pages/admin/AccountList.tsx    |  3 +-
 .../demobank-ui/src/pages/admin/RemoveAccount.tsx  |  1 +
 .../src/pages/business/CreateCashout.tsx           | 43 ++++++++++------------
 .../src/pages/business/ShowCashoutDetails.tsx      | 20 +++++++++-
 packages/taler-util/src/http-client/bank-core.ts   |  2 +-
 10 files changed, 66 insertions(+), 62 deletions(-)

diff --git a/packages/demobank-ui/src/hooks/circuit.ts 
b/packages/demobank-ui/src/hooks/circuit.ts
index fc17c0184..e7a28bd98 100644
--- a/packages/demobank-ui/src/hooks/circuit.ts
+++ b/packages/demobank-ui/src/hooks/circuit.ts
@@ -96,32 +96,6 @@ export function useEstimator(): CashoutEstimators {
   };
 }
 
-export function useRatiosAndFeeConfig() {
-  const { api, config } = useBankCoreApiContext();
-
-  function fetcher() {
-    return api.getConversionRates()
-  }
-
-  const { data, error } = 
useSWR<TalerCoreBankResultByMethod<"getConversionRates">, TalerHttpError>(
-    !config.have_cashout || !config.fiat_currency ? false : [, 
"getConversionRates"], fetcher, {
-    refreshInterval: 60 * 1000,
-    refreshWhenHidden: false,
-    revalidateOnFocus: false,
-    revalidateIfStale: false,
-    revalidateOnReconnect: false,
-    refreshWhenOffline: false,
-    errorRetryCount: 0,
-    errorRetryInterval: 1,
-    shouldRetryOnError: false,
-    keepPreviousData: true,
-  });
-
-  if (data) return data;
-  if (error) return error;
-  return undefined;
-}
-
 export function useBusinessAccounts() {
   const { state: credentials } = useBackendState();
   const token = credentials.status !== "loggedIn" ? undefined : 
credentials.token
@@ -130,7 +104,8 @@ export function useBusinessAccounts() {
   const [offset, setOffset] = useState<string | undefined>();
 
   function fetcher([token, offset]: [AccessToken, string]) {
-    return api.getAccounts(token, {
+    //FIXME: add account name filter
+    return api.getAccounts(token,{}, {
       limit: MAX_RESULT_SIZE,
       offset,
       order: "asc"
@@ -183,13 +158,16 @@ function notUndefined(c: CashoutWithId | undefined): c is 
CashoutWithId {
 }
 export function useCashouts(account: string) {
   const { state: credentials } = useBackendState();
-  const { api } = useBankCoreApiContext();
+  const { api, config } = useBankCoreApiContext();
   const token = credentials.status !== "loggedIn" ? undefined : 
credentials.token
 
   async function fetcher([username, token]: [string, AccessToken]) {
     const list = await api.getAccountCashouts({ username, token })
     if (list.type !== "ok") {
-      assertUnreachable(list.type)
+      if (list.case === "cashout-not-supported") {
+        throw Error("cashout is not supported")
+      }
+      assertUnreachable(list.case)
     }
     const all: Array<CashoutWithId | undefined> = await 
Promise.all(list.body.cashouts.map(c => {
       return api.getCashoutById({ username, token }, c.cashout_id).then(r => {
@@ -203,7 +181,7 @@ export function useCashouts(account: string) {
   }
 
   const { data, error } = useSWR<OperationOk<{ cashouts: CashoutWithId[] }>, 
TalerHttpError>(
-    [account, token, "getAccountCashouts"], fetcher, {
+    !config.have_cashout ? false : [account, token, "getAccountCashouts"], 
fetcher, {
     refreshInterval: 0,
     refreshWhenHidden: false,
     revalidateOnFocus: false,
diff --git a/packages/demobank-ui/src/pages/AccountPage/state.ts 
b/packages/demobank-ui/src/pages/AccountPage/state.ts
index 793593f0d..6da066d77 100644
--- a/packages/demobank-ui/src/pages/AccountPage/state.ts
+++ b/packages/demobank-ui/src/pages/AccountPage/state.ts
@@ -14,11 +14,11 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-import { Amounts, HttpStatusCode, TalerError, TalerErrorCode, parsePaytoUri } 
from "@gnu-taler/taler-util";
-import { ErrorType, notifyError, useTranslationContext } from 
"@gnu-taler/web-util/browser";
+import { Amounts, TalerError, parsePaytoUri } from "@gnu-taler/taler-util";
+import { useTranslationContext } from "@gnu-taler/web-util/browser";
 import { useAccountDetails } from "../../hooks/access.js";
-import { Props, State } from "./index.js";
 import { assertUnreachable } from "../WithdrawalOperationPage.js";
+import { Props, State } from "./index.js";
 
 export function useComponentState({ account, goToConfirmOperation }: Props): 
State {
   const result = useAccountDetails(account);
@@ -48,6 +48,11 @@ export function useComponentState({ account, 
goToConfirmOperation }: Props): Sta
         status: "login",
         reason: "not-found",
       }
+      case "no-rights": return {
+        //users are forbiden to see others account
+        status: "login",
+        reason: "not-found",
+      }
       default: {
         assertUnreachable(result)
       }
diff --git a/packages/demobank-ui/src/pages/ShowAccountDetails.tsx 
b/packages/demobank-ui/src/pages/ShowAccountDetails.tsx
index 74346985a..b109441a6 100644
--- a/packages/demobank-ui/src/pages/ShowAccountDetails.tsx
+++ b/packages/demobank-ui/src/pages/ShowAccountDetails.tsx
@@ -43,6 +43,7 @@ export function ShowAccountDetails({
     switch (result.case) {
       case "not-found": return <LoginForm reason="not-found" />
       case "unauthorized": return <LoginForm reason="forbidden" />
+      case "no-rights": return <LoginForm reason="forbidden" />
       default: assertUnreachable(result)
     }
   }
@@ -77,6 +78,12 @@ export function ShowAccountDetails({
             description: resp.detail.hint as TranslatedString,
             debug: resp.detail,
           })
+          case "cant-change-legal-name-or-admin": return notify({
+            type: "error",
+            title: i18n.str`Can't change legal name`,
+            description: resp.detail.hint as TranslatedString,
+            debug: resp.detail,
+          })
           default: assertUnreachable(resp)
         }
       }
diff --git a/packages/demobank-ui/src/pages/UpdateAccountPassword.tsx 
b/packages/demobank-ui/src/pages/UpdateAccountPassword.tsx
index f23285528..b14c6d90b 100644
--- a/packages/demobank-ui/src/pages/UpdateAccountPassword.tsx
+++ b/packages/demobank-ui/src/pages/UpdateAccountPassword.tsx
@@ -59,7 +59,7 @@ export function UpdateAccountPassword({
             type: "error",
             title: i18n.str`Not authorized to change the password, maybe the 
session is invalid.`
           })
-          case "no-rights": return notify({
+          case "old-password-invalid-or-not-allowed": return notify({
             type: "error",
             title: current ? 
               i18n.str`This user have no right on to change the password.` :
diff --git a/packages/demobank-ui/src/pages/admin/Account.tsx 
b/packages/demobank-ui/src/pages/admin/Account.tsx
index a1e80ccb9..1818de655 100644
--- a/packages/demobank-ui/src/pages/admin/Account.tsx
+++ b/packages/demobank-ui/src/pages/admin/Account.tsx
@@ -25,6 +25,7 @@ export function WireTransfer({ toAccount, onRegister, 
onCancel, onSuccess }: { o
     switch (result.case) {
       case "unauthorized": return <LoginForm reason="forbidden" 
onRegister={onRegister} />
       case "not-found": return <LoginForm reason="not-found" 
onRegister={onRegister} />
+      case "no-rights": return <LoginForm reason="not-found" 
onRegister={onRegister} />
       default: assertUnreachable(result)
     }
   }
diff --git a/packages/demobank-ui/src/pages/admin/AccountList.tsx 
b/packages/demobank-ui/src/pages/admin/AccountList.tsx
index 7d3dd5595..a88badb58 100644
--- a/packages/demobank-ui/src/pages/admin/AccountList.tsx
+++ b/packages/demobank-ui/src/pages/admin/AccountList.tsx
@@ -31,7 +31,8 @@ export function AccountList({ onRemoveAccount, 
onShowAccountDetails, onUpdateAcc
   if (result.data.type === "fail") {
     switch (result.data.case) {
       case "unauthorized": return <div>un auth</div>
-      default: assertUnreachable(result.data.case)
+      case "no-rights": return <div>un auth</div>
+      default: assertUnreachable(result.data)
     }
   }
 
diff --git a/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx 
b/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx
index 4aa17e302..89f634080 100644
--- a/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx
+++ b/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx
@@ -43,6 +43,7 @@ export function RemoveAccount({
     switch (result.case) {
       case "unauthorized": return <LoginForm reason="forbidden" />
       case "not-found": return <LoginForm reason="not-found" />
+      case "no-rights": return <LoginForm reason="not-found" />
       default: assertUnreachable(result)
     }
   }
diff --git a/packages/demobank-ui/src/pages/business/CreateCashout.tsx 
b/packages/demobank-ui/src/pages/business/CreateCashout.tsx
index a3a48eed4..a71915622 100644
--- a/packages/demobank-ui/src/pages/business/CreateCashout.tsx
+++ b/packages/demobank-ui/src/pages/business/CreateCashout.tsx
@@ -14,7 +14,6 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 import {
-  AmountJson,
   Amounts,
   TalerError,
   TranslatedString
@@ -23,10 +22,10 @@ import {
   notify,
   useTranslationContext
 } from "@gnu-taler/web-util/browser";
-import { format } from "date-fns";
 import { Fragment, VNode, h } from "preact";
 import { useEffect, useState } from "preact/hooks";
 import { mutate } from "swr";
+import { Attention } from "../../components/Attention.js";
 import { ErrorLoading } from "../../components/ErrorLoading.js";
 import { Loading } from "../../components/Loading.js";
 import { ShowInputErrorLabel } from "../../components/ShowInputErrorLabel.js";
@@ -34,9 +33,7 @@ import { useBankCoreApiContext } from 
"../../context/config.js";
 import { useAccountDetails } from "../../hooks/access.js";
 import { useBackendState } from "../../hooks/backend.js";
 import {
-  useCashoutDetails,
-  useEstimator,
-  useRatiosAndFeeConfig,
+  useEstimator
 } from "../../hooks/circuit.js";
 import {
   TanChannel,
@@ -46,7 +43,6 @@ import {
 import { LoginForm } from "../LoginForm.js";
 import { InputAmount } from "../PaytoWireTransferForm.js";
 import { assertUnreachable } from "../WithdrawalOperationPage.js";
-import { Attention } from "../../components/Attention.js";
 
 interface Props {
   account: string;
@@ -71,7 +67,6 @@ export function CreateCashout({
   onCancel,
 }: Props): VNode {
   const { i18n } = useTranslationContext();
-  const resultRatios = useRatiosAndFeeConfig();
   const resultAccount = useAccountDetails(accountName);
   const {
     estimateByCredit: calculateFromCredit,
@@ -93,19 +88,17 @@ export function CreateCashout({
     </Attention>
   }
 
-  if (!resultAccount || !resultRatios) {
+  if (!resultAccount) {
     return <Loading />
   }
   if (resultAccount instanceof TalerError) {
     return <ErrorLoading error={resultAccount} />
   }
-  if (resultRatios instanceof TalerError) {
-    return <ErrorLoading error={resultRatios} />
-  }
   if (resultAccount.type === "fail") {
     switch (resultAccount.case) {
       case "unauthorized": return <LoginForm reason="forbidden" />
       case "not-found": return <LoginForm reason="not-found" />
+      case "no-rights": return <LoginForm reason="not-found" />
       default: assertUnreachable(resultAccount)
     }
   }
@@ -133,14 +126,16 @@ export function CreateCashout({
   const zeroCalc = { debit: zero, credit: zero, beforeFee: zero };
   const [calc, setCalc] = useState(zeroCalc);
 
-  const sellRate = ratio.sell_at_ratio;
-  const sellFee = !ratio.sell_out_fee
+  const sellRate = config.conversion_info?.sell_at_ratio;
+  const sellFee = !config.conversion_info?.sell_out_fee
     ? zero
     : Amounts.parseOrThrow(
-      `${account.balance.currency}:${ratio.sell_out_fee}`,
+      `${account.balance.currency}:${config.conversion_info.sell_out_fee}`,
     );
 
-  if (!sellRate || sellRate < 0) return <div>error rate</div>;
+  if (sellRate === undefined || sellRate < 0) return <div>error rate</div>;
+
+  const safeSellRate = sellRate
 
   const amount = Amounts.parseOrThrow(
     `${!form.isDebit ? config.fiat_currency.name : 
account.balance.currency}:${!form.amount ? "0" : form.amount
@@ -151,8 +146,8 @@ export function CreateCashout({
     async function doAsync() {
       await withRuntimeErrorHandling(i18n, async () => {
         const resp = await (form.isDebit ?
-          calculateFromDebit(amount, sellFee, sellRate) :
-          calculateFromCredit(amount, sellFee, sellRate));
+          calculateFromDebit(amount, sellFee, safeSellRate) :
+          calculateFromCredit(amount, sellFee, safeSellRate));
         setCalc(resp)
       })
     }
@@ -383,12 +378,6 @@ export function CreateCashout({
                       description: resp.detail.hint as TranslatedString,
                       debug: resp.detail,
                     });
-                    case "no-allowed": return notify({
-                      type: "error",
-                      title: i18n.str`This user is not allowed to make a 
cashout`,
-                      description: resp.detail.hint as TranslatedString,
-                      debug: resp.detail,
-                    });
                     case "no-contact-info": return notify({
                       type: "error",
                       title: i18n.str`Need a contact data where to send the 
TAN`,
@@ -401,12 +390,18 @@ export function CreateCashout({
                       description: resp.detail.hint as TranslatedString,
                       debug: resp.detail,
                     });
-                    case "tan-not-supported": return notify({
+                    case "cashout-or-tan-not-supported": return notify({
                       type: "error",
                       title: i18n.str`The bank does not support the TAN 
channel for this operation`,
                       description: resp.detail.hint as TranslatedString,
                       debug: resp.detail,
                     });
+                    // case "": return notify({
+                    //   type: "error",
+                    //   title: i18n.str`This user is not allowed to make a 
cashout`,
+                    //   description: resp.detail.hint as TranslatedString,
+                    //   debug: resp.detail,
+                    // });
                     default: assertUnreachable(resp)
                   }
                 }
diff --git a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx 
b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx
index 5c09e2001..b8e566348 100644
--- a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx
+++ b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx
@@ -38,6 +38,7 @@ import {
   withRuntimeErrorHandling
 } from "../../utils.js";
 import { assertUnreachable } from "../WithdrawalOperationPage.js";
+import { Attention } from "../../components/Attention.js";
 
 interface Props {
   id: string;
@@ -62,8 +63,11 @@ export function ShowCashoutDetails({
   }
   if (result.type === "fail") {
     switch (result.case) {
-      case "already-aborted": return <div>this cashout is already aborted</div>
-      default: assertUnreachable(result.case)
+      case "already-aborted": return <Attention type="warning" 
title={i18n.str`This cashout has already been aborted.`}>
+      </Attention>
+      case "cashout-not-supported": return <Attention type="warning" 
title={i18n.str`Cashouts are not supported`}>
+      </Attention>
+      default: assertUnreachable(result)
     }
   }
   const errors = undefinedIfEmpty({
@@ -175,6 +179,12 @@ export function ShowCashoutDetails({
                         description: resp.detail.hint as TranslatedString,
                         debug: resp.detail,
                       })
+                      case "cashout-not-supported": return notify({
+                        type: "error",
+                        title: i18n.str`Cashout operation is not supported.`,
+                        description: resp.detail.hint as TranslatedString,
+                        debug: resp.detail,
+                      })
                       default: {
                         assertUnreachable(resp)
                       }
@@ -219,6 +229,12 @@ export function ShowCashoutDetails({
                         description: resp.detail.hint as TranslatedString,
                         debug: resp.detail,
                       })
+                      case "cashout-not-supported": return notify({
+                        type: "error",
+                        title: i18n.str`Cashout operation is not supported.`,
+                        description: resp.detail.hint as TranslatedString,
+                        debug: resp.detail,
+                      })
                       default: assertUnreachable(resp)
                     }
                   }
diff --git a/packages/taler-util/src/http-client/bank-core.ts 
b/packages/taler-util/src/http-client/bank-core.ts
index bd35552f7..b9cce6c72 100644
--- a/packages/taler-util/src/http-client/bank-core.ts
+++ b/packages/taler-util/src/http-client/bank-core.ts
@@ -201,7 +201,7 @@ export class TalerCoreBankHttpClient {
     switch (resp.status) {
       case HttpStatusCode.Ok: return opSuccess(resp, 
codecForPublicAccountsResponse())
       case HttpStatusCode.NoContent: return opFixedSuccess({ public_accounts: 
[] })
-      case HttpStatusCode.ServiceUnavailable: return 
opKnownFailure("public-account-not-supported", resp);
+      case HttpStatusCode.NotFound: return opFixedSuccess({ public_accounts: 
[] })
       default: return opUnknownFailure(resp, await resp.text())
     }
   }

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