merchant-backoffice

ZZZ: Inactive/Deprecated
Log | Files | Refs | Submodules | README

commit d972287890401efa538cd0bb1b8e27505782d7d5
parent 04623aa3b6ab7c86f06191c7a8754fd2e988f096
Author: ms <ms@taler.net>
Date:   Fri,  8 Apr 2022 23:17:25 +0200

input validation

Diffstat:
Mpackages/bank/src/pages/home/index.tsx | 21+++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx @@ -127,13 +127,16 @@ function goPublicAccounts(pageStateSetter: StateUpdater<PageStateType>) { */ function validateAmount(maybeAmount: string): any { const amountRegex = "^[0-9]+(\.[0-9]+)?$"; + if (!maybeAmount) { + console.log(`Entered amount (${maybeAmount}) mismatched <input> pattern.`); + return; + } if (typeof maybeAmount !== "undefined" || maybeAmount !== "") { console.log("Maybe valid amount: " + maybeAmount); // tolerating comma instead of point. - maybeAmount = maybeAmount.replace(",", "."); const re = RegExp(amountRegex) if (!re.test(maybeAmount)) { - console.log(`Not withdrawing invalid amount '${maybeAmount}'.`); + console.log(`Not using invalid amount '${maybeAmount}'.`); return false; } } @@ -782,20 +785,20 @@ function PaytoWireTransfer(Props: any): VNode { pattern={amountRegex} onInput={(e): void => { amountInput = e.currentTarget.value; - }} />&nbsp;<label>{`${currency}:X.Y`}</label><br /><br /> + }} />&nbsp;<label>{currency}</label><br /><br /> <input type="submit" onClick={() => { - amountInput = validateAmount(amountInput); + amountInput = amountInput.replace(",", "."); + if (!validateAmount(amountInput)) return; /** * By invalid amounts, the validator prints error messages * on the console, and the browser colourizes the amount input * box to indicate a error. */ - if (!amountInput) return; if (!RegExp(ibanRegex).test(receiverInput)) return; transactionData = { - paytoUri: `payto://iban/${receiverInput}?message=${subjectInput}`, + paytoUri: `payto://iban/${receiverInput}?message=${encodeURIComponent(subjectInput)}`, amount: `${currency}:${amountInput}` }; createTransactionCall( @@ -1364,7 +1367,9 @@ function Account(Props: any): VNode { {logOut}<br /> </div> <section id="menu"> - <p>{i18n`Bank account balance:`} <br /> <b>{`${balance.value} ${balance.currency}`}</b></p> + <p>{i18n`Bank account balance:`} <br /> + { data.balance.credit_debit_indicator == "debit" ? (<b>-</b>) : null } + <b>{`${balance.value} ${balance.currency}`}</b></p> </section> <CurrencyContext.Provider value={balance.currency}> {Props.children} @@ -1474,7 +1479,7 @@ function PublicHistories(Props: any): VNode { setShowAccount(data.publicAccounts[1].accountLabel); console.log(`Public history tab: ${showAccount}`); - // Ask first story of all the public accounts. + // Ask story of all the public accounts. for (const account of data.publicAccounts) { console.log("Asking transactions for", account.accountLabel) const isSelected = account.accountLabel == showAccount;