From aa6227b2b858d48272129c96fcf3d7fae39bba30 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 27 Oct 2022 16:06:41 -0300 Subject: showing error field when there is not account yet --- .../src/wallet/AddAccount/views.tsx | 194 +++++++++++++-------- 1 file changed, 120 insertions(+), 74 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet/AddAccount/views.tsx') diff --git a/packages/taler-wallet-webextension/src/wallet/AddAccount/views.tsx b/packages/taler-wallet-webextension/src/wallet/AddAccount/views.tsx index fa7014d70..d6ab7e967 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddAccount/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/AddAccount/views.tsx @@ -105,7 +105,11 @@ export function ReadyView({ > Cancel - @@ -113,6 +117,118 @@ export function ReadyView({ ); } +function BitcoinAddressAccount({ field }: { field: TextFieldHandler }): VNode { + const { i18n } = useTranslationContext(); + const [value, setValue] = useState(undefined); + const errors = undefinedIfEmpty({ + value: !value ? i18n.str`Can't be empty` : undefined, + }); + return ( + + { + setValue(v); + if (!errors) { + field.onInput(`payto://bitcoin/${value}`); + } + }} + /> + {value !== undefined && errors?.value && ( + {errors?.value}} /> + )} + + ); +} + +function undefinedIfEmpty(obj: T): T | undefined { + return Object.keys(obj).some((k) => (obj as any)[k] !== undefined) + ? obj + : undefined; +} + +function TalerBankAddressAccount({ + field, +}: { + field: TextFieldHandler; +}): VNode { + const { i18n } = useTranslationContext(); + const [host, setHost] = useState(undefined); + const [account, setAccount] = useState(undefined); + const errors = undefinedIfEmpty({ + host: !host ? i18n.str`Can't be empty` : undefined, + account: !account ? i18n.str`Can't be empty` : undefined, + }); + return ( + + { + setHost(v); + if (!errors) { + field.onInput(`payto://x-taler-bank/${host}/${account}`); + } + }} + />{" "} + {host !== undefined && errors?.host && ( + {errors?.host}} /> + )} + { + setAccount(v || ""); + if (!errors) { + field.onInput(`payto://x-taler-bank/${host}/${account}`); + } + }} + />{" "} + {account !== undefined && errors?.account && ( + {errors?.account}} /> + )} + + ); +} + +function IbanAddressAccount({ field }: { field: TextFieldHandler }): VNode { + const { i18n } = useTranslationContext(); + const [value, setValue] = useState(undefined); + const errors = undefinedIfEmpty({ + value: !value ? i18n.str`Can't be empty` : undefined, + }); + return ( + + { + setValue(v); + if (!errors) { + field.onInput(`payto://iba/${value}`); + } + }} + /> + {value !== undefined && errors?.value && ( + {errors?.value}} /> + )} + + ); +} + function CustomFieldByAccountType({ type, field, @@ -120,84 +236,14 @@ function CustomFieldByAccountType({ type: string; field: TextFieldHandler; }): VNode { - const p = parsePaytoUri(field.value); - const parts = !p ? [] : p.targetPath.split("/"); - const initialPart1 = parts.length > 0 ? parts[0] : ""; - const initialPart2 = parts.length > 1 ? parts[1] : ""; - const [part1, setPart1] = useState(initialPart1); - const [part2, setPart2] = useState(initialPart2); - function updateField(): void { - if (part1 && part2) { - field.onInput(`payto://${type}/${part1}/${part2}`); - } else { - if (part1) field.onInput(`payto://${type}/${part1}`); - } - } - if (type === "bitcoin") { - return ( - - {field.error && {field.error}} />} - { - setPart1(v); - updateField(); - }} - /> - - ); + return ; } if (type === "x-taler-bank") { - return ( - - {field.error && {field.error}} />} - { - setPart1(v); - updateField(); - }} - />{" "} - { - setPart2(v); - updateField(); - }} - /> - - ); + return ; } if (type === "iban") { - return ( - - {field.error && {field.error}} />} - { - setPart1(v); - updateField(); - }} - /> - - ); + return ; } return ; } -- cgit v1.2.3