diff options
author | Sebastian <sebasjm@gmail.com> | 2023-09-25 09:31:17 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-09-25 14:50:45 -0300 |
commit | 0b2c03dc5e1060cd229aeafb84263f171b5a9788 (patch) | |
tree | d95fc53b31cb8188be8f4697b1a8d01495b3a41b /packages/demobank-ui/src/pages | |
parent | fd9ed97fdc60baaa3f74a3f7b02c6831c6d6948b (diff) | |
download | wallet-core-0b2c03dc5e1060cd229aeafb84263f171b5a9788.tar.xz |
new libeufin api
Diffstat (limited to 'packages/demobank-ui/src/pages')
8 files changed, 25 insertions, 33 deletions
diff --git a/packages/demobank-ui/src/pages/AccountPage/state.ts b/packages/demobank-ui/src/pages/AccountPage/state.ts index 3df463f4e..a23d3b569 100644 --- a/packages/demobank-ui/src/pages/AccountPage/state.ts +++ b/packages/demobank-ui/src/pages/AccountPage/state.ts @@ -63,9 +63,7 @@ export function useComponentState({ account, goToBusinessAccount, goToConfirmOpe const { data } = result; - // FIXME: balance - // const balance = Amounts.parseOrThrow(data.balance.amount); - const balance = Amounts.parseOrThrow(data.balance); + const balance = Amounts.parseOrThrow(data.balance.amount); const debitThreshold = Amounts.parseOrThrow(data.debit_threshold); const payto = parsePaytoUri(data.payto_uri); diff --git a/packages/demobank-ui/src/pages/AccountPage/views.tsx b/packages/demobank-ui/src/pages/AccountPage/views.tsx index b3996c5fc..32aedebf2 100644 --- a/packages/demobank-ui/src/pages/AccountPage/views.tsx +++ b/packages/demobank-ui/src/pages/AccountPage/views.tsx @@ -14,16 +14,14 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { Amounts, stringifyPaytoUri } from "@gnu-taler/taler-util"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { Fragment, h, VNode } from "preact"; +import { Fragment, VNode, h } from "preact"; import { Transactions } from "../../components/Transactions/index.js"; -import { PaymentOptions } from "../PaymentOptions.js"; -import { State } from "./index.js"; -import { CopyButton } from "../../components/CopyButton.js"; -import { bankUiSettings } from "../../settings.js"; import { useBusinessAccountDetails } from "../../hooks/circuit.js"; import { useSettings } from "../../hooks/settings.js"; +import { bankUiSettings } from "../../settings.js"; +import { PaymentOptions } from "../PaymentOptions.js"; +import { State } from "./index.js"; export function InvalidIbanView({ error }: State.InvalidIban) { return ( diff --git a/packages/demobank-ui/src/pages/BankFrame.tsx b/packages/demobank-ui/src/pages/BankFrame.tsx index 214aac063..39ca09f1b 100644 --- a/packages/demobank-ui/src/pages/BankFrame.tsx +++ b/packages/demobank-ui/src/pages/BankFrame.tsx @@ -474,11 +474,9 @@ function AccountBalance({ account }: { account: string }): VNode { const result = useAccountDetails(account); if (!result.ok) return <div /> - // FIXME: balance return <div> - {Amounts.currencyOf(result.data.balance)} {Amounts.stringifyValue(result.data.balance)} - {/* {Amounts.currencyOf(result.data.balance.amount)} + {Amounts.currencyOf(result.data.balance.amount)} {result.data.balance.credit_debit_indicator === "debit" ? "-" : ""} - {Amounts.stringifyValue(result.data.balance.amount)} */} + {Amounts.stringifyValue(result.data.balance.amount)} </div> } diff --git a/packages/demobank-ui/src/pages/LoginForm.tsx b/packages/demobank-ui/src/pages/LoginForm.tsx index cfef71b9a..f1ba439ac 100644 --- a/packages/demobank-ui/src/pages/LoginForm.tsx +++ b/packages/demobank-ui/src/pages/LoginForm.tsx @@ -18,13 +18,11 @@ import { HttpStatusCode, TranslatedString } from "@gnu-taler/taler-util"; import { ErrorType, notifyError, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useEffect, useRef, useState } from "preact/hooks"; +import { ShowInputErrorLabel } from "../components/ShowInputErrorLabel.js"; import { useBackendContext } from "../context/backend.js"; +import { useCredentialsChecker } from "../hooks/useCredentialsChecker.js"; import { bankUiSettings } from "../settings.js"; import { undefinedIfEmpty } from "../utils.js"; -import { USERNAME_REGEX } from "./RegistrationPage.js"; -import { ShowInputErrorLabel } from "../components/ShowInputErrorLabel.js"; -import { AccessToken, useCredentialsChecker } from "../hooks/useCredentialsChecker.js"; -import { useCredentialsCheckerOld } from "../hooks/backend.js"; /** * Collect and submit login data. @@ -62,7 +60,7 @@ export function LoginForm({ onRegister }: { onRegister?: () => void }): VNode { setBusy({}) const result = await requestNewLoginToken(username, password); if (result.valid) { - backend.logIn({ username, password }); + backend.logIn({ username, token: result.token }); } else { const { cause } = result; switch (cause.type) { diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx index 5325f43ab..a2543f977 100644 --- a/packages/demobank-ui/src/pages/RegistrationPage.tsx +++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx @@ -28,6 +28,7 @@ import { bankUiSettings } from "../settings.js"; import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js"; import { ShowInputErrorLabel } from "../components/ShowInputErrorLabel.js"; import { getRandomPassword, getRandomUsername } from "./rnd.js"; +import { useCredentialsChecker } from "../hooks/useCredentialsChecker.js"; const logger = new Logger("RegistrationPage"); @@ -58,6 +59,7 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on const [name, setName] = useState<string | undefined>(); const [password, setPassword] = useState<string | undefined>(); const [repeatPassword, setRepeatPassword] = useState<string | undefined>(); + const {requestNewLoginToken} = useCredentialsChecker() const { register } = useTestingAPI(); const { i18n } = useTranslationContext(); @@ -83,8 +85,11 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on if (!username || !password || !name) return; try { await register({ name, username, password }); + const resp = await requestNewLoginToken(username, password) setUsername(undefined); - backend.logIn({ username, password }); + if (resp.valid) { + backend.logIn({ username, token: resp.token }); + } onComplete(); } catch (error) { if (error instanceof RequestError) { @@ -125,7 +130,10 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on setRepeatPassword(undefined); const username = `_${user.first}-${user.second}_` await register({ username, name: `${user.first} ${user.second}`, password: pass }); - backend.logIn({ username, password: pass }); + const resp = await requestNewLoginToken(username, pass) + if (resp.valid) { + backend.logIn({ username, token: resp.token }); + } onComplete(); } catch (error) { if (error instanceof RequestError) { diff --git a/packages/demobank-ui/src/pages/admin/Account.tsx b/packages/demobank-ui/src/pages/admin/Account.tsx index d368c4319..8ea59cdcb 100644 --- a/packages/demobank-ui/src/pages/admin/Account.tsx +++ b/packages/demobank-ui/src/pages/admin/Account.tsx @@ -17,11 +17,8 @@ export function AdminAccount({ onRegister }: { onRegister: () => void }): VNode } const { data } = result; - //FIXME: libeufin does not follow the spec - const balance = Amounts.parseOrThrow(data.balance); - const balanceIsDebit = true; - // const balance = Amounts.parseOrThrow(data.balance.amount); - // const balanceIsDebit = result.data.balance.credit_debit_indicator == "debit"; + const balance = Amounts.parseOrThrow(data.balance.amount); + const balanceIsDebit = result.data.balance.credit_debit_indicator == "debit"; const debitThreshold = Amounts.parseOrThrow(result.data.debit_threshold); const limit = balanceIsDebit diff --git a/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx b/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx index 63a7c79f3..1e5370afc 100644 --- a/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx +++ b/packages/demobank-ui/src/pages/admin/RemoveAccount.tsx @@ -41,9 +41,7 @@ export function RemoveAccount({ if (focus) ref.current?.focus(); }, [focus]); - //FIXME: libeufin does not follow the spec - const balance = Amounts.parse(result.data.balance); - // const balance = Amounts.parse(result.data.balance.amount); + const balance = Amounts.parse(result.data.balance.amount); if (!balance) { return <div>there was an error reading the balance</div>; } diff --git a/packages/demobank-ui/src/pages/business/Home.tsx b/packages/demobank-ui/src/pages/business/Home.tsx index 427cfc656..628ae328d 100644 --- a/packages/demobank-ui/src/pages/business/Home.tsx +++ b/packages/demobank-ui/src/pages/business/Home.tsx @@ -236,11 +236,8 @@ function CreateCashout({ if (!ratiosResult.ok) return onLoadNotOk(ratiosResult); const config = ratiosResult.data; - //FIXME: libeufin does not follow the spec - const balance = Amounts.parseOrThrow(result.data.balance); - const balanceIsDebit = true; - // const balance = Amounts.parseOrThrow(result.data.balance.amount); - // const balanceIsDebit = result.data.balance.credit_debit_indicator == "debit"; + const balance = Amounts.parseOrThrow(result.data.balance.amount); + const balanceIsDebit = result.data.balance.credit_debit_indicator == "debit"; const debitThreshold = Amounts.parseOrThrow(result.data.debit_threshold); const zero = Amounts.zeroOfCurrency(balance.currency); |