diff options
author | Sebastian <sebasjm@gmail.com> | 2023-11-22 13:33:44 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-11-22 15:20:28 -0300 |
commit | 33c0267b37eecf44dc9f04e124eb44d27cba700c (patch) | |
tree | 9d5549dbb5a415b44005ab05711fc66c4643cbc9 /packages/demobank-ui/src/pages | |
parent | 5eec408d9fb5e8c2375937166997ef8267a4053c (diff) | |
download | wallet-core-33c0267b37eecf44dc9f04e124eb44d27cba700c.tar.gz wallet-core-33c0267b37eecf44dc9f04e124eb44d27cba700c.tar.bz2 wallet-core-33c0267b37eecf44dc9f04e124eb44d27cba700c.zip |
settings and preferences, getting conversion info
Diffstat (limited to 'packages/demobank-ui/src/pages')
12 files changed, 56 insertions, 63 deletions
diff --git a/packages/demobank-ui/src/pages/AccountPage/views.tsx b/packages/demobank-ui/src/pages/AccountPage/views.tsx index 0f5236192..cfee684fa 100644 --- a/packages/demobank-ui/src/pages/AccountPage/views.tsx +++ b/packages/demobank-ui/src/pages/AccountPage/views.tsx @@ -18,7 +18,7 @@ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { Attention } from "@gnu-taler/web-util/browser"; import { Transactions } from "../../components/Transactions/index.js"; -import { useSettings } from "../../hooks/settings.js"; +import { usePreferences } from "../../hooks/preferences.js"; import { PaymentOptions } from "../PaymentOptions.js"; import { State } from "./index.js"; @@ -32,7 +32,7 @@ const IS_PUBLIC_ACCOUNT_ENABLED = false function ShowDemoInfo(): VNode { const { i18n } = useTranslationContext(); - const [settings, updateSettings] = useSettings(); + const [settings, updateSettings] = usePreferences(); if (!settings.showDemoDescription) return <Fragment /> return <Attention title={i18n.str`This is a demo bank`} onClose={() => { updateSettings("showDemoDescription", false); diff --git a/packages/demobank-ui/src/pages/BankFrame.tsx b/packages/demobank-ui/src/pages/BankFrame.tsx index f0baae3a3..5fef04b66 100644 --- a/packages/demobank-ui/src/pages/BankFrame.tsx +++ b/packages/demobank-ui/src/pages/BankFrame.tsx @@ -20,9 +20,9 @@ import { ComponentChildren, Fragment, VNode, h } from "preact"; import { useEffect, useErrorBoundary } from "preact/hooks"; import { useAccountDetails } from "../hooks/access.js"; import { useBackendState } from "../hooks/backend.js"; -import { getAllBooleanSettings, getLabelForSetting, useSettings } from "../hooks/settings.js"; -import { bankUiSettings } from "../settings.js"; +import { getAllBooleanPreferences, getLabelForPreferences, usePreferences } from "../hooks/preferences.js"; import { RenderAmount } from "./PaytoWireTransferForm.js"; +import { useSettingsContext } from "../context/settings.js"; const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : undefined; @@ -37,7 +37,8 @@ export function BankFrame({ }): VNode { const { i18n } = useTranslationContext(); const backend = useBackendState(); - const [settings, updateSettings] = useSettings(); + const settings = useSettingsContext(); + const [preferences, updatePreferences] = usePreferences(); const [error, resetError] = useErrorBoundary(); @@ -59,12 +60,12 @@ export function BankFrame({ <div class="bg-indigo-600 pb-32"> <Header title="Bank" - iconLinkURL={bankUiSettings.iconLinkURL ?? "#"} + iconLinkURL={settings.iconLinkURL ?? "#"} onLogout={backend.state.status !== "loggedIn" ? undefined : () => { backend.logOut() - updateSettings("currentWithdrawalOperationId", undefined); + updatePreferences("currentWithdrawalOperationId", undefined); }} - sites={bankUiSettings.demoSites ?? []} + sites={settings.demoSites ?? new Array<Array<string>>(new Array<string>())} supportedLangs={["en", "es", "de"]} > <li> @@ -72,18 +73,18 @@ export function BankFrame({ <i18n.Translate>Preferences</i18n.Translate> </div> <ul role="list" class="space-y-1"> - {getAllBooleanSettings().map(set => { - const isOn: boolean = !!settings[set] + {getAllBooleanPreferences().map(set => { + const isOn: boolean = !!preferences[set] return <li class="mt-2 pl-2"> <div class="flex items-center justify-between"> <span class="flex flex-grow flex-col"> <span class="text-sm text-black font-medium leading-6 " id="availability-label"> - {getLabelForSetting(set, i18n)} + {getLabelForPreferences(set, i18n)} </span> </span> <button type="button" data-enabled={isOn} class="bg-indigo-600 data-[enabled=false]:bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" role="switch" aria-checked="false" aria-labelledby="availability-label" aria-describedby="availability-description" - onClick={() => { updateSettings(set, !isOn); }}> + onClick={() => { updatePreferences(set, !isOn); }}> <span aria-hidden="true" data-enabled={isOn} class="translate-x-5 data-[enabled=false]:translate-x-0 pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span> </button> </div> @@ -130,7 +131,7 @@ export function BankFrame({ } function MaybeShowDebugInfo({ info }: { info: any }): VNode { - const [settings] = useSettings() + const [settings] = usePreferences() if (settings.showDebugInfo) { return <pre class="whitespace-break-spaces "> {info} diff --git a/packages/demobank-ui/src/pages/LoginForm.tsx b/packages/demobank-ui/src/pages/LoginForm.tsx index 018416390..02ec75dbf 100644 --- a/packages/demobank-ui/src/pages/LoginForm.tsx +++ b/packages/demobank-ui/src/pages/LoginForm.tsx @@ -15,18 +15,14 @@ */ import { TranslatedString } from "@gnu-taler/taler-util"; -import { Notification, useLocalNotification, useTranslationContext } from "@gnu-taler/web-util/browser"; +import { LocalNotificationBanner, ShowInputErrorLabel, useLocalNotification, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useEffect, useRef, useState } from "preact/hooks"; -import { ShowInputErrorLabel } from "@gnu-taler/web-util/browser"; import { useBankCoreApiContext } from "../context/config.js"; import { useBackendState } from "../hooks/backend.js"; -import { bankUiSettings } from "../settings.js"; -import { undefinedIfEmpty, withRuntimeErrorHandling } from "../utils.js"; -import { assertUnreachable } from "./WithdrawalOperationPage.js"; +import { undefinedIfEmpty } from "../utils.js"; import { doAutoFocus } from "./PaytoWireTransferForm.js"; -import { Attention } from "@gnu-taler/web-util/browser"; -import { LocalNotificationBanner } from "@gnu-taler/web-util/browser"; +import { assertUnreachable } from "./WithdrawalOperationPage.js"; /** @@ -40,6 +36,7 @@ export function LoginForm({ reason, onRegister }: { reason?: "not-found" | "forb const { i18n } = useTranslationContext(); const { api } = useBankCoreApiContext(); const [notification, notify, handleError] = useLocalNotification() + const {config} = useBankCoreApiContext(); /** * Register form may be shown in the initialization step. @@ -208,7 +205,7 @@ export function LoginForm({ reason, onRegister }: { reason?: "not-found" | "forb </div>} </form> - {bankUiSettings.allowRegistrations && onRegister && + {config.allow_registrations && onRegister && <p class="mt-10 text-center text-sm text-gray-500 border-t"> <button type="submit" class="flex mt-4 rounded-md bg-blue-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-blue-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600" diff --git a/packages/demobank-ui/src/pages/OperationState/state.ts b/packages/demobank-ui/src/pages/OperationState/state.ts index 2d33ff78b..30f7419f0 100644 --- a/packages/demobank-ui/src/pages/OperationState/state.ts +++ b/packages/demobank-ui/src/pages/OperationState/state.ts @@ -21,12 +21,12 @@ import { mutate } from "swr"; import { useBankCoreApiContext } from "../../context/config.js"; import { useWithdrawalDetails } from "../../hooks/access.js"; import { useBackendState } from "../../hooks/backend.js"; -import { useSettings } from "../../hooks/settings.js"; +import { usePreferences } from "../../hooks/preferences.js"; import { assertUnreachable } from "../WithdrawalOperationPage.js"; import { Props, State } from "./index.js"; export function useComponentState({ currency, onClose }: Props): utils.RecursiveState<State> { - const [settings, updateSettings] = useSettings() + const [settings, updateSettings] = usePreferences() const { state: credentials } = useBackendState() const creds = credentials.status !== "loggedIn" ? undefined : credentials const { api } = useBankCoreApiContext() diff --git a/packages/demobank-ui/src/pages/OperationState/views.tsx b/packages/demobank-ui/src/pages/OperationState/views.tsx index e7db566ea..a06147039 100644 --- a/packages/demobank-ui/src/pages/OperationState/views.tsx +++ b/packages/demobank-ui/src/pages/OperationState/views.tsx @@ -20,7 +20,7 @@ import { Fragment, VNode, h } from "preact"; import { useEffect, useMemo, useState } from "preact/hooks"; import { QR } from "../../components/QR.js"; import { ShowInputErrorLabel } from "@gnu-taler/web-util/browser"; -import { useSettings } from "../../hooks/settings.js"; +import { usePreferences } from "../../hooks/preferences.js"; import { undefinedIfEmpty } from "../../utils.js"; import { State } from "./index.js"; import { LocalNotificationBanner } from "@gnu-taler/web-util/browser"; @@ -46,7 +46,7 @@ export function InvalidReserveView({ reserve, onClose }: State.InvalidReserve) { export function NeedConfirmationView({ error, onAbort: doAbort, onConfirm: doConfirm, busy }: State.NeedConfirmation) { const { i18n } = useTranslationContext() - const [settings] = useSettings() + const [settings] = usePreferences() const [notification, notify, errorHandler] = useLocalNotification() const captchaNumbers = useMemo(() => { @@ -309,7 +309,7 @@ export function AbortedView({ error, onClose }: State.Aborted) { export function ConfirmedView({ error, onClose }: State.Confirmed) { const { i18n } = useTranslationContext(); - const [settings, updateSettings] = useSettings() + const [settings, updateSettings] = usePreferences() return ( <Fragment> diff --git a/packages/demobank-ui/src/pages/PaymentOptions.tsx b/packages/demobank-ui/src/pages/PaymentOptions.tsx index 2e756b86d..76d20867e 100644 --- a/packages/demobank-ui/src/pages/PaymentOptions.tsx +++ b/packages/demobank-ui/src/pages/PaymentOptions.tsx @@ -20,7 +20,7 @@ import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { PaytoWireTransferForm, doAutoFocus } from "./PaytoWireTransferForm.js"; import { WalletWithdrawForm } from "./WalletWithdrawForm.js"; -import { useSettings } from "../hooks/settings.js"; +import { usePreferences } from "../hooks/preferences.js"; /** * Let the user choose a payment option, @@ -28,7 +28,7 @@ import { useSettings } from "../hooks/settings.js"; */ export function PaymentOptions({ limit, goToConfirmOperation }: { limit: AmountJson, goToConfirmOperation: (id: string) => void }): VNode { const { i18n } = useTranslationContext(); - const [settings] = useSettings(); + const [settings] = usePreferences(); const [tab, setTab] = useState<"charge-wallet" | "wire-transfer" | undefined>(); diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx index fdaa28bbb..9c3b21097 100644 --- a/packages/demobank-ui/src/pages/RegistrationPage.tsx +++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx @@ -15,18 +15,18 @@ */ import { AccessToken, Logger, TranslatedString } from "@gnu-taler/taler-util"; import { + LocalNotificationBanner, + ShowInputErrorLabel, useLocalNotification, useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useState } from "preact/hooks"; -import { ShowInputErrorLabel } from "@gnu-taler/web-util/browser"; import { useBankCoreApiContext } from "../context/config.js"; import { useBackendState } from "../hooks/backend.js"; -import { bankUiSettings } from "../settings.js"; -import { undefinedIfEmpty, withRuntimeErrorHandling } from "../utils.js"; +import { undefinedIfEmpty } from "../utils.js"; import { getRandomPassword, getRandomUsername } from "./rnd.js"; -import { LocalNotificationBanner } from "@gnu-taler/web-util/browser"; +import { useSettingsContext } from "../context/settings.js"; const logger = new Logger("RegistrationPage"); @@ -38,7 +38,8 @@ export function RegistrationPage({ onCancel: () => void; }): VNode { const { i18n } = useTranslationContext(); - if (!bankUiSettings.allowRegistrations) { + const {config} = useBankCoreApiContext(); + if (!config.allow_registrations) { return ( <p>{i18n.str`Currently, the bank is not accepting new registrations!`}</p> ); @@ -62,6 +63,7 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on const [email, setEmail] = useState<string | undefined>(); const [repeatPassword, setRepeatPassword] = useState<string | undefined>(); const [notification, notify, handleError] = useLocalNotification() + const settings = useSettingsContext(); const { api } = useBankCoreApiContext() // const { register } = useTestingAPI(); @@ -177,7 +179,8 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on async function doRandomRegistration(tries: number = 3) { const user = getRandomUsername(); - const pass = getRandomPassword(); + + const pass = settings.simplePasswordForRandomAccounts ? "123" : getRandomPassword(); const username = `_${user.first}-${user.second}_` await doRegistrationAndLogin(name, username, pass) onComplete(); @@ -389,7 +392,7 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on </form> - {bankUiSettings.allowRandomAccountCreation && + {settings.allowRandomAccountCreation && <p class="mt-10 text-center text-sm text-gray-500 border-t"> <button type="submit" class="flex mt-4 w-full justify-center rounded-md bg-green-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-green-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-green-600" diff --git a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx index a9a661c25..5eef95f1e 100644 --- a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx +++ b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx @@ -32,7 +32,7 @@ import { useState } from "preact/hooks"; import { Attention } from "@gnu-taler/web-util/browser"; import { useBankCoreApiContext } from "../context/config.js"; import { useBackendState } from "../hooks/backend.js"; -import { useSettings } from "../hooks/settings.js"; +import { usePreferences } from "../hooks/preferences.js"; import { undefinedIfEmpty, withRuntimeErrorHandling } from "../utils.js"; import { OperationState } from "./OperationState/index.js"; import { InputAmount, doAutoFocus } from "./PaytoWireTransferForm.js"; @@ -50,7 +50,7 @@ function OldWithdrawalForm({ goToConfirmOperation, limit, onCancel, focus }: { onCancel: () => void; }): VNode { const { i18n } = useTranslationContext(); - const [settings, updateSettings] = useSettings() + const [settings, updateSettings] = usePreferences() const { state: credentials } = useBackendState(); const creds = credentials.status !== "loggedIn" ? undefined : credentials @@ -240,7 +240,7 @@ export function WalletWithdrawForm({ onCancel: () => void; }): VNode { const { i18n } = useTranslationContext(); - const [settings, updateSettings] = useSettings() + const [settings, updateSettings] = usePreferences() return (<div class="grid grid-cols-1 gap-x-8 gap-y-8 pt-10 md:grid-cols-3 bg-gray-100 my-4 px-4 pb-4 rounded-lg"> <div class="px-4 sm:px-0"> diff --git a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx index 7fec76d2f..be8ff8b58 100644 --- a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx +++ b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx @@ -33,7 +33,7 @@ import { useMemo, useState } from "preact/hooks"; import { mutate } from "swr"; import { ShowInputErrorLabel } from "@gnu-taler/web-util/browser"; import { useBankCoreApiContext } from "../context/config.js"; -import { useSettings } from "../hooks/settings.js"; +import { usePreferences } from "../hooks/preferences.js"; import { undefinedIfEmpty, withRuntimeErrorHandling } from "../utils.js"; import { RenderAmount } from "./PaytoWireTransferForm.js"; import { assertUnreachable } from "./WithdrawalOperationPage.js"; @@ -60,7 +60,7 @@ export function WithdrawalConfirmationQuestion({ withdrawUri, }: Props): VNode { const { i18n } = useTranslationContext(); - const [settings, updateSettings] = useSettings() + const [settings, updateSettings] = usePreferences() const captchaNumbers = useMemo(() => { return { diff --git a/packages/demobank-ui/src/pages/WithdrawalOperationPage.tsx b/packages/demobank-ui/src/pages/WithdrawalOperationPage.tsx index 5ed57a0f7..7060b7a98 100644 --- a/packages/demobank-ui/src/pages/WithdrawalOperationPage.tsx +++ b/packages/demobank-ui/src/pages/WithdrawalOperationPage.tsx @@ -25,7 +25,7 @@ import { import { Fragment, VNode, h } from "preact"; import { Attention } from "@gnu-taler/web-util/browser"; import { useBankCoreApiContext } from "../context/config.js"; -import { useSettings } from "../hooks/settings.js"; +import { usePreferences } from "../hooks/preferences.js"; import { WithdrawalQRCode } from "./WithdrawalQRCode.js"; const logger = new Logger("AccountPage"); @@ -44,7 +44,7 @@ export function WithdrawalOperationPage({ }); const parsedUri = parseWithdrawUri(uri); const { i18n } = useTranslationContext(); - const [settings, updateSettings] = useSettings(); + const [settings, updateSettings] = usePreferences(); if (!parsedUri) { return <Attention type="danger" title={i18n.str`The Withdrawal URI is not valid`}> diff --git a/packages/demobank-ui/src/pages/business/CreateCashout.tsx b/packages/demobank-ui/src/pages/business/CreateCashout.tsx index 1838dbda3..c5f4ebc4e 100644 --- a/packages/demobank-ui/src/pages/business/CreateCashout.tsx +++ b/packages/demobank-ui/src/pages/business/CreateCashout.tsx @@ -77,7 +77,7 @@ export function CreateCashout({ estimateByCredit: calculateFromCredit, estimateByDebit: calculateFromDebit, } = useEstimator(); - const { api, config } = useBankCoreApiContext() + const { config } = useBankCoreApiContext() const [form, setForm] = useState<Partial<FormType>>({ isDebit: true, amount: "2" }); const [notification, notify, handleError] = useLocalNotification() const info = useConversionInfo(); @@ -108,35 +108,29 @@ export function CreateCashout({ return <ErrorLoading error={info} /> } + const conversionInfo = info.body.conversion_info + if (!conversionInfo) { + return <div>conversion enabled but server replied without conversion_info</div> + } + const account = { balance: Amounts.parseOrThrow(resultAccount.body.balance.amount), balanceIsDebit: resultAccount.body.balance.credit_debit_indicator == "debit", debitThreshold: Amounts.parseOrThrow(resultAccount.body.debit_threshold) } - const { fiat_currency, regional_currency, cashout_ratio, cashout_fee } = info.body + const {fiat_currency, regional_currency} = info.body const regionalZero = Amounts.zeroOfCurrency(regional_currency); const fiatZero = Amounts.zeroOfCurrency(fiat_currency); const limit = account.balanceIsDebit ? Amounts.sub(account.debitThreshold, account.balance).amount : Amounts.add(account.balance, account.debitThreshold).amount; - const zeroCalc = { debit: regionalZero, credit: fiatZero, beforeFee: regionalZero }; + const zeroCalc = { debit: regionalZero, credit: fiatZero, beforeFee: fiatZero }; const [calc, setCalc] = useState(zeroCalc); - - const sellRate = Number.parseFloat(cashout_ratio); - const sellFee = !cashout_fee - ? fiatZero - : Amounts.parseOrThrow(cashout_fee); - - if (sellRate === undefined || sellRate < 0) return <div>error rate d - <pre> - {JSON.stringify(info.body, undefined, 2)} - </pre> - </div>; - - const safeSellRate = sellRate - + console.log(calc) + const sellFee = Amounts.parseOrThrow(conversionInfo.cashout_fee); + const sellRate = conversionInfo.cashout_ratio /** * can be in regional currency or fiat currency * depending on the isDebit flag @@ -150,8 +144,8 @@ export function CreateCashout({ await handleError(async () => { if (Amounts.isNonZero(inputAmount)) { const resp = await (form.isDebit ? - calculateFromDebit(inputAmount, fiat_currency, sellFee, safeSellRate) : - calculateFromCredit(inputAmount, regional_currency, sellFee, safeSellRate)); + calculateFromDebit(inputAmount, sellFee) : + calculateFromCredit(inputAmount, sellFee)); setCalc(resp) } }) diff --git a/packages/demobank-ui/src/pages/rnd.ts b/packages/demobank-ui/src/pages/rnd.ts index 32c3a934f..46111425e 100644 --- a/packages/demobank-ui/src/pages/rnd.ts +++ b/packages/demobank-ui/src/pages/rnd.ts @@ -1,5 +1,4 @@ import { createEddsaKeyPair, encodeCrock, getRandomBytes } from "@gnu-taler/taler-util" -import { bankUiSettings } from "../settings.js" const noun = [ @@ -2890,6 +2889,5 @@ export function getRandomUsername(): { first: string, second: string } { } export function getRandomPassword(): string { - if (bankUiSettings.simplePasswordForRandomAccounts) return "123" return encodeCrock(getRandomBytes(16)) }
\ No newline at end of file |