From 958747bd08172ce00bc84ea3c543eac414a1d39b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 7 Apr 2023 17:31:01 -0300 Subject: validate iban --- .../src/wallet/ManageAccount/state.ts | 19 ++--- .../src/wallet/ManageAccount/stories.tsx | 15 ++-- .../src/wallet/ManageAccount/views.tsx | 99 ++++++++++++---------- .../src/wallet/Transaction.stories.tsx | 4 - 4 files changed, 69 insertions(+), 68 deletions(-) diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts b/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts index d8bc7d980..d7c7d2b48 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts @@ -40,10 +40,18 @@ export function useComponentState({ api.wallet.call(WalletApiOperation.ListKnownBankAccounts, { currency }), ); const { devMode } = useDevContext(); + const accountType: Record = { + iban: "IBAN", + // "x-taler-bank": "Taler Bank", + }; + if (devMode) { + accountType["bitcoin"] = "Bitcoin"; + accountType["x-taler-bank"] = "Taler Bank"; + } const [payto, setPayto] = useState(""); const [alias, setAlias] = useState(""); - const [type, setType] = useState(""); + const [type, setType] = useState("iban"); if (!hook) { return { @@ -58,15 +66,6 @@ export function useComponentState({ }; } - const accountType: Record = { - "": "Choose one account type", - iban: "IBAN", - // "x-taler-bank": "Taler Bank", - }; - if (devMode) { - accountType["bitcoin"] = "Bitcoin"; - accountType["x-taler-bank"] = "Taler Bank"; - } const uri = parsePaytoUri(payto); const found = hook.response.accounts.findIndex( diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/stories.tsx b/packages/taler-wallet-webextension/src/wallet/ManageAccount/stories.tsx index e20d4e0e8..81c1fcf5a 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManageAccount/stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManageAccount/stories.tsx @@ -32,12 +32,11 @@ export const JustTwoBitcoinAccounts = tests.createExample(ReadyView, { currency: "ARS", accountType: { list: { - "": "Choose one account type", iban: "IBAN", - // bitcoin: "Bitcoin", - // "x-taler-bank": "Taler Bank", + bitcoin: "Bitcoin", + "x-taler-bank": "Taler Bank", }, - value: "", + value: "bitcoin", }, alias: { value: "", @@ -86,12 +85,11 @@ export const WithAllTypeOfAccounts = tests.createExample(ReadyView, { currency: "ARS", accountType: { list: { - "": "Choose one account type", iban: "IBAN", - // bitcoin: "Bitcoin", - // "x-taler-bank": "Taler Bank", + bitcoin: "Bitcoin", + "x-taler-bank": "Taler Bank", }, - value: "", + value: "x-taler-bank", }, alias: { value: "", @@ -167,7 +165,6 @@ export const AddingIbanAccount = tests.createExample(ReadyView, { currency: "ARS", accountType: { list: { - "": "Choose one account type", iban: "IBAN", // bitcoin: "Bitcoin", // "x-taler-bank": "Taler Bank", diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx b/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx index 75e1feca4..fb32e5a59 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx @@ -21,18 +21,14 @@ import { PaytoUriIBAN, PaytoUriTalerBank, stringifyPaytoUri, + validateIban, } from "@gnu-taler/taler-util"; import { styled } from "@linaria/react"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { ErrorMessage } from "../../components/ErrorMessage.js"; import { SelectList } from "../../components/SelectList.js"; -import { - Input, - SubTitle, - SvgIcon, - WarningText, -} from "../../components/styled/index.js"; +import { Input, SubTitle, SvgIcon } from "../../components/styled/index.js"; import { useTranslationContext } from "../../context/translation.js"; import { Button } from "../../mui/Button.js"; import { TextFieldHandler } from "../../mui/handlers.js"; @@ -111,38 +107,47 @@ export function ReadyView({ description={error} /> )} -

- - + {Object.entries(accountType.list).map(([key, name], idx) => ( +

{ + if (accountType.onChange) { + accountType.onChange(key); + } + }} + > + {name} +
+ ))} + +
+

+ - +

+
+

+

- {accountType.value === "" ? undefined : ( - -

- -

-

- -

-
- )}