[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant-backoffice] branch master updated: fix wire transfer sub
From: |
gnunet |
Subject: |
[taler-merchant-backoffice] branch master updated: fix wire transfer submission |
Date: |
Mon, 21 Feb 2022 09:47:00 +0100 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository merchant-backoffice.
The following commit(s) were added to refs/heads/master by this push:
new 6aa4937 fix wire transfer submission
6aa4937 is described below
commit 6aa49378d152c4b099263a272bd574b85508ce5d
Author: MS <ms@taler.net>
AuthorDate: Mon Feb 21 09:46:54 2022 +0100
fix wire transfer submission
---
packages/bank/src/pages/home/index.tsx | 68 +++++++++++++++++++++-------------
1 file changed, 42 insertions(+), 26 deletions(-)
diff --git a/packages/bank/src/pages/home/index.tsx
b/packages/bank/src/pages/home/index.tsx
index 32aed84..55d1adc 100644
--- a/packages/bank/src/pages/home/index.tsx
+++ b/packages/bank/src/pages/home/index.tsx
@@ -57,7 +57,7 @@ interface BackendStateType {
*/
interface TransactionRequestType {
paytoUri: string;
- amount?: string;
+ amount?: string; // with currency.
}
/**
@@ -105,6 +105,26 @@ interface AccountStateType {
* Helpers. *
***********/
+/**
+ * Validate (the number part of) an amount. If needed,
+ * replace comma with a dot. Returns 'false' whenever
+ * the input is invalid, the valid amount otherwise.
+ */
+function validateAmount(maybeAmount: string): string {
+ const amountRegex = "^[0-9]+(\.[0-9]+)?$";
+ 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}'.`);
+ return false;
+ }
+ }
+ return maybeAmount;
+}
+
/**
* Extract IBAN from a Payto URI.
*/
@@ -118,7 +138,7 @@ function getIbanFromPayto(url: string): string {
}
/**
- * Parse amount.
+ * Extract value and currency from a $currency:x.y amount.
*/
function parseAmount(val: string): Amount {
const format = /^[A-Z]+:[0-9]+(\.[0-9]+)?$/;
@@ -154,17 +174,6 @@ async function postToBackend(
}
const { username, password } = backendState;
let headers = prepareHeaders(username, password);
- /**
- * NOTE: tests show that when a same object is being
- * POSTed, caching might prevent same requests from being
- * made. Hence, trying to POST twice the same amount might
- * get silently ignored.
- *
- * headers.append("cache-control", "no-store");
- * headers.append("cache-control", "no-cache");
- * headers.append("pragma", "no-cache");
- * */
-
// Backend URL must have been stored _with_ a final slash.
const url = new URL(uri, backendState.url)
return await fetch(url.href, {
@@ -176,7 +185,6 @@ async function postToBackend(
}
function useTransactionPageNumber(): [number, StateUpdater<number>] {
-
const ret = useNotNullLocalStorage("transaction-page", "0");
const retObj = JSON.parse(ret[0]);
const retSetter: StateUpdater<number> = function(val) {
@@ -653,6 +661,7 @@ function PaytoWireTransfer(Props: any): VNode {
const currency = useContext(CurrencyContext);
const i18n = useTranslator();
const amountRegex = "^[0-9]+(\.[0-9]+)?$";
+ var amountInput = "";
var transactionData: TransactionRequestType;
return <div>
@@ -661,10 +670,7 @@ function PaytoWireTransfer(Props: any): VNode {
placeholder="amount"
pattern={amountRegex}
onInput={(e): void => {
- transactionData = {
- ...transactionData,
- amount: e.currentTarget.value,
- };
+ amountInput = e.currentTarget.value;
}} />
<label>{currency}</label>
<input
@@ -678,6 +684,17 @@ function PaytoWireTransfer(Props: any): VNode {
};
}} />
<button onClick={() => {
+ amountInput = validateAmount(amountInput);
+ /**
+ * 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;
+ transactionData = {
+ ...transactionData,
+ amount: `${currency}:${amountInput}`
+ };
createTransactionCall(
transactionData,
backendState,
@@ -699,14 +716,13 @@ function TalerWithdrawal(Props: any): VNode {
var submitButton = <button
onClick={() => {
- console.log("Maybe valid amount", submitAmount);
- submitAmount = submitAmount.replace(",", "."); // tolerating comma
instead of point.
- const re = RegExp(amountRegex)
- if (!re.test(submitAmount)) {
- console.log(`Not withdrawing invalid amount '${submitAmount}'.`);
- return;
- }
- console.log("Valid amount", submitAmount);
+ submitAmount = validateAmount(submitAmount);
+ /**
+ * By invalid amounts, the validator prints error messages
+ * on the console, and the browser colourizes the amount input
+ * box to indicate a error.
+ */
+ if (!submitAmount) return;
createWithdrawalCall(
`${currency}:${submitAmount}`,
backendState,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-merchant-backoffice] branch master updated: fix wire transfer submission,
gnunet <=