From 8eaed3dd626b7bd1b438733eebaa3d089332df49 Mon Sep 17 00:00:00 2001 From: kushagrasarathe <76868364+kushagrasarathe@users.noreply.github.com> Date: Wed, 27 Aug 2025 22:20:42 +0530 Subject: [PATCH 1/3] fix: bank claim flow runtime error --- public/game/peanut-game.html | 4 +- .../AddWithdraw/DynamicBankAccountForm.tsx | 97 +++++++++++++------ 2 files changed, 72 insertions(+), 29 deletions(-) diff --git a/public/game/peanut-game.html b/public/game/peanut-game.html index 535e337c3..1f25ae27e 100644 --- a/public/game/peanut-game.html +++ b/public/game/peanut-game.html @@ -1001,7 +1001,7 @@ * Maximum obstacle grouping count. * @const */ - ;(Obstacle.MAX_OBSTACLE_LENGTH = 3), + ;((Obstacle.MAX_OBSTACLE_LENGTH = 3), (Obstacle.prototype = { /** * Initialise the DOM for the obstacle. @@ -1103,7 +1103,7 @@ ) } }, - }) + })) /** * Obstacle definitions. * minGap: minimum pixel space betweeen obstacles. diff --git a/src/components/AddWithdraw/DynamicBankAccountForm.tsx b/src/components/AddWithdraw/DynamicBankAccountForm.tsx index 296fd55ea..79e3c9603 100644 --- a/src/components/AddWithdraw/DynamicBankAccountForm.tsx +++ b/src/components/AddWithdraw/DynamicBankAccountForm.tsx @@ -1,5 +1,5 @@ 'use client' -import { forwardRef, useImperativeHandle, useMemo, useState } from 'react' +import { forwardRef, useImperativeHandle, useMemo, useState, useEffect } from 'react' import { useForm, Controller } from 'react-hook-form' import { useAuth } from '@/context/authContext' import { Button } from '@/components/0_Bruddle/Button' @@ -65,6 +65,7 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D control, handleSubmit, setValue, + getValues, formState: { errors, isValid, isValidating, touchedFields }, } = useForm({ defaultValues: { @@ -82,15 +83,33 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D ...initialData, }, mode: 'onBlur', + reValidateMode: 'onSubmit', }) useImperativeHandle(ref, () => ({ handleSubmit: handleSubmit(onSubmit), })) + // Clear submission error when form becomes valid and BIC field is filled (if shown) + useEffect(() => { + if (submissionError && isValid && (!showBicField || getValues('bic'))) { + setSubmissionError(null) + } + }, [isValid, submissionError, showBicField, getValues]) + const onSubmit = async (data: IBankAccountDetails) => { + // If validation is still running, don't proceed + if (isValidating) { + console.log('Validation still checking, skipping submission') + return + } + + // Clear any existing submission errors before starting + if (submissionError) { + setSubmissionError(null) + } + setIsSubmitting(true) - setSubmissionError(null) try { const isUs = country.toUpperCase() === 'USA' const isMx = country.toUpperCase() === 'MX' @@ -105,22 +124,38 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D const accountNumber = isMx ? data.clabe : data.accountNumber const { firstName, lastName } = data - let bic = data.bic + let bic = data.bic || getValues('bic') + const iban = data.iban || getValues('iban') - if (isIban && !bic) { - try { - bic = await getBicFromIban(accountNumber) - if (!bic) { + // for IBAN countries, ensure BIC is available + if (isIban) { + // if BIC field is shown but empty, don't proceed + if (showBicField && !bic) { + setIsSubmitting(false) + setSubmissionError('BIC is required') + return + } + + // if BIC field is not shown and no BIC available, try to get it automatically + if (!showBicField && !bic) { + try { + const autoBic = await getBicFromIban(accountNumber) + if (autoBic) { + bic = autoBic + // set the BIC value in the form without showing the field + setValue('bic', autoBic, { shouldValidate: false }) + } else { + setShowBicField(true) + setIsSubmitting(false) + setSubmissionError('BIC is required') + return + } + } catch (error) { setShowBicField(true) setIsSubmitting(false) setSubmissionError('BIC is required') return } - } catch (error) { - setShowBicField(true) - setIsSubmitting(false) - setSubmissionError('BIC is required') - return } } @@ -150,7 +185,7 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D const result = await onSuccess(payload as AddBankAccountPayload, { ...data, - iban: isIban ? data.accountNumber : undefined, + iban: isIban ? data.accountNumber || iban : undefined, accountNumber: isIban ? '' : data.accountNumber, bic: bic, country, @@ -164,7 +199,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D } } catch (error: any) { setSubmissionError(error.message) - } finally { setIsSubmitting(false) } } @@ -233,13 +267,7 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D

Enter bank account details

-
{ - e.preventDefault() - handleSubmit(onSubmit)() - }} - className="space-y-4" - > + {flow === 'claim' && !user?.user.userId && (
{renderInput('firstName', 'First Name', { required: 'First name is required' })} @@ -314,10 +342,25 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D {isIban && showBicField && - renderInput('bic', 'BIC', { - required: 'BIC is required', - validate: async (value: string) => (await validateBic(value)) || 'Invalid BIC code', - })} + renderInput( + 'bic', + 'BIC', + { + required: 'BIC is required', + validate: async (value: string) => { + if (!value || value.trim().length === 0) return 'BIC is required' + const isValid = await validateBic(value.trim()) + return isValid || 'Invalid BIC code' + }, + }, + 'text', + undefined, + (field) => { + if (field.value && field.value.trim().length > 0 && submissionError) { + setSubmissionError(null) + } + } + )} {isUs && renderInput('routingNumber', 'Routing Number', { required: 'Routing number is required', @@ -345,8 +388,8 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D variant="purple" shadowSize="4" className="!mt-4 w-full" - loading={isSubmitting || isValidating} - disabled={isSubmitting || !isValid || isValidating} + loading={isSubmitting} + disabled={isSubmitting || !isValid} > Review From c4c5cfa0891c5a49880aa9541e0a03bb5b8a521b Mon Sep 17 00:00:00 2001 From: kushagrasarathe <76868364+kushagrasarathe@users.noreply.github.com> Date: Wed, 27 Aug 2025 23:16:33 +0530 Subject: [PATCH 2/3] fix: dont have iban as optional --- .../AddWithdraw/DynamicBankAccountForm.tsx | 4 ++-- .../Claim/Link/views/BankFlowManager.view.tsx | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/AddWithdraw/DynamicBankAccountForm.tsx b/src/components/AddWithdraw/DynamicBankAccountForm.tsx index 79e3c9603..534d99fcb 100644 --- a/src/components/AddWithdraw/DynamicBankAccountForm.tsx +++ b/src/components/AddWithdraw/DynamicBankAccountForm.tsx @@ -32,7 +32,7 @@ export type IBankAccountDetails = { city: string state: string postalCode: string - iban?: string + iban: string country: string } @@ -185,7 +185,7 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D const result = await onSuccess(payload as AddBankAccountPayload, { ...data, - iban: isIban ? data.accountNumber || iban : undefined, + iban: isIban ? data.accountNumber || iban || '' : '', accountNumber: isIban ? '' : data.accountNumber, bic: bic, country, diff --git a/src/components/Claim/Link/views/BankFlowManager.view.tsx b/src/components/Claim/Link/views/BankFlowManager.view.tsx index 5cbdda8ff..e9b37f297 100644 --- a/src/components/Claim/Link/views/BankFlowManager.view.tsx +++ b/src/components/Claim/Link/views/BankFlowManager.view.tsx @@ -246,12 +246,16 @@ export const BankFlowManager = (props: IClaimScreenProps) => { name: addBankAccountResponse.data.details.accountOwnerName || user?.user.fullName || '', iban: addBankAccountResponse.data.type === 'iban' - ? addBankAccountResponse.data.identifier - : undefined, + ? addBankAccountResponse.data.identifier || '' + : '', clabe: - addBankAccountResponse.data.type === 'clabe' ? addBankAccountResponse.data.identifier : '', + addBankAccountResponse.data.type === 'clabe' + ? addBankAccountResponse.data.identifier || '' + : '', accountNumber: - addBankAccountResponse.data.type === 'us' ? addBankAccountResponse.data.identifier : '', + addBankAccountResponse.data.type === 'us' + ? addBankAccountResponse.data.identifier || '' + : '', country: addBankAccountResponse.data.details.countryCode, id: addBankAccountResponse.data.id, bridgeAccountId: addBankAccountResponse.data.bridgeAccountId, @@ -360,9 +364,9 @@ export const BankFlowManager = (props: IClaimScreenProps) => { const bankDetails: IBankAccountDetails & { id?: string; bridgeAccountId?: string } = { name: account.details.accountOwnerName || user?.user.fullName || '', - iban: account.type === 'iban' ? account.identifier : undefined, - clabe: account.type === 'clabe' ? account.identifier : '', - accountNumber: account.type === 'us' ? account.identifier : '', + iban: account.type === 'iban' ? account.identifier || '' : '', + clabe: account.type === 'clabe' ? account.identifier || '' : '', + accountNumber: account.type === 'us' ? account.identifier || '' : '', country: account.details.countryCode, id: account.id, bridgeAccountId: account.bridgeAccountId, From f99debfb033eb2f7f2fa138df06959eea2c2984c Mon Sep 17 00:00:00 2001 From: kushagrasarathe <76868364+kushagrasarathe@users.noreply.github.com> Date: Wed, 27 Aug 2025 23:21:10 +0530 Subject: [PATCH 3/3] fix: merge conflicts --- .../AddWithdraw/DynamicBankAccountForm.tsx | 75 ------------------- 1 file changed, 75 deletions(-) diff --git a/src/components/AddWithdraw/DynamicBankAccountForm.tsx b/src/components/AddWithdraw/DynamicBankAccountForm.tsx index 2ef3c0818..534d99fcb 100644 --- a/src/components/AddWithdraw/DynamicBankAccountForm.tsx +++ b/src/components/AddWithdraw/DynamicBankAccountForm.tsx @@ -1,6 +1,5 @@ 'use client' import { forwardRef, useImperativeHandle, useMemo, useState, useEffect } from 'react' -import { forwardRef, useImperativeHandle, useMemo, useState, useEffect } from 'react' import { useForm, Controller } from 'react-hook-form' import { useAuth } from '@/context/authContext' import { Button } from '@/components/0_Bruddle/Button' @@ -67,7 +66,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D handleSubmit, setValue, getValues, - getValues, formState: { errors, isValid, isValidating, touchedFields }, } = useForm({ defaultValues: { @@ -86,7 +84,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D }, mode: 'onBlur', reValidateMode: 'onSubmit', - reValidateMode: 'onSubmit', }) useImperativeHandle(ref, () => ({ @@ -100,13 +97,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D } }, [isValid, submissionError, showBicField, getValues]) - // Clear submission error when form becomes valid and BIC field is filled (if shown) - useEffect(() => { - if (submissionError && isValid && (!showBicField || getValues('bic'))) { - setSubmissionError(null) - } - }, [isValid, submissionError, showBicField, getValues]) - const onSubmit = async (data: IBankAccountDetails) => { // If validation is still running, don't proceed if (isValidating) { @@ -119,17 +109,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D setSubmissionError(null) } - // If validation is still running, don't proceed - if (isValidating) { - console.log('Validation still checking, skipping submission') - return - } - - // Clear any existing submission errors before starting - if (submissionError) { - setSubmissionError(null) - } - setIsSubmitting(true) try { const isUs = country.toUpperCase() === 'USA' @@ -148,38 +127,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D let bic = data.bic || getValues('bic') const iban = data.iban || getValues('iban') - // for IBAN countries, ensure BIC is available - if (isIban) { - // if BIC field is shown but empty, don't proceed - if (showBicField && !bic) { - setIsSubmitting(false) - setSubmissionError('BIC is required') - return - } - - // if BIC field is not shown and no BIC available, try to get it automatically - if (!showBicField && !bic) { - try { - const autoBic = await getBicFromIban(accountNumber) - if (autoBic) { - bic = autoBic - // set the BIC value in the form without showing the field - setValue('bic', autoBic, { shouldValidate: false }) - } else { - setShowBicField(true) - setIsSubmitting(false) - setSubmissionError('BIC is required') - return - } - } catch (error) { - setShowBicField(true) - setIsSubmitting(false) - setSubmissionError('BIC is required') - return - } - let bic = data.bic || getValues('bic') - const iban = data.iban || getValues('iban') - // for IBAN countries, ensure BIC is available if (isIban) { // if BIC field is shown but empty, don't proceed @@ -320,7 +267,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D

Enter bank account details

- {flow === 'claim' && !user?.user.userId && (
@@ -415,25 +361,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D } } )} - renderInput( - 'bic', - 'BIC', - { - required: 'BIC is required', - validate: async (value: string) => { - if (!value || value.trim().length === 0) return 'BIC is required' - const isValid = await validateBic(value.trim()) - return isValid || 'Invalid BIC code' - }, - }, - 'text', - undefined, - (field) => { - if (field.value && field.value.trim().length > 0 && submissionError) { - setSubmissionError(null) - } - } - )} {isUs && renderInput('routingNumber', 'Routing Number', { required: 'Routing number is required', @@ -463,8 +390,6 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D className="!mt-4 w-full" loading={isSubmitting} disabled={isSubmitting || !isValid} - loading={isSubmitting} - disabled={isSubmitting || !isValid} > Review