summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-12-06 07:55:52 -0300
committerSebastian <sebasjm@gmail.com>2023-12-06 14:10:09 -0300
commitcb9c115becb7fafb89f64d02f3555efddaeba03e (patch)
treeefdc0bfb8c896b3695f8c34cff432b3672ff72e2
parenta7ec09cd8e0d6cf80d2f714c9310d58f19673541 (diff)
downloadwallet-core-cb9c115becb7fafb89f64d02f3555efddaeba03e.tar.gz
wallet-core-cb9c115becb7fafb89f64d02f3555efddaeba03e.tar.bz2
wallet-core-cb9c115becb7fafb89f64d02f3555efddaeba03e.zip
default threshold
-rw-r--r--packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx1
-rw-r--r--packages/demobank-ui/src/pages/admin/AccountForm.tsx38
2 files changed, 19 insertions, 20 deletions
diff --git a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx
index d435673a2..92419b7ed 100644
--- a/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx
+++ b/packages/demobank-ui/src/pages/account/ShowAccountDetails.tsx
@@ -135,6 +135,7 @@ export function ShowAccountDetails({
focus={update}
noCashout={credentials.status === "loggedIn" ? credentials.isUserAdministrator : undefined}
username={account}
+ admin={credentials.status === "loggedIn" ? credentials.isUserAdministrator : undefined}
template={result.body}
purpose={update ? "update" : "show"}
onChange={(a) => setSubmitAccount(a)}
diff --git a/packages/demobank-ui/src/pages/admin/AccountForm.tsx b/packages/demobank-ui/src/pages/admin/AccountForm.tsx
index e76204a81..61702f7d4 100644
--- a/packages/demobank-ui/src/pages/admin/AccountForm.tsx
+++ b/packages/demobank-ui/src/pages/admin/AccountForm.tsx
@@ -1,12 +1,11 @@
-import { AmountString, Amounts, ChallengeContactData, PaytoString, TalerCorebankApi, TranslatedString, buildPayto, parsePaytoUri, stringifyPaytoUri } from "@gnu-taler/taler-util";
+import { AmountString, Amounts, PaytoString, TalerCorebankApi, buildPayto, parsePaytoUri, stringifyPaytoUri } from "@gnu-taler/taler-util";
import { CopyButton, ShowInputErrorLabel, useTranslationContext } from "@gnu-taler/web-util/browser";
import { ComponentChildren, Fragment, VNode, h } from "preact";
import { useState } from "preact/hooks";
-import { ErrorMessageMappingFor, PartialButDefined, RecursivePartial, WithIntermediate, undefinedIfEmpty, validateIBAN } from "../../utils.js";
+import { useBankCoreApiContext } from "../../context/config.js";
+import { ErrorMessageMappingFor, PartialButDefined, WithIntermediate, undefinedIfEmpty, validateIBAN } from "../../utils.js";
import { InputAmount, doAutoFocus } from "../PaytoWireTransferForm.js";
import { assertUnreachable } from "../WithdrawalOperationPage.js";
-import { useBackendContext } from "../../context/backend.js";
-import { useBankCoreApiContext } from "../../context/config.js";
import { getRandomPassword } from "../rnd.js";
const IBAN_REGEX = /^[A-Z][A-Z0-9]*$/;
@@ -16,7 +15,6 @@ const REGEX_JUST_NUMBERS_REGEX = /^\+[0-9 ]*$/;
export type AccountFormData = TalerCorebankApi.AccountData & {
username: string,
- debitAmount: string,
isExchange: boolean,
isPublic: boolean,
}
@@ -27,10 +25,11 @@ type ChangeByPurposeType = {
"show": undefined
}
/**
- * Create valid account object to update or create
- * Take template as initial values for the form
- * Purpose indicate if all field al read only (show), part of them (update)
- * or none (create)
+ * FIXME:
+ * is_public is missing on PATCH
+ * account email/password should require 2FA
+ *
+ *
* @param param0
* @returns
*/
@@ -53,21 +52,21 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({
onChange: ChangeByPurposeType[PurposeType];
purpose: PurposeType;
}): VNode {
- const initial = initializeFromTemplate(username, template);
+ const { config } = useBankCoreApiContext()
+
+ const initial = initializeFromTemplate(username, template, config.default_debit_threshold);
const [form, setForm] = useState(initial);
const [errors, setErrors] = useState<
ErrorMessageMappingFor<typeof initial> | undefined
>(undefined);
const { i18n } = useTranslationContext();
- const { config } = useBankCoreApiContext()
-
function updateForm(newForm: typeof initial): void {
const parsed = !newForm.cashout_payto_uri
? undefined
: buildPayto("iban", newForm.cashout_payto_uri, undefined);;
- const trimmedAmountStr = newForm.debitAmount?.trim();
+ const trimmedAmountStr = newForm.debit_threshold?.trim();
const parsedAmount = Amounts.parse(`${config.currency}:${trimmedAmountStr}`);
const errors = undefinedIfEmpty<ErrorMessageMappingFor<typeof initial>>({
@@ -98,8 +97,6 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({
? (purpose === "create" ? i18n.str`required` : undefined)
: !parsedAmount
? i18n.str`not valid`
- : Amounts.isZero(parsedAmount)
- ? i18n.str`should be greater than 0`
: undefined,
name: !newForm.name ? i18n.str`required` : undefined,
username: !newForm.username ? i18n.str`required` : undefined,
@@ -130,7 +127,7 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({
email: newForm.contact_data?.email,
phone: newForm.contact_data?.phone,
}),
- debit_threshold: newForm.debit_threshold as AmountString,
+ debit_threshold: `${config.currency}:${newForm.debit_threshold}` as AmountString,
internal_payto_uri: internalURI,
is_public: newForm.isPublic,
is_taler_exchange: newForm.isExchange,
@@ -141,6 +138,7 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({
case "update": {
//typescript doesn't correctly narrow a generic type
const callback = onChange as ChangeByPurposeType["update"]
+
const result: TalerCorebankApi.AccountReconfiguration = {
cashout_payto_uri: cashoutURI,
challenge_contact_data: undefinedIfEmpty({
@@ -363,9 +361,9 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({
name="debit"
left
currency={config.currency}
- value={form.debitAmount ?? ""}
+ value={form.debit_threshold ?? ""}
onChange={(e) => {
- form.debitAmount = e
+ form.debit_threshold = e as AmountString
updateForm(structuredClone(form))
}}
/>
@@ -427,17 +425,17 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({
</form>
);
}
-// JNTMECG7RM3AAQB6SRAZNWDSM8
function initializeFromTemplate(
username: string | undefined,
account: TalerCorebankApi.AccountData | undefined,
+ default_debit_threshold: AmountString,
): WithIntermediate<AccountFormData> {
const emptyAccount = {
cashout_payto_uri: undefined,
contact_data: undefined,
payto_uri: undefined,
balance: undefined,
- debit_threshold: undefined,
+ debit_threshold: Amounts.stringifyValue(default_debit_threshold) as AmountString,
name: undefined,
};
const emptyContact = {