diff options
author | Sebastian <sebasjm@gmail.com> | 2024-06-13 15:46:15 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-06-13 15:46:15 -0300 |
commit | ea17520cbdf0e0904605e2a18365d63ab4aeb3a6 (patch) | |
tree | 8ad587ab50ce8fb9e143363279606b5a712dacc9 /packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx | |
parent | 4f7eac1af8704d11fb3f58650558f932791f3d8e (diff) | |
download | wallet-core-ea17520cbdf0e0904605e2a18365d63ab4aeb3a6.tar.xz |
fix #8932
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/accounts/create/CreatePage.tsx | 83 |
1 files changed, 73 insertions, 10 deletions
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 8b583308f..2f19d0c91 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 @@ -19,7 +19,13 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { TalerMerchantApi } from "@gnu-taler/taler-util"; +import { + HttpStatusCode, + TalerError, + TalerMerchantApi, + TranslatedString, + assertUnreachable, +} from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; @@ -34,6 +40,7 @@ import { InputSelector } from "../../../../components/form/InputSelector.js"; import { ImportingAccountModal } from "../../../../components/modal/index.js"; import { undefinedIfEmpty } from "../../../../utils/table.js"; import { safeConvertURL } from "../update/UpdatePage.js"; +import { testRevenueAPI } from "./index.js"; type Entity = TalerMerchantApi.AccountAddDetails; @@ -50,6 +57,9 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { const [importing, setImporting] = useState(false); const [state, setState] = useState<Partial<Entity>>({}); const facadeURL = safeConvertURL(state.credit_facade_url); + const [testError, setTestError] = useState<TranslatedString | undefined>( + undefined, + ); const errors: FormErrors<Entity> = { payto_uri: !state.payto_uri ? i18n.str`required` : undefined, @@ -110,6 +120,46 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { credit_facade_url, }); }; + + async function testAccountInfo() { + const revenueAPI = !state.credit_facade_url + ? undefined + : new URL("./", state.credit_facade_url); + + if (revenueAPI) { + const resp = await testRevenueAPI( + revenueAPI, + state.credit_facade_credentials, + ); + if (resp instanceof TalerError) { + setTestError(i18n.str`The request to check the revenue API failed.`); + return; + } + if (resp.type === "fail") { + switch (resp.case) { + case HttpStatusCode.BadRequest: { + setTestError(i18n.str`Server replied with "bad request".`); + return; + } + case HttpStatusCode.Unauthorized: { + setTestError(i18n.str`Unauthorized, try with another credentials.`); + + return; + } + case HttpStatusCode.NotFound: { + setTestError( + i18n.str`The endpoint doesn't seems to be a Taler Revenue API.`, + ); + return; + } + default: { + assertUnreachable(resp); + } + } + } + } + } + return ( <div> {importing && ( @@ -119,27 +169,30 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { }} onConfirm={(ac) => { const u = new URL(ac.infoURL); - const user = u.username - const pwd = u.password + const user = u.username; + const pwd = u.password; u.password = ""; u.username = ""; const credit_facade_url = u.href; setState({ payto_uri: ac.accountURI, - credit_facade_credentials: user || pwd ? { - type: "basic", - password: pwd, - username: user, - }: undefined, + credit_facade_credentials: + user || pwd + ? { + type: "basic", + password: pwd, + username: user, + } + : undefined, credit_facade_url, - }) + }); // if (u.username && ac.accesToken) { // state.credit_facade_credentials = { // type: "bearer", // token: ac.accesToken, // username: u.username, // }; - // } else + // } else setImporting(false); }} /> @@ -196,6 +249,16 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { class="button is-info" data-tooltip={i18n.str`Need to complete marked fields`} onClick={() => { + testAccountInfo(); + }} + > + <i18n.Translate>Test account info</i18n.Translate> + </button> + + <button + class="button is-info" + data-tooltip={i18n.str`Need to complete marked fields`} + onClick={() => { setImporting(true); }} > |