From ea17520cbdf0e0904605e2a18365d63ab4aeb3a6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 13 Jun 2024 15:46:15 -0300 Subject: fix #8932 --- .../paths/instance/accounts/create/CreatePage.tsx | 83 +++++++++++++++++++--- .../src/paths/instance/accounts/create/index.tsx | 80 +-------------------- .../src/paths/instance/transfers/list/index.tsx | 2 +- 3 files changed, 75 insertions(+), 90 deletions(-) (limited to 'packages/merchant-backoffice-ui/src') 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>({}); const facadeURL = safeConvertURL(state.credit_facade_url); + const [testError, setTestError] = useState( + undefined, + ); const errors: FormErrors = { 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 (
{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); }} /> @@ -192,6 +245,16 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {
+ +