From d845c0cf225a0f05214f368f4a98257238f53d07 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 19 Jan 2024 17:09:43 -0300 Subject: fixes #8147 --- .../demobank-ui/src/components/Cashouts/views.tsx | 37 ++-- packages/demobank-ui/src/pages/LoginForm.tsx | 6 +- .../demobank-ui/src/pages/RegistrationPage.tsx | 4 +- .../demobank-ui/src/pages/SolveChallengePage.tsx | 12 ++ .../src/pages/account/ShowAccountDetails.tsx | 4 +- packages/demobank-ui/src/pages/admin/AdminHome.tsx | 25 ++- .../src/pages/business/CreateCashout.tsx | 10 ++ .../src/pages/business/ShowCashoutDetails.tsx | 193 +-------------------- 8 files changed, 74 insertions(+), 217 deletions(-) diff --git a/packages/demobank-ui/src/components/Cashouts/views.tsx b/packages/demobank-ui/src/components/Cashouts/views.tsx index c3fdec796..cb1c24aa7 100644 --- a/packages/demobank-ui/src/components/Cashouts/views.tsx +++ b/packages/demobank-ui/src/components/Cashouts/views.tsx @@ -32,13 +32,11 @@ export function FailedView({ error }: State.Failed) { {error.detail.hint} - case HttpStatusCode.NotFound: return -
- {error.detail.hint} -
-
- default: assertUnreachable(error) + case HttpStatusCode.NotImplemented: { + return + ; + } + default: assertUnreachable(error.case) } } @@ -51,6 +49,16 @@ export function ReadyView({ cashouts, onSelected }: State.Ready): VNode { if (resp instanceof TalerError) { return } + if (resp.type === "fail") { + switch (resp.case) { + case HttpStatusCode.NotImplemented: { + return + ; + } + default: assertUnreachable(resp.case) + } + } + if (!cashouts.length) return
const txByDate = cashouts.reduce((prev, cur) => { const d = cur.creation_time.t_s === "never" @@ -74,10 +82,8 @@ export function ReadyView({ cashouts, onSelected }: State.Ready): VNode { {i18n.str`Created`} - {i18n.str`Confirmed`} {i18n.str`Total debit`} {i18n.str`Total credit`} - {i18n.str`Status`} {i18n.str`Subject`} @@ -91,9 +97,6 @@ export function ReadyView({ cashouts, onSelected }: State.Ready): VNode { {txs.map(item => { const creationTime = item.creation_time.t_s === "never" ? "" : format(item.creation_time.t_s * 1000, "HH:mm:ss", { locale: dateLocale }) - const confirmationTime = item.confirmation_time - ? item.confirmation_time.t_s === "never" ? i18n.str`never` : format(item.confirmation_time.t_s, "dd/MM/yyyy HH:mm:ss", { locale: dateLocale }) - : "-" return ( { @@ -101,6 +104,8 @@ export function ReadyView({ cashouts, onSelected }: State.Ready): VNode { onSelected(item.id); }} class="relative py-2 pl-2 pr-2 text-sm ">
{creationTime}
+ {//FIXME: implement responsive view + } {/*
Amount
@@ -123,10 +128,6 @@ export function ReadyView({ cashouts, onSelected }: State.Ready): VNode {
*/} - { - e.preventDefault(); - onSelected(item.id); - }} class="hidden sm:table-cell px-3 py-3.5 text-sm text-gray-500 cursor-pointer">{confirmationTime} { e.preventDefault(); onSelected(item.id); @@ -136,10 +137,6 @@ export function ReadyView({ cashouts, onSelected }: State.Ready): VNode { onSelected(item.id); }} class="hidden sm:table-cell px-3 py-3.5 text-sm text-green-600 cursor-pointer"> - { - e.preventDefault(); - onSelected(item.id); - }} class="hidden sm:table-cell px-3 py-3.5 text-sm text-gray-500 cursor-pointer">{item.status} { e.preventDefault(); onSelected(item.id); diff --git a/packages/demobank-ui/src/pages/LoginForm.tsx b/packages/demobank-ui/src/pages/LoginForm.tsx index 627252682..7ec490c19 100644 --- a/packages/demobank-ui/src/pages/LoginForm.tsx +++ b/packages/demobank-ui/src/pages/LoginForm.tsx @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { TranslatedString } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TranslatedString } from "@gnu-taler/taler-util"; import { LocalNotificationBanner, ShowInputErrorLabel, useLocalNotification, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useEffect, useRef, useState } from "preact/hooks"; @@ -76,13 +76,13 @@ export function LoginForm({ currentUser, fixedUser, onRegister }: { fixedUser?: backend.logIn({ username, token: resp.body.access_token }); } else { switch (resp.case) { - case "wrong-credentials": return notify({ + case HttpStatusCode.Unauthorized: return notify({ type: "error", title: i18n.str`Wrong credentials for "${username}"`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }) - case "not-found": return notify({ + case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`Account not found`, description: resp.detail.hint as TranslatedString, diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx index 005a0bc2c..e948a5dad 100644 --- a/packages/demobank-ui/src/pages/RegistrationPage.tsx +++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx @@ -177,13 +177,13 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on backend.logIn({ username, token: resp.body.access_token }); } else { switch (resp.case) { - case "wrong-credentials": return notify({ + case HttpStatusCode.Unauthorized: return notify({ type: "error", title: i18n.str`Wrong credentials for "${username}"`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }) - case "not-found": return notify({ + case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`Account not found`, description: resp.detail.hint as TranslatedString, diff --git a/packages/demobank-ui/src/pages/SolveChallengePage.tsx b/packages/demobank-ui/src/pages/SolveChallengePage.tsx index 3647f2b65..d0ac5ab75 100644 --- a/packages/demobank-ui/src/pages/SolveChallengePage.tsx +++ b/packages/demobank-ui/src/pages/SolveChallengePage.tsx @@ -27,6 +27,7 @@ import { parsePaytoUri } from "@gnu-taler/taler-util"; import { + Attention, Loading, LocalNotificationBanner, ShowInputErrorLabel, @@ -528,6 +529,17 @@ function ShowCashoutDetails({ request }: { request: TalerCorebankApi.CashoutRequ if (info instanceof TalerError) { return } + if (info.type === "fail") { + switch (info.case) { + case HttpStatusCode.NotImplemented: { + return + ; + } + default: assertUnreachable(info.case) + } + } + + return {request.subject !== undefined &&
diff --git a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx index ca3e2fbdf..0dfdb39f3 100644 --- a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx +++ b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx @@ -93,9 +93,9 @@ export function ShowAccountDetails({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }) - case TalerErrorCode.BANK_NON_ADMIN_PATCH_CONTACT: return notify({ + case TalerErrorCode.BANK_MISSING_TAN_INFO: return notify({ type: "error", - title: i18n.str`You can't change the contact data, please contact the your account administrator.`, + title: i18n.str`No information for the selected authentication channel.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }) diff --git a/packages/demobank-ui/src/pages/admin/AdminHome.tsx b/packages/demobank-ui/src/pages/admin/AdminHome.tsx index c03f228cd..b7ef3aa00 100644 --- a/packages/demobank-ui/src/pages/admin/AdminHome.tsx +++ b/packages/demobank-ui/src/pages/admin/AdminHome.tsx @@ -1,5 +1,5 @@ -import { AmountString, Amounts, CurrencySpecification, TalerCorebankApi, TalerError, assertUnreachable } from "@gnu-taler/taler-util"; -import { useLang, useTranslationContext } from "@gnu-taler/web-util/browser"; +import { AmountString, Amounts, CurrencySpecification, HttpStatusCode, TalerCorebankApi, TalerError, assertUnreachable } from "@gnu-taler/taler-util"; +import { Attention, useLang, useTranslationContext } from "@gnu-taler/web-util/browser"; import { format, getDate, getHours, getMonth, getYear, setDate, setHours, setMonth, setYear, sub } from "date-fns"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; @@ -90,10 +90,23 @@ function Metrics(): VNode { if (resp instanceof TalerError) { return } + if (!respInfo) return ; + if (respInfo instanceof TalerError) { + return + } + if (respInfo.type === "fail") { + switch (respInfo.case) { + case HttpStatusCode.NotImplemented: { + return + ; + } + default: assertUnreachable(respInfo.case) + } + } + if (resp.current.type !== "ok" || resp.previous.type !== "ok") { return } - const fiatSpec = respInfo && (!(respInfo instanceof TalerError)) ? respInfo.body.fiat_currency_specification : undefined return
@@ -135,7 +148,7 @@ function Metrics(): VNode {
- {!fiatSpec || resp.current.body.type !== "with-conversions" || resp.previous.body.type !== "with-conversions" ? undefined : + {resp.current.body.type !== "with-conversions" || resp.previous.body.type !== "with-conversions" ? undefined :
@@ -144,7 +157,7 @@ function Metrics(): VNode {
@@ -154,7 +167,7 @@ function Metrics(): VNode {
diff --git a/packages/demobank-ui/src/pages/business/CreateCashout.tsx b/packages/demobank-ui/src/pages/business/CreateCashout.tsx index f9962fbde..a39a379de 100644 --- a/packages/demobank-ui/src/pages/business/CreateCashout.tsx +++ b/packages/demobank-ui/src/pages/business/CreateCashout.tsx @@ -120,6 +120,16 @@ export function CreateCashout({ if (info instanceof TalerError) { return } + if (info.type === "fail") { + switch (info.case) { + case HttpStatusCode.NotImplemented: { + return + ; + } + default: assertUnreachable(info.case) + } + } + const conversionInfo = info.body.conversion_rate if (!conversionInfo) { diff --git a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx index a55bf3ab6..b4d5b6584 100644 --- a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx +++ b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx @@ -54,18 +54,13 @@ export function ShowCashoutDetails({ }: Props): VNode { const { i18n, dateLocale } = useTranslationContext(); const { state } = useBackendState(); - const creds = state.status !== "loggedIn" ? undefined : state - const { api } = useBankCoreApiContext() const cid = Number.parseInt(id, 10) const result = useCashoutDetails(Number.isNaN(cid) ? undefined : cid); - const [code, setCode] = useState(undefined); - const [notification, notify, handleError] = useLocalNotification() const info = useConversionInfo(); if (Number.isNaN(cid)) { - //TODO: better error message - return
cashout id should be a number
+ return } if (!result) { return @@ -89,116 +84,19 @@ export function ShowCashoutDetails({ if (info instanceof TalerError) { return } - - const errors = undefinedIfEmpty({ - code: !code ? i18n.str`required` : undefined, - }); - /** - * @deprecated - */ - const isPending = String(result.body.status).toUpperCase() === "PENDING"; - const { fiat_currency_specification, regional_currency_specification } = info.body - // won't implement in retry in old API 3:0:3 since request_uid is missing - async function doAbortCashout() { - if (!creds) return; - await handleError(async () => { - const resp = await api.abortCashoutById(creds, cid); - if (resp.type === "ok") { - onCancel(); - } else { - switch (resp.case) { - case HttpStatusCode.NotFound: return notify({ - type: "error", - title: i18n.str`Cashout not found. It may be also mean that it was already aborted.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - case HttpStatusCode.Conflict: return notify({ - type: "error", - title: i18n.str`Cashout was already confimed.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - case HttpStatusCode.NotImplemented: return notify({ - type: "error", - title: i18n.str`Cashout operation is not supported.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - default: { - assertUnreachable(resp) - } - } + if (info.type === "fail") { + switch (info.case) { + case HttpStatusCode.NotImplemented: { + return } - }) - } - async function doConfirmCashout() { - if (!creds || !code) return; - await handleError(async () => { - const resp = await api.confirmCashoutById(creds, cid, { - tan: code, - }); - if (resp.type === "ok") { - mutate(() => true)//clean cashout state - } else { - switch (resp.case) { - case HttpStatusCode.NotFound: return notify({ - type: "error", - title: i18n.str`Cashout not found. It may be also mean that it was already aborted.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({ - type: "error", - title: i18n.str`The account does not have sufficient funds`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }); - case TalerErrorCode.BANK_BAD_CONVERSION: return notify({ - type: "error", - title: i18n.str`The conversion rate was incorrectly applied`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }); - case TalerErrorCode.BANK_CONFIRM_ABORT_CONFLICT: return notify({ - type: "error", - title: i18n.str`The cashout operation is already aborted.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }); - case TalerErrorCode.BANK_CONFIRM_INCOMPLETE: return notify({ - type: "error", - title: i18n.str`Missing destination account.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - case HttpStatusCode.TooManyRequests: return notify({ - type: "error", - title: i18n.str`Too many failed attempts.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - case HttpStatusCode.NotImplemented: return notify({ - type: "error", - title: i18n.str`Cashout operation is not supported.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - case TalerErrorCode.BANK_TAN_CHALLENGE_FAILED: return notify({ - type: "error", - title: i18n.str`The code for this cashout is invalid.`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }) - default: assertUnreachable(resp) - } - } - }) + default: assertUnreachable(info.case) + } } + const { fiat_currency_specification, regional_currency_specification } = info.body + return (
-
@@ -208,16 +106,6 @@ export function ShowCashoutDetails({
Subject
{result.body.subject}
- - -
-
- Status -
-
- {result.body.status} -
-
@@ -252,14 +140,6 @@ export function ShowCashoutDetails({
- {result.body.confirmation_time && result.body.confirmation_time.t_s !== "never" ? -
-
Confirmed
-
- {format(result.body.confirmation_time.t_s * 1000, "dd/MM/yyyy HH:mm:ss", { locale: dateLocale })} -
-
- : undefined}
@@ -267,61 +147,6 @@ export function ShowCashoutDetails({ - {!isPending ? undefined : - -
-
{ - e.preventDefault() - }} - > -
- -
-
- { - setCode(e.currentTarget.value) - }} - /> -
- -
-
-
- - -
-
- }

-- cgit v1.2.3