diff options
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 | 25 |
1 files changed, 12 insertions, 13 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 255caa375..d05375b6c 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 @@ -32,6 +32,7 @@ import { Input } from "../../../../components/form/Input.js"; import { InputPaytoForm } from "../../../../components/form/InputPaytoForm.js"; import { InputSelector } from "../../../../components/form/InputSelector.js"; import { undefinedIfEmpty } from "../../../../utils/table.js"; +import { safeConvertURL } from "../update/UpdatePage.js"; type Entity = TalerMerchantApi.AccountAddDetails & { repeatPassword: string }; @@ -42,19 +43,11 @@ interface Props { const accountAuthType = ["none", "basic"]; -function isValidURL(s: string): boolean { - try { - const parsed = new URL("/", s); - return parsed instanceof URL; - } catch (e) { - return false; - } -} - export function CreatePage({ onCreate, onBack }: Props): VNode { const { i18n } = useTranslationContext(); const [state, setState] = useState<Partial<Entity>>({}); + const facadeURL = safeConvertURL(state.credit_facade_url); const errors: FormErrors<Entity> = { payto_uri: !state.payto_uri ? i18n.str`required` : undefined, @@ -74,9 +67,15 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { }), credit_facade_url: !state.credit_facade_url ? undefined - : !isValidURL(state.credit_facade_url) - ? i18n.str`not valid url` - : undefined, + : !facadeURL + ? i18n.str`Invalid url` + : !facadeURL.href.endsWith("/") + ? i18n.str`URL should end with a '/'` + : facadeURL.searchParams.size > 0 + ? i18n.str`URL should not contain params` + : facadeURL.hash + ? i18n.str`URL should not hash param` + : undefined, repeatPassword: !state.credit_facade_credentials ? undefined : state.credit_facade_credentials.type === "basic" && @@ -94,7 +93,7 @@ export function CreatePage({ onCreate, onBack }: Props): VNode { if (hasErrors) return Promise.reject(); const credit_facade_url = !state.credit_facade_url ? undefined - : new URL("/", state.credit_facade_url).href; + : facadeURL?.href; const credit_facade_credentials: | TalerMerchantApi.FacadeCredentials | undefined = |