diff options
Diffstat (limited to 'packages/bank-ui/src')
5 files changed, 93 insertions, 17 deletions
diff --git a/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx b/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx index a3bb091c1..157e1c3a9 100644 --- a/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx +++ b/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx @@ -30,7 +30,7 @@ import { assertUnreachable, buildPayto, parsePaytoUri, - stringifyPaytoUri + stringifyPaytoUri, } from "@gnu-taler/taler-util"; import { InternationalizationAPI, @@ -190,11 +190,7 @@ export function PaytoWireTransferForm({ amount: sAmount, }; const check = IdempotencyRetry.tryFiveTimes(); - const resp = await api.createTransaction( - credentials, - request, - check, - ); + const resp = await api.createTransaction(credentials, request, check); mutate(() => true); if (resp.type === "fail") { switch (resp.case) { @@ -248,6 +244,15 @@ export function PaytoWireTransferForm({ debug: resp.detail, when: AbsoluteTime.now(), }); + case TalerErrorCode.BANK_CONVERSION_AMOUNT_TO_SMALL: { + return notify({ + type: "error", + title: i18n.str`The amount is less than the minimum allowed.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + } case HttpStatusCode.NotFound: return notify({ type: "error", diff --git a/packages/bank-ui/src/pages/RegistrationPage.tsx b/packages/bank-ui/src/pages/RegistrationPage.tsx index 5dd19a63f..897a02efa 100644 --- a/packages/bank-ui/src/pages/RegistrationPage.tsx +++ b/packages/bank-ui/src/pages/RegistrationPage.tsx @@ -13,10 +13,7 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { - HttpStatusCode, - TalerErrorCode -} from "@gnu-taler/taler-util"; +import { HttpStatusCode, TalerErrorCode } from "@gnu-taler/taler-util"; import { LocalNotificationBanner, RouteDefinition, @@ -143,6 +140,8 @@ function RegistrationForm({ return i18n.str`Authentication channel is not supported.`; case TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT: return i18n.str`Only admin is allow to set debt limit.`; + case TalerErrorCode.BANK_NON_ADMIN_SET_MIN_CASHOUT: + return i18n.str`Only the administrator can change the minimun cashout limit.`; case TalerErrorCode.BANK_NON_ADMIN_SET_TAN_CHANNEL: return i18n.str`Only admin can create accounts with second factor authentication.`; } diff --git a/packages/bank-ui/src/pages/account/ShowAccountDetails.tsx b/packages/bank-ui/src/pages/account/ShowAccountDetails.tsx index 69a186ca1..7118da704 100644 --- a/packages/bank-ui/src/pages/account/ShowAccountDetails.tsx +++ b/packages/bank-ui/src/pages/account/ShowAccountDetails.tsx @@ -183,6 +183,15 @@ export function ShowAccountDetails({ when: AbsoluteTime.now(), }); } + case TalerErrorCode.BANK_NON_ADMIN_SET_MIN_CASHOUT: { + return notify({ + type: "error", + title: i18n.str`Only the administrator can change the minimun cashout limit.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + } default: assertUnreachable(resp); } diff --git a/packages/bank-ui/src/pages/admin/AccountForm.tsx b/packages/bank-ui/src/pages/admin/AccountForm.tsx index c8195ddb0..21e3e6588 100644 --- a/packages/bank-ui/src/pages/admin/AccountForm.tsx +++ b/packages/bank-ui/src/pages/admin/AccountForm.tsx @@ -52,6 +52,7 @@ const REGEX_JUST_NUMBERS_REGEX = /^\+[0-9 ]*$/; export type AccountFormData = { debit_threshold?: string; + min_cashout?: string; isExchange?: boolean; isPublic?: boolean; name?: string; @@ -111,6 +112,9 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ debit_threshold: Amounts.stringifyValue( template?.debit_threshold ?? config.default_debit_threshold, ), + min_cashout: Amounts.stringifyValue( + template?.min_cashout ?? `${config.currency}:0`, + ), isExchange: template?.is_taler_exchange, isPublic: template?.is_public, name: template?.name ?? "", @@ -140,12 +144,18 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ (config.allow_edit_cashout_payto_uri || userIsAdmin)); const editableThreshold = userIsAdmin && (purpose === "create" || purpose === "update"); + const editableMinCashout = + userIsAdmin && (purpose === "create" || purpose === "update"); const editableAccount = purpose === "create" && userIsAdmin; function updateForm(newForm: typeof defaultValue): void { - const trimmedAmountStr = newForm.debit_threshold?.trim(); - const parsedAmount = Amounts.parse( - `${config.currency}:${trimmedAmountStr}`, + const trimmedMinCashoutStr = newForm.min_cashout?.trim(); + const parsedMinCashout = Amounts.parse( + `${config.currency}:${trimmedMinCashoutStr}`, + ); + const trimmedDebitThresholdStr = newForm.debit_threshold?.trim(); + const parsedDebitThreshold = Amounts.parse( + `${config.currency}:${trimmedDebitThresholdStr}`, ); const errors = undefinedIfEmpty< @@ -189,9 +199,16 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ : undefined, debit_threshold: !editableThreshold ? undefined - : !trimmedAmountStr + : !trimmedDebitThresholdStr + ? undefined + : !parsedDebitThreshold + ? i18n.str`Not valid` + : undefined, + min_cashout: !editableMinCashout + ? undefined + : !trimmedMinCashoutStr ? undefined - : !parsedAmount + : !parsedMinCashout ? i18n.str`Not valid` : undefined, name: !editableName @@ -248,9 +265,12 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ } const internalURI = !internal ? undefined : stringifyPaytoUri(internal); - const threshold = !parsedAmount + const threshold = !parsedDebitThreshold + ? undefined + : Amounts.stringify(parsedDebitThreshold); + const minCashout = !parsedMinCashout ? undefined - : Amounts.stringify(parsedAmount); + : Amounts.stringify(parsedMinCashout); switch (purpose) { case "create": { @@ -265,6 +285,7 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ phone: !newForm.phone ? undefined : newForm.phone, }), debit_threshold: threshold ?? config.default_debit_threshold, + min_cashout: minCashout, cashout_payto_uri: cashoutURI, payto_uri: internalURI, is_public: newForm.isPublic, @@ -288,6 +309,7 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ phone: !newForm.phone ? undefined : newForm.phone, }), debit_threshold: threshold, + min_cashout: minCashout, is_public: newForm.isPublic, name: newForm.name, tan_channel: @@ -533,6 +555,38 @@ export function AccountForm<PurposeType extends keyof ChangeByPurposeType>({ </div> <div class="sm:col-span-5"> + <label + for="minCashout" + class="block text-sm font-medium leading-6 text-gray-900" + >{i18n.str`Minimum cashout`}</label> + <InputAmount + name="minCashout" + left + currency={config.currency} + value={form.min_cashout ?? defaultValue.min_cashout} + onChange={ + !editableMinCashout + ? undefined + : (e) => { + form.min_cashout = e as AmountString; + updateForm(structuredClone(form)); + } + } + /> + <ShowInputErrorLabel + message={ + errors?.min_cashout ? String(errors?.min_cashout) : undefined + } + isDirty={form.min_cashout !== undefined} + /> + <p class="mt-2 text-sm text-gray-500"> + <i18n.Translate> + Custom minimum cashout amount for this account. + </i18n.Translate> + </p> + </div> + + <div class="sm:col-span-5"> <div class="flex items-center justify-between"> <span class="flex flex-grow flex-col"> <span diff --git a/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx b/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx index 7d2d449b0..3898088ed 100644 --- a/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx +++ b/packages/bank-ui/src/pages/admin/CreateNewAccount.tsx @@ -146,6 +146,15 @@ export function CreateNewAccount({ debug: resp.detail, when: AbsoluteTime.now(), }); + case TalerErrorCode.BANK_NON_ADMIN_SET_MIN_CASHOUT: { + return notify({ + type: "error", + title: i18n.str`Only the administrator can change the minimun cashout limit.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + } default: assertUnreachable(resp); } |