diff options
author | Sebastian <sebasjm@gmail.com> | 2023-05-05 08:38:28 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-05-05 08:52:58 -0300 |
commit | b64bb455a2d51f7e19e517c0bd158ff7d7d9557f (patch) | |
tree | 3a91ee40c5ac4b355d2ef33965a9bc2dfd1ef275 /packages/merchant-backoffice-ui/src/paths/instance/reserves | |
parent | e90991973c359f1aca5bd34b3344e0295dae0c5d (diff) | |
download | wallet-core-b64bb455a2d51f7e19e517c0bd158ff7d7d9557f.tar.xz |
update to new web-utils imports
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/reserves')
10 files changed, 151 insertions, 133 deletions
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 ( <Template onConfirm={onConfirm} onCreateAnother={onCreateAnother}> @@ -90,76 +76,115 @@ export function CreatedSuccessfully({ </div> </div> </div> - {links.length === 0 ? ( - <Fragment> - <p class="is-size-5"> - The response of the reserve creation have invalid accounts. List of - invalid payto URIs below: - </p> - <ul> - {entity.response.accounts.map((a, idx) => { - return <li key={idx}>{a.payto_uri}</li>; - })} - </ul> - </Fragment> - ) : links.length === 1 ? ( - <Fragment> - <p class="is-size-5"> - <i18n.Translate> - 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. - </i18n.Translate> - </p> - <p style={{ margin: 10 }}> - <b>Exchange bank account</b> - </p> - <QR text={links[0]} /> - <p class="is-size-5"> - <i18n.Translate> - If your system supports RFC 8905, you can do this by opening this - URI: - </i18n.Translate> - </p> - <pre> - <a target="_blank" rel="noreferrer" href={links[0]}> - {links[0]} - </a> - </pre> - </Fragment> - ) : ( - <div> - <p class="is-size-5"> - <i18n.Translate> - 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. - </i18n.Translate> - </p> + <ShowAccountsOfReserveAsQRWithLink + accounts={entity.response.accounts ?? []} + message={entity.response.reserve_pub} + amount={entity.request.initial_balance} + /> + </Template> + ); +} - <p style={{ margin: 10 }}> - <b>Exchange bank accounts</b> - </p> - <p class="is-size-5"> - <i18n.Translate> - If your system supports RFC 8905, you can do this by clicking on - the URI below the QR code: - </i18n.Translate> - </p> - {links.map((link) => { - return ( - <Fragment> - <QR text={link} /> - <pre> - <a target="_blank" rel="noreferrer" href={link}> - {link} - </a> - </pre> - </Fragment> - ); +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 ( + <Fragment> + <p class="is-size-5"> + The reserve have invalid accounts. List of invalid payto URIs below: + </p> + <ul> + {accounts.map((a, idx) => { + return <li key={idx}>{a.payto_uri}</li>; })} - </div> - )} - </Template> + </ul> + </Fragment> + ); + } + + if (links.length === 1) { + return ( + <Fragment> + <p class="is-size-5"> + <i18n.Translate> + 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. + </i18n.Translate> + </p> + <p style={{ margin: 10 }}> + <b>Exchange bank account</b> + </p> + <QR text={links[0]} /> + <p class="is-size-5"> + <i18n.Translate> + If your system supports RFC 8905, you can do this by opening this + URI: + </i18n.Translate> + </p> + <pre> + <a target="_blank" rel="noreferrer" href={links[0]}> + {links[0]} + </a> + </pre> + </Fragment> + ); + } + + return ( + <div> + <p class="is-size-5"> + <i18n.Translate> + 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. + </i18n.Translate> + </p> + + <p style={{ margin: 10 }}> + <b>Exchange bank accounts</b> + </p> + <p class="is-size-5"> + <i18n.Translate> + If your system supports RFC 8905, you can do this by clicking on the + URI below the QR code: + </i18n.Translate> + </p> + {links.map((link) => { + return ( + <Fragment> + <QR text={link} /> + <pre> + <a target="_blank" rel="noreferrer" href={link}> + {link} + </a> + </pre> + </Fragment> + ); + })} + </div> ); } 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 ( <div class="columns"> @@ -111,11 +105,6 @@ export function DetailPage({ id, selected, onBack }: Props): VNode { /> </Fragment> )} - <Input<Entity> - name="payto_uri" - label={i18n.str`Account address`} - readonly - /> <Input name="id" label={i18n.str`Subject`} readonly /> </FormProvider> @@ -143,30 +132,13 @@ export function DetailPage({ id, selected, onBack }: Props): VNode { </div> </div> </Fragment> - ) : ( - <Fragment> - <p class="is-size-5"> - <i18n.Translate> - 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. - </i18n.Translate> - </p> - <p class="is-size-5"> - <i18n.Translate> - If your system supports RFC 8905, you can do this by opening - this URI: - </i18n.Translate> - </p> - <pre> - <a target="_blank" rel="noreferrer" href={link}> - {link} - </a> - </pre> - <QR text={link} /> - </Fragment> - )} + ) : selected.accounts ? ( + <ShowAccountsOfReserveAsQRWithLink + accounts={selected.accounts} + amount={selected.merchant_initial_amount} + message={id} + /> + ) : undefined} <div class="buttons is-right mt-5"> <button class="button" onClick={onBack}> 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 index cd1318922..2592e2c6e 100644 --- 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 @@ -54,7 +54,14 @@ export const Funded = createExample(TestedComponent, { }, merchant_initial_amount: "TESTKUDOS:10", pickup_amount: "TESTKUDOS:10", - payto_uri: "payto://x-taler-bank/bank.taler:8080/account", + accounts: [ + { + payto_uri: "payto://x-taler-bank/bank.taler:8080/account", + credit_restrictions: [], + debit_restrictions: [], + master_sig: "", + }, + ], exchange_url: "http://exchange.taler/", }, }); @@ -73,7 +80,14 @@ export const NotYetFunded = createExample(TestedComponent, { }, merchant_initial_amount: "TESTKUDOS:10", pickup_amount: "TESTKUDOS:10", - payto_uri: "payto://x-taler-bank/bank.taler:8080/account", + accounts: [ + { + payto_uri: "payto://x-taler-bank/bank.taler:8080/account", + credit_restrictions: [], + debit_restrictions: [], + master_sig: "", + }, + ], exchange_url: "http://exchange.taler/", }, }); @@ -92,7 +106,14 @@ export const FundedWithEmptyTips = createExample(TestedComponent, { }, merchant_initial_amount: "TESTKUDOS:10", pickup_amount: "TESTKUDOS:10", - payto_uri: "payto://x-taler-bank/bank.taler:8080/account", + accounts: [ + { + payto_uri: "payto://x-taler-bank/bank.taler:8080/account", + credit_restrictions: [], + debit_restrictions: [], + master_sig: "", + }, + ], exchange_url: "http://exchange.taler/", tips: [ { 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 index e7919aab1..8e2a74529 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/details/index.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { ErrorType, HttpError } from "@gnu-taler/web-util/lib/index.browser"; +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"; diff --git a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.tsx b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.tsx index 3a591c555..1882f50d3 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/AutorizeTipModal.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 { h, VNode } from "preact"; import { useState } from "preact/hooks"; import * as yup from "yup"; 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 index 36768855d..1f229d7cb 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/Table.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 { format } from "date-fns"; import { Fragment, h, VNode } from "preact"; import { MerchantBackend, WithId } from "../../../../declaration.js"; 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 index d2a821136..14387c2a9 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/index.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/reserves/list/index.tsx @@ -23,7 +23,7 @@ import { ErrorType, HttpError, useTranslationContext, -} from "@gnu-taler/web-util/lib/index.browser"; +} from "@gnu-taler/web-util/browser"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Loading } from "../../../../components/exception/loading.js"; |