From 7c7cccf6fd5c21c3e25dee2572a13b6adc897aca Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 24 Oct 2022 10:56:07 +0200 Subject: bank: code formatting --- packages/demobank-ui/src/pages/home/index.tsx | 1781 ++++++++++++--------- packages/demobank-ui/src/pages/notfound/index.tsx | 20 +- packages/demobank-ui/src/pages/profile/index.tsx | 4 +- 3 files changed, 1035 insertions(+), 770 deletions(-) (limited to 'packages/demobank-ui/src/pages') diff --git a/packages/demobank-ui/src/pages/home/index.tsx b/packages/demobank-ui/src/pages/home/index.tsx index bf9764b78..2116e1f89 100644 --- a/packages/demobank-ui/src/pages/home/index.tsx +++ b/packages/demobank-ui/src/pages/home/index.tsx @@ -1,21 +1,43 @@ +/* + This file is part of GNU Taler + (C) 2022 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ -import useSWR, { SWRConfig as _SWRConfig, useSWRConfig } from 'swr'; -import { h, Fragment, VNode, createContext } from 'preact'; -import { useRef, useState, useEffect, StateUpdater, useContext } from 'preact/hooks'; -import { Buffer } from 'buffer'; -import { useTranslator, Translate } from '../../i18n'; -import { QR } from '../../components/QR'; -import { useNotNullLocalStorage, useLocalStorage } from '../../hooks'; -import '../../scss/main.scss'; -import talerLogo from '../../assets/logo-white.svg'; -import { LangSelectorLikePy as LangSelector } from '../../components/menu/LangSelector'; +import useSWR, { SWRConfig as _SWRConfig, useSWRConfig } from "swr"; +import { h, Fragment, VNode, createContext } from "preact"; +import { + useRef, + useState, + useEffect, + StateUpdater, + useContext, +} from "preact/hooks"; +import { Buffer } from "buffer"; +import { useTranslator, Translate } from "../../i18n"; +import { QR } from "../../components/QR"; +import { useNotNullLocalStorage, useLocalStorage } from "../../hooks"; +import "../../scss/main.scss"; +import talerLogo from "../../assets/logo-white.svg"; +import { LangSelectorLikePy as LangSelector } from "../../components/menu/LangSelector"; // FIXME: Fix usages of SWRConfig, doing this isn't the best practice (but hey, it works for now) const SWRConfig = _SWRConfig as any; -const UI_ALLOW_REGISTRATIONS = ('__LIBEUFIN_UI_ALLOW_REGISTRATIONS__') ?? 1; -const UI_IS_DEMO = ('__LIBEUFIN_UI_IS_DEMO__') ?? 0; -const UI_BANK_NAME = ('__LIBEUFIN_UI_BANK_NAME__') ?? 'Taler Bank'; +const UI_ALLOW_REGISTRATIONS = "__LIBEUFIN_UI_ALLOW_REGISTRATIONS__" ?? 1; +const UI_IS_DEMO = "__LIBEUFIN_UI_IS_DEMO__" ?? 0; +const UI_BANK_NAME = "__LIBEUFIN_UI_BANK_NAME__" ?? "Taler Bank"; /** * FIXME: @@ -135,17 +157,23 @@ function maybeDemoContent(content: VNode) { } async function fetcher(url: string) { - return fetch(url).then((r) => (r.json())); + return fetch(url).then((r) => r.json()); } function genCaptchaNumbers(): string { - return `${Math.floor(Math.random() * 10)} + ${Math.floor(Math.random() * 10)}`; + return `${Math.floor(Math.random() * 10)} + ${Math.floor( + Math.random() * 10, + )}`; } /** * Bring the state to show the public accounts page. */ function goPublicAccounts(pageStateSetter: StateUpdater) { - return () => pageStateSetter((prevState) => ({ ...prevState, showPublicHistories: true })) + return () => + pageStateSetter((prevState) => ({ + ...prevState, + showPublicHistories: true, + })); } /** @@ -154,15 +182,15 @@ function goPublicAccounts(pageStateSetter: StateUpdater) { * the input is invalid, the valid amount otherwise. */ function validateAmount(maybeAmount: string): any { - const amountRegex = '^[0-9]+(\.[0-9]+)?$'; + const amountRegex = "^[0-9]+(.[0-9]+)?$"; if (!maybeAmount) { console.log(`Entered amount (${maybeAmount}) mismatched pattern.`); return; } - if (typeof maybeAmount !== 'undefined' || maybeAmount !== '') { + if (typeof maybeAmount !== "undefined" || maybeAmount !== "") { console.log(`Maybe valid amount: ${maybeAmount}`); // tolerating comma instead of point. - const re = RegExp(amountRegex) + const re = RegExp(amountRegex); if (!re.test(maybeAmount)) { console.log(`Not using invalid amount '${maybeAmount}'.`); return false; @@ -175,10 +203,10 @@ function validateAmount(maybeAmount: string): any { * Extract IBAN from a Payto URI. */ function getIbanFromPayto(url: string): string { - const pathSplit = new URL(url).pathname.split('/'); + const pathSplit = new URL(url).pathname.split("/"); let lastIndex = pathSplit.length - 1; // Happens if the path ends with "/". - if (pathSplit[lastIndex] === '') lastIndex--; + if (pathSplit[lastIndex] === "") lastIndex--; const iban = pathSplit[lastIndex]; return iban; } @@ -188,10 +216,9 @@ function getIbanFromPayto(url: string): string { */ function parseAmount(val: string): Amount { const format = /^[A-Z]+:[0-9]+(\.[0-9]+)?$/; - if (!format.test(val)) - throw Error(`Backend gave invalid amount: ${val}.`) - const amountSplit = val.split(':'); - return { value: amountSplit[1], currency: amountSplit[0] } + if (!format.test(val)) throw Error(`Backend gave invalid amount: ${val}.`); + const amountSplit = val.split(":"); + return { value: amountSplit[1], currency: amountSplit[0] }; } /** @@ -199,8 +226,8 @@ function parseAmount(val: string): Amount { * exception if not found. */ function getUsername(backendState: BackendStateTypeOpt): string { - if (typeof backendState === 'undefined') - throw Error('Username can\'t be found in a undefined backend state.') + if (typeof backendState === "undefined") + throw Error("Username can't be found in a undefined backend state."); return backendState.username; } @@ -213,30 +240,32 @@ function getUsername(backendState: BackendStateTypeOpt): string { async function postToBackend( uri: string, backendState: BackendStateTypeOpt, - body: string + body: string, ): Promise { - if (typeof backendState === 'undefined') - throw Error('Credentials can\'t be found in a undefined backend state.') + if (typeof backendState === "undefined") + throw Error("Credentials can't be found in a undefined backend state."); const { username, password } = backendState; const headers = prepareHeaders(username, password); // Backend URL must have been stored _with_ a final slash. - const url = new URL(uri, backendState.url) + const url = new URL(uri, backendState.url); return await fetch(url.href, { - method: 'POST', + method: "POST", headers, body, - } - ); + }); } function useTransactionPageNumber(): [number, StateUpdater] { - const ret = useNotNullLocalStorage('transaction-page', '0'); + const ret = useNotNullLocalStorage("transaction-page", "0"); const retObj = JSON.parse(ret[0]); const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? JSON.stringify(val(retObj)) : JSON.stringify(val) - ret[1](newVal) - } + const newVal = + val instanceof Function + ? JSON.stringify(val(retObj)) + : JSON.stringify(val); + ret[1](newVal); + }; return [retObj, retSetter]; } @@ -246,13 +275,10 @@ function useTransactionPageNumber(): [number, StateUpdater] { function prepareHeaders(username: string, password: string) { const headers = new Headers(); headers.append( - 'Authorization', - `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}` + "Authorization", + `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`, ); - headers.append( - 'Content-Type', - 'application/json' - ) + headers.append("Content-Type", "application/json"); return headers; } @@ -261,10 +287,11 @@ function prepareHeaders(username: string, password: string) { // That allows the app to be pointed to a arbitrary // euFin backend when launched via "pnpm dev". const getRootPath = () => { - const maybeRootPath = typeof window !== undefined - ? window.location.origin + window.location.pathname - : '/'; - if (!maybeRootPath.endsWith('/')) return `${maybeRootPath}/`; + const maybeRootPath = + typeof window !== undefined + ? window.location.origin + window.location.pathname + : "/"; + if (!maybeRootPath.endsWith("/")) return `${maybeRootPath}/`; return maybeRootPath; }; @@ -278,16 +305,18 @@ const getRootPath = () => { * handle of the data entered by the user in fields. */ function useShowPublicAccount( - state?: string + state?: string, ): [string | undefined, StateUpdater] { - - const ret = useLocalStorage('show-public-account', JSON.stringify(state)); + const ret = useLocalStorage("show-public-account", JSON.stringify(state)); const retObj: string | undefined = ret[0] ? JSON.parse(ret[0]) : ret[0]; const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? JSON.stringify(val(retObj)) : JSON.stringify(val) - ret[1](newVal) - } - return [retObj, retSetter] + const newVal = + val instanceof Function + ? JSON.stringify(val(retObj)) + : JSON.stringify(val); + ret[1](newVal); + }; + return [retObj, retSetter]; } /** @@ -296,16 +325,15 @@ function useShowPublicAccount( type RawPaytoInputType = string; type RawPaytoInputTypeOpt = RawPaytoInputType | undefined; function useRawPaytoInputType( - state?: RawPaytoInputType + state?: RawPaytoInputType, ): [RawPaytoInputTypeOpt, StateUpdater] { - - const ret = useLocalStorage('raw-payto-input-state', state); + const ret = useLocalStorage("raw-payto-input-state", state); const retObj: RawPaytoInputTypeOpt = ret[0]; const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? val(retObj) : val - ret[1](newVal) - } - return [retObj, retSetter] + const newVal = val instanceof Function ? val(retObj) : val; + ret[1](newVal); + }; + return [retObj, retSetter]; } /** @@ -317,16 +345,23 @@ function useRawPaytoInputType( */ type WireTransferRequestTypeOpt = WireTransferRequestType | undefined; function useWireTransferRequestType( - state?: WireTransferRequestType + state?: WireTransferRequestType, ): [WireTransferRequestTypeOpt, StateUpdater] { - - const ret = useLocalStorage('wire-transfer-request-state', JSON.stringify(state)); - const retObj: WireTransferRequestTypeOpt = ret[0] ? JSON.parse(ret[0]) : ret[0]; + const ret = useLocalStorage( + "wire-transfer-request-state", + JSON.stringify(state), + ); + const retObj: WireTransferRequestTypeOpt = ret[0] + ? JSON.parse(ret[0]) + : ret[0]; const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? JSON.stringify(val(retObj)) : JSON.stringify(val) - ret[1](newVal) - } - return [retObj, retSetter] + const newVal = + val instanceof Function + ? JSON.stringify(val(retObj)) + : JSON.stringify(val); + ret[1](newVal); + }; + return [retObj, retSetter]; } /** @@ -336,16 +371,23 @@ function useWireTransferRequestType( */ type CredentialsRequestTypeOpt = CredentialsRequestType | undefined; function useCredentialsRequestType( - state?: CredentialsRequestType + state?: CredentialsRequestType, ): [CredentialsRequestTypeOpt, StateUpdater] { - - const ret = useLocalStorage('credentials-request-state', JSON.stringify(state)); - const retObj: CredentialsRequestTypeOpt = ret[0] ? JSON.parse(ret[0]) : ret[0]; + const ret = useLocalStorage( + "credentials-request-state", + JSON.stringify(state), + ); + const retObj: CredentialsRequestTypeOpt = ret[0] + ? JSON.parse(ret[0]) + : ret[0]; const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? JSON.stringify(val(retObj)) : JSON.stringify(val) - ret[1](newVal) - } - return [retObj, retSetter] + const newVal = + val instanceof Function + ? JSON.stringify(val(retObj)) + : JSON.stringify(val); + ret[1](newVal); + }; + return [retObj, retSetter]; } /** @@ -355,16 +397,18 @@ function useCredentialsRequestType( */ type BackendStateTypeOpt = BackendStateType | undefined; function useBackendState( - state?: BackendStateType + state?: BackendStateType, ): [BackendStateTypeOpt, StateUpdater] { - - const ret = useLocalStorage('backend-state', JSON.stringify(state)); + const ret = useLocalStorage("backend-state", JSON.stringify(state)); const retObj: BackendStateTypeOpt = ret[0] ? JSON.parse(ret[0]) : ret[0]; const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? JSON.stringify(val(retObj)) : JSON.stringify(val) - ret[1](newVal) - } - return [retObj, retSetter] + const newVal = + val instanceof Function + ? JSON.stringify(val(retObj)) + : JSON.stringify(val); + ret[1](newVal); + }; + return [retObj, retSetter]; } /** @@ -373,16 +417,18 @@ function useBackendState( */ type AccountStateTypeOpt = AccountStateType | undefined; function useAccountState( - state?: AccountStateType + state?: AccountStateType, ): [AccountStateTypeOpt, StateUpdater] { - - const ret = useLocalStorage('account-state', JSON.stringify(state)); + const ret = useLocalStorage("account-state", JSON.stringify(state)); const retObj: AccountStateTypeOpt = ret[0] ? JSON.parse(ret[0]) : ret[0]; const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? JSON.stringify(val(retObj)) : JSON.stringify(val) - ret[1](newVal) - } - return [retObj, retSetter] + const newVal = + val instanceof Function + ? JSON.stringify(val(retObj)) + : JSON.stringify(val); + ret[1](newVal); + }; + return [retObj, retSetter]; } /** @@ -397,16 +443,19 @@ function usePageState( hasError: false, hasInfo: false, withdrawalInProgress: false, - } + }, ): [PageStateType, StateUpdater] { - const ret = useNotNullLocalStorage('page-state', JSON.stringify(state)); + const ret = useNotNullLocalStorage("page-state", JSON.stringify(state)); const retObj: PageStateType = JSON.parse(ret[0]); - console.log('Current page state', retObj); + console.log("Current page state", retObj); const retSetter: StateUpdater = function (val) { - const newVal = val instanceof Function ? JSON.stringify(val(retObj)) : JSON.stringify(val) - console.log('Setting new page state', newVal) - ret[1](newVal) - } + const newVal = + val instanceof Function + ? JSON.stringify(val(retObj)) + : JSON.stringify(val); + console.log("Setting new page state", newVal); + ret[1](newVal); + }; return [retObj, retSetter]; } @@ -432,19 +481,27 @@ function usePageState( async function abortWithdrawalCall( backendState: BackendStateTypeOpt, withdrawalId: string | undefined, - pageStateSetter: StateUpdater + pageStateSetter: StateUpdater, ) { - if (typeof backendState === 'undefined') { - console.log('No credentials found.'); - pageStateSetter((prevState) => ({ ...prevState, hasError: true, error: 'No credentials found.' })) + if (typeof backendState === "undefined") { + console.log("No credentials found."); + pageStateSetter((prevState) => ({ + ...prevState, + hasError: true, + error: "No credentials found.", + })); return; } - if (typeof withdrawalId === 'undefined') { - console.log('No withdrawal ID found.'); - pageStateSetter((prevState) => ({ ...prevState, hasError: true, error: 'No withdrawal ID found.' })) + if (typeof withdrawalId === "undefined") { + console.log("No withdrawal ID found."); + pageStateSetter((prevState) => ({ + ...prevState, + hasError: true, + error: "No withdrawal ID found.", + })); return; } - let res:any; + let res: any; try { const { username, password } = backendState; const headers = prepareHeaders(username, password); @@ -462,36 +519,38 @@ async function abortWithdrawalCall( // Backend URL must have been stored _with_ a final slash. const url = new URL( `access-api/accounts/${backendState.username}/withdrawals/${withdrawalId}/abort`, - backendState.url - ) - res = await fetch(url.href, { method: 'POST', headers }) + backendState.url, + ); + res = await fetch(url.href, { method: "POST", headers }); } catch (error) { - console.log('Could not abort the withdrawal', error); + console.log("Could not abort the withdrawal", error); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Could not abort the withdrawal: ${error}` - })) + error: `Could not abort the withdrawal: ${error}`, + })); return; } if (!res.ok) { - console.log(`Withdrawal abort gave response error (${res.status})`, res.statusText); + console.log( + `Withdrawal abort gave response error (${res.status})`, + res.statusText, + ); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Withdrawal abortion gave response error (${res.status})` - })) + error: `Withdrawal abortion gave response error (${res.status})`, + })); return; } - console.log('Withdrawal operation aborted!'); + console.log("Withdrawal operation aborted!"); pageStateSetter((prevState) => { const { ...rest } = prevState; return { ...rest, - info: 'Withdrawal aborted!' - } - }) - + info: "Withdrawal aborted!", + }; + }); } /** @@ -507,17 +566,24 @@ async function abortWithdrawalCall( async function confirmWithdrawalCall( backendState: BackendStateTypeOpt, withdrawalId: string | undefined, - pageStateSetter: StateUpdater + pageStateSetter: StateUpdater, ) { - - if (typeof backendState === 'undefined') { - console.log('No credentials found.'); - pageStateSetter((prevState) => ({ ...prevState, hasError: true, error: 'No credentials found.' })) + if (typeof backendState === "undefined") { + console.log("No credentials found."); + pageStateSetter((prevState) => ({ + ...prevState, + hasError: true, + error: "No credentials found.", + })); return; } - if (typeof withdrawalId === 'undefined') { - console.log('No withdrawal ID found.'); - pageStateSetter((prevState) => ({ ...prevState, hasError: true, error: 'No withdrawal ID found.' })) + if (typeof withdrawalId === "undefined") { + console.log("No withdrawal ID found."); + pageStateSetter((prevState) => ({ + ...prevState, + hasError: true, + error: "No withdrawal ID found.", + })); return; } let res: Response; @@ -538,39 +604,42 @@ async function confirmWithdrawalCall( // Backend URL must have been stored _with_ a final slash. const url = new URL( `access-api/accounts/${backendState.username}/withdrawals/${withdrawalId}/confirm`, - backendState.url - ) + backendState.url, + ); res = await fetch(url.href, { - method: 'POST', - headers - }) + method: "POST", + headers, + }); } catch (error) { - console.log('Could not POST withdrawal confirmation to the bank', error); + console.log("Could not POST withdrawal confirmation to the bank", error); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Could not confirm the withdrawal: ${error}` - })) + error: `Could not confirm the withdrawal: ${error}`, + })); return; } - if (res ? !res.ok : true) { // assume not ok if res is null - console.log(`Withdrawal confirmation gave response error (${res.status})`, res.statusText); + if (res ? !res.ok : true) { + // assume not ok if res is null + console.log( + `Withdrawal confirmation gave response error (${res.status})`, + res.statusText, + ); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Withdrawal confirmation gave response error (${res.status})` - })) + error: `Withdrawal confirmation gave response error (${res.status})`, + })); return; } - console.log('Withdrawal operation confirmed!'); + console.log("Withdrawal operation confirmed!"); pageStateSetter((prevState) => { const { talerWithdrawUri, ...rest } = prevState; return { ...rest, - info: 'Withdrawal confirmed!' - } - }) - + info: "Withdrawal confirmed!", + }; + }); } /** @@ -587,43 +656,44 @@ async function createTransactionCall( * Optional since the raw payto form doesn't have * a stateful management of the input data yet. */ - cleanUpForm: () => void + cleanUpForm: () => void, ) { - let res:any; + let res: any; try { res = await postToBackend( `access-api/accounts/${getUsername(backendState)}/transactions`, backendState, - JSON.stringify(req) - ) - } - catch (error) { - console.log('Could not POST transaction request to the bank', error); + JSON.stringify(req), + ); + } catch (error) { + console.log("Could not POST transaction request to the bank", error); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Could not create the wire transfer: ${error}` - })) + error: `Could not create the wire transfer: ${error}`, + })); return; } // POST happened, status not sure yet. if (!res.ok) { const responseText = JSON.stringify(await res.json()); - console.log(`Transfer creation gave response error: ${responseText} (${res.status})`); + console.log( + `Transfer creation gave response error: ${responseText} (${res.status})`, + ); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Transfer creation gave response error: ${responseText} (${res.status})` - })) + error: `Transfer creation gave response error: ${responseText} (${res.status})`, + })); return; } // status is 200 OK here, tell the user. - console.log('Wire transfer created!'); + console.log("Wire transfer created!"); pageStateSetter((prevState) => ({ ...prevState, hasInfo: true, - info: 'Wire transfer created!' - })) + info: "Wire transfer created!", + })); // Only at this point the input data can // be discarded. @@ -642,15 +712,19 @@ async function createTransactionCall( async function createWithdrawalCall( amount: string, backendState: BackendStateTypeOpt, - pageStateSetter: StateUpdater + pageStateSetter: StateUpdater, ) { - if (typeof backendState === 'undefined') { - console.log('Page has a problem: no credentials found in the state.'); - pageStateSetter((prevState) => ({ ...prevState, hasError: true, error: 'No credentials given.' })) + if (typeof backendState === "undefined") { + console.log("Page has a problem: no credentials found in the state."); + pageStateSetter((prevState) => ({ + ...prevState, + hasError: true, + error: "No credentials given.", + })); return; } - let res:any; + let res: any; try { const { username, password } = backendState; const headers = prepareHeaders(username, password); @@ -658,42 +732,43 @@ async function createWithdrawalCall( // Let bank generate withdraw URI: const url = new URL( `access-api/accounts/${backendState.username}/withdrawals`, - backendState.url - ) + backendState.url, + ); res = await fetch(url.href, { - method: 'POST', + method: "POST", headers, body: JSON.stringify({ amount }), - } - ); + }); } catch (error) { - console.log('Could not POST withdrawal request to the bank', error); + console.log("Could not POST withdrawal request to the bank", error); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Could not create withdrawal operation: ${error}` - })) + error: `Could not create withdrawal operation: ${error}`, + })); return; } if (!res.ok) { const responseText = await res.text(); - console.log(`Withdrawal creation gave response error: ${responseText} (${res.status})`); + console.log( + `Withdrawal creation gave response error: ${responseText} (${res.status})`, + ); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: `Withdrawal creation gave response error: ${responseText} (${res.status})` - })) + error: `Withdrawal creation gave response error: ${responseText} (${res.status})`, + })); return; } - console.log('Withdrawal operation created!'); + console.log("Withdrawal operation created!"); const resp = await res.json(); pageStateSetter((prevState: PageStateType) => ({ ...prevState, withdrawalInProgress: true, talerWithdrawUri: resp.taler_withdraw_uri, - withdrawalId: resp.withdrawal_id - })) + withdrawalId: resp.withdrawal_id, + })); } async function loginCall( @@ -703,17 +778,15 @@ async function loginCall( * functions can be retrieved from the state. */ backendStateSetter: StateUpdater, - pageStateSetter: StateUpdater + pageStateSetter: StateUpdater, ) { - /** * Optimistically setting the state as 'logged in', and * let the Account component request the balance to check * whether the credentials are valid. */ pageStateSetter((prevState) => ({ ...prevState, isLoggedIn: true })); let baseUrl = getRootPath(); - if (!baseUrl.endsWith('/')) - baseUrl += '/'; + if (!baseUrl.endsWith("/")) baseUrl += "/"; backendStateSetter((prevState) => ({ ...prevState, @@ -723,7 +796,6 @@ async function loginCall( })); } - /** * This function requests /register. * @@ -739,51 +811,54 @@ async function registrationCall( * the state. */ backendStateSetter: StateUpdater, - pageStateSetter: StateUpdater + pageStateSetter: StateUpdater, ) { - let baseUrl = getRootPath(); /** * If the base URL doesn't end with slash and the path * is not empty, then the concatenation made by URL() * drops the last path element. */ - if (!baseUrl.endsWith('/')) - baseUrl += '/' + if (!baseUrl.endsWith("/")) baseUrl += "/"; const headers = new Headers(); - headers.append( - 'Content-Type', - 'application/json' - ) - const url = new URL('access-api/testing/register', baseUrl) - let res:any; + headers.append("Content-Type", "application/json"); + const url = new URL("access-api/testing/register", baseUrl); + let res: any; try { res = await fetch(url.href, { - method: 'POST', + method: "POST", body: JSON.stringify(req), - headers + headers, }); } catch (error) { - console.log(`Could not POST new registration to the bank (${url.href})`, error); + console.log( + `Could not POST new registration to the bank (${url.href})`, + error, + ); pageStateSetter((prevState) => ({ - ...prevState, hasError: true, error: 'Registration failed, please report.' + ...prevState, + hasError: true, + error: "Registration failed, please report.", })); return; } if (!res.ok) { const errorRaw = await res.text(); - console.log(`New registration gave response error (${res.status})`, errorRaw); + console.log( + `New registration gave response error (${res.status})`, + errorRaw, + ); pageStateSetter((prevState) => ({ ...prevState, hasError: true, - error: errorRaw + error: errorRaw, })); } else { pageStateSetter((prevState) => ({ ...prevState, isLoggedIn: true, - tryRegister: false + tryRegister: false, })); backendStateSetter((prevState) => ({ ...prevState, @@ -799,12 +874,15 @@ async function registrationCall( *************************/ function Currency(): VNode { - const { data, error } = useSWR(`${getRootPath()}integration-api/config`, fetcher); - if (typeof error !== 'undefined') + const { data, error } = useSWR( + `${getRootPath()}integration-api/config`, + fetcher, + ); + if (typeof error !== "undefined") return error: currency could not be retrieved; - if (typeof data === 'undefined') return "..."; - console.log('found bank config', data); + if (typeof data === "undefined") return "..."; + console.log("found bank config", data); return data.currency; } @@ -814,8 +892,8 @@ function ErrorBanner(Props: any): VNode | null { if (!pageState.hasError) return null; const rval = ( -

{pageState.error} -

); +

{pageState.error}

+ ); delete pageState.error; pageState.hasError = false; return rval; @@ -826,9 +904,7 @@ function StatusBanner(Props: any): VNode | null { const i18n = useTranslator(); if (!pageState.hasInfo) return null; - const rval = ( -

{pageState.error} -

); + const rval =

{pageState.error}

; delete pageState.info_msg; pageState.hasInfo = false; return rval; @@ -837,7 +913,7 @@ function StatusBanner(Props: any): VNode | null { function BankFrame(Props: any): VNode { const i18n = useTranslator(); const [pageState, pageStateSetter] = useContext(PageContext); - console.log('BankFrame state', pageState); + console.log("BankFrame state", pageState); const logOut = ( ); + }} + >{i18n`Logout`} + + ); // Prepare demo sites links. const DEMO_SITES = [ - ['Landing', '__DEMO_SITE_LANDING_URL__'], - ['Bank', '__DEMO_SITE_BANK_URL__'], - ['Essay Shop', '__DEMO_SITE_BLOG_URL__'], - ['Donations', '__DEMO_SITE_DONATIONS_URL__'], - ['Survey', '__DEMO_SITE_SURVEY_URL__'], + ["Landing", "__DEMO_SITE_LANDING_URL__"], + ["Bank", "__DEMO_SITE_BANK_URL__"], + ["Essay Shop", "__DEMO_SITE_BLOG_URL__"], + ["Donations", "__DEMO_SITE_DONATIONS_URL__"], + ["Survey", "__DEMO_SITE_SURVEY_URL__"], ]; const demo_sites = []; for (const i in DEMO_SITES) - demo_sites.push({DEMO_SITES[i][0]}) + demo_sites.push({DEMO_SITES[i][0]}); return ( -
+

- { - UI_BANK_NAME - } - + {UI_BANK_NAME} -

{ - maybeDemoContent(

- This part of the demo shows how a bank that supports - Taler directly would work. In addition to using your own - bank account, you can also see the transaction history of - some Public Accounts. -

- ) - } + + {maybeDemoContent( +

+ + This part of the demo shows how a bank that supports Taler + directly would work. In addition to using your own bank account, + you can also see the transaction history of some{" "} + + Public Accounts + + . + +

, + )}
{i18n`Taler logo`} + style="margin: 2em 2em" + />