From f0046ec557bf8d52aaf5cb13cf03ab98450adc0a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 2 Jan 2024 12:10:55 -0300 Subject: do not send extra if empty --- .../src/paths/instance/orders/create/CreatePage.tsx | 2 +- packages/merchant-backoffice-ui/src/utils/table.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx index 52ee9d351..2b1741276 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx @@ -235,7 +235,7 @@ export function CreatePage({ amount: order.pricing.order_price, summary: order.pricing.summary, products: productList, - extra: JSON.stringify(value.extra), + extra: undefinedIfEmpty(value.extra), pay_deadline: value.payments.pay_deadline ? { t_s: Math.floor(value.payments.pay_deadline.getTime() / 1000), diff --git a/packages/merchant-backoffice-ui/src/utils/table.ts b/packages/merchant-backoffice-ui/src/utils/table.ts index 71358e25f..db2b2021c 100644 --- a/packages/merchant-backoffice-ui/src/utils/table.ts +++ b/packages/merchant-backoffice-ui/src/utils/table.ts @@ -51,7 +51,7 @@ export function buildActions( */ export function undefinedIfEmpty< T extends Record | Array, ->(obj: T): T | undefined { +>(obj: T | undefined): T | undefined { if (obj === undefined) return undefined; return Object.values(obj).some((v) => v !== undefined) ? obj : undefined; } -- cgit v1.2.3 From b0610d24571593909cd6683b340fa266de046e31 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 8 Jan 2024 14:24:07 -0300 Subject: order config using relative time --- .../src/components/form/InputDuration.tsx | 126 ++++++++------- .../src/components/picker/DurationPicker.tsx | 2 +- .../merchant-backoffice-ui/src/declaration.d.ts | 7 +- .../src/paths/admin/create/CreatePage.tsx | 116 +++++++------- .../paths/instance/orders/create/CreatePage.tsx | 178 ++++++++++----------- .../src/paths/instance/update/UpdatePage.tsx | 73 +++------ 6 files changed, 240 insertions(+), 262 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx b/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx index ef4df1df4..8b6b5636d 100644 --- a/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx @@ -20,16 +20,19 @@ */ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { formatDuration, intervalToDuration } from "date-fns"; -import { h, VNode } from "preact"; +import { ComponentChildren, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { SimpleModal } from "../modal/index.js"; import { DurationPicker } from "../picker/DurationPicker.js"; import { InputProps, useField } from "./useField.js"; +import { Duration } from "@gnu-taler/taler-util"; export interface Props extends InputProps { expand?: boolean; readonly?: boolean; withForever?: boolean; + side?: ComponentChildren; + withoutClear?: boolean; } export function InputDuration({ @@ -41,19 +44,22 @@ export function InputDuration({ help, readonly, withForever, + withoutClear, + side, }: Props): VNode { const [opened, setOpened] = useState(false); const { i18n } = useTranslationContext(); - const { error, required, value, onChange } = useField(name); + const { error, required, value: anyValue, onChange } = useField(name); let strValue = ""; + const value: Duration = anyValue if (!value) { strValue = ""; - } else if (value.d_us === "forever") { + } else if (value.d_ms === "forever") { strValue = i18n.str`forever`; } else { strValue = formatDuration( - intervalToDuration({ start: 0, end: value.d_us / 1000 }), + intervalToDuration({ start: 0, end: value.d_ms }), { locale: { formatDistance: (name, value) => { @@ -97,72 +103,80 @@ export function InputDuration({ )} -
-
-
-

- +

+
+
+

+ { + if (!readonly) setOpened(true); + }} + /> + {required && ( + + + + )} +

+
{ if (!readonly) setOpened(true); }} - /> - {required && ( - - - - )} - {help} -

-
{ - if (!readonly) setOpened(true); - }} - > - - - - - + > + + + + + +
+ {error &&

{error}

}
- {error &&

{error}

} + {withForever && ( + + + + )} + {!readonly && !withoutClear && ( + + + + )} + {side}
- {withForever && ( - - - - )} - {!readonly && ( - - - - )} + + {help} +
+ + {opened && ( setOpened(false)}> { - onChange({ d_us: v } as any); + onChange({ d_ms: v } as any); }} /> diff --git a/packages/merchant-backoffice-ui/src/components/picker/DurationPicker.tsx b/packages/merchant-backoffice-ui/src/components/picker/DurationPicker.tsx index 0968b0a17..ba003cce5 100644 --- a/packages/merchant-backoffice-ui/src/components/picker/DurationPicker.tsx +++ b/packages/merchant-backoffice-ui/src/components/picker/DurationPicker.tsx @@ -42,7 +42,7 @@ export function DurationPicker({ onChange, value, }: Props): VNode { - const ss = 1000 * 1000; + const ss = 1000; const ms = ss * 60; const hs = ms * 60; const ds = hs * 24; diff --git a/packages/merchant-backoffice-ui/src/declaration.d.ts b/packages/merchant-backoffice-ui/src/declaration.d.ts index dc53e3e83..f99dd1867 100644 --- a/packages/merchant-backoffice-ui/src/declaration.d.ts +++ b/packages/merchant-backoffice-ui/src/declaration.d.ts @@ -23,7 +23,7 @@ type HashCode = string; type EddsaPublicKey = string; type EddsaSignature = string; type WireTransferIdentifierRawP = string; -type RelativeTime = Duration; +type RelativeTime = TalerProtocolDuration; type ImageDataUrl = string; type MerchantUserType = "business" | "individual"; @@ -38,9 +38,12 @@ interface Timestamp { // never happen. t_s: number | "never"; } -interface Duration { +interface TalerProtocolDuration { d_us: number | "forever"; } +interface Duration { + d_ms: number | "forever"; +} interface WithId { id: string; diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx index 093c24c3d..d13b7e929 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx @@ -32,13 +32,16 @@ import { MerchantBackend } from "../../../declaration.js"; import { INSTANCE_ID_REGEX } from "../../../utils/constants.js"; import { undefinedIfEmpty } from "../../../utils/table.js"; import { SetTokenNewInstanceModal } from "../../../components/modal/index.js"; +import { Duration } from "@gnu-taler/taler-util"; -export type Entity = MerchantBackend.Instances.InstanceConfigurationMessage & { +export type Entity = Omit, "default_wire_transfer_delay"> & { auth_token?: string; + default_pay_delay: Duration, + default_wire_transfer_delay: Duration, }; interface Props { - onCreate: (d: Entity) => Promise; + onCreate: (d: MerchantBackend.Instances.InstanceConfigurationMessage) => Promise; onBack?: () => void; forceId?: string; } @@ -49,8 +52,8 @@ function with_defaults(id?: string): Partial { // accounts: [], user_type: "business", use_stefan: true, - default_pay_delay: { d_us: 2 * 1000 * 60 * 60 * 1000 }, // two hours - default_wire_transfer_delay: { d_us: 1000 * 2 * 60 * 60 * 24 * 1000 }, // two days + default_pay_delay: { d_ms: 2 * 60 * 60 * 1000 }, // two hours + default_wire_transfer_delay: { d_ms: 2 * 60 * 60 * 24 * 1000 }, // two days }; } @@ -88,9 +91,9 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { default_pay_delay: !value.default_pay_delay ? i18n.str`required` : !!value.default_wire_transfer_delay && - value.default_wire_transfer_delay.d_us !== "forever" && - value.default_pay_delay.d_us !== "forever" && - value.default_pay_delay.d_us > value.default_wire_transfer_delay.d_us ? + value.default_wire_transfer_delay.d_ms !== "forever" && + value.default_pay_delay.d_ms !== "forever" && + value.default_pay_delay.d_ms > value.default_wire_transfer_delay.d_ms ? i18n.str`pay delay can't be greater than wire transfer delay` : undefined, default_wire_transfer_delay: !value.default_wire_transfer_delay ? i18n.str`required` @@ -124,7 +127,12 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { if (!value.jurisdiction) value.jurisdiction = {}; // remove above use conversion // schema.validateSync(value, { abortEarly: false }) - return onCreate(value as Entity); + value.default_pay_delay = Duration.toTalerProtocolDuration(value.default_pay_delay!) as any + value.default_wire_transfer_delay = Duration.toTalerProtocolDuration(value.default_wire_transfer_delay!) as any + // delete value.default_pay_delay; + // delete value.default_wire_transfer_delay; + + return onCreate(value as any as MerchantBackend.Instances.InstanceConfigurationMessage); }; function updateToken(token: string | null) { @@ -174,54 +182,54 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode {
-
-

- -

+
+

+ +

+
-
-
-
- {!isTokenSet ? ( -

- - Access token is not yet configured. This instance can't be - created. - -

- ) : value.auth_token === undefined ? ( -

- - No access token. Authorization must be handled externally. - -

- ) : ( -

- - Access token is set. Authorization is handled by the - merchant backend. - -

- )} +
+
+ {!isTokenSet ? ( +

+ + Access token is not yet configured. This instance can't be + created. + +

+ ) : value.auth_token === undefined ? ( +

+ + No access token. Authorization must be handled externally. + +

+ ) : ( +

+ + Access token is set. Authorization is handled by the + merchant backend. + +

+ )} +
-
{onBack && (
- {/*
-
-

- -

-
-
*/}
-- cgit v1.2.3 From c019f4c040e82baebdbbda8208f10be2fbc19566 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 8 Jan 2024 16:22:48 -0300 Subject: duration label --- .../src/components/form/InputDuration.tsx | 6 ++-- .../paths/instance/orders/create/CreatePage.tsx | 32 +++++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx b/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx index 8b6b5636d..7aa2703a4 100644 --- a/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx @@ -93,7 +93,7 @@ export function InputDuration({ return (
-
+
-
-
+
+

diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx index a30f79169..fbfd023c1 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx @@ -22,7 +22,7 @@ import { AbsoluteTime, Amounts, Duration, TalerProtocolDuration } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { format, isFuture } from "date-fns"; -import { Fragment, VNode, h } from "preact"; +import { ComponentChildren, Fragment, VNode, h } from "preact"; import { useEffect, useState } from "preact/hooks"; import { FormErrors, @@ -334,10 +334,6 @@ export function CreatePage({ // user required to set the taler options const requiresSomeTalerOptions = noDefault_payDeadline || noDefault_wireDeadline - const whenPay = !value.payments?.pay_deadline ? undefined : AbsoluteTime.addDuration(AbsoluteTime.now(), value.payments.pay_deadline) - const whenRefund = !value.payments?.refund_deadline ? undefined : AbsoluteTime.addDuration(AbsoluteTime.now(), value.payments.refund_deadline) - const whenWire = !value.payments?.wire_transfer_deadline ? undefined : AbsoluteTime.addDuration(AbsoluteTime.now(), value.payments.wire_transfer_deadline) - const whenAutoRefund = !value.payments?.auto_refund_deadline ? undefined : AbsoluteTime.addDuration(AbsoluteTime.now(), value.payments.auto_refund_deadline) return (

@@ -500,7 +496,7 @@ export function CreatePage({ {(settings.advanceOrderMode || noDefault_payDeadline) && } withForever withoutClear tooltip={i18n.str`Time for the customer to pay for the offer before it expires. Inventory products will be reserved until this deadline. Time start to run after the order is created.`} @@ -524,7 +520,7 @@ export function CreatePage({ {settings.advanceOrderMode && } withForever withoutClear tooltip={i18n.str`Time while the order can be refunded by the merchant. Time starts after the order is created.`} @@ -547,7 +543,7 @@ export function CreatePage({ {(settings.advanceOrderMode || noDefault_wireDeadline) && } withoutClear withForever tooltip={i18n.str`Time for the exchange to make the wire transfer. Time starts after the order is created.`} @@ -569,8 +565,8 @@ export function CreatePage({ />} {settings.advanceOrderMode && } tooltip={i18n.str`Time until which the wallet will automatically check for refunds without user interaction.`} withForever />} @@ -691,3 +687,19 @@ function asProduct(p: ProductAndQuantity): MerchantBackend.Product { } +function DeadlineHelp({ duration }: { duration?: Duration }): VNode { + const { i18n } = useTranslationContext(); + const [now, setNow] = useState(AbsoluteTime.now()) + useEffect(() => { + const iid = setInterval(() => { + setNow(AbsoluteTime.now()) + }, 60 * 1000) + return () => { + clearInterval(iid) + } + }) + if (!duration) return Disabled + const when = AbsoluteTime.addDuration(now, duration) + if (when.t_ms === "never") return No deadline + return Deadline at {format(when.t_ms, "dd/MM/yy HH:mm")} +} -- cgit v1.2.3 From 0438062ec39a1a183d3f952318e62fb1c63baf97 Mon Sep 17 00:00:00 2001 From: Sebastian Marchano Date: Fri, 12 Jan 2024 14:42:56 +0000 Subject: Translated using Weblate (Spanish) Currently translated at 53.4% (284 of 531 strings) Translation: GNU Taler/Merchant Backoffice Translate-URL: https://weblate.taler.net/projects/gnu-taler/merchant-backoffice/es/ --- packages/merchant-backoffice-ui/src/i18n/es.po | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/i18n/es.po b/packages/merchant-backoffice-ui/src/i18n/es.po index 10ec0cf3b..1d3b3b279 100644 --- a/packages/merchant-backoffice-ui/src/i18n/es.po +++ b/packages/merchant-backoffice-ui/src/i18n/es.po @@ -17,8 +17,8 @@ msgstr "" "Project-Id-Version: Taler Wallet\n" "Report-Msgid-Bugs-To: taler@gnu.org\n" "POT-Creation-Date: 2016-11-23 00:00+0100\n" -"PO-Revision-Date: 2023-08-13 10:14+0000\n" -"Last-Translator: Javier Sepulveda \n" +"PO-Revision-Date: 2024-01-12 20:30+0000\n" +"Last-Translator: Sebastian Marchano \n" "Language-Team: Spanish \n" "Language: es\n" @@ -26,7 +26,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.13.1\n" +"X-Generator: Weblate 5.2.1\n" #: src/components/modal/index.tsx:71 #, c-format @@ -41,7 +41,7 @@ msgstr "%1$s" #: src/components/modal/index.tsx:84 #, c-format msgid "Close" -msgstr "" +msgstr "Cerrar" #: src/components/modal/index.tsx:124 #, c-format @@ -165,7 +165,7 @@ msgstr "Instancias" #: src/paths/admin/list/TableActive.tsx:93 #, c-format msgid "Delete" -msgstr "Eliminar" +msgstr "Borrar" #: src/paths/admin/list/TableActive.tsx:99 #, c-format @@ -558,9 +558,9 @@ msgid "required" msgstr "requerido" #: src/paths/instance/orders/create/CreatePage.tsx:157 -#, fuzzy, c-format +#, c-format msgid "not valid" -msgstr "no es un json válido" +msgstr "no válido" #: src/paths/instance/orders/create/CreatePage.tsx:159 #, c-format @@ -2338,22 +2338,22 @@ msgstr "Esta no es una dirección de Ethereum válida." #: src/components/form/InputPaytoForm.tsx:118 #, c-format msgid "IBAN numbers usually have more that 4 digits" -msgstr "Números IBAN usualmente tienen más de 4 dígitos" +msgstr "Los números IBAN usualmente tienen mas de 4 digitos" #: src/components/form/InputPaytoForm.tsx:120 #, c-format msgid "IBAN numbers usually have less that 34 digits" -msgstr "Número IBAN usualmente tienen menos de 34 dígitos" +msgstr "Los números IBAN usualmente tienen menos de 34 digitos" #: src/components/form/InputPaytoForm.tsx:128 #, c-format msgid "IBAN country code not found" -msgstr "Código IBAN de país no encontrado" +msgstr "Código de pais de IBAN no encontrado" #: src/components/form/InputPaytoForm.tsx:153 #, c-format msgid "IBAN number is not valid, checksum is wrong" -msgstr "Número IBAN no es válido, la suma de verificación es incorrecta" +msgstr "El número IBAN no es válido, falló la verificación" #: src/components/form/InputPaytoForm.tsx:248 #, c-format @@ -2460,7 +2460,7 @@ msgstr "" #: src/components/instance/DefaultInstanceFormFields.tsx:64 #, c-format msgid "Email" -msgstr "" +msgstr "Correo eletrónico" #: src/components/instance/DefaultInstanceFormFields.tsx:65 #, c-format -- cgit v1.2.3 From 68f3bcdc6cece62176849ab065e82630ebc4deae Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 14 Jan 2024 18:29:42 -0300 Subject: Fixes #8084 updating the reference state creates an invalid duration value which breaks the component --- .../src/paths/admin/create/CreatePage.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx index d13b7e929..f95beba19 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/CreatePage.tsx @@ -118,21 +118,23 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode { const submit = (): Promise => { // use conversion instead of this - const newToken = value.auth_token; - value.auth_token = undefined; - value.auth = newToken === null || newToken === undefined + const newValue = structuredClone(value); + + const newToken = newValue.auth_token; + newValue.auth_token = undefined; + newValue.auth = newToken === null || newToken === undefined ? { method: "external" } : { method: "token", token: `secret-token:${newToken}` }; - if (!value.address) value.address = {}; - if (!value.jurisdiction) value.jurisdiction = {}; + if (!newValue.address) newValue.address = {}; + if (!newValue.jurisdiction) newValue.jurisdiction = {}; // remove above use conversion // schema.validateSync(value, { abortEarly: false }) - value.default_pay_delay = Duration.toTalerProtocolDuration(value.default_pay_delay!) as any - value.default_wire_transfer_delay = Duration.toTalerProtocolDuration(value.default_wire_transfer_delay!) as any + newValue.default_pay_delay = Duration.toTalerProtocolDuration(newValue.default_pay_delay!) as any + newValue.default_wire_transfer_delay = Duration.toTalerProtocolDuration(newValue.default_wire_transfer_delay!) as any // delete value.default_pay_delay; // delete value.default_wire_transfer_delay; - return onCreate(value as any as MerchantBackend.Instances.InstanceConfigurationMessage); + return onCreate(newValue as any as MerchantBackend.Instances.InstanceConfigurationMessage); }; function updateToken(token: string | null) { -- cgit v1.2.3 From 421b5c0acfa310fcb7f1893bf81e38f2876e1cbf Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 18 Jan 2024 16:16:21 -0300 Subject: fix templates --- .../merchant-backoffice-ui/src/Application.tsx | 6 +- .../src/ApplicationReadyRoutes.tsx | 5 +- .../merchant-backoffice-ui/src/InstanceRoutes.tsx | 20 +- .../src/components/form/InputDuration.tsx | 3 + .../instance/otp_devices/create/CreatePage.tsx | 9 +- .../paths/instance/templates/create/CreatePage.tsx | 190 ++++++++++++------- .../src/paths/instance/templates/list/index.tsx | 2 +- .../paths/instance/templates/update/UpdatePage.tsx | 205 ++++++++++++++------- 8 files changed, 284 insertions(+), 156 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx index e832d3107..0c509ef45 100644 --- a/packages/merchant-backoffice-ui/src/Application.tsx +++ b/packages/merchant-backoffice-ui/src/Application.tsx @@ -19,14 +19,16 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { HttpStatusCode, LibtoolVersion } from "@gnu-taler/taler-util"; +import { HttpStatusCode, LibtoolVersion, TranslatedString } from "@gnu-taler/taler-util"; import { ErrorType, TranslationProvider, + notifyError, + notifyException, useTranslationContext, } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; -import { useMemo } from "preact/hooks"; +import { useEffect, useErrorBoundary, useMemo } from "preact/hooks"; import { ApplicationReadyRoutes } from "./ApplicationReadyRoutes.js"; import { Loading } from "./components/exception/loading.js"; import { diff --git a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx index 47177e97e..3dc34d1a9 100644 --- a/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/ApplicationReadyRoutes.tsx @@ -18,12 +18,12 @@ * * @author Sebastian Javier Marchano (sebasjm) */ -import { HttpStatusCode } from "@gnu-taler/taler-util"; +import { HttpStatusCode, TranslatedString } from "@gnu-taler/taler-util"; import { ErrorType, useTranslationContext } from "@gnu-taler/web-util/browser"; import { createHashHistory } from "history"; import { Fragment, VNode, h } from "preact"; import { Route, Router, route } from "preact-router"; -import { useState } from "preact/hooks"; +import { useEffect, useErrorBoundary, useState } from "preact/hooks"; import { InstanceRoutes } from "./InstanceRoutes.js"; import { NotConnectedAppMenu, @@ -54,7 +54,6 @@ export function ApplicationReadyRoutes(): VNode { updateToken(token) setUnauthorized(false) } - const result = useBackendInstancesTestForAdmin(); const clearTokenAndGoToRoot = () => { diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx index c3c20bcc4..b5680eabb 100644 --- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx @@ -23,11 +23,12 @@ import { useTranslationContext, HttpError, ErrorType, + GlobalNotificationsBanner, } from "@gnu-taler/web-util/browser"; import { format } from "date-fns"; import { Fragment, FunctionComponent, h, VNode } from "preact"; import { Route, route, Router } from "preact-router"; -import { useCallback, useEffect, useMemo, useState } from "preact/hooks"; +import { useCallback, useEffect, useErrorBoundary, useMemo, useState } from "preact/hooks"; import { Loading } from "./components/exception/loading.js"; import { Menu, NotificationCard } from "./components/menu/index.js"; import { useBackendContext } from "./context/backend.js"; @@ -77,6 +78,7 @@ import { Notification } from "./utils/types.js"; import { LoginToken, MerchantBackend } from "./declaration.js"; import { Settings } from "./paths/settings/index.js"; import { dateFormatForSettings, useSettings } from "./hooks/useSettings.js"; +import { TranslatedString } from "@gnu-taler/taler-util"; export enum InstancePaths { error = "/error", @@ -151,7 +153,7 @@ export function InstanceRoutes({ const [token, updateToken] = useBackendInstanceToken(id); const { i18n } = useTranslationContext(); - type GlobalNotifState = (Notification & { to: string }) | undefined; + type GlobalNotifState = (Notification & { to: string | undefined }) | undefined; const [globalNotification, setGlobalNotification] = useState(undefined); @@ -163,9 +165,8 @@ export function InstanceRoutes({ } onLoginPass() }; - // const updateLoginStatus = (url: string, token?: string) => { - // changeToken(token); - // }; + + const [error] = useErrorBoundary(); const value = useMemo( () => ({ id, token, admin, changeToken }), @@ -264,6 +265,15 @@ export function InstanceRoutes({ /> + {error && + + {(error instanceof Error ? error.stack : String(error)) as TranslatedString} + + }} /> + } { diff --git a/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx b/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx index 7aa2703a4..c9226ad69 100644 --- a/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx +++ b/packages/merchant-backoffice-ui/src/components/form/InputDuration.tsx @@ -58,6 +58,9 @@ export function InputDuration({ } else if (value.d_ms === "forever") { strValue = i18n.str`forever`; } else { + if (value.d_ms === undefined) { + throw Error(`assertion error: duration should have a d_ms but got '${JSON.stringify(value)}'`) + } strValue = formatDuration( intervalToDuration({ start: 0, end: value.d_ms }), { diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx index 5f1ae26a3..94424132b 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx @@ -28,16 +28,11 @@ import { FormProvider, } from "../../../../components/form/FormProvider.js"; import { Input } from "../../../../components/form/Input.js"; -import { InputCurrency } from "../../../../components/form/InputCurrency.js"; -import { InputDuration } from "../../../../components/form/InputDuration.js"; -import { InputNumber } from "../../../../components/form/InputNumber.js"; -import { useBackendContext } from "../../../../context/backend.js"; -import { MerchantBackend } from "../../../../declaration.js"; import { InputSelector } from "../../../../components/form/InputSelector.js"; import { InputWithAddon } from "../../../../components/form/InputWithAddon.js"; +import { useBackendContext } from "../../../../context/backend.js"; +import { MerchantBackend } from "../../../../declaration.js"; import { isBase32RFC3548Charset, randomBase32Key } from "../../../../utils/crypto.js"; -import { QR } from "../../../../components/exception/QR.js"; -import { useInstanceContext } from "../../../../context/instance.js"; type Entity = MerchantBackend.OTP.OtpDeviceAddDetails; diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx index 947f3572c..a2c0c9dfb 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx @@ -20,8 +20,11 @@ */ import { + AmountString, Amounts, + Duration, MerchantTemplateContractDetails, + assertUnreachable, } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; @@ -50,10 +53,20 @@ enum Steps { NON_FIXED, } -type Entity = MerchantBackend.Template.TemplateAddDetails & { type: Steps }; +// type Entity = MerchantBackend.Template.TemplateAddDetails & { type: Steps }; +type Entity = { + id?: string, + description?: string, + otpId?: string, + summary?: string, + amount?: AmountString, + minimum_age?: number, + pay_duration?: Duration, + type: Steps, +}; interface Props { - onCreate: (d: Entity) => Promise; + onCreate: (d: MerchantBackend.Template.TemplateAddDetails) => Promise; onBack?: () => void; } @@ -63,57 +76,51 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { const devices = useInstanceOtpDevices() const [state, setState] = useState>({ - template_contract: { - minimum_age: 0, - pay_duration: { - d_us: 1000 * 1000 * 60 * 30, //30 min - }, + minimum_age: 0, + pay_duration: { + d_ms: 1000 * 60 * 30, //30 min }, type: Steps.NON_FIXED, }); - const parsedPrice = !state.template_contract?.amount + const parsedPrice = !state.amount ? undefined - : Amounts.parse(state.template_contract?.amount); + : Amounts.parse(state.amount); const errors: FormErrors = { - template_id: !state.template_id + id: !state.id ? i18n.str`should not be empty` - : !/[a-zA-Z0-9]*/.test(state.template_id) + : !/[a-zA-Z0-9]*/.test(state.id) ? i18n.str`no valid. only characters and numbers` : undefined, - template_description: !state.template_description + description: !state.description ? i18n.str`should not be empty` : undefined, - template_contract: !state.template_contract + amount: !(state.type === Steps.FIXED_PRICE || state.type === Steps.BOTH_FIXED) ? undefined - : undefinedIfEmpty({ - amount: !(state.type === Steps.FIXED_PRICE || state.type === Steps.BOTH_FIXED) - ? undefined - : !state.template_contract?.amount - ? i18n.str`required` - : !parsedPrice - ? i18n.str`not valid` - : Amounts.isZero(parsedPrice) - ? i18n.str`must be greater than 0` - : undefined, - summary: !(state.type === Steps.FIXED_SUMMARY || state.type === Steps.BOTH_FIXED) - ? undefined - : !state.template_contract?.summary - ? i18n.str`required` + : !state.amount + ? i18n.str`required` + : !parsedPrice + ? i18n.str`not valid` + : Amounts.isZero(parsedPrice) + ? i18n.str`must be greater than 0` : undefined, - minimum_age: - state.template_contract.minimum_age < 0 - ? i18n.str`should be greater that 0` - : undefined, - pay_duration: !state.template_contract.pay_duration - ? i18n.str`can't be empty` - : state.template_contract.pay_duration.d_us === "forever" - ? undefined - : state.template_contract.pay_duration.d_us < 1000 * 1000 //less than one second - ? i18n.str`to short` - : undefined, - } as Partial), + summary: !(state.type === Steps.FIXED_SUMMARY || state.type === Steps.BOTH_FIXED) + ? undefined + : !state.summary + ? i18n.str`required` + : undefined, + minimum_age: + state.minimum_age && state.minimum_age < 0 + ? i18n.str`should be greater that 0` + : undefined, + pay_duration: !state.pay_duration + ? i18n.str`can't be empty` + : state.pay_duration.d_ms === "forever" + ? undefined + : state.pay_duration.d_ms < 1000 //less than one second + ? i18n.str`to short` + : undefined, }; const hasErrors = Object.keys(errors).some( @@ -121,21 +128,56 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { ); const submitForm = () => { - if (hasErrors) return Promise.reject(); - if (state.template_contract) { - if (state.type === Steps.NON_FIXED) { - delete state.template_contract.amount; - delete state.template_contract.summary; - } else if (state.type === Steps.FIXED_SUMMARY) { - delete state.template_contract.amount; - } else if (state.type === Steps.FIXED_PRICE) { - delete state.template_contract.summary; - } - } - delete state.type - return onCreate(state as any); - }; - + if (hasErrors || state.type === undefined) return Promise.reject(); + switch (state.type) { + case Steps.FIXED_PRICE: return onCreate({ + template_id: state.id!, + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + amount: state.amount!, + // summary: state.summary, + }, + otp_id: state.otpId! + }) + case Steps.FIXED_SUMMARY: return onCreate({ + template_id: state.id!, + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + // amount: state.amount!, + summary: state.summary, + }, + otp_id: state.otpId!, + }) + case Steps.NON_FIXED: return onCreate({ + template_id: state.id!, + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + // amount: state.amount!, + // summary: state.summary, + }, + otp_id: state.otpId!, + }) + case Steps.BOTH_FIXED: return onCreate({ + template_id: state.id!, + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + amount: state.amount!, + summary: state.summary, + }, + otp_id: state.otpId!, + }) + default: assertUnreachable(state.type) + // return onCreate(state); + }; + } const deviceList = !devices.ok ? [] : devices.data.otp_devices return ( @@ -150,21 +192,22 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { errors={errors} > - name="template_id" - help={`${backendURL}/templates/${state.template_id ?? ""}`} + name="id" + help={`${backendURL}/templates/${state.id ?? ""}`} label={i18n.str`Identifier`} tooltip={i18n.str`Name of the template in URLs.`} /> - name="template_description" + name="description" label={i18n.str`Description`} help="" tooltip={i18n.str`Describe what this template stands for`} /> - name="type" label={i18n.str`Type`} help={(() => { + if (state.type === undefined) return "" switch (state.type) { case Steps.NON_FIXED: return i18n.str`User will be able to input price and summary before payment.` case Steps.FIXED_PRICE: return i18n.str`User will be able to add a summary before payment.` @@ -189,41 +232,52 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { }} /> {state.type === Steps.BOTH_FIXED || state.type === Steps.FIXED_SUMMARY ? - + name="summary" inputType="multiline" label={i18n.str`Fixed summary`} tooltip={i18n.str`If specified, this template will create order with the same summary`} /> : undefined} {state.type === Steps.BOTH_FIXED || state.type === Steps.FIXED_PRICE ? - + name="amount" label={i18n.str`Fixed price`} tooltip={i18n.str`If specified, this template will create order with the same price`} /> : undefined} - + name="minimum_age" label={i18n.str`Minimum age`} help="" tooltip={i18n.str`Is this contract restricted to some age?`} /> - + name="pay_duration" label={i18n.str`Payment timeout`} help="" tooltip={i18n.str`How much time has the customer to complete the payment once the order was created.`} /> - name="otp_id" + name="otpId" label={i18n.str`OTP device`} readonly + side={} tooltip={i18n.str`Use to verify transaction in offline mode.`} /> setState((v) => ({ ...v, otp_id: p?.id }))} + onChange={(p) => setState((v) => ({ ...v, otpId: p?.id }))} list={deviceList.map(e => ({ description: e.device_description, id: e.otp_device_id diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx index b9767442f..2d50e3924 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/list/index.tsx @@ -86,7 +86,7 @@ export default function ListTemplates({ Promise; + onUpdate: (d: MerchantBackend.Template.TemplatePatchDetails) => Promise; onBack?: () => void; - template: Entity; + template: MerchantBackend.Template.TemplateDetails; } export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { @@ -61,53 +71,59 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { const { url: backendURL } = useBackendContext() const intialStep = - template.template_contract?.amount === undefined && template.template_contract?.summary === undefined + template.template_contract.amount === undefined && template.template_contract.summary === undefined ? Steps.NON_FIXED - : template.template_contract?.summary === undefined + : template.template_contract.summary === undefined ? Steps.FIXED_PRICE - : template.template_contract?.amount === undefined + : template.template_contract.amount === undefined ? Steps.FIXED_SUMMARY : Steps.BOTH_FIXED; - const [state, setState] = useState>({ ...template, type: intialStep }); + const [state, setState] = useState>({ + amount: template.template_contract.amount as AmountString | undefined, + description: template.template_description, + minimum_age: template.template_contract.minimum_age, + otpId: template.otp_id, + pay_duration: template.template_contract.pay_duration ? Duration.fromTalerProtocolDuration(template.template_contract.pay_duration) : undefined, + summary: template.template_contract.summary, + type: intialStep, + }); + const devices = useInstanceOtpDevices() + const deviceList = !devices.ok ? [] : devices.data.otp_devices - const parsedPrice = !state.template_contract?.amount + const parsedPrice = !state.amount ? undefined - : Amounts.parse(state.template_contract?.amount); + : Amounts.parse(state.amount); const errors: FormErrors = { - template_description: !state.template_description + description: !state.description ? i18n.str`should not be empty` : undefined, - template_contract: !state.template_contract + amount: !(state.type === Steps.FIXED_PRICE || state.type === Steps.BOTH_FIXED) ? undefined - : undefinedIfEmpty({ - amount: !(state.type === Steps.FIXED_PRICE || state.type === Steps.BOTH_FIXED) - ? undefined - : !state.template_contract?.amount - ? i18n.str`required` - : !parsedPrice - ? i18n.str`not valid` - : Amounts.isZero(parsedPrice) - ? i18n.str`must be greater than 0` - : undefined, - summary: !(state.type === Steps.FIXED_SUMMARY || state.type === Steps.BOTH_FIXED) - ? undefined - : !state.template_contract?.summary - ? i18n.str`required` - : undefined, - minimum_age: - state.template_contract.minimum_age < 0 - ? i18n.str`should be greater that 0` + : !state.amount + ? i18n.str`required` + : !parsedPrice + ? i18n.str`not valid` + : Amounts.isZero(parsedPrice) + ? i18n.str`must be greater than 0` : undefined, - pay_duration: !state.template_contract.pay_duration - ? i18n.str`can't be empty` - : state.template_contract.pay_duration.d_us === "forever" - ? undefined - : state.template_contract.pay_duration.d_us < 1000 * 1000 // less than one second - ? i18n.str`to short` - : undefined, - } as Partial), + summary: !(state.type === Steps.FIXED_SUMMARY || state.type === Steps.BOTH_FIXED) + ? undefined + : !state.summary + ? i18n.str`required` + : undefined, + minimum_age: + state.minimum_age && state.minimum_age < 0 + ? i18n.str`should be greater that 0` + : undefined, + pay_duration: !state.pay_duration + ? i18n.str`can't be empty` + : state.pay_duration.d_ms === "forever" + ? undefined + : state.pay_duration.d_ms < 1000 // less than one second + ? i18n.str`to short` + : undefined, }; const hasErrors = Object.keys(errors).some( @@ -115,19 +131,50 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { ); const submitForm = () => { - if (hasErrors) return Promise.reject(); - if (state.template_contract) { - if (state.type === Steps.NON_FIXED) { - delete state.template_contract.amount; - delete state.template_contract.summary; - } else if (state.type === Steps.FIXED_SUMMARY) { - delete state.template_contract.amount; - } else if (state.type === Steps.FIXED_PRICE) { - delete state.template_contract.summary; - } + if (hasErrors || state.type === undefined) return Promise.reject(); + switch (state.type) { + case Steps.FIXED_PRICE: return onUpdate({ + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + amount: state.amount!, + // summary: state.summary, + }, + otp_id: state.otpId! + }) + case Steps.FIXED_SUMMARY: return onUpdate({ + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + // amount: state.amount!, + summary: state.summary, + }, + otp_id: state.otpId!, + }) + case Steps.NON_FIXED: return onUpdate({ + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + // amount: state.amount!, + // summary: state.summary, + }, + otp_id: state.otpId!, + }) + case Steps.BOTH_FIXED: return onUpdate({ + template_description: state.description!, + template_contract: { + minimum_age: state.minimum_age!, + pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!), + amount: state.amount!, + summary: state.summary, + }, + otp_id: state.otpId!, + }) + default: assertUnreachable(state.type) } - delete state.type - return onUpdate(state as any); }; @@ -140,7 +187,7 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode {
- {backendURL}/templates/{template.id} + {backendURL}/templates/{template.otp_id}
@@ -157,16 +204,9 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { valueHandler={setState} errors={errors} > - - name="id" - addonBefore={`templates/`} - readonly - label={i18n.str`Identifier`} - tooltip={i18n.str`Name of the template in URLs.`} - /> - name="template_description" + name="description" label={i18n.str`Description`} help="" tooltip={i18n.str`Describe what this template stands for`} @@ -199,32 +239,57 @@ export function UpdatePage({ template, onUpdate, onBack }: Props): VNode { }} /> {state.type === Steps.BOTH_FIXED || state.type === Steps.FIXED_SUMMARY ? - + name="summary" inputType="multiline" label={i18n.str`Fixed summary`} tooltip={i18n.str`If specified, this template will create order with the same summary`} /> : undefined} {state.type === Steps.BOTH_FIXED || state.type === Steps.FIXED_PRICE ? - + name="amount" label={i18n.str`Fixed price`} tooltip={i18n.str`If specified, this template will create order with the same price`} /> : undefined} - + name="minimum_age" label={i18n.str`Minimum age`} help="" tooltip={i18n.str`Is this contract restricted to some age?`} /> - + name="pay_duration" label={i18n.str`Payment timeout`} help="" tooltip={i18n.str`How much time has the customer to complete the payment once the order was created.`} /> + + name="otpId" + label={i18n.str`OTP device`} + readonly + side={} + tooltip={i18n.str`Use to verify transaction in offline mode.`} + /> + setState((v) => ({ ...v, otpId: p?.id }))} + list={deviceList.map(e => ({ + description: e.device_description, + id: e.otp_device_id + }))} + />
-- cgit v1.2.3 From e9c6b105d18f142cf4d4b203e734513df1e5021c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 18 Jan 2024 17:50:57 -0300 Subject: update config from merchant --- .../merchant-backoffice-ui/src/Application.tsx | 8 ++--- .../merchant-backoffice-ui/src/context/config.ts | 9 ++--- .../merchant-backoffice-ui/src/declaration.d.ts | 40 +++++++++++++++++++++- 3 files changed, 46 insertions(+), 11 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx index 0c509ef45..27ae26de5 100644 --- a/packages/merchant-backoffice-ui/src/Application.tsx +++ b/packages/merchant-backoffice-ui/src/Application.tsx @@ -61,10 +61,10 @@ function ApplicationStatusRoutes(): VNode { const result = useBackendConfig(); const { i18n } = useTranslationContext(); - const { currency, version } = result.ok && result.data + const configData = result.ok && result.data ? result.data - : { currency: "unknown", version: "unknown" }; - const ctx = useMemo(() => ({ currency, version }), [currency, version]); + : undefined; + const ctx = useMemo(() => (configData), [configData]); if (!result.ok) { if (result.loading) return ; @@ -159,7 +159,7 @@ function ApplicationStatusRoutes(): VNode { return (
- +
diff --git a/packages/merchant-backoffice-ui/src/context/config.ts b/packages/merchant-backoffice-ui/src/context/config.ts index 040bd0341..9fe655301 100644 --- a/packages/merchant-backoffice-ui/src/context/config.ts +++ b/packages/merchant-backoffice-ui/src/context/config.ts @@ -21,12 +21,9 @@ import { createContext } from "preact"; import { useContext } from "preact/hooks"; +import { MerchantBackend } from "../declaration.js"; -interface Type { - currency: string; - version: string; -} -const Context = createContext(null!); +const Context = createContext(null!); export const ConfigContextProvider = Context.Provider; -export const useConfigContext = (): Type => useContext(Context); +export const useConfigContext = (): MerchantBackend.VersionResponse => useContext(Context); diff --git a/packages/merchant-backoffice-ui/src/declaration.d.ts b/packages/merchant-backoffice-ui/src/declaration.d.ts index f99dd1867..38ab9d254 100644 --- a/packages/merchant-backoffice-ui/src/declaration.d.ts +++ b/packages/merchant-backoffice-ui/src/declaration.d.ts @@ -274,8 +274,46 @@ export namespace MerchantBackend { // Name of the protocol. name: "taler-merchant"; - // Currency supported by this backend. + // Default (!) currency supported by this backend. + // This is the currency that the backend should + // suggest by default to the user when entering + // amounts. See currencies for a list of + // supported currencies and how to render them. currency: string; + + // How services should render currencies supported + // by this backend. Maps + // currency codes (e.g. "EUR" or "KUDOS") to + // the respective currency specification. + // All currencies in this map are supported by + // the backend. Note that the actual currency + // specifications are a *hint* for applications + // that would like *advice* on how to render amounts. + // Applications *may* ignore the currency specification + // if they know how to render currencies that they are + // used with. + currencies: { currency: CurrencySpecification }; + + // Array of exchanges trusted by the merchant. + // Since protocol v6. + exchanges: ExchangeConfigInfo[]; + } + + interface ExchangeConfigInfo { + + // Base URL of the exchange REST API. + base_url: string; + + // Currency for which the merchant is configured + // to trust the exchange. + // May not be the one the exchange actually uses, + // but is the only one we would trust this exchange for. + currency: string; + + // Offline master public key of the exchange. The + // /keys data must be signed with this public + // key for us to trust it. + master_pub: EddsaPublicKey; } interface Location { // Nation with its own government. -- cgit v1.2.3 From e8d82efd3947558f23ccff702e997b2bc8783d41 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 19 Jan 2024 10:29:35 -0300 Subject: fix: missing changes in merchant --- .../merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx | 5 +++++ packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx | 5 +++++ .../merchant-backoffice-ui/src/paths/instance/details/stories.tsx | 5 +++++ .../src/paths/instance/templates/update/index.tsx | 2 +- packages/merchant-backoffice-ui/src/paths/settings/index.tsx | 2 +- 5 files changed, 17 insertions(+), 2 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx index 91b6b4b56..93ada2374 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/Create.stories.tsx @@ -41,6 +41,11 @@ function createExample( value={{ currency: "ARS", version: "1", + currencies: { + currency: "TESTKUDOS" + }, + exchanges: [], + name: "taler-merchant" }} > diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx index 0012f9b9b..0161e9dc1 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/stories.tsx @@ -41,6 +41,11 @@ function createExample( value={{ currency: "TESTKUDOS", version: "1", + currencies: { + currency: "TESTKUDOS" + }, + exchanges: [], + name: "taler-merchant" }} > diff --git a/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx b/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx index 367fabce2..d7f61a8a5 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/details/stories.tsx @@ -41,6 +41,11 @@ function createExample( value={{ currency: "TESTKUDOS", version: "1", + currencies: { + currency: "TESTKUDOS" + }, + exchanges: [], + name: "taler-merchant" }} > diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx index 3adca45db..fb9b1d8aa 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/update/index.tsx @@ -80,7 +80,7 @@ export default function UpdateTemplate({ { return updateTemplate(tid, data) diff --git a/packages/merchant-backoffice-ui/src/paths/settings/index.tsx b/packages/merchant-backoffice-ui/src/paths/settings/index.tsx index 87bd2fa39..8e69537ec 100644 --- a/packages/merchant-backoffice-ui/src/paths/settings/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/settings/index.tsx @@ -16,7 +16,7 @@ function getBrowserLang(): string | undefined { export function Settings({ onClose }: { onClose?: () => void }): VNode { const { i18n } = useTranslationContext() const borwserLang = getBrowserLang() - const { update } = useLang() + const { update } = useLang(undefined, {}) const [value, updateValue] = useSettings() const errors: FormErrors = { -- cgit v1.2.3 From a324ba367a75fc790f9456e479e7bbf22abe00aa Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 24 Jan 2024 17:48:00 -0300 Subject: fixes #8265 --- packages/merchant-backoffice-ui/src/Application.tsx | 2 +- .../src/paths/instance/orders/create/CreatePage.tsx | 2 +- .../src/paths/instance/token/DetailPage.tsx | 12 ++++++------ .../src/paths/instance/webhooks/create/CreatePage.tsx | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx index 27ae26de5..e78a6fc0b 100644 --- a/packages/merchant-backoffice-ui/src/Application.tsx +++ b/packages/merchant-backoffice-ui/src/Application.tsx @@ -94,7 +94,7 @@ function ApplicationStatusRoutes(): VNode {
- + {!hasToken && { if (hasToken) { - const ot = `secret-token:${form.old_token}` as AccessToken; - onClearToken(ot) + const oldToken = `secret-token:${form.old_token}` as AccessToken; + onClearToken(oldToken) } else { onClearToken(undefined) } diff --git a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx index 434d69412..bfa2a883e 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/webhooks/create/CreatePage.tsx @@ -120,7 +120,7 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {

The text below support mustache template engine. Any string between

{{
and
}}
will - be replaced with replaced with the value of the correspoding variable. + be replaced with replaced with the value of the corresponding variable.

For example

{{contract_terms.amount}}
will be replaced -- cgit v1.2.3 From 9b48c0d32fc1289fa1a7da8fb269e4f412350edb Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 29 Jan 2024 13:55:33 -0300 Subject: fix #8185 --- .../merchant-backoffice-ui/src/paths/login/index.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/paths/login/index.tsx b/packages/merchant-backoffice-ui/src/paths/login/index.tsx index 1c98b7c9b..6c33dd06e 100644 --- a/packages/merchant-backoffice-ui/src/paths/login/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/login/index.tsx @@ -20,12 +20,14 @@ */ import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { ComponentChildren, h, VNode } from "preact"; +import { ComponentChildren, Fragment, h, VNode } from "preact"; import { useCallback, useEffect, useState } from "preact/hooks"; import { useBackendContext } from "../../context/backend.js"; import { useInstanceContext } from "../../context/instance.js"; import { AccessToken, LoginToken } from "../../declaration.js"; import { useCredentialsChecker } from "../../hooks/backend.js"; +import { NotificationCard } from "../../components/menu/index.js"; +import { Notification } from "../../utils/types.js"; interface Props { onConfirm: (token: LoginToken | undefined) => void; @@ -40,6 +42,8 @@ export function LoginPage({ onConfirm }: Props): VNode { const { admin, id } = useInstanceContext(); const { requestNewLoginToken } = useCredentialsChecker(); const [token, setToken] = useState(""); + const [notif, setNotif] = useState(undefined); + const { i18n } = useTranslationContext(); @@ -53,6 +57,10 @@ export function LoginPage({ onConfirm }: Props): VNode { onConfirm({ token, expiration }); } else { onConfirm(undefined); + setNotif({ + message: "Your password is incorrect", + type: "ERROR", + }); } }, [id, token]) @@ -71,6 +79,7 @@ export function LoginPage({ onConfirm }: Props): VNode { class="modal-card-body" style={{ border: "1px solid", borderTop: 0, borderBottom: 0 }} > +

Need the access token for the instance.

@@ -120,7 +129,8 @@ export function LoginPage({ onConfirm }: Props): VNode {
) } - return ( + return ( +
+

Confirm +

+ + ); } -- cgit v1.2.3 From f14c643f4a66fc56199eb4aba66a7d5429911db7 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 30 Jan 2024 23:09:52 +0100 Subject: harness,util,others: complete otp integration test, move rfc3548 to taler-util --- .../instance/otp_devices/create/CreatePage.tsx | 27 ++++++---- .../instance/otp_devices/update/UpdatePage.tsx | 47 +++++++++++------ .../merchant-backoffice-ui/src/utils/crypto.ts | 61 ---------------------- 3 files changed, 48 insertions(+), 87 deletions(-) delete mode 100644 packages/merchant-backoffice-ui/src/utils/crypto.ts (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx index 94424132b..b709b216c 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatePage.tsx @@ -19,8 +19,12 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { + isRfc3548Base32Charset, + randomRfc3548Base32Key, +} from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { Fragment, h, VNode } from "preact"; +import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; import { @@ -32,7 +36,6 @@ import { InputSelector } from "../../../../components/form/InputSelector.js"; import { InputWithAddon } from "../../../../components/form/InputWithAddon.js"; import { useBackendContext } from "../../../../context/backend.js"; import { MerchantBackend } from "../../../../declaration.js"; -import { isBase32RFC3548Charset, randomBase32Key } from "../../../../utils/crypto.js"; type Entity = MerchantBackend.OTP.OtpDeviceAddDetails; @@ -44,7 +47,6 @@ interface Props { const algorithms = [0, 1, 2]; const algorithmsNames = ["off", "30s 8d TOTP-SHA1", "30s 8d eTOTP-SHA1"]; - export function CreatePage({ onCreate, onBack }: Props): VNode { const { i18n } = useTranslationContext(); const backend = useBackendContext(); @@ -54,22 +56,24 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { const [showKey, setShowKey] = useState(false); const errors: FormErrors = { - otp_device_id: !state.otp_device_id ? i18n.str`required` + otp_device_id: !state.otp_device_id + ? i18n.str`required` : !/[a-zA-Z0-9]*/.test(state.otp_device_id) ? i18n.str`no valid. only characters and numbers` : undefined, otp_algorithm: !state.otp_algorithm ? i18n.str`required` : undefined, - otp_key: !state.otp_key ? i18n.str`required` : - !isBase32RFC3548Charset(state.otp_key) + otp_key: !state.otp_key + ? i18n.str`required` + : !isRfc3548Base32Charset(state.otp_key) ? i18n.str`just letters and numbers from 2 to 7` : state.otp_key.length !== 32 ? i18n.str`size of the key should be 32` : undefined, - otp_device_description: !state.otp_device_description ? i18n.str`required` + otp_device_description: !state.otp_device_description + ? i18n.str`required` : !/[a-zA-Z0-9]*/.test(state.otp_device_description) ? i18n.str`no valid. only characters and numbers` : undefined, - }; const hasErrors = Object.keys(errors).some( @@ -124,7 +128,7 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { setShowKey(!showKey); }} addonAfter={ - + {showKey ? ( ) : ( @@ -137,7 +141,10 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { data-tooltip={i18n.str`generate random secret key`} class="button is-info mr-3" onClick={(e) => { - setState((s) => ({ ...s, otp_key: randomBase32Key() })); + setState((s) => ({ + ...s, + otp_key: randomRfc3548Base32Key(), + })); }} > random diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/UpdatePage.tsx index b82807cc7..85bb272aa 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/UpdatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/UpdatePage.tsx @@ -19,6 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { randomRfc3548Base32Key } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; @@ -28,10 +29,9 @@ import { FormProvider, } from "../../../../components/form/FormProvider.js"; import { Input } from "../../../../components/form/Input.js"; -import { MerchantBackend, WithId } from "../../../../declaration.js"; import { InputSelector } from "../../../../components/form/InputSelector.js"; import { InputWithAddon } from "../../../../components/form/InputWithAddon.js"; -import { randomBase32Key } from "../../../../utils/crypto.js"; +import { MerchantBackend, WithId } from "../../../../declaration.js"; type Entity = MerchantBackend.OTP.OtpDevicePatchDetails & WithId; @@ -48,8 +48,7 @@ export function UpdatePage({ device, onUpdate, onBack }: Props): VNode { const [state, setState] = useState>(device); const [showKey, setShowKey] = useState(false); - const errors: FormErrors = { - }; + const errors: FormErrors = {}; const hasErrors = Object.keys(errors).some( (k) => (errors as any)[k] !== undefined, @@ -106,16 +105,23 @@ export function UpdatePage({ device, onUpdate, onBack }: Props): VNode { label={i18n.str`Device key`} readonly={state.otp_key === undefined} inputType={showKey ? "text" : "password"} - help={state.otp_key === undefined ? "Not modified" : "Be sure to be very hard to guess or use the random generator"} + help={ + state.otp_key === undefined + ? "Not modified" + : "Be sure to be very hard to guess or use the random generator" + } tooltip={i18n.str`Your device need to have exactly the same value`} fromStr={(v) => v.toUpperCase()} addonAfterAction={() => { setShowKey(!showKey); }} addonAfter={ - { - setShowKey(!showKey); - }}> + { + setShowKey(!showKey); + }} + > {showKey ? ( ) : ( @@ -124,25 +130,34 @@ export function UpdatePage({ device, onUpdate, onBack }: Props): VNode { } side={ - state.otp_key === undefined ? : + state.otp_key === undefined ? ( + + ) : ( + ) } /> - ) : undefined} + ) : undefined}{" "} +
{onBack && ( diff --git a/packages/merchant-backoffice-ui/src/utils/crypto.ts b/packages/merchant-backoffice-ui/src/utils/crypto.ts deleted file mode 100644 index 27e6ade02..000000000 --- a/packages/merchant-backoffice-ui/src/utils/crypto.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -const encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; -// base32 RFC 3548 -function encodeBase32(data: ArrayBuffer) { - const dataBytes = new Uint8Array(data); - let sb = ""; - const size = data.byteLength; - let bitBuf = 0; - let numBits = 0; - let pos = 0; - while (pos < size || numBits > 0) { - if (pos < size && numBits < 5) { - const d = dataBytes[pos++]; - bitBuf = (bitBuf << 8) | d; - numBits += 8; - } - if (numBits < 5) { - // zero-padding - bitBuf = bitBuf << (5 - numBits); - numBits = 5; - } - const v = (bitBuf >>> (numBits - 5)) & 31; - sb += encTable[v]; - numBits -= 5; - } - return sb; -} - -export function isBase32RFC3548Charset(s: string): boolean { - for (let idx = 0; idx < s.length; idx++) { - const c = s.charAt(idx); - if (encTable.indexOf(c) === -1) return false; - } - return true; -} - -export function randomBase32Key(): string { - var buf = new Uint8Array(20); - window.crypto.getRandomValues(buf); - return encodeBase32(buf); -} -- cgit v1.2.3 From 6e370c3502a8e6474d4665eb42ae1bfdec3034a1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 9 Feb 2024 09:43:29 -0300 Subject: wip #8325 remove rewards --- .../merchant-backoffice-ui/src/InstanceRoutes.tsx | 39 --- .../src/components/menu/SideBar.tsx | 8 - .../merchant-backoffice-ui/src/hooks/backend.ts | 32 --- .../src/hooks/reserve.test.ts | 245 +--------------- .../merchant-backoffice-ui/src/hooks/reserves.ts | 89 +----- .../src/paths/instance/index.stories.ts | 1 - .../instance/reserves/create/Create.stories.tsx | 43 --- .../paths/instance/reserves/create/CreatePage.tsx | 277 ------------------ .../create/CreatedSuccessfully.stories.tsx | 120 -------- .../reserves/create/CreatedSuccessfully.tsx | 190 ------------ .../src/paths/instance/reserves/create/index.tsx | 71 ----- .../paths/instance/reserves/details/DetailPage.tsx | 266 ----------------- .../instance/reserves/details/Details.stories.tsx | 126 -------- .../paths/instance/reserves/details/RewardInfo.tsx | 88 ------ .../src/paths/instance/reserves/details/index.tsx | 68 ----- .../instance/reserves/list/AutorizeRewardModal.tsx | 124 -------- .../instance/reserves/list/CreatedSuccessfully.tsx | 102 ------- .../paths/instance/reserves/list/List.stories.tsx | 96 ------- .../src/paths/instance/reserves/list/Table.tsx | 320 --------------------- .../src/paths/instance/reserves/list/index.tsx | 171 ----------- .../merchant-backoffice-ui/src/schemas/index.ts | 21 -- 21 files changed, 3 insertions(+), 2494 deletions(-) delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/create/Create.stories.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.stories.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/details/Details.stories.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/details/RewardInfo.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/details/index.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeRewardModal.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/list/CreatedSuccessfully.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/list/List.stories.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx delete mode 100644 packages/merchant-backoffice-ui/src/paths/instance/reserves/list/index.tsx (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx index b5680eabb..a7fd3eb0f 100644 --- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx @@ -52,9 +52,6 @@ import ProductUpdatePage from "./paths/instance/products/update/index.js"; import BankAccountCreatePage from "./paths/instance/accounts/create/index.js"; import BankAccountListPage from "./paths/instance/accounts/list/index.js"; import BankAccountUpdatePage from "./paths/instance/accounts/update/index.js"; -import ReservesCreatePage from "./paths/instance/reserves/create/index.js"; -import ReservesDetailsPage from "./paths/instance/reserves/details/index.js"; -import ReservesListPage from "./paths/instance/reserves/list/index.js"; import TemplateCreatePage from "./paths/instance/templates/create/index.js"; import TemplateUsePage from "./paths/instance/templates/use/index.js"; import TemplateQrPage from "./paths/instance/templates/qr/index.js"; @@ -643,42 +640,6 @@ export function InstanceRoutes({ }} /> - {/** - * reserves pages - */} - { - route(InstancePaths.reserves_details.replace(":rid", id)); - }} - onCreate={() => { - route(InstancePaths.reserves_new); - }} - /> - { - route(InstancePaths.reserves_list); - }} - /> - { - route(InstancePaths.reserves_list); - }} - onBack={() => { - route(InstancePaths.reserves_list); - }} - /> {/** diff --git a/packages/merchant-backoffice-ui/src/components/menu/SideBar.tsx b/packages/merchant-backoffice-ui/src/components/menu/SideBar.tsx index cfc00148e..3146cf5e9 100644 --- a/packages/merchant-backoffice-ui/src/components/menu/SideBar.tsx +++ b/packages/merchant-backoffice-ui/src/components/menu/SideBar.tsx @@ -158,14 +158,6 @@ export function Sidebar({ -
  • - - - - - Reserves - -
  • diff --git a/packages/merchant-backoffice-ui/src/hooks/backend.ts b/packages/merchant-backoffice-ui/src/hooks/backend.ts index 8d99546a8..3a31fcf9b 100644 --- a/packages/merchant-backoffice-ui/src/hooks/backend.ts +++ b/packages/merchant-backoffice-ui/src/hooks/backend.ts @@ -132,8 +132,6 @@ interface useBackendInstanceRequestType { options?: RequestOptions, ) => Promise>; fetcher: (endpoint: string) => Promise>; - reserveDetailFetcher: (endpoint: string) => Promise>; - rewardsDetailFetcher: (endpoint: string) => Promise>; multiFetcher: (params: [url: string[]]) => Promise[]>; orderFetcher: ( params: [endpoint: string, @@ -353,34 +351,6 @@ export function useBackendInstanceRequest(): useBackendInstanceRequestType { [baseUrl, token], ); - const reserveDetailFetcher = useCallback( - function reserveDetailFetcherImpl( - endpoint: string, - ): Promise> { - return requestHandler(baseUrl, endpoint, { - params: { - rewards: "yes", - }, - token, - }); - }, - [baseUrl, token], - ); - - const rewardsDetailFetcher = useCallback( - function rewardsDetailFetcherImpl( - endpoint: string, - ): Promise> { - return requestHandler(baseUrl, endpoint, { - params: { - pickups: "yes", - }, - token, - }); - }, - [baseUrl, token], - ); - const transferFetcher = useCallback( function transferFetcherImpl( args: [endpoint: string, @@ -468,8 +438,6 @@ export function useBackendInstanceRequest(): useBackendInstanceRequestType { fetcher, multiFetcher, orderFetcher, - reserveDetailFetcher, - rewardsDetailFetcher, transferFetcher, templateFetcher, webhookFetcher, diff --git a/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts b/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts index b3eecd754..186af1f61 100644 --- a/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts +++ b/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts @@ -19,25 +19,19 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import * as tests from "@gnu-taler/web-util/testing"; import { expect } from "chai"; import { MerchantBackend } from "../declaration.js"; import { useInstanceReserves, - useReserveDetails, useReservesAPI, - useRewardDetails, } from "./reserves.js"; import { ApiMockEnvironment } from "./testing.js"; import { - API_AUTHORIZE_REWARD, - API_AUTHORIZE_REWARD_FOR_RESERVE, API_CREATE_RESERVE, API_DELETE_RESERVE, - API_GET_RESERVE_BY_ID, - API_GET_REWARD_BY_ID, - API_LIST_RESERVES, + API_LIST_RESERVES } from "./urls.js"; -import * as tests from "@gnu-taler/web-util/testing"; describe("reserve api interaction with listing", () => { it("should evict cache when creating a reserve", async () => { @@ -211,238 +205,3 @@ describe("reserve api interaction with listing", () => { expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); }); }); - -describe("reserve api interaction with details", () => { - it("should evict cache when adding a reward for a specific reserve", async () => { - const env = new ApiMockEnvironment(); - - env.addRequestExpectation(API_GET_RESERVE_BY_ID("11"), { - response: { - accounts: [{ payto_uri: "payto://here" }], - rewards: [{ reason: "why?", reward_id: "id1", total_amount: "USD:10" }], - } as MerchantBackend.Rewards.ReserveDetail, - qparam: { - rewards: "yes", - }, - }); - - const hookBehavior = await tests.hookBehaveLikeThis( - () => { - const api = useReservesAPI(); - const query = useReserveDetails("11"); - return { query, api }; - }, - {}, - [ - ({ query, api }) => { - expect(query.loading).true; - }, - ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ - result: "ok", - }); - expect(query.loading).false; - expect(query.ok).true; - if (!query.ok) return; - expect(query.data).deep.equals({ - accounts: [{ payto_uri: "payto://here" }], - rewards: [{ reason: "why?", reward_id: "id1", total_amount: "USD:10" }], - }); - - env.addRequestExpectation(API_AUTHORIZE_REWARD_FOR_RESERVE("11"), { - request: { - amount: "USD:12", - justification: "not", - next_url: "http://taler.net", - }, - response: { - reward_id: "id2", - taler_reward_uri: "uri", - reward_expiration: { t_s: 1 }, - reward_status_url: "url", - }, - }); - - env.addRequestExpectation(API_GET_RESERVE_BY_ID("11"), { - response: { - accounts: [{ payto_uri: "payto://here" }], - rewards: [ - { reason: "why?", reward_id: "id1", total_amount: "USD:10" }, - { reason: "not", reward_id: "id2", total_amount: "USD:12" }, - ], - } as MerchantBackend.Rewards.ReserveDetail, - qparam: { - rewards: "yes", - }, - }); - - api.authorizeRewardReserve("11", { - amount: "USD:12", - justification: "not", - next_url: "http://taler.net", - }); - }, - ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ - result: "ok", - }); - expect(query.loading).false; - - expect(query.loading).false; - expect(query.ok).true; - if (!query.ok) return; - - expect(query.data).deep.equals({ - accounts: [{ payto_uri: "payto://here" }], - rewards: [ - { reason: "why?", reward_id: "id1", total_amount: "USD:10" }, - { reason: "not", reward_id: "id2", total_amount: "USD:12" }, - ], - }); - }, - ], - env.buildTestingContext(), - ); - - expect(hookBehavior).deep.eq({ result: "ok" }); - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); - - it("should evict cache when adding a reward for a random reserve", async () => { - const env = new ApiMockEnvironment(); - - env.addRequestExpectation(API_GET_RESERVE_BY_ID("11"), { - response: { - accounts: [{ payto_uri: "payto://here" }], - rewards: [{ reason: "why?", reward_id: "id1", total_amount: "USD:10" }], - } as MerchantBackend.Rewards.ReserveDetail, - qparam: { - rewards: "yes", - }, - }); - - const hookBehavior = await tests.hookBehaveLikeThis( - () => { - const api = useReservesAPI(); - const query = useReserveDetails("11"); - return { query, api }; - }, - {}, - [ - ({ query, api }) => { - expect(query.loading).true; - }, - ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ - result: "ok", - }); - expect(query.loading).false; - expect(query.ok).true; - if (!query.ok) return; - expect(query.data).deep.equals({ - accounts: [{ payto_uri: "payto://here" }], - rewards: [{ reason: "why?", reward_id: "id1", total_amount: "USD:10" }], - }); - - env.addRequestExpectation(API_AUTHORIZE_REWARD, { - request: { - amount: "USD:12", - justification: "not", - next_url: "http://taler.net", - }, - response: { - reward_id: "id2", - taler_reward_uri: "uri", - reward_expiration: { t_s: 1 }, - reward_status_url: "url", - }, - }); - - env.addRequestExpectation(API_GET_RESERVE_BY_ID("11"), { - response: { - accounts: [{ payto_uri: "payto://here" }], - rewards: [ - { reason: "why?", reward_id: "id1", total_amount: "USD:10" }, - { reason: "not", reward_id: "id2", total_amount: "USD:12" }, - ], - } as MerchantBackend.Rewards.ReserveDetail, - qparam: { - rewards: "yes", - }, - }); - - api.authorizeReward({ - amount: "USD:12", - justification: "not", - next_url: "http://taler.net", - }); - }, - ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ - result: "ok", - }); - expect(query.loading).false; - expect(query.ok).true; - if (!query.ok) return; - - expect(query.data).deep.equals({ - accounts: [{ payto_uri: "payto://here" }], - rewards: [ - { reason: "why?", reward_id: "id1", total_amount: "USD:10" }, - { reason: "not", reward_id: "id2", total_amount: "USD:12" }, - ], - }); - }, - ], - env.buildTestingContext(), - ); - - expect(hookBehavior).deep.eq({ result: "ok" }); - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); -}); - -describe("reserve api interaction with reward details", () => { - it("should list rewards", async () => { - const env = new ApiMockEnvironment(); - - env.addRequestExpectation(API_GET_REWARD_BY_ID("11"), { - response: { - total_picked_up: "USD:12", - reason: "not", - } as MerchantBackend.Rewards.RewardDetails, - qparam: { - pickups: "yes", - }, - }); - - const hookBehavior = await tests.hookBehaveLikeThis( - () => { - const query = useRewardDetails("11"); - return { query }; - }, - {}, - [ - ({ query }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ - result: "ok", - }); - expect(query.loading).true; - }, - ({ query }) => { - expect(query.loading).false; - expect(query.ok).true; - if (!query.ok) return; - expect(query.data).deep.equals({ - total_picked_up: "USD:12", - reason: "not", - }); - }, - ], - env.buildTestingContext(), - ); - - expect(hookBehavior).deep.eq({ result: "ok" }); - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); -}); diff --git a/packages/merchant-backoffice-ui/src/hooks/reserves.ts b/packages/merchant-backoffice-ui/src/hooks/reserves.ts index b719bfbe6..62dc48412 100644 --- a/packages/merchant-backoffice-ui/src/hooks/reserves.ts +++ b/packages/merchant-backoffice-ui/src/hooks/reserves.ts @@ -49,40 +49,6 @@ export function useReservesAPI(): ReserveMutateAPI { return res; }; - const authorizeRewardReserve = async ( - pub: string, - data: MerchantBackend.Rewards.RewardCreateRequest, - ): Promise> => { - const res = await request( - `/private/reserves/${pub}/authorize-reward`, - { - method: "POST", - data, - }, - ); - - //evict reserve details query - await mutate([`/private/reserves/${pub}`]); - - return res; - }; - - const authorizeReward = async ( - data: MerchantBackend.Rewards.RewardCreateRequest, - ): Promise> => { - const res = await request( - `/private/rewards`, - { - method: "POST", - data, - }, - ); - - //evict all details query - await mutateAll(/.*private\/reserves\/.*/); - - return res; - }; const deleteReserve = async ( pub: string, @@ -97,20 +63,13 @@ export function useReservesAPI(): ReserveMutateAPI { return res; }; - return { createReserve, authorizeReward, authorizeRewardReserve, deleteReserve }; + return { createReserve, deleteReserve }; } export interface ReserveMutateAPI { createReserve: ( data: MerchantBackend.Rewards.ReserveCreateRequest, ) => Promise>; - authorizeRewardReserve: ( - id: string, - data: MerchantBackend.Rewards.RewardCreateRequest, - ) => Promise>; - authorizeReward: ( - data: MerchantBackend.Rewards.RewardCreateRequest, - ) => Promise>; deleteReserve: ( id: string, ) => Promise>; @@ -133,49 +92,3 @@ export function useInstanceReserves(): HttpResponse< return { loading: true }; } -export function useReserveDetails( - reserveId: string, -): HttpResponse< - MerchantBackend.Rewards.ReserveDetail, - MerchantBackend.ErrorDetail -> { - const { reserveDetailFetcher } = useBackendInstanceRequest(); - - const { data, error, isValidating } = useSWR< - HttpResponseOk, - RequestError - >([`/private/reserves/${reserveId}`], reserveDetailFetcher, { - refreshInterval: 0, - refreshWhenHidden: false, - revalidateOnFocus: false, - revalidateOnReconnect: false, - refreshWhenOffline: false, - }); - - if (isValidating) return { loading: true, data: data?.data }; - if (data) return data; - if (error) return error.cause; - return { loading: true }; -} - -export function useRewardDetails( - rewardId: string, -): HttpResponse { - const { rewardsDetailFetcher } = useBackendInstanceRequest(); - - const { data, error, isValidating } = useSWR< - HttpResponseOk, - RequestError - >([`/private/rewards/${rewardId}`], rewardsDetailFetcher, { - refreshInterval: 0, - refreshWhenHidden: false, - revalidateOnFocus: false, - revalidateOnReconnect: false, - refreshWhenOffline: false, - }); - - if (isValidating) return { loading: true, data: data?.data }; - if (data) return data; - if (error) return error.cause; - return { loading: true }; -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/index.stories.ts b/packages/merchant-backoffice-ui/src/paths/instance/index.stories.ts index 1d8c76ff9..50918e131 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/index.stories.ts +++ b/packages/merchant-backoffice-ui/src/paths/instance/index.stories.ts @@ -16,4 +16,3 @@ export * as details from "./details/stories.js"; export * as kycList from "./kyc/list/ListPage.stories.js"; -export * as reserve from "./reserves/create/CreatedSuccessfully.stories.js"; diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/Create.stories.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/Create.stories.tsx deleted file mode 100644 index 5542c028a..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/Create.stories.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { h, VNode, FunctionalComponent } from "preact"; -import { CreatePage as TestedComponent } from "./CreatePage.js"; - -export default { - title: "Pages/Reserve/Create", - component: TestedComponent, - argTypes: { - onCreate: { action: "onCreate" }, - onBack: { action: "onBack" }, - }, -}; - -function createExample( - Component: FunctionalComponent, - props: Partial, -) { - const r = (args: any) => ; - r.args = props; - return r; -} - -export const Example = createExample(TestedComponent, {}); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx deleted file mode 100644 index e46941b6d..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx +++ /dev/null @@ -1,277 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { HttpError, RequestError, useApiContext, useTranslationContext } from "@gnu-taler/web-util/browser"; -import { Fragment, h, VNode } from "preact"; -import { StateUpdater, useEffect, useState } from "preact/hooks"; -import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; -import { - FormErrors, - FormProvider, -} from "../../../../components/form/FormProvider.js"; -import { Input } from "../../../../components/form/Input.js"; -import { InputCurrency } from "../../../../components/form/InputCurrency.js"; -import { InputSelector } from "../../../../components/form/InputSelector.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { - PAYTO_WIRE_METHOD_LOOKUP, - URL_REGEX, -} from "../../../../utils/constants.js"; -import { useBackendBaseRequest } from "../../../../hooks/backend.js"; -import { parsePaytoUri } from "@gnu-taler/taler-util"; - -type Entity = MerchantBackend.Rewards.ReserveCreateRequest; - -interface Props { - onCreate: (d: Entity) => Promise; - onBack?: () => void; -} - -enum Steps { - EXCHANGE, - WIRE_METHOD, -} - -interface ViewProps { - step: Steps; - setCurrentStep: (s: Steps) => void; - reserve: Partial; - onBack?: () => void; - submitForm: () => Promise; - setReserve: StateUpdater>; -} -function ViewStep({ - step, - setCurrentStep, - reserve, - onBack, - submitForm, - setReserve, -}: ViewProps): VNode { - const { i18n } = useTranslationContext(); - const {request} = useApiContext() - const [wireMethods, setWireMethods] = useState>([]); - const [exchangeQueryError, setExchangeQueryError] = useState< - string | undefined - >(undefined); - - useEffect(() => { - setExchangeQueryError(undefined); - }, [reserve.exchange_url]); - - switch (step) { - case Steps.EXCHANGE: { - const errors: FormErrors = { - initial_balance: !reserve.initial_balance - ? "cannot be empty" - : !(parseInt(reserve.initial_balance.split(":")[1], 10) > 0) - ? i18n.str`it should be greater than 0` - : undefined, - exchange_url: !reserve.exchange_url - ? i18n.str`cannot be empty` - : !URL_REGEX.test(reserve.exchange_url) - ? i18n.str`must be a valid URL` - : !exchangeQueryError - ? undefined - : exchangeQueryError, - }; - - const hasErrors = Object.keys(errors).some( - (k) => (errors as any)[k] !== undefined, - ); - - return ( - - - object={reserve} - errors={errors} - valueHandler={setReserve} - > - - name="initial_balance" - label={i18n.str`Initial balance`} - tooltip={i18n.str`balance prior to deposit`} - /> - - name="exchange_url" - label={i18n.str`Exchange URL`} - tooltip={i18n.str`URL of exchange`} - /> - - -
    - {onBack && ( - - )} - { - if (!reserve.exchange_url) { - return Promise.resolve(); - } - - return request(reserve.exchange_url, "keys") - .then((r) => { - console.log(r) - if (r.loading) return; - if (r.ok) { - const wireMethods = r.data.accounts.map((a: any) => { - const p = parsePaytoUri(a.payto_uri); - const r = p?.targetType - return r - }).filter((x:any) => !!x); - setWireMethods(Array.from(new Set(wireMethods))); - } - setCurrentStep(Steps.WIRE_METHOD); - return; - }) - .catch((r: RequestError<{}>) => { - console.log(r.cause) - setExchangeQueryError(r.cause.message); - }); - }} - data-tooltip={ - hasErrors - ? i18n.str`Need to complete marked fields` - : "confirm operation" - } - disabled={hasErrors} - > - Next - -
    -
    - ); - } - - case Steps.WIRE_METHOD: { - const errors: FormErrors = { - wire_method: !reserve.wire_method - ? i18n.str`cannot be empty` - : undefined, - }; - - const hasErrors = Object.keys(errors).some( - (k) => (errors as any)[k] !== undefined, - ); - return ( - - - object={reserve} - errors={errors} - valueHandler={setReserve} - > - - name="initial_balance" - label={i18n.str`Initial balance`} - tooltip={i18n.str`balance prior to deposit`} - readonly - /> - - name="exchange_url" - label={i18n.str`Exchange URL`} - tooltip={i18n.str`URL of exchange`} - readonly - /> - - name="wire_method" - label={i18n.str`Wire method`} - tooltip={i18n.str`method to use for wire transfer`} - values={wireMethods} - placeholder={i18n.str`Select one wire method`} - /> - -
    - {onBack && ( - - )} - - Confirm - -
    -
    - ); - } - } -} - -export function CreatePage({ onCreate, onBack }: Props): VNode { - const [reserve, setReserve] = useState>({}); - - const submitForm = () => { - return onCreate(reserve as Entity); - }; - - const [currentStep, setCurrentStep] = useState(Steps.EXCHANGE); - - return ( -
    - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.stories.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.stories.tsx deleted file mode 100644 index 445ca3ef0..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.stories.tsx +++ /dev/null @@ -1,120 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { h, VNode, FunctionalComponent } from "preact"; -import { CreatedSuccessfully as TestedComponent } from "./CreatedSuccessfully.js"; -import * as tests from "@gnu-taler/web-util/testing"; - -export default { - title: "Pages/Reserve/CreatedSuccessfully", - component: TestedComponent, - argTypes: { - onCreate: { action: "onCreate" }, - onBack: { action: "onBack" }, - }, -}; - -export const OneBankAccount = tests.createExample(TestedComponent, { - entity: { - request: { - exchange_url: "http://exchange.taler/", - initial_balance: "TESTKUDOS:1", - wire_method: "x-taler-bank", - }, - response: { - accounts: [ - { - payto_uri: "payto://x-taler-bank/bank.taler:8080/exchange_account", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "asd", - conversion_url: "", - }, - ], - reserve_pub: "WEQWDASDQWEASDADASDQWEQWEASDAS", - }, - }, -}); - -export const ThreeBankAccount = tests.createExample(TestedComponent, { - entity: { - request: { - exchange_url: "http://exchange.taler/", - initial_balance: "TESTKUDOS:1", - wire_method: "x-taler-bank", - }, - response: { - accounts: [ - { - payto_uri: "payto://x-taler-bank/bank.taler:8080/exchange_account", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "asd", - conversion_url: "", - }, - { - payto_uri: "payto://x-taler-bank/bank1.taler:8080/asd", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "asd", - conversion_url: "", - }, - { - payto_uri: "payto://x-taler-bank/bank2.taler:8080/qwe", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "asd", - conversion_url: "", - }, - ], - reserve_pub: "WEQWDASDQWEASDADASDQWEQWEASDAS", - }, - }, -}); - -export const NoBankAccount = tests.createExample(TestedComponent, { - entity: { - request: { - exchange_url: "http://exchange.taler/", - initial_balance: "TESTKUDOS:1", - wire_method: "x-taler-bank", - }, - response: { - accounts: [ - { - payto_uri: "payo://x-talr-bank/bank.taler:8080/exchange_account", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "asd", - conversion_url: "", - }, - { - payto_uri: "payto://x-taler-bank", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "asd", - conversion_url: "", - }, - ], - reserve_pub: "WEQWDASDQWEASDADASDQWEQWEASDAS", - }, - }, -}); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx deleted file mode 100644 index 1d512c843..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx +++ /dev/null @@ -1,190 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -import { parsePaytoUri, stringifyPaytoUri } from "@gnu-taler/taler-util"; -import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { Fragment, VNode, h } from "preact"; -import { QR } from "../../../../components/exception/QR.js"; -import { CreatedSuccessfully as Template } from "../../../../components/notifications/CreatedSuccessfully.js"; -import { MerchantBackend, WireAccount } from "../../../../declaration.js"; - -type Entity = { - request: MerchantBackend.Rewards.ReserveCreateRequest; - response: MerchantBackend.Rewards.ReserveCreateConfirmation; -}; - -interface Props { - entity: Entity; - onConfirm: () => void; - onCreateAnother?: () => void; -} - -function isNotUndefined(x: X | undefined): x is X { - return !!x; -} - -export function CreatedSuccessfully({ - entity, - onConfirm, - onCreateAnother, -}: Props): VNode { - const { i18n } = useTranslationContext(); - return ( - - ); -} - -export function ShowAccountsOfReserveAsQRWithLink({ - accounts, - message, - amount, -}: { - accounts: WireAccount[]; - message: string; - amount: string; -}): VNode { - const { i18n } = useTranslationContext(); - const accountsInfo = !accounts - ? [] - : accounts - .map((acc) => { - const p = parsePaytoUri(acc.payto_uri); - if (p) { - p.params["message"] = message; - p.params["amount"] = amount; - } - return p; - }) - .filter(isNotUndefined); - - const links = accountsInfo.map((a) => stringifyPaytoUri(a)); - - if (links.length === 0) { - return ( - -

    - The reserve have invalid accounts. List of invalid payto URIs below: -

    -
      - {accounts.map((a, idx) => { - return
    • {a.payto_uri}
    • ; - })} -
    -
    - ); - } - - if (links.length === 1) { - return ( - -

    - - To complete the setup of the reserve, you must now initiate a wire - transfer using the given wire transfer subject and crediting the - specified amount to the indicated account of the exchange. - -

    -

    - Exchange bank account -

    - -

    - - If your system supports RFC 8905, you can do this by opening this - URI: - -

    -
    -          
    -            {links[0]}
    -          
    -        
    -
    - ); - } - - return ( -
    -

    - - To complete the setup of the reserve, you must now initiate a wire - transfer using the given wire transfer subject and crediting the - specified amount to one of the indicated account of the exchange. - -

    - -

    - Exchange bank accounts -

    -

    - - If your system supports RFC 8905, you can do this by clicking on the - URI below the QR code: - -

    - {links.map((link) => { - return ( - - -
    -              
    -                {link}
    -              
    -            
    -
    - ); - })} -
    - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx deleted file mode 100644 index 4bbaf1459..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { Fragment, h, VNode } from "preact"; -import { useState } from "preact/hooks"; -import { NotificationCard } from "../../../../components/menu/index.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { useReservesAPI } from "../../../../hooks/reserves.js"; -import { Notification } from "../../../../utils/types.js"; -import { CreatedSuccessfully } from "./CreatedSuccessfully.js"; -import { CreatePage } from "./CreatePage.js"; -interface Props { - onBack: () => void; - onConfirm: () => void; -} -export default function CreateReserve({ onBack, onConfirm }: Props): VNode { - const { createReserve } = useReservesAPI(); - const [notif, setNotif] = useState(undefined); - const { i18n } = useTranslationContext(); - - const [createdOk, setCreatedOk] = useState< - | { - request: MerchantBackend.Rewards.ReserveCreateRequest; - response: MerchantBackend.Rewards.ReserveCreateConfirmation; - } - | undefined - >(undefined); - - if (createdOk) { - return ; - } - - return ( - - - { - return createReserve(request) - .then((r) => setCreatedOk({ request, response: r.data })) - .catch((error) => { - setNotif({ - message: i18n.str`could not create reserve`, - type: "ERROR", - description: error.message, - }); - }); - }} - /> - - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx deleted file mode 100644 index d8840eeac..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx +++ /dev/null @@ -1,266 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { - Amounts, - parsePaytoUri, - stringifyPaytoUri, -} from "@gnu-taler/taler-util"; -import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { format } from "date-fns"; -import { Fragment, h, VNode } from "preact"; -import { useState } from "preact/hooks"; -import { QR } from "../../../../components/exception/QR.js"; -import { FormProvider } from "../../../../components/form/FormProvider.js"; -import { Input } from "../../../../components/form/Input.js"; -import { InputCurrency } from "../../../../components/form/InputCurrency.js"; -import { InputDate } from "../../../../components/form/InputDate.js"; -import { TextField } from "../../../../components/form/TextField.js"; -import { SimpleModal } from "../../../../components/modal/index.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { useRewardDetails } from "../../../../hooks/reserves.js"; -import { RewardInfo } from "./RewardInfo.js"; -import { ShowAccountsOfReserveAsQRWithLink } from "../create/CreatedSuccessfully.js"; -import { datetimeFormatForSettings, useSettings } from "../../../../hooks/useSettings.js"; - -type Entity = MerchantBackend.Rewards.ReserveDetail; -type CT = MerchantBackend.ContractTerms; - -interface Props { - onBack: () => void; - selected: Entity; - id: string; -} - -export function DetailPage({ id, selected, onBack }: Props): VNode { - const { i18n } = useTranslationContext(); - const didExchangeAckTransfer = Amounts.isNonZero( - Amounts.parseOrThrow(selected.exchange_initial_amount), - ); - - return ( -
    -
    -
    -
    - - - name="creation_time" - label={i18n.str`Created at`} - readonly - /> - - name="expiration_time" - label={i18n.str`Valid until`} - readonly - /> - - name="merchant_initial_amount" - label={i18n.str`Created balance`} - readonly - /> - - name="exchange_url" - label={i18n.str`Exchange URL`} - readonly - > - - {selected.exchange_url} - - - - {didExchangeAckTransfer && ( - - - name="exchange_initial_amount" - label={i18n.str`Exchange balance`} - readonly - /> - - name="pickup_amount" - label={i18n.str`Picked up`} - readonly - /> - - name="committed_amount" - label={i18n.str`Committed`} - readonly - /> - - )} - - - - {didExchangeAckTransfer ? ( - -
    -
    -

    - - - - Rewards -

    -
    -
    -
    -
    - {selected.rewards && selected.rewards.length > 0 ? ( - - ) : ( - - )} - - - - - - ) : selected.accounts ? ( - - ) : undefined} - -
    - -
    - - -
    -
    - ); -} - -function EmptyTable(): VNode { - const { i18n } = useTranslationContext(); - return ( -
    -

    - - - -

    -

    - - No reward has been authorized from this reserve - -

    -
    - ); -} - -interface TableProps { - rewards: MerchantBackend.Rewards.RewardStatusEntry[]; -} - -function Table({ rewards }: TableProps): VNode { - const { i18n } = useTranslationContext(); - return ( -
    -
    - - - - - - - - - - {rewards.map((t, i) => { - return ; - })} - -
    - Authorized - - Picked up - - Reason - - Expiration -
    -
    - ); -} - -function RewardRow({ - id, - entry, -}: { - id: string; - entry: MerchantBackend.Rewards.RewardStatusEntry; -}) { - const [selected, setSelected] = useState(false); - const result = useRewardDetails(id); - const [settings] = useSettings(); - if (result.loading) { - return ( - - ... - ... - ... - ... - - ); - } - if (!result.ok) { - return ( - - ... {/* authorized */} - {entry.total_amount} - {entry.reason} - ... {/* expired */} - - ); - } - const info = result.data; - function onSelect() { - setSelected(true); - } - return ( - - {selected && ( - setSelected(false)} - > - - - )} - - {info.total_authorized} - {info.total_picked_up} - {info.reason} - - {info.expiration.t_s === "never" - ? "never" - : format(info.expiration.t_s * 1000, datetimeFormatForSettings(settings))} - - - - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/Details.stories.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/Details.stories.tsx deleted file mode 100644 index 41c715f20..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/Details.stories.tsx +++ /dev/null @@ -1,126 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { h, VNode, FunctionalComponent } from "preact"; -import { DetailPage as TestedComponent } from "./DetailPage.js"; - -export default { - title: "Pages/Reserve/Detail", - component: TestedComponent, - argTypes: { - onUpdate: { action: "onUpdate" }, - onBack: { action: "onBack" }, - }, -}; - -function createExample( - Component: FunctionalComponent, - props: Partial, -) { - const r = (args: any) => ; - r.args = props; - return r; -} - -export const Funded = createExample(TestedComponent, { - id: "THISISTHERESERVEID", - selected: { - active: true, - committed_amount: "TESTKUDOS:10", - creation_time: { - t_s: new Date().getTime() / 1000, - }, - exchange_initial_amount: "TESTKUDOS:10", - expiration_time: { - t_s: new Date().getTime() / 1000, - }, - merchant_initial_amount: "TESTKUDOS:10", - pickup_amount: "TESTKUDOS:10", - accounts: [ - { - payto_uri: "payto://x-taler-bank/bank.taler:8080/account", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "", - }, - ], - exchange_url: "http://exchange.taler/", - }, -}); - -export const NotYetFunded = createExample(TestedComponent, { - id: "THISISTHERESERVEID", - selected: { - active: true, - committed_amount: "TESTKUDOS:10", - creation_time: { - t_s: new Date().getTime() / 1000, - }, - exchange_initial_amount: "TESTKUDOS:0", - expiration_time: { - t_s: new Date().getTime() / 1000, - }, - merchant_initial_amount: "TESTKUDOS:10", - pickup_amount: "TESTKUDOS:10", - accounts: [ - { - payto_uri: "payto://x-taler-bank/bank.taler:8080/account", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "", - }, - ], - exchange_url: "http://exchange.taler/", - }, -}); - -export const FundedWithEmptyRewards = createExample(TestedComponent, { - id: "THISISTHERESERVEID", - selected: { - active: true, - committed_amount: "TESTKUDOS:10", - creation_time: { - t_s: new Date().getTime() / 1000, - }, - exchange_initial_amount: "TESTKUDOS:10", - expiration_time: { - t_s: new Date().getTime() / 1000, - }, - merchant_initial_amount: "TESTKUDOS:10", - pickup_amount: "TESTKUDOS:10", - accounts: [ - { - payto_uri: "payto://x-taler-bank/bank.taler:8080/account", - credit_restrictions: [], - debit_restrictions: [], - master_sig: "", - }, - ], - exchange_url: "http://exchange.taler/", - rewards: [ - { - reason: "asdasd", - reward_id: "123", - total_amount: "TESTKUDOS:1", - }, - ], - }, -}); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/RewardInfo.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/RewardInfo.tsx deleted file mode 100644 index 780068a91..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/RewardInfo.tsx +++ /dev/null @@ -1,88 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ -import { stringifyRewardUri } from "@gnu-taler/taler-util"; -import { format } from "date-fns"; -import { Fragment, h, VNode } from "preact"; -import { useBackendContext } from "../../../../context/backend.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { datetimeFormatForSettings, useSettings } from "../../../../hooks/useSettings.js"; - -type Entity = MerchantBackend.Rewards.RewardDetails; - -interface Props { - id: string; - entity: Entity; - amount: string; -} - -export function RewardInfo({ id: merchantRewardId, amount, entity }: Props): VNode { - const { url: backendURL } = useBackendContext() - const [settings] = useSettings(); - const rewardURL = stringifyRewardUri({ merchantBaseUrl: backendURL, merchantRewardId }) - return ( - -
    -
    - -
    -
    -
    -

    - -

    -
    -
    -
    -
    -
    - -
    -
    - -
    -
    -
    -
    - -
    -
    -
    -

    - -

    -
    -
    -
    -
    - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/index.tsx deleted file mode 100644 index 8e2a74529..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/index.tsx +++ /dev/null @@ -1,68 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { ErrorType, HttpError } from "@gnu-taler/web-util/browser"; -import { Fragment, h, VNode } from "preact"; -import { Loading } from "../../../../components/exception/loading.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { useReserveDetails } from "../../../../hooks/reserves.js"; -import { DetailPage } from "./DetailPage.js"; -import { HttpStatusCode } from "@gnu-taler/taler-util"; - -interface Props { - rid: string; - - onUnauthorized: () => VNode; - onLoadError: (error: HttpError) => VNode; - onNotFound: () => VNode; - onDelete: () => void; - onBack: () => void; -} -export default function DetailReserve({ - rid, - onUnauthorized, - onLoadError, - onNotFound, - onBack, - onDelete, -}: Props): VNode { - const result = useReserveDetails(rid); - - if (result.loading) return ; - if (!result.ok) { - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.Unauthorized - ) - return onUnauthorized(); - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.NotFound - ) - return onNotFound(); - return onLoadError(result); - } - return ( - - - - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeRewardModal.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeRewardModal.tsx deleted file mode 100644 index e205ee621..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeRewardModal.tsx +++ /dev/null @@ -1,124 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { h, VNode } from "preact"; -import { useState } from "preact/hooks"; -import * as yup from "yup"; -import { - FormErrors, - FormProvider, -} from "../../../../components/form/FormProvider.js"; -import { Input } from "../../../../components/form/Input.js"; -import { InputCurrency } from "../../../../components/form/InputCurrency.js"; -import { - ConfirmModal, - ContinueModal, -} from "../../../../components/modal/index.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { AuthorizeRewardSchema } from "../../../../schemas/index.js"; -import { CreatedSuccessfully } from "./CreatedSuccessfully.js"; - -interface AuthorizeRewardModalProps { - onCancel: () => void; - onConfirm: (value: MerchantBackend.Rewards.RewardCreateRequest) => void; - rewardAuthorized?: { - response: MerchantBackend.Rewards.RewardCreateConfirmation; - request: MerchantBackend.Rewards.RewardCreateRequest; - }; -} - -export function AuthorizeRewardModal({ - onCancel, - onConfirm, - rewardAuthorized, -}: AuthorizeRewardModalProps): VNode { - // const result = useOrderDetails(id) - type State = MerchantBackend.Rewards.RewardCreateRequest; - const [form, setValue] = useState>({}); - const { i18n } = useTranslationContext(); - - // const [errors, setErrors] = useState>({}) - let errors: FormErrors = {}; - try { - AuthorizeRewardSchema.validateSync(form, { abortEarly: false }); - } catch (err) { - if (err instanceof yup.ValidationError) { - const yupErrors = err.inner as any[]; - errors = yupErrors.reduce( - (prev, cur) => - !cur.path ? prev : { ...prev, [cur.path]: cur.message }, - {}, - ); - } - } - const hasErrors = Object.keys(errors).some( - (k) => (errors as any)[k] !== undefined, - ); - - const validateAndConfirm = () => { - onConfirm(form as State); - }; - if (rewardAuthorized) { - return ( - - - - ); - } - - return ( - - - errors={errors} - object={form} - valueHandler={setValue} - > - - name="amount" - label={i18n.str`Amount`} - tooltip={i18n.str`amount of reward`} - /> - - name="justification" - label={i18n.str`Justification`} - inputType="multiline" - tooltip={i18n.str`reason for the reward`} - /> - - name="next_url" - label={i18n.str`URL after reward`} - tooltip={i18n.str`URL to visit after reward payment`} - /> - - - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/CreatedSuccessfully.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/CreatedSuccessfully.tsx deleted file mode 100644 index b78236bc7..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/CreatedSuccessfully.tsx +++ /dev/null @@ -1,102 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ -import { format } from "date-fns"; -import { Fragment, h, VNode } from "preact"; -import { CreatedSuccessfully as Template } from "../../../../components/notifications/CreatedSuccessfully.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { datetimeFormatForSettings, useSettings } from "../../../../hooks/useSettings.js"; - -type Entity = MerchantBackend.Rewards.RewardCreateConfirmation; - -interface Props { - entity: Entity; - request: MerchantBackend.Rewards.RewardCreateRequest; - onConfirm: () => void; - onCreateAnother?: () => void; -} - -export function CreatedSuccessfully({ - request, - entity, - onConfirm, - onCreateAnother, -}: Props): VNode { - const [settings] = useSettings(); - return ( - -
    -
    - -
    -
    -
    -

    - -

    -
    -
    -
    -
    -
    - -
    -
    -
    -

    - -

    -
    -
    -
    -
    -
    - -
    -
    -
    -

    - -

    -
    -
    -
    -
    -
    - -
    -
    -
    -

    - -

    -
    -
    -
    -
    - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/List.stories.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/List.stories.tsx deleted file mode 100644 index b070bbde3..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/List.stories.tsx +++ /dev/null @@ -1,96 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { h, VNode, FunctionalComponent } from "preact"; -import { CardTable as TestedComponent } from "./Table.js"; - -export default { - title: "Pages/Reserve/List", - component: TestedComponent, -}; - -function createExample( - Component: FunctionalComponent, - props: Partial, -) { - const r = (args: any) => ; - r.args = props; - return r; -} - -export const AllFunded = createExample(TestedComponent, { - instances: [ - { - id: "reseverId", - active: true, - committed_amount: "TESTKUDOS:10", - creation_time: { - t_s: new Date().getTime() / 1000, - }, - exchange_initial_amount: "TESTKUDOS:10", - expiration_time: { - t_s: new Date().getTime() / 1000, - }, - merchant_initial_amount: "TESTKUDOS:10", - pickup_amount: "TESTKUDOS:10", - reserve_pub: "WEQWDASDQWEASDADASDQWEQWEASDAS", - }, - { - id: "reseverId2", - active: true, - committed_amount: "TESTKUDOS:13", - creation_time: { - t_s: new Date().getTime() / 1000, - }, - exchange_initial_amount: "TESTKUDOS:10", - expiration_time: { - t_s: new Date().getTime() / 1000, - }, - merchant_initial_amount: "TESTKUDOS:10", - pickup_amount: "TESTKUDOS:10", - reserve_pub: "WEQWDASDQWEASDADASDQWEQWEASDAS", - }, - ], -}); - -export const Empty = createExample(TestedComponent, { - instances: [], -}); - -export const OneNotYetFunded = createExample(TestedComponent, { - instances: [ - { - id: "reseverId", - active: true, - committed_amount: "TESTKUDOS:0", - creation_time: { - t_s: new Date().getTime() / 1000, - }, - exchange_initial_amount: "TESTKUDOS:0", - expiration_time: { - t_s: new Date().getTime() / 1000, - }, - merchant_initial_amount: "TESTKUDOS:10", - pickup_amount: "TESTKUDOS:10", - reserve_pub: "WEQWDASDQWEASDADASDQWEQWEASDAS", - }, - ], -}); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx deleted file mode 100644 index 795e7ec82..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx +++ /dev/null @@ -1,320 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { format } from "date-fns"; -import { Fragment, h, VNode } from "preact"; -import { MerchantBackend, WithId } from "../../../../declaration.js"; -import { datetimeFormatForSettings, useSettings } from "../../../../hooks/useSettings.js"; - -type Entity = MerchantBackend.Rewards.ReserveStatusEntry & WithId; - -interface Props { - instances: Entity[]; - onNewReward: (id: Entity) => void; - onSelect: (id: Entity) => void; - onDelete: (id: Entity) => void; - onCreate: () => void; -} - -export function CardTable({ - instances, - onCreate, - onSelect, - onNewReward, - onDelete, -}: Props): VNode { - const [withoutFunds, withFunds] = instances.reduce((prev, current) => { - const amount = current.exchange_initial_amount; - if (amount.endsWith(":0")) { - prev[0] = prev[0].concat(current); - } else { - prev[1] = prev[1].concat(current); - } - return prev; - }, new Array>([], [])); - - const { i18n } = useTranslationContext(); - - return ( - - {withoutFunds.length > 0 && ( -
    -
    -

    - - - - Reserves not yet funded -

    -
    -
    -
    -
    - -
    -
    -
    -
    - )} - -
    -
    -

    - - - - Reserves ready -

    -
    -
    - - - -
    -
    -
    -
    -
    - {withFunds.length > 0 ? ( - - ) : ( - - )} - - - - - - ); -} -interface TableProps { - instances: Entity[]; - onNewReward: (id: Entity) => void; - onDelete: (id: Entity) => void; - onSelect: (id: Entity) => void; -} - -function Table({ instances, onNewReward, onSelect, onDelete }: TableProps): VNode { - const { i18n } = useTranslationContext(); - const [settings] = useSettings(); - return ( -
    -
    - - - - - - - - - - - {instances.map((i) => { - return ( - - - - - - - - - ); - })} - -
    - Created at - - Expires at - - Initial - - Picked up - - Committed - -
    onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.creation_time.t_s === "never" - ? "never" - : format(i.creation_time.t_s * 1000, datetimeFormatForSettings(settings))} - onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.expiration_time.t_s === "never" - ? "never" - : format( - i.expiration_time.t_s * 1000, - datetimeFormatForSettings(settings), - )} - onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.exchange_initial_amount} - onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.pickup_amount} - onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.committed_amount} - -
    - - -
    -
    -
    - ); -} - -function EmptyTable(): VNode { - const { i18n } = useTranslationContext(); - return ( -
    -

    - - - -

    -

    - - There is no ready reserves yet, add more pressing the + sign or fund - them - -

    -
    - ); -} - -function TableWithoutFund({ - instances, - onSelect, - onDelete, -}: TableProps): VNode { - const { i18n } = useTranslationContext(); - const [settings] = useSettings(); - return ( -
    - - - - - - - - - - {instances.map((i) => { - return ( - - - - - - - ); - })} - -
    - Created at - - Expires at - - Expected Balance - -
    onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.creation_time.t_s === "never" - ? "never" - : format(i.creation_time.t_s * 1000, datetimeFormatForSettings(settings))} - onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.expiration_time.t_s === "never" - ? "never" - : format( - i.expiration_time.t_s * 1000, - datetimeFormatForSettings(settings), - )} - onSelect(i)} - style={{ cursor: "pointer" }} - > - {i.merchant_initial_amount} - -
    - -
    -
    -
    - ); -} diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/index.tsx deleted file mode 100644 index b26ff0000..000000000 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/index.tsx +++ /dev/null @@ -1,171 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021-2023 Taler Systems S.A. - - GNU 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. - - GNU 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 - GNU Taler; see the file COPYING. If not, see - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { - ErrorType, - HttpError, - useTranslationContext, -} from "@gnu-taler/web-util/browser"; -import { h, VNode } from "preact"; -import { useState } from "preact/hooks"; -import { Loading } from "../../../../components/exception/loading.js"; -import { NotificationCard } from "../../../../components/menu/index.js"; -import { MerchantBackend } from "../../../../declaration.js"; -import { - useInstanceReserves, - useReservesAPI, -} from "../../../../hooks/reserves.js"; -import { Notification } from "../../../../utils/types.js"; -import { AuthorizeRewardModal } from "./AutorizeRewardModal.js"; -import { CardTable } from "./Table.js"; -import { HttpStatusCode } from "@gnu-taler/taler-util"; -import { ConfirmModal } from "../../../../components/modal/index.js"; - -interface Props { - onUnauthorized: () => VNode; - onLoadError: (e: HttpError) => VNode; - onSelect: (id: string) => void; - onNotFound: () => VNode; - onCreate: () => void; -} - -interface RewardConfirmation { - response: MerchantBackend.Rewards.RewardCreateConfirmation; - request: MerchantBackend.Rewards.RewardCreateRequest; -} - -export default function ListRewards({ - onUnauthorized, - onLoadError, - onNotFound, - onSelect, - onCreate, -}: Props): VNode { - const result = useInstanceReserves(); - const { deleteReserve, authorizeRewardReserve } = useReservesAPI(); - const [notif, setNotif] = useState(undefined); - const { i18n } = useTranslationContext(); - const [reserveForReward, setReserveForReward] = useState( - undefined, - ); - const [deleting, setDeleting] = - useState(null); - const [rewardAuthorized, setRewardAuthorized] = useState< - RewardConfirmation | undefined - >(undefined); - - if (result.loading) return ; - if (!result.ok) { - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.Unauthorized - ) - return onUnauthorized(); - if ( - result.type === ErrorType.CLIENT && - result.status === HttpStatusCode.NotFound - ) - return onNotFound(); - return onLoadError(result); - } - - return ( -
    - - - {reserveForReward && ( - { - setReserveForReward(undefined); - setRewardAuthorized(undefined); - }} - rewardAuthorized={rewardAuthorized} - onConfirm={async (request) => { - try { - const response = await authorizeRewardReserve( - reserveForReward, - request, - ); - setRewardAuthorized({ - request, - response: response.data, - }); - } catch (error) { - setNotif({ - message: i18n.str`could not create the reward`, - type: "ERROR", - description: error instanceof Error ? error.message : undefined, - }); - setReserveForReward(undefined); - } - }} - /> - )} - - r.active) - .map((o) => ({ ...o, id: o.reserve_pub }))} - onCreate={onCreate} - onDelete={(reserve) => { - setDeleting(reserve) - }} - onSelect={(reserve) => onSelect(reserve.id)} - onNewReward={(reserve) => setReserveForReward(reserve.id)} - /> - - {deleting && ( - setDeleting(null)} - onConfirm={async (): Promise => { - try { - await deleteReserve(deleting.reserve_pub); - setNotif({ - message: i18n.str`Reserve for "${deleting.merchant_initial_amount}" (ID: ${deleting.reserve_pub}) has been deleted`, - type: "SUCCESS", - }); - } catch (error) { - setNotif({ - message: i18n.str`Failed to delete reserve`, - type: "ERROR", - description: error instanceof Error ? error.message : undefined, - }); - } - setDeleting(null); - }} - > -

    - If you delete the reserve for "{deleting.merchant_initial_amount}" you won't be able to create more rewards.
    - Reserve ID: {deleting.reserve_pub} -

    -

    - Deleting an template cannot be undone. -

    -
    - )} - -
    - ); -} diff --git a/packages/merchant-backoffice-ui/src/schemas/index.ts b/packages/merchant-backoffice-ui/src/schemas/index.ts index c97d41204..5d168d6ac 100644 --- a/packages/merchant-backoffice-ui/src/schemas/index.ts +++ b/packages/merchant-backoffice-ui/src/schemas/index.ts @@ -124,27 +124,6 @@ export const InstanceSchema = yup.object().shape({ export const InstanceUpdateSchema = InstanceSchema.clone().omit(["id"]); export const InstanceCreateSchema = InstanceSchema.clone(); -export const AuthorizeRewardSchema = yup.object().shape({ - justification: yup.string().required(), - amount: yup - .string() - .required() - .test("amount", "the amount is not valid", currencyWithAmountIsValid) - .test("amount_positive", "the amount is not valid", currencyGreaterThan0), - next_url: yup.string().required(), -}); - -const stringIsValidJSON = (value?: string) => { - const p = value?.trim(); - if (!p) return true; - try { - JSON.parse(p); - return true; - } catch { - return false; - } -}; - export const OrderCreateSchema = yup.object().shape({ pricing: yup .object() -- cgit v1.2.3 From 8055f8834974773170f83c7013174e141ced53cb Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 9 Feb 2024 11:11:34 -0300 Subject: fix #8354: show import key after updating --- .../merchant-backoffice-ui/src/declaration.d.ts | 4 ---- .../instance/orders/details/Detail.stories.tsx | 2 -- .../otp_devices/create/CreatedSuccessfully.tsx | 4 ---- .../src/paths/instance/otp_devices/list/Table.tsx | 2 +- .../paths/instance/otp_devices/update/index.tsx | 24 +++++++++++++++++++--- 5 files changed, 22 insertions(+), 14 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/declaration.d.ts b/packages/merchant-backoffice-ui/src/declaration.d.ts index 38ab9d254..d716fe132 100644 --- a/packages/merchant-backoffice-ui/src/declaration.d.ts +++ b/packages/merchant-backoffice-ui/src/declaration.d.ts @@ -912,10 +912,6 @@ export namespace MerchantBackend { // available, otherwise empty array. wire_details: TransactionWireTransfer[]; - // Reports about trouble obtaining wire transfer details, - // empty array if no trouble were encountered. - wire_reports: TransactionWireReport[]; - // The refund details for this order. One entry per // refunded coin; empty array if there are no refunds. refund_details: RefundDetails[]; diff --git a/packages/merchant-backoffice-ui/src/paths/instance/orders/details/Detail.stories.tsx b/packages/merchant-backoffice-ui/src/paths/instance/orders/details/Detail.stories.tsx index 6e73a01a5..8b892e122 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/orders/details/Detail.stories.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/orders/details/Detail.stories.tsx @@ -91,7 +91,6 @@ export const PaidNotRefundable = createExample(TestedComponent, { refund_details: [], refund_pending: false, wire_details: [], - wire_reports: [], wired: false, }, }); @@ -115,7 +114,6 @@ export const PaidRefundable = createExample(TestedComponent, { refund_details: [], refund_pending: false, wire_details: [], - wire_reports: [], wired: false, }, }); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx index db3842711..45939c19d 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx @@ -29,10 +29,6 @@ interface Props { onConfirm: () => void; } -function isNotUndefined(x: X | undefined): x is X { - return !!x; -} - export function CreatedSuccessfully({ entity, onConfirm, diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/Table.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/Table.tsx index 0c28027fe..b7c22c17f 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/Table.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/list/Table.tsx @@ -161,7 +161,7 @@ function Table({ onClick={(): void => onSelect(i)} style={{ cursor: "pointer" }} > - {i.otp_device_id} + {i.device_description}
    diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx index 52f6c6c29..7c7092a4e 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/update/index.tsx @@ -33,6 +33,7 @@ import { Notification } from "../../../../utils/types.js"; import { UpdatePage } from "./UpdatePage.js"; import { HttpStatusCode } from "@gnu-taler/taler-util"; import { useOtpDeviceAPI, useOtpDeviceDetails } from "../../../../hooks/otp.js"; +import { CreatedSuccessfully } from "../create/CreatedSuccessfully.js"; export type Entity = MerchantBackend.OTP.OtpDevicePatchDetails & WithId; @@ -55,6 +56,7 @@ export default function UpdateValidator({ const { updateOtpDevice } = useOtpDeviceAPI(); const result = useOtpDeviceDetails(vid); const [notif, setNotif] = useState(undefined); + const [keyUpdated, setKeyUpdated] = useState(null) const { i18n } = useTranslationContext(); @@ -73,6 +75,10 @@ export default function UpdateValidator({ return onLoadError(result); } + if (keyUpdated) { + return + } + return ( @@ -85,9 +91,21 @@ export default function UpdateValidator({ otp_ctr: result.data.otp_ctr }} onBack={onBack} - onUpdate={(data) => { - return updateOtpDevice(vid, data) - .then(onConfirm) + onUpdate={async (newInfo) => { + return updateOtpDevice(vid, newInfo) + .then((d) => { + if (newInfo.otp_key) { + setKeyUpdated({ + otp_algorithm: newInfo.otp_algorithm, + otp_device_description: newInfo.otp_device_description, + otp_device_id: newInfo.id, + otp_key: newInfo.otp_key, + otp_ctr: newInfo.otp_ctr, + }) + } else { + onConfirm() + } + }) .catch((error) => { setNotif({ message: i18n.str`could not update template`, -- cgit v1.2.3 From 59fa89ab7a824f4c372896aba09dc247f048adf0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 9 Feb 2024 12:17:30 -0300 Subject: fix #8356: warn about no accounts for admin, prevent using the instance without bank account for non-admin --- .../merchant-backoffice-ui/src/Application.tsx | 10 ++++----- .../merchant-backoffice-ui/src/InstanceRoutes.tsx | 26 ++++++++++++++++++++++ packages/merchant-backoffice-ui/src/hooks/bank.ts | 18 +++++---------- .../src/paths/instance/accounts/list/index.tsx | 8 ++++++- 4 files changed, 43 insertions(+), 19 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/Application.tsx b/packages/merchant-backoffice-ui/src/Application.tsx index e78a6fc0b..57ecb5299 100644 --- a/packages/merchant-backoffice-ui/src/Application.tsx +++ b/packages/merchant-backoffice-ui/src/Application.tsx @@ -19,16 +19,14 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { HttpStatusCode, LibtoolVersion, TranslatedString } from "@gnu-taler/taler-util"; +import { HttpStatusCode, LibtoolVersion } from "@gnu-taler/taler-util"; import { ErrorType, TranslationProvider, - notifyError, - notifyException, - useTranslationContext, + useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; -import { useEffect, useErrorBoundary, useMemo } from "preact/hooks"; +import { useMemo } from "preact/hooks"; import { ApplicationReadyRoutes } from "./ApplicationReadyRoutes.js"; import { Loading } from "./components/exception/loading.js"; import { @@ -140,7 +138,7 @@ function ApplicationStatusRoutes(): VNode { ); } - const SUPPORTED_VERSION = "5:0:1" + const SUPPORTED_VERSION = "8:1:4" if (result.data && !LibtoolVersion.compare( SUPPORTED_VERSION, result.data.version, diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx index a7fd3eb0f..1f3a2b1f8 100644 --- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx @@ -76,6 +76,7 @@ import { LoginToken, MerchantBackend } from "./declaration.js"; import { Settings } from "./paths/settings/index.js"; import { dateFormatForSettings, useSettings } from "./hooks/useSettings.js"; import { TranslatedString } from "@gnu-taler/taler-util"; +import { useInstanceBankAccounts } from "./hooks/bank.js"; export enum InstancePaths { error = "/error", @@ -170,6 +171,9 @@ export function InstanceRoutes({ [id, token, admin], ); + const instance = useInstanceBankAccounts(); + const accounts = !instance.ok ? undefined : instance.data.accounts; + function ServerErrorRedirectTo(to: InstancePaths | AdminPaths) { return function ServerErrorRedirectToImpl( error: HttpError, @@ -247,6 +251,28 @@ export function InstanceRoutes({ updateDefaultToken(undefined) }; + if (accounts !== undefined && !admin && accounts.length < 1) { + return + { + route(InstancePaths.interface) + }} + path={path} + onLogout={clearTokenAndGoToRoot} + setInstanceName={setInstanceName} + isPasswordOk={defaultToken !== undefined} + /> + + { }} /> + + } + return ( = { @@ -106,6 +106,10 @@ export interface BankAccountAPI { export interface InstanceBankAccountFilter { } +export function revalidateInstanceBankAccounts() { + // mutate(key => key instanceof) + return mutate((key) => Array.isArray(key) && key[key.length - 1] === "/private/accounts", undefined, { revalidate: true }); +} export function useInstanceBankAccounts( args?: InstanceBankAccountFilter, updatePosition?: (id: string) => void, @@ -113,17 +117,7 @@ export function useInstanceBankAccounts( MerchantBackend.BankAccounts.AccountsSummaryResponse, MerchantBackend.ErrorDetail > { - // return { - // ok: true, - // loadMore() { }, - // loadMorePrev() { }, - // data: { - // accounts: Object.values(MOCKED_ACCOUNTS).map(e => ({ - // ...e, - // active: true, - // })) - // } - // } + const { fetcher } = useBackendInstanceRequest(); const [pageAfter, setPageAfter] = useState(1); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx index 100241e22..04b6c51fd 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/list/index.tsx @@ -74,7 +74,13 @@ export default function ListOtpDevices({ return ( - + {result.data.accounts.length < 1 && + + } Date: Sat, 10 Feb 2024 13:53:56 +0000 Subject: Translated using Weblate (Spanish) Currently translated at 53.4% (284 of 531 strings) Translation: GNU Taler/Merchant Backoffice Translate-URL: https://weblate.taler.net/projects/gnu-taler/merchant-backoffice/es/ --- packages/merchant-backoffice-ui/src/i18n/es.po | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/i18n/es.po b/packages/merchant-backoffice-ui/src/i18n/es.po index 1d3b3b279..786bfa652 100644 --- a/packages/merchant-backoffice-ui/src/i18n/es.po +++ b/packages/merchant-backoffice-ui/src/i18n/es.po @@ -17,8 +17,8 @@ msgstr "" "Project-Id-Version: Taler Wallet\n" "Report-Msgid-Bugs-To: taler@gnu.org\n" "POT-Creation-Date: 2016-11-23 00:00+0100\n" -"PO-Revision-Date: 2024-01-12 20:30+0000\n" -"Last-Translator: Sebastian Marchano \n" +"PO-Revision-Date: 2024-02-11 12:17+0000\n" +"Last-Translator: Saul Palomino Ramos \n" "Language-Team: Spanish \n" "Language: es\n" @@ -375,7 +375,7 @@ msgstr "Descripcion" #: src/components/form/InputSearchProduct.tsx:94 #, fuzzy, c-format msgid "Product" -msgstr "Productos" +msgstr "AssistIA" #: src/components/form/InputSearchProduct.tsx:95 #, c-format @@ -444,7 +444,7 @@ msgstr "Ningun impuesto configurado para este producto." #: src/components/form/InputTaxes.tsx:119 #, c-format msgid "Amount" -msgstr "Monto" +msgstr "100000" #: src/components/form/InputTaxes.tsx:120 #, c-format @@ -452,8 +452,8 @@ msgid "" "Taxes can be in currencies that differ from the main currency used by the " "merchant." msgstr "" -"Impuestos pueden estar en divisas que difieren de la principal divisa usada " -"por el comerciante." +"10% Impuestos pueden estar en divisas que difieren de la principal divisa " +"usada por el comerciante." #: src/components/form/InputTaxes.tsx:122 #, c-format @@ -2760,7 +2760,7 @@ msgstr "ID de pedido" #: src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx:101 #, c-format msgid "Payment URL" -msgstr "URL de pago" +msgstr "https://demo.kresus.org" #, c-format #~ msgid "Couldn't access the server" -- cgit v1.2.3 From 975a087956c8c392801515db4b6809a368b83e20 Mon Sep 17 00:00:00 2001 From: Sebastian Marchano Date: Mon, 12 Feb 2024 18:59:45 +0000 Subject: Translated using Weblate (Spanish) Currently translated at 53.4% (284 of 531 strings) Translation: GNU Taler/Merchant Backoffice Translate-URL: https://weblate.taler.net/projects/gnu-taler/merchant-backoffice/es/ --- packages/merchant-backoffice-ui/src/i18n/es.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/i18n/es.po b/packages/merchant-backoffice-ui/src/i18n/es.po index 786bfa652..7b6e9b6e0 100644 --- a/packages/merchant-backoffice-ui/src/i18n/es.po +++ b/packages/merchant-backoffice-ui/src/i18n/es.po @@ -17,8 +17,8 @@ msgstr "" "Project-Id-Version: Taler Wallet\n" "Report-Msgid-Bugs-To: taler@gnu.org\n" "POT-Creation-Date: 2016-11-23 00:00+0100\n" -"PO-Revision-Date: 2024-02-11 12:17+0000\n" -"Last-Translator: Saul Palomino Ramos \n" +"PO-Revision-Date: 2024-02-12 19:05+0000\n" +"Last-Translator: Sebastian Marchano \n" "Language-Team: Spanish \n" "Language: es\n" @@ -375,7 +375,7 @@ msgstr "Descripcion" #: src/components/form/InputSearchProduct.tsx:94 #, fuzzy, c-format msgid "Product" -msgstr "AssistIA" +msgstr "Productos" #: src/components/form/InputSearchProduct.tsx:95 #, c-format @@ -444,7 +444,7 @@ msgstr "Ningun impuesto configurado para este producto." #: src/components/form/InputTaxes.tsx:119 #, c-format msgid "Amount" -msgstr "100000" +msgstr "Monto" #: src/components/form/InputTaxes.tsx:120 #, c-format -- cgit v1.2.3 From 9efe5429c2e6dbf97122f2ae6fc4ae2fdd64da7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCgel?= Date: Tue, 13 Feb 2024 14:32:12 +0000 Subject: Translated using Weblate (Spanish) Currently translated at 53.4% (284 of 531 strings) Translation: GNU Taler/Merchant Backoffice Translate-URL: https://weblate.taler.net/projects/gnu-taler/merchant-backoffice/es/ --- packages/merchant-backoffice-ui/src/i18n/es.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/i18n/es.po b/packages/merchant-backoffice-ui/src/i18n/es.po index 7b6e9b6e0..2c4bc64a7 100644 --- a/packages/merchant-backoffice-ui/src/i18n/es.po +++ b/packages/merchant-backoffice-ui/src/i18n/es.po @@ -17,8 +17,8 @@ msgstr "" "Project-Id-Version: Taler Wallet\n" "Report-Msgid-Bugs-To: taler@gnu.org\n" "POT-Creation-Date: 2016-11-23 00:00+0100\n" -"PO-Revision-Date: 2024-02-12 19:05+0000\n" -"Last-Translator: Sebastian Marchano \n" +"PO-Revision-Date: 2024-02-13 14:40+0000\n" +"Last-Translator: Stefan Kügel \n" "Language-Team: Spanish \n" "Language: es\n" @@ -452,8 +452,8 @@ msgid "" "Taxes can be in currencies that differ from the main currency used by the " "merchant." msgstr "" -"10% Impuestos pueden estar en divisas que difieren de la principal divisa " -"usada por el comerciante." +"Impuestos pueden estar en divisas que difieren de la principal divisa usada " +"por el comerciante." #: src/components/form/InputTaxes.tsx:122 #, c-format @@ -2760,7 +2760,7 @@ msgstr "ID de pedido" #: src/paths/instance/orders/create/OrderCreatedSuccessfully.tsx:101 #, c-format msgid "Payment URL" -msgstr "https://demo.kresus.org" +msgstr "URL de pago" #, c-format #~ msgid "Couldn't access the server" -- cgit v1.2.3 From 6c2d6e9ad96b0eeb3f88b4b54bb75f87ba244e87 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 20 Feb 2024 17:33:43 -0300 Subject: fix #8451 --- .../paths/instance/accounts/create/CreatePage.tsx | 22 ++++++++++--- .../src/paths/instance/accounts/create/index.tsx | 6 ++-- .../paths/instance/accounts/update/UpdatePage.tsx | 36 +++++++++++++--------- 3 files changed, 41 insertions(+), 23 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx index 6e4786a47..8539e6783 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx @@ -36,7 +36,7 @@ import { undefinedIfEmpty } from "../../../../utils/table.js"; type Entity = MerchantBackend.BankAccounts.AccountAddDetails & { repeatPassword: string }; interface Props { - onCreate: (d: Entity) => Promise; + onCreate: (d: MerchantBackend.BankAccounts.AccountAddDetails) => Promise; onBack?: () => void; } @@ -44,7 +44,7 @@ const accountAuthType = ["none", "basic"]; function isValidURL(s: string): boolean { try { - const u = new URL(s) + const u = new URL("/", s) return true; } catch (e) { return false; @@ -88,8 +88,22 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { const submitForm = () => { if (hasErrors) return Promise.reject(); - delete state.repeatPassword - return onCreate(state as any); + const credit_facade_url = !state.credit_facade_url ? undefined : new URL("/", state.credit_facade_url).href + const credit_facade_credentials: MerchantBackend.BankAccounts.FacadeCredentials | undefined = + credit_facade_url == undefined ? undefined : + state.credit_facade_credentials?.type === "basic" ? { + type: "basic", + password: state.credit_facade_credentials.password, + username: state.credit_facade_credentials.username, + } : { + type: "none" + } + + return onCreate({ + payto_uri: state.payto_uri!, + credit_facade_credentials, + credit_facade_url, + }); }; return ( diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx index 7d33d25ce..b458efe31 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/create/index.tsx @@ -24,11 +24,9 @@ import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { NotificationCard } from "../../../../components/menu/index.js"; import { MerchantBackend } from "../../../../declaration.js"; -import { useWebhookAPI } from "../../../../hooks/webhooks.js"; +import { useBankAccountAPI } from "../../../../hooks/bank.js"; import { Notification } from "../../../../utils/types.js"; import { CreatePage } from "./CreatePage.js"; -import { useOtpDeviceAPI } from "../../../../hooks/otp.js"; -import { useBankAccountAPI } from "../../../../hooks/bank.js"; export type Entity = MerchantBackend.BankAccounts.AccountAddDetails; interface Props { @@ -53,7 +51,7 @@ export default function CreateValidator({ onConfirm, onBack }: Props): VNode { }) .catch((error) => { setNotif({ - message: i18n.str`could not create device`, + message: i18n.str`could not create account`, type: "ERROR", description: error.message, }); diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx index e0e0ba7ed..9514ed0dc 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx @@ -49,8 +49,14 @@ export function UpdatePage({ account, onUpdate, onBack }: Props): VNode { const [state, setState] = useState>(account); + // @ts-expect-error "unedit" is fine since is part of the accountAuthType values + if (state.credit_facade_credentials?.type === "unedit") { + // we use this to set creds to undefined but server don't get this type + state.credit_facade_credentials = undefined + } + const errors: FormErrors = { - credit_facade_url: !state.credit_facade_url ? i18n.str`required` : !isValidURL(state.credit_facade_url) ? i18n.str`invalid url` : undefined, + credit_facade_url: !state.credit_facade_url ? undefined : !isValidURL(state.credit_facade_url) ? i18n.str`invalid url` : undefined, credit_facade_credentials: undefinedIfEmpty({ username: state.credit_facade_credentials?.type !== "basic" ? undefined @@ -73,19 +79,19 @@ export function UpdatePage({ account, onUpdate, onBack }: Props): VNode { const submitForm = () => { if (hasErrors) return Promise.reject(); - const creds: typeof state.credit_facade_credentials = - state.credit_facade_credentials?.type === "basic" ? { - type: "basic", - password: state.credit_facade_credentials.password, - username: state.credit_facade_credentials.username, - } : state.credit_facade_credentials?.type === "none" ? { - type: "none" - } : undefined; - - return onUpdate({ - credit_facade_credentials: creds, - credit_facade_url: state.credit_facade_url, - }); + const credit_facade_url = !state.credit_facade_url ? undefined : new URL("/", state.credit_facade_url).href + + const credit_facade_credentials: MerchantBackend.BankAccounts.FacadeCredentials | undefined = + credit_facade_url == undefined || state.credit_facade_credentials === undefined ? undefined : + state.credit_facade_credentials.type === "basic" ? { + type: "basic", + password: state.credit_facade_credentials.password, + username: state.credit_facade_credentials.username, + } : { + type: "none" + }; + + return onUpdate({ credit_facade_credentials, credit_facade_url }); }; return ( @@ -187,7 +193,7 @@ export function UpdatePage({ account, onUpdate, onBack }: Props): VNode { function isValidURL(s: string): boolean { try { - const u = new URL(s) + const u = new URL("/", s) return true; } catch (e) { return false; -- cgit v1.2.3 From f5b14b774e3c7f4e240082fac00b1be0a622b096 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 21 Feb 2024 16:06:26 -0300 Subject: fix #8473 --- packages/merchant-backoffice-ui/src/AdminRoutes.tsx | 3 ++- packages/merchant-backoffice-ui/src/InstanceRoutes.tsx | 2 +- packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/AdminRoutes.tsx b/packages/merchant-backoffice-ui/src/AdminRoutes.tsx index 91dec09b0..70b28a838 100644 --- a/packages/merchant-backoffice-ui/src/AdminRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/AdminRoutes.tsx @@ -17,6 +17,7 @@ import { h, VNode } from "preact"; import { Router, route, Route } from "preact-router"; import InstanceCreatePage from "./paths/admin/create/index.js"; import InstanceListPage from "./paths/admin/list/index.js"; +import { InstancePaths } from "./InstanceRoutes.js"; export enum AdminPaths { list_instances = "/instances", @@ -42,7 +43,7 @@ export function AdminRoutes(): VNode { component={InstanceCreatePage} onBack={() => route(AdminPaths.list_instances)} onConfirm={() => { - // route(AdminPaths.list_instances); + route(InstancePaths.bank_list); }} // onError={(error: any) => { diff --git a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx index 1f3a2b1f8..8eb0cd717 100644 --- a/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx +++ b/packages/merchant-backoffice-ui/src/InstanceRoutes.tsx @@ -231,7 +231,7 @@ export function InstanceRoutes({ { - route(InstancePaths.order_list); + route(InstancePaths.bank_list); }} /> diff --git a/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx b/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx index 23f41ecff..2de019276 100644 --- a/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/admin/create/index.tsx @@ -62,7 +62,7 @@ export default function Create({ onBack, onConfirm, forceId }: Props): VNode { } else { updateToken(undefined) } - } + } onConfirm(); } catch (ex) { if (ex instanceof Error) { -- cgit v1.2.3 From ac132ac890634ced772478cee850518527ffbd9f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 27 Feb 2024 09:51:04 -0300 Subject: grammar --- .../src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/merchant-backoffice-ui/src') diff --git a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx index 45939c19d..a48b6fe63 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/otp_devices/create/CreatedSuccessfully.tsx @@ -44,7 +44,7 @@ export function CreatedSuccessfully({