From b64bb455a2d51f7e19e517c0bd158ff7d7d9557f Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 5 May 2023 08:38:28 -0300 Subject: update to new web-utils imports --- .../paths/instance/reserves/create/CreatePage.tsx | 2 +- .../create/CreatedSuccessfully.stories.tsx | 2 +- .../reserves/create/CreatedSuccessfully.tsx | 197 ++++++++++++--------- .../src/paths/instance/reserves/create/index.tsx | 2 +- .../paths/instance/reserves/details/DetailPage.tsx | 46 +---- .../instance/reserves/details/Details.stories.tsx | 27 ++- .../src/paths/instance/reserves/details/index.tsx | 2 +- .../instance/reserves/list/AutorizeTipModal.tsx | 2 +- .../src/paths/instance/reserves/list/Table.tsx | 2 +- .../src/paths/instance/reserves/list/index.tsx | 2 +- 10 files changed, 151 insertions(+), 133 deletions(-) (limited to 'packages/merchant-backoffice-ui/src/paths/instance/reserves') 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 index c0c36e651..fccb20121 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatePage.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; +import { 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"; 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 index 4b634c6c0..445ca3ef0 100644 --- 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 @@ -21,7 +21,7 @@ import { h, VNode, FunctionalComponent } from "preact"; import { CreatedSuccessfully as TestedComponent } from "./CreatedSuccessfully.js"; -import { tests } from "@gnu-taler/web-util/lib/index.browser"; +import * as tests from "@gnu-taler/web-util/testing"; export default { title: "Pages/Reserve/CreatedSuccessfully", 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 index 7ba531a94..94fcdaff7 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/CreatedSuccessfully.tsx @@ -15,11 +15,11 @@ */ import { parsePaytoUri, stringifyPaytoUri } from "@gnu-taler/taler-util"; -import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; -import { Fragment, h, VNode } from "preact"; +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 } from "../../../../declaration.js"; +import { MerchantBackend, WireAccount } from "../../../../declaration.js"; type Entity = { request: MerchantBackend.Tips.ReserveCreateRequest; @@ -41,20 +41,6 @@ export function CreatedSuccessfully({ onConfirm, onCreateAnother, }: Props): VNode { - const accountsInfo = !entity.response.accounts - ? [] - : entity.response.accounts - .map((acc) => { - const p = parsePaytoUri(acc.payto_uri); - if (p) { - p.params["message"] = entity.response.reserve_pub; - p.params["amount"] = entity.request.initial_balance; - } - return p; - }) - .filter(isNotUndefined); - - const links = accountsInfo.map((a) => stringifyPaytoUri(a)); const { i18n } = useTranslationContext(); return ( + ); +} -

- 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}
-                  
-                
-
- ); +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: +

+ +
+ ); + } + + 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 index 0d39fc298..8a4fe1565 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/create/index.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; +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"; 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 index 54e8123e4..b0173b5d3 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/DetailPage.tsx @@ -24,7 +24,7 @@ import { parsePaytoUri, stringifyPaytoUri, } from "@gnu-taler/taler-util"; -import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; +import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { format } from "date-fns"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; @@ -38,6 +38,7 @@ import { SimpleModal } from "../../../../components/modal/index.js"; import { MerchantBackend } from "../../../../declaration.js"; import { useTipDetails } from "../../../../hooks/reserves.js"; import { TipInfo } from "./TipInfo.js"; +import { ShowAccountsOfReserveAsQRWithLink } from "../create/CreatedSuccessfully.js"; type Entity = MerchantBackend.Tips.ReserveDetail; type CT = MerchantBackend.ContractTerms; @@ -53,13 +54,6 @@ export function DetailPage({ id, selected, onBack }: Props): VNode { const didExchangeAckTransfer = Amounts.isNonZero( Amounts.parseOrThrow(selected.exchange_initial_amount), ); - const p = parsePaytoUri(selected.payto_uri); - if (p) { - p.params["message"] = id; - p.params["amount"] = selected.merchant_initial_amount; - } - - const link = !p ? selected.payto_uri : stringifyPaytoUri(p); return (
@@ -111,11 +105,6 @@ export function DetailPage({ id, selected, onBack }: Props): VNode { /> )} - - name="payto_uri" - label={i18n.str`Account address`} - readonly - /> @@ -143,30 +132,13 @@ export function DetailPage({ id, selected, onBack }: Props): VNode {
- ) : ( - -

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

-

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

-
-                
-                  {link}
-                
-              
- -
- )} + ) : selected.accounts ? ( + + ) : undefined}