diff options
Diffstat (limited to 'packages/merchant-backoffice/src/paths/instance/reserves/create')
5 files changed, 0 insertions, 413 deletions
diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/create/Create.stories.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/create/Create.stories.tsx deleted file mode 100644 index e138770..0000000 --- a/packages/merchant-backoffice/src/paths/instance/reserves/create/Create.stories.tsx +++ /dev/null @@ -1,42 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 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 <http://www.gnu.org/licenses/> - */ - -/** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ - -import { h, VNode, FunctionalComponent } from 'preact'; -import { CreatePage as TestedComponent } from './CreatePage'; - - -export default { - title: 'Pages/Reserve/Create', - component: TestedComponent, - argTypes: { - onCreate: { action: 'onCreate' }, - onBack: { action: 'onBack' }, - }, -}; - -function createExample<Props>(Component: FunctionalComponent<Props>, props: Partial<Props>) { - const r = (args: any) => <Component {...args} /> - r.args = props - return r -} - -export const Example = createExample(TestedComponent, { -}); diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatePage.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatePage.tsx deleted file mode 100644 index 2e85cf9..0000000 --- a/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatePage.tsx +++ /dev/null @@ -1,168 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 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 <http://www.gnu.org/licenses/> - */ - -/** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ - -import { Fragment, h, VNode } from "preact"; -import { StateUpdater, useEffect, useState } from "preact/hooks"; -import { FormErrors, FormProvider } from "../../../../components/form/FormProvider"; -import { Input } from "../../../../components/form/Input"; -import { InputCurrency } from "../../../../components/form/InputCurrency"; -import { ExchangeBackend, MerchantBackend } from "../../../../declaration"; -import { Translate, useTranslator } from "../../../../i18n"; -import { AsyncButton } from "../../../../components/exception/AsyncButton"; -import { canonicalizeBaseUrl, ExchangeKeysJson } from "@gnu-taler/taler-util" -import { PAYTO_WIRE_METHOD_LOOKUP, URL_REGEX } from "../../../../utils/constants"; -import { request } from "../../../../hooks/backend"; -import { InputSelector } from "../../../../components/form/InputSelector"; - -type Entity = MerchantBackend.Tips.ReserveCreateRequest - -interface Props { - onCreate: (d: Entity) => Promise<void>; - onBack?: () => void; -} - - -enum Steps { - EXCHANGE, - WIRE_METHOD, -} - -interface ViewProps { - step: Steps, - setCurrentStep: (s: Steps) => void; - reserve: Partial<Entity>; - onBack?: () => void; - submitForm: () => Promise<void>; - setReserve: StateUpdater<Partial<Entity>>; -} -function ViewStep({ step, setCurrentStep, reserve, onBack, submitForm, setReserve }: ViewProps): VNode { - const i18n = useTranslator() - const [wireMethods, setWireMethods] = useState<Array<string>>([]) - const [exchangeQueryError, setExchangeQueryError] = useState<string | undefined>(undefined) - - useEffect(() => { - setExchangeQueryError(undefined) - }, [reserve.exchange_url]) - - switch (step) { - case Steps.EXCHANGE: { - const errors: FormErrors<Entity> = { - initial_balance: !reserve.initial_balance ? 'cannot be empty' : !(parseInt(reserve.initial_balance.split(':')[1], 10) > 0) ? i18n`it should be greater than 0` : undefined, - exchange_url: !reserve.exchange_url ? i18n`cannot be empty` : !URL_REGEX.test(reserve.exchange_url) ? i18n`must be a valid URL` : !exchangeQueryError ? undefined : exchangeQueryError, - } - - const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !== undefined) - - return <Fragment> - <FormProvider<Entity> object={reserve} errors={errors} valueHandler={setReserve}> - <InputCurrency<Entity> name="initial_balance" label={i18n`Initial balance`} tooltip={i18n`balance prior to deposit`} /> - <Input<Entity> name="exchange_url" label={i18n`Exchange URL`} tooltip={i18n`URL of exchange`} /> - </FormProvider> - - <div class="buttons is-right mt-5"> - {onBack && <button class="button" onClick={onBack} ><Translate>Cancel</Translate></button>} - <AsyncButton class="has-tooltip-left" onClick={() => { - return request<ExchangeBackend.WireResponse>(`${reserve.exchange_url}wire`).then(r => { - const wireMethods = r.data.accounts.map(a => { - const match = PAYTO_WIRE_METHOD_LOOKUP.exec(a.payto_uri) - return match && match[1] || '' - }) - setWireMethods(wireMethods) - setCurrentStep(Steps.WIRE_METHOD) - return - }).catch((r: any) => { - setExchangeQueryError(r.message) - }) - }} data-tooltip={ - hasErrors ? i18n`Need to complete marked fields` : 'confirm operation' - } disabled={hasErrors} ><Translate>Next</Translate></AsyncButton> - </div> - </Fragment> - } - - case Steps.WIRE_METHOD: { - const errors: FormErrors<Entity> = { - wire_method: !reserve.wire_method ? i18n`cannot be empty` : undefined, - } - - const hasErrors = Object.keys(errors).some(k => (errors as any)[k] !== undefined) - return <Fragment> - <FormProvider<Entity> object={reserve} errors={errors} valueHandler={setReserve}> - <InputCurrency<Entity> name="initial_balance" label={i18n`Initial balance`} tooltip={i18n`balance prior to deposit`} readonly /> - <Input<Entity> name="exchange_url" label={i18n`Exchange URL`} tooltip={i18n`URL of exchange`} readonly /> - <InputSelector<Entity> name="wire_method" label={i18n`Wire method`} tooltip={i18n`method to use for wire transfer`} values={wireMethods} placeholder={i18n`Select one wire method`} /> - </FormProvider> - <div class="buttons is-right mt-5"> - {onBack && <button class="button" onClick={() => setCurrentStep(Steps.EXCHANGE)} ><Translate>Back</Translate></button>} - <AsyncButton onClick={submitForm} data-tooltip={ - hasErrors ? i18n`Need to complete marked fields` : 'confirm operation' - } disabled={hasErrors} ><Translate>Confirm</Translate></AsyncButton> - </div> - </Fragment> - - } - } -} - -export function CreatePage({ onCreate, onBack }: Props): VNode { - const [reserve, setReserve] = useState<Partial<Entity>>({}) - - - const submitForm = () => { - return onCreate(reserve as Entity) - } - - const [currentStep, setCurrentStep] = useState(Steps.EXCHANGE) - - - return <div> - <section class="section is-main-section"> - <div class="columns"> - <div class="column" /> - <div class="column is-four-fifths"> - - <div class="tabs is-toggle is-fullwidth is-small"> - <ul> - <li class={currentStep === Steps.EXCHANGE ? "is-active" : ""}> - <a style={{ cursor: 'initial' }}> - <span>Step 1: Specify exchange</span> - </a> - </li> - <li class={currentStep === Steps.WIRE_METHOD ? "is-active" : ""}> - <a style={{ cursor: 'initial' }}> - <span>Step 2: Select wire method</span> - </a> - </li> - </ul> - </div> - - <ViewStep step={currentStep} reserve={reserve} - setCurrentStep={setCurrentStep} - setReserve={setReserve} - submitForm={submitForm} - onBack={onBack} - /> - </div> - <div class="column" /> - </div> - </section> - </div> -} diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatedSuccessfully.stories.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatedSuccessfully.stories.tsx deleted file mode 100644 index f013040..0000000 --- a/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatedSuccessfully.stories.tsx +++ /dev/null @@ -1,53 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 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 <http://www.gnu.org/licenses/> - */ - -/** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ - -import { h, VNode, FunctionalComponent } from 'preact'; -import { CreatedSuccessfully as TestedComponent } from './CreatedSuccessfully'; - - -export default { - title: 'Pages/Reserve/CreatedSuccessfully', - component: TestedComponent, - argTypes: { - onCreate: { action: 'onCreate' }, - onBack: { action: 'onBack' }, - }, -}; - -function createExample<Props>(Component: FunctionalComponent<Props>, props: Partial<Props>) { - const r = (args: any) => <Component {...args} /> - r.args = props - return r -} - -export const Example = createExample(TestedComponent, { - entity: { - request: { - exchange_url: 'http://exchange.taler/', - initial_balance: 'TESTKUDOS:1', - wire_method: 'x-taler-bank', - }, - response: { - payto_uri: 'payto://x-taler-bank/bank.taler:8080/exchange_account', - reserve_pub: 'WEQWDASDQWEASDADASDQWEQWEASDAS' - } - } -}); diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatedSuccessfully.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatedSuccessfully.tsx deleted file mode 100644 index 255486d..0000000 --- a/packages/merchant-backoffice/src/paths/instance/reserves/create/CreatedSuccessfully.tsx +++ /dev/null @@ -1,79 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 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 <http://www.gnu.org/licenses/> - */ - -import { h, VNode } from "preact"; -import { CreatedSuccessfully as Template } from "../../../../components/notifications/CreatedSuccessfully"; -import { MerchantBackend } from "../../../../declaration"; -import { Translate } from "../../../../i18n"; -import { QR } from "../../../../components/exception/QR"; - -type Entity = { request: MerchantBackend.Tips.ReserveCreateRequest, response: MerchantBackend.Tips.ReserveCreateConfirmation }; - -interface Props { - entity: Entity; - onConfirm: () => void; - onCreateAnother?: () => void; -} - -export function CreatedSuccessfully({ entity, onConfirm, onCreateAnother }: Props): VNode { - const link = `${entity.response.payto_uri}?message=${entity.response.reserve_pub}&amount=${entity.request.initial_balance}` - - return <Template onConfirm={onConfirm} onCreateAnother={onCreateAnother}> - <div class="field is-horizontal"> - <div class="field-label is-normal"> - <label class="label">Amount</label> - </div> - <div class="field-body is-flex-grow-3"> - <div class="field"> - <p class="control"> - <input readonly class="input" value={entity.request.initial_balance} /> - </p> - </div> - </div> - </div> - <div class="field is-horizontal"> - <div class="field-label is-normal"> - <label class="label">Exchange bank account</label> - </div> - <div class="field-body is-flex-grow-3"> - <div class="field"> - <p class="control"> - <input readonly class="input" value={entity.response.payto_uri} /> - </p> - </div> - </div> - </div> - <div class="field is-horizontal"> - <div class="field-label is-normal"> - <label class="label">Wire transfer subject</label> - </div> - <div class="field-body is-flex-grow-3"> - <div class="field"> - <p class="control"> - <input class="input" readonly value={entity.response.reserve_pub} /> - </p> - </div> - </div> - </div> - <p class="is-size-5"><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.</Translate></p> - <p class="is-size-5"><Translate>If your system supports RFC 8905, you can do this by opening this URI:</Translate></p> - <pre> - <a target="_blank" rel="noreferrer" href={link}>{link}</a> - </pre> - <QR text={link} /> - </Template>; -} - diff --git a/packages/merchant-backoffice/src/paths/instance/reserves/create/index.tsx b/packages/merchant-backoffice/src/paths/instance/reserves/create/index.tsx deleted file mode 100644 index 5c2fdaf..0000000 --- a/packages/merchant-backoffice/src/paths/instance/reserves/create/index.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 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 <http://www.gnu.org/licenses/> - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { Fragment, h, VNode } from "preact"; -import { useState } from "preact/hooks"; -import { NotificationCard } from "../../../../components/menu"; -import { MerchantBackend } from "../../../../declaration"; -import { useReservesAPI } from "../../../../hooks/reserves"; -import { useTranslator } from "../../../../i18n"; -import { Notification } from "../../../../utils/types"; -import { CreatedSuccessfully } from "./CreatedSuccessfully"; -import { CreatePage } from "./CreatePage"; -interface Props { - onBack: () => void; - onConfirm: () => void; -} -export default function CreateReserve({ onBack, onConfirm }: Props): VNode { - const { createReserve } = useReservesAPI(); - const [notif, setNotif] = useState<Notification | undefined>(undefined); - const i18n = useTranslator(); - - const [createdOk, setCreatedOk] = useState< - | { - request: MerchantBackend.Tips.ReserveCreateRequest; - response: MerchantBackend.Tips.ReserveCreateConfirmation; - } - | undefined - >(undefined); - - if (createdOk) { - return <CreatedSuccessfully entity={createdOk} onConfirm={onConfirm} />; - } - - return ( - <Fragment> - <NotificationCard notification={notif} /> - <CreatePage - onBack={onBack} - onCreate={(request: MerchantBackend.Tips.ReserveCreateRequest) => { - return createReserve(request) - .then((r) => setCreatedOk({ request, response: r.data })) - .catch((error) => { - setNotif({ - message: i18n`could not create reserve`, - type: "ERROR", - description: error.message, - }); - }); - }} - /> - </Fragment> - ); -} |