taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 5a1786aea8150379a7087717194cad3ea1c9b48a
parent bb6890e05dc562a8f40c0ac949de2fd247a82019
Author: Sebastian <sebasjm@taler-systems.com>
Date:   Mon, 18 May 2026 11:13:19 -0300

currency id fixed

Diffstat:
Mpackages/merchant-backoffice-ui/src/paths/instance/orders/create/CreatePage.tsx | 4++--
Mpackages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx | 2+-
Mpackages/merchant-backoffice-ui/src/paths/newAccount/index.tsx | 8++++++--
Mpackages/taler-util/src/operation.ts | 30++++++++++++++++++++++++++++++
Mpackages/taler-util/src/types-taler-merchant.ts | 16++++++++++++----
5 files changed, 51 insertions(+), 9 deletions(-)

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 @@ -341,7 +341,7 @@ export function CreatePage({ case HttpStatusCode.Conflict: return i18n.str`Conflict`; case HttpStatusCode.Gone: - return i18n.str`Product with ID "${fail.body.product_id}" is out of stock.`; + return i18n.str`Product with ID "${fail.body.product_id}" is out of stock. You can sell at least ${fail.body.available_quantity} in the current stock.`; case HttpStatusCode.UnavailableForLegalReasons: return i18n.str`No payment service would accept a payment because of KYC requirements.`; default: @@ -388,7 +388,7 @@ export function CreatePage({ const { currency } = useCurrenciesContext(); - const zero = !currency ? undefined : Amounts.zeroOfCurrency(currency.name); + const zero = !currency ? undefined : Amounts.zeroOfCurrency(currency.id); const totalPriceInventory = inventoryList.reduce((prev, cur) => { const p = Amounts.parseOrThrow(cur.product.price); 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 @@ -157,7 +157,7 @@ export function CreatePage({ (k) => (errors as Record<string, unknown>)[k] !== undefined, ); - const zero = !currency ? undefined : Amounts.zeroOfCurrency(currency.name); + const zero = !currency ? undefined : Amounts.zeroOfCurrency(currency.id); const contract_amount = state.amount_editable ? undefined diff --git a/packages/merchant-backoffice-ui/src/paths/newAccount/index.tsx b/packages/merchant-backoffice-ui/src/paths/newAccount/index.tsx @@ -100,13 +100,17 @@ export function NewAccount({ onCancel, onCreated }: Props): VNode { {}, ); - const [value, setValue] = useState<Partial<Account>>(savedForm); - const serverRequiresEmail = config.mandatory_tan_channels?.indexOf(TanChannel.EMAIL) !== -1; const serverRequiresSms = config.mandatory_tan_channels?.indexOf(TanChannel.SMS) !== -1; + const [value, setValue] = useState<Partial<Account>>({ + ...savedForm, + email: !serverRequiresEmail ? undefined : savedForm.email, + phone: !serverRequiresSms ? undefined : savedForm.phone, + }); + let phoneRegex: RegExp | undefined = undefined; if (config.phone_regex) { try { diff --git a/packages/taler-util/src/operation.ts b/packages/taler-util/src/operation.ts @@ -269,6 +269,36 @@ export function succeedOrThrow<R>(resp: OperationResult<R, unknown>): R { } /** + * The operation is expected to fail. + * Return the error details. + * Throw if the operation didn't fail with expected code. + * + * @param resp + * @param s + * @returns + */ +export function failOrThrow<E>( + resp: OperationResult<unknown, E>, + s: E, +): TalerErrorDetail | undefined { + if (isOperationOk(resp)) { + throw TalerError.fromException( + new Error(`request succeed but failure "${s}" was expected`), + ); + } + if (isOperationFail(resp) && resp.case === s) { + return resp.detail; + } + throw TalerError.fromException( + new Error( + `request failed with "${JSON.stringify( + resp, + )}" but case "${s}" was expected`, + ), + ); +} + +/** * The operation is expected to fail with a body. * Return the body of the result. * Throw if the operation didn't fail with expected code. diff --git a/packages/taler-util/src/types-taler-merchant.ts b/packages/taler-util/src/types-taler-merchant.ts @@ -2906,20 +2906,26 @@ export interface PostOrderResponse { token?: ClaimToken; } export interface OutOfStockResponse { + // Product ID of an out-of-stock item. product_id: string; - // Requested quantity. + // Legacy integer quantity requested. Deprecated; see unit_requested_quantity. requested_quantity: Integer; - // Available quantity (must be below requested_quantity). + // Requested quantity using "<integer>[.<fraction>]" syntax with up to six fractional digits. + unit_requested_quantity: string; + + // Legacy integer availability (must be below requested_quantity). available_quantity: Integer; + // Available quantity using "<integer>[.<fraction>]" syntax with up to six fractional digits. + unit_available_quantity: string; + // When do we expect the product to be again in stock? // Optional, not given if unknown. restock_expected?: Timestamp; } - export interface OrderHistory { // Timestamp-sorted array of all orders matching the query. // The order of the sorting depends on the sign of delta. @@ -4973,7 +4979,9 @@ export const codecForOutOfStockResponse = (): Codec<OutOfStockResponse> => .property("product_id", codecForString()) .property("available_quantity", codecForNumber()) .property("requested_quantity", codecForNumber()) - .property("restock_expected", codecForTimestamp) + .property("unit_available_quantity", codecForString()) + .property("unit_requested_quantity", codecForString()) + .property("restock_expected", codecOptional(codecForTimestamp)) .build("TalerMerchantApi.OutOfStockResponse"); export const codecForOrderHistory = (): Codec<OrderHistory> =>