taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit f9502ad5a529e7b5d011dd0cc948473c25c3aff5
parent e54e1e482c10b919627f56b61a8490855e2ac92a
Author: Iván Ávalos <avalos@disroot.org>
Date:   Sat,  7 Sep 2024 12:44:17 +0200

webex: load deposit wire methods from wallet core

Diffstat:
Mpackages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts | 57++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 13 deletions(-)

diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts b/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts @@ -26,7 +26,6 @@ import { useBackendContext } from "../../context/backend.js"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { AccountByType, Props, State } from "./index.js"; -import { useSettings } from "../../hooks/useSettings.js"; export function useComponentState({ scope, @@ -36,28 +35,22 @@ export function useComponentState({ const api = useBackendContext(); const { pushAlertOnError } = useAlertContext(); const { i18n } = useTranslationContext(); + const hook = useAsyncAsHook(() => api.wallet.call(WalletApiOperation.ListKnownBankAccounts, { currency: scope.currency }), ); - const accountType: Record<string, string> = { - iban: "IBAN", - }; - const [settings] = useSettings(); - if (settings.extendedAccountTypes) { - accountType["bitcoin"] = "Bitcoin"; - accountType["x-taler-bank"] = "Taler Bank"; - } - const [payto, setPayto] = useState(""); - const [alias, setAlias] = useState(""); - const [type, setType] = useState("iban"); + const hook2 = useAsyncAsHook(() => + api.wallet.call(WalletApiOperation.GetDepositWireTypesForCurrency, { currency: scope.currency, scopeInfo: scope }), + ); - if (!hook) { + if (!hook || !hook2) { return { status: "loading", error: undefined, }; } + if (hook.hasError) { return { status: "error", @@ -68,6 +61,44 @@ export function useComponentState({ }; } + if (hook2.hasError) { + return { + status: "error", + error: alertFromError( + i18n, + i18n.str`Could not load supported wire methods`, + hook2), + }; + } + + if (hook2.response.wireTypes.length === 0) { + return { + status: "error", + error: { + type: "error", + message: i18n.str`No wire methods supported for this currency`, + description: i18n.str``, + cause: new Error("something"), + context: {}, + }, + }; + } + + const [payto, setPayto] = useState(""); + const [alias, setAlias] = useState(""); + const [type, setType] = useState(hook2.response.wireTypes[0]); + + const accountType: Record<string, string> = {}; + hook2.response.wireTypes.forEach(t => { + if (t === "iban") { + accountType[t] = "IBAN" + } else if (t === "x-taler-bank") { + accountType[t] = "x-taler-bank" + } else if (t === "bitcoin") { + accountType[t] = "Bitcoin" + } + }); + const uri = parsePaytoUri(payto); const found = hook.response.accounts.findIndex(