diff options
author | Sebastian <sebasjm@gmail.com> | 2022-10-14 11:40:38 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-10-14 11:41:53 -0300 |
commit | da9ec5eb16298d8ca5690800eca1c15f5a6cfaa5 (patch) | |
tree | 56b637054c94462cada2a067cfb7cce46fefe651 /packages/taler-wallet-webextension/src/wallet/AddAccount/state.ts | |
parent | ca8da4ed380b308abdc894145c7e1a102bfd6cf0 (diff) | |
download | wallet-core-da9ec5eb16298d8ca5690800eca1c15f5a6cfaa5.tar.xz |
refactored terms of service to remove duplicated code
prettfied some sources
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/AddAccount/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/AddAccount/state.ts | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/AddAccount/state.ts b/packages/taler-wallet-webextension/src/wallet/AddAccount/state.ts index 8f7920d35..f14c4c1bb 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddAccount/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddAccount/state.ts @@ -20,16 +20,18 @@ import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import * as wxApi from "../../wxApi.js"; import { Props, State } from "./index.js"; -export function useComponentState({ currency, onAccountAdded, onCancel }: Props, api: typeof wxApi): State { +export function useComponentState( + { currency, onAccountAdded, onCancel }: Props, + api: typeof wxApi, +): State { const hook = useAsyncAsHook(async () => { const { accounts } = await api.listKnownBankAccounts(currency); return { accounts }; }); - const [payto, setPayto] = useState("") - const [alias, setAlias] = useState("") - const [type, setType] = useState("") - + const [payto, setPayto] = useState(""); + const [alias, setAlias] = useState(""); + const [type, setType] = useState(""); if (!hook) { return { @@ -41,31 +43,38 @@ export function useComponentState({ currency, onAccountAdded, onCancel }: Props, return { status: "loading-error", error: hook, - } + }; } const accountType: Record<string, string> = { "": "Choose one account", - "iban": "IBAN", - "bitcoin": "Bitcoin", - "x-taler-bank": "Taler Bank" - } - const uri = parsePaytoUri(payto) - const found = hook.response.accounts.findIndex(a => stringifyPaytoUri(a.uri) === payto) !== -1 + iban: "IBAN", + bitcoin: "Bitcoin", + "x-taler-bank": "Taler Bank", + }; + const uri = parsePaytoUri(payto); + const found = + hook.response.accounts.findIndex( + (a) => stringifyPaytoUri(a.uri) === payto, + ) !== -1; async function addAccount(): Promise<void> { if (!uri || found) return; - await api.addKnownBankAccounts(uri, currency, alias) - onAccountAdded(payto) + await api.addKnownBankAccounts(uri, currency, alias); + onAccountAdded(payto); } - const paytoUriError = payto === "" ? undefined - : !uri ? "the uri is not ok" - : found ? "that account is already present" - : undefined + const paytoUriError = + payto === "" + ? undefined + : !uri + ? "the uri is not ok" + : found + ? "that account is already present" + : undefined; - const unableToAdd = !type || !alias || paytoUriError + const unableToAdd = !type || !alias || paytoUriError; return { status: "ready", @@ -75,27 +84,27 @@ export function useComponentState({ currency, onAccountAdded, onCancel }: Props, list: accountType, value: type, onChange: async (v) => { - setType(v) - } + setType(v); + }, }, alias: { value: alias, onInput: async (v) => { - setAlias(v) + setAlias(v); }, }, uri: { value: payto, error: paytoUriError, onInput: async (v) => { - setPayto(v) - } + setPayto(v); + }, }, onAccountAdded: { - onClick: unableToAdd ? undefined : addAccount + onClick: unableToAdd ? undefined : addAccount, }, onCancel: { - onClick: async () => onCancel() - } + onClick: async () => onCancel(), + }, }; } |