summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorng <�>2022-10-22 23:51:12 +0200
committerng <�>2022-10-22 23:51:12 +0200
commita83abd5fe2445dbdbd606f738cb9fd6dd295caf0 (patch)
tree7a9200254960f9251c354067ade3b2a72d26ab7b /packages
parent9a795b7d12925598733bccbba6813f611f584a3b (diff)
downloadmerchant-backoffice-a83abd5fe2445dbdbd606f738cb9fd6dd295caf0.tar.gz
merchant-backoffice-a83abd5fe2445dbdbd606f738cb9fd6dd295caf0.tar.bz2
merchant-backoffice-a83abd5fe2445dbdbd606f738cb9fd6dd295caf0.zip
fix: 🐛 Fix several regex bugs
Diffstat (limited to 'packages')
-rw-r--r--packages/bank/src/pages/home/index.tsx204
1 files changed, 99 insertions, 105 deletions
diff --git a/packages/bank/src/pages/home/index.tsx b/packages/bank/src/pages/home/index.tsx
index c0dce56..ca090a4 100644
--- a/packages/bank/src/pages/home/index.tsx
+++ b/packages/bank/src/pages/home/index.tsx
@@ -155,7 +155,7 @@ function goPublicAccounts(pageStateSetter: StateUpdater<PageStateType>) {
* the input is invalid, the valid amount otherwise.
*/
function validateAmount(maybeAmount: string): any {
- const amountRegex = '^[0-9]+(\.[0-9]+)?$';
+ const amountRegex = '^[0-9]+(\\.[0-9]+)?$';
if (!maybeAmount) {
console.log(`Entered amount (${maybeAmount}) mismatched <input> pattern.`);
return;
@@ -445,7 +445,7 @@ async function abortWithdrawalCall(
pageStateSetter((prevState) => ({ ...prevState, hasError: true, error: 'No withdrawal ID found.' }))
return;
}
- let res:any;
+ let res: any;
try {
const { username, password } = backendState;
const headers = prepareHeaders(username, password);
@@ -590,7 +590,7 @@ async function createTransactionCall(
*/
cleanUpForm: () => void
) {
- let res:any;
+ let res: any;
try {
res = await postToBackend(
`access-api/accounts/${getUsername(backendState)}/transactions`,
@@ -651,7 +651,7 @@ async function createWithdrawalCall(
return;
}
- let res:any;
+ let res: any;
try {
const { username, password } = backendState;
const headers = prepareHeaders(username, password);
@@ -732,7 +732,7 @@ async function loginCall(
* the backend's (to store the login credentials) and
* the page's (to indicate a successful login or a problem).
*/
-async function registrationCall(
+const registrationCall = async (
req: CredentialsRequestType,
/**
* FIXME: figure out if the two following
@@ -741,8 +741,7 @@ async function registrationCall(
*/
backendStateSetter: StateUpdater<BackendStateTypeOpt>,
pageStateSetter: StateUpdater<PageStateType>
-) {
-
+) => {
let baseUrl = getRootPath();
/**
* If the base URL doesn't end with slash and the path
@@ -758,7 +757,7 @@ async function registrationCall(
'application/json'
)
const url = new URL('access-api/testing/register', baseUrl)
- let res:any;
+ let res: any;
try {
res = await fetch(url.href, {
method: 'POST',
@@ -799,7 +798,9 @@ async function registrationCall(
* Functional components. *
*************************/
-function Currency(): VNode {
+// TODO: Check if this will continue to be unused code
+// Currently unused
+const Currency = (): VNode => {
const { data, error } = useSWR(`${getRootPath()}integration-api/config`, fetcher);
if (typeof error !== 'undefined')
return <b>error: currency could not be retrieved</b>;
@@ -809,9 +810,8 @@ function Currency(): VNode {
return data.currency;
}
-function ErrorBanner(Props: any): VNode | null {
+const ErrorBanner = (Props: any): VNode | null => {
const [pageState, pageStateSetter] = Props.pageState;
- const i18n = useTranslator();
if (!pageState.hasError) return null;
const rval = (
@@ -822,9 +822,8 @@ function ErrorBanner(Props: any): VNode | null {
return rval;
}
-function StatusBanner(Props: any): VNode | null {
+const StatusBanner = (Props: any): VNode | null => {
const [pageState, pageStateSetter] = Props.pageState;
- const i18n = useTranslator();
if (!pageState.hasInfo) return null;
const rval = (
@@ -835,7 +834,7 @@ function StatusBanner(Props: any): VNode | null {
return rval;
}
-function BankFrame(Props: any): VNode {
+const BankFrame = (Props: any): VNode => {
const i18n = useTranslator();
const [pageState, pageStateSetter] = useContext(PageContext);
console.log('BankFrame state', pageState);
@@ -931,17 +930,15 @@ function BankFrame(Props: any): VNode {
}
-function PaytoWireTransfer(Props: any): VNode {
+const PaytoWireTransfer = (Props: any): VNode => {
const currency = useContext(CurrencyContext);
const [pageState, pageStateSetter] = useContext(PageContext); // NOTE: used for go-back button?
const [submitData, submitDataSetter] = useWireTransferRequestType();
const [rawPaytoInput, rawPaytoInputSetter] = useRawPaytoInputType();
const i18n = useTranslator();
const { focus, backendState } = Props
- const amountRegex = '^[0-9]+(\.[0-9]+)?$';
+ const amountRegex = '^[0-9]+(\\.[0-9]+)?$';
const ibanRegex = '^[A-Z][A-Z][0-9]+$';
- const receiverInput = '';
- const subjectInput = '';
let transactionData: TransactionRequestType;
const ref = useRef<HTMLInputElement>(null)
useEffect(() => {
@@ -1073,7 +1070,7 @@ function PaytoWireTransfer(Props: any): VNode {
value={rawPaytoInput}
required
placeholder={i18n`payto address`}
- pattern={`payto://iban/[A-Z][A-Z][0-9]+\?message=[a-zA-Z0-9 ]+&amount=${currency}:[0-9]+(\.[0-9]+)?`}
+ pattern={`payto://iban/[A-Z][A-Z][0-9]+\\?message=[a-zA-Z0-9 ]+&amount=${currency}:[0-9]+(\\.[0-9]+)?`}
onInput={(e): void => {
rawPaytoInputSetter(e.currentTarget.value)
}} />
@@ -1103,7 +1100,7 @@ function PaytoWireTransfer(Props: any): VNode {
transactionData,
backendState,
pageStateSetter,
- () => rawPaytoInputSetter(p => '')
+ () => rawPaytoInputSetter(() => '')
);
}} />
</p>
@@ -1122,7 +1119,7 @@ function PaytoWireTransfer(Props: any): VNode {
* Additional authentication required to complete the operation.
* Not providing a back button, only abort.
*/
-function TalerWithdrawalConfirmationQuestion(Props: any): VNode {
+const TalerWithdrawalConfirmationQuestion = (Props: any): VNode => {
const [pageState, pageStateSetter] = useContext(PageContext);
const { backendState } = Props;
const i18n = useTranslator();
@@ -1194,7 +1191,7 @@ function TalerWithdrawalConfirmationQuestion(Props: any): VNode {
</Fragment>);
}
-function QrCodeSection({ talerWithdrawUri, abortButton }: { talerWithdrawUri: string, abortButton: h.JSX.Element }) {
+const QrCodeSection = ({ talerWithdrawUri, abortButton }: { talerWithdrawUri: string, abortButton: h.JSX.Element }) => {
const i18n = useTranslator();
useEffect(() => {
//Taler Wallet WebExtension is listening to headers response and tab updates.
@@ -1224,12 +1221,12 @@ function TalerWithdrawalQRCode(Props: any): VNode {
const {
withdrawalId,
talerWithdrawUri,
- accountLabel,
- backendState } = Props;
+ backendState
+ } = Props;
const i18n = useTranslator();
const abortButton = <a class="pure-button" onClick={() => {
pageStateSetter((prevState: PageStateType) => {
- const { withdrawalId, talerWithdrawUri, ...rest } = prevState;
+ const { ...rest } = prevState;
return { ...rest, withdrawalInProgress: false };
})
}}>{i18n`Abort`}</a>
@@ -1286,12 +1283,12 @@ function TalerWithdrawalQRCode(Props: any): VNode {
-function WalletWithdraw(Props: any): VNode {
+const WalletWithdraw = (Props: any): VNode => {
const { backendState, pageStateSetter, focus } = Props;
const currency = useContext(CurrencyContext);
const i18n = useTranslator();
let submitAmount = '5.00';
- const amountRegex = '^[0-9]+(\.[0-9]+)?$';
+ const amountRegex = '^[0-9]+(\\.[0-9]+)?$';
const ref = useRef<HTMLInputElement>(null)
useEffect(() => {
@@ -1358,7 +1355,7 @@ function WalletWithdraw(Props: any): VNode {
* Let the user choose a payment option,
* then specify the details trigger the action.
*/
-function PaymentOptions(Props: any): VNode {
+const PaymentOptions = (Props: any): VNode => {
const { backendState, pageStateSetter, focus } = Props;
const currency = useContext(CurrencyContext);
const i18n = useTranslator();
@@ -1400,10 +1397,10 @@ function PaymentOptions(Props: any): VNode {
</article>);
}
-function RegistrationButton(Props: any): VNode {
- const { backendStateSetter, pageStateSetter } = Props;
+const RegistrationButton = (Props: any): VNode => {
+ const { pageStateSetter } = Props;
const i18n = useTranslator();
- if (UI_ALLOW_REGISTRATIONS)
+ if (UI_ALLOW_REGISTRATIONS)
return (<button
class="pure-button pure-button-secondary btn-cancel"
onClick={() => {
@@ -1411,16 +1408,13 @@ function RegistrationButton(Props: any): VNode {
}}>
{i18n`Register`}
</button>);
-
-
return (<span />);
-
}
/**
* Collect and submit login data.
*/
-function LoginForm(Props: any): VNode {
+const LoginForm = (Props: any): VNode => {
const { backendStateSetter, pageStateSetter } = Props;
const [submitData, submitDataSetter] = useCredentialsRequestType();
const i18n = useTranslator();
@@ -1495,7 +1489,7 @@ function LoginForm(Props: any): VNode {
/**
* Collect and submit registration data.
*/
-function RegistrationForm(Props: any): VNode {
+const RegistrationForm = (Props: any): VNode => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [pageState, pageStateSetter] = useContext(PageContext);
const [submitData, submitDataSetter] = useCredentialsRequestType();
@@ -1625,15 +1619,15 @@ function Transactions(Props: any): VNode {
if (typeof error !== 'undefined') {
console.log('transactions not found error', error);
switch (error.status) {
- case 404: {
- return <p>Transactions page {pageNumber} was not found.</p>
- }
- case 401: {
- return <p>Wrong credentials given.</p>
- }
- default: {
- return <p>Transaction page {pageNumber} could not be retrieved.</p>
- }
+ case 404: {
+ return <p>Transactions page {pageNumber} was not found.</p>
+ }
+ case 401: {
+ return <p>Wrong credentials given.</p>
+ }
+ default: {
+ return <p>Transaction page {pageNumber} could not be retrieved.</p>
+ }
}
}
if (!data) {
@@ -1709,48 +1703,48 @@ function Account(Props: any): VNode {
* message in the case-branch.
*/
switch (error.status) {
- case 404: {
- pageStateSetter((prevState: PageStateType) => ({
- ...prevState,
- hasError: true,
- isLoggedIn: false,
- error: i18n`Username or account label '${accountLabel}' not found. Won't login.`
- }));
-
- /**
- * 404 should never stick to the cache, because they
- * taint successful future registrations. How? After
- * registering, the user gets navigated to this page,
- * therefore a previous 404 on this SWR key (the requested
- * resource) would still appear as valid and cause this
- * page not to be shown! A typical case is an attempted
- * login of a unregistered user X, and then a registration
- * attempt of the same user X: in this case, the failed
- * login would cache a 404 error to X's profile, resulting
- * in the legitimate request after the registration to still
- * be flagged as 404. Clearing the cache should prevent
- * this. */
- (cache as any).clear();
- return <p>Profile not found...</p>;
- }
- case 401: {
- pageStateSetter((prevState: PageStateType) => ({
- ...prevState,
- hasError: true,
- isLoggedIn: false,
- error: i18n`Wrong credentials given.`
- }));
- return <p>Wrong credentials...</p>;
- }
- default: {
- pageStateSetter((prevState: PageStateType) => ({
- ...prevState,
- hasError: true,
- isLoggedIn: false,
- error: i18n`Account information could not be retrieved.`
- }));
- return <p>Unknown problem...</p>;
- }
+ case 404: {
+ pageStateSetter((prevState: PageStateType) => ({
+ ...prevState,
+ hasError: true,
+ isLoggedIn: false,
+ error: i18n`Username or account label '${accountLabel}' not found. Won't login.`
+ }));
+
+ /**
+ * 404 should never stick to the cache, because they
+ * taint successful future registrations. How? After
+ * registering, the user gets navigated to this page,
+ * therefore a previous 404 on this SWR key (the requested
+ * resource) would still appear as valid and cause this
+ * page not to be shown! A typical case is an attempted
+ * login of a unregistered user X, and then a registration
+ * attempt of the same user X: in this case, the failed
+ * login would cache a 404 error to X's profile, resulting
+ * in the legitimate request after the registration to still
+ * be flagged as 404. Clearing the cache should prevent
+ * this. */
+ (cache as any).clear();
+ return <p>Profile not found...</p>;
+ }
+ case 401: {
+ pageStateSetter((prevState: PageStateType) => ({
+ ...prevState,
+ hasError: true,
+ isLoggedIn: false,
+ error: i18n`Wrong credentials given.`
+ }));
+ return <p>Wrong credentials...</p>;
+ }
+ default: {
+ pageStateSetter((prevState: PageStateType) => ({
+ ...prevState,
+ hasError: true,
+ isLoggedIn: false,
+ error: i18n`Account information could not be retrieved.`
+ }));
+ return <p>Unknown problem...</p>;
+ }
}
}
if (!data) return <p>Retrieving the profile page...</p>;
@@ -1873,24 +1867,24 @@ function PublicHistories(Props: any): VNode {
if (typeof error !== 'undefined') {
console.log('account error', error);
switch (error.status) {
- case 404:
- console.log('public accounts: 404', error);
- Props.pageStateSetter((prevState: PageStateType) => ({
- ...prevState,
- hasError: true,
- showPublicHistories: false,
- error: i18n`List of public accounts was not found.`
- }));
- break;
- default:
- console.log('public accounts: non-404 error', error);
- Props.pageStateSetter((prevState: PageStateType) => ({
- ...prevState,
- hasError: true,
- showPublicHistories: false,
- error: i18n`List of public accounts could not be retrieved.`
- }));
- break;
+ case 404:
+ console.log('public accounts: 404', error);
+ Props.pageStateSetter((prevState: PageStateType) => ({
+ ...prevState,
+ hasError: true,
+ showPublicHistories: false,
+ error: i18n`List of public accounts was not found.`
+ }));
+ break;
+ default:
+ console.log('public accounts: non-404 error', error);
+ Props.pageStateSetter((prevState: PageStateType) => ({
+ ...prevState,
+ hasError: true,
+ showPublicHistories: false,
+ error: i18n`List of public accounts could not be retrieved.`
+ }));
+ break;
}
}
if (!data)