Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/app/actions/external-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const API_URL = process.env.PEANUT_API_URL!
export async function createBridgeExternalAccountForGuest(
customerId: string,
accountDetails: AddBankAccountPayload
): Promise<IBridgeAccount | { error: string }> {
): Promise<IBridgeAccount | { error: string; source?: string }> {
try {
const response = await fetchWithSentry(`${API_URL}/bridge/customers/${customerId}/external-accounts`, {
method: 'POST',
Expand All @@ -23,6 +23,12 @@ export async function createBridgeExternalAccountForGuest(

const data = await response.json()

if (data?.code === 'invalid_parameters') {
const source =
typeof data.source === 'string' ? data.source : data?.source?.key
return { error: data?.message ?? 'Invalid parameters', source }
}

if (!response.ok) {
return { error: data.error || 'Failed to create external account.' }
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/AddWithdraw/DynamicBankAccountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,11 @@ export const DynamicBankAccountForm = forwardRef<{ handleSubmit: () => void }, D
>
Review
</Button>
{submissionError && <ErrorAlert description={submissionError} />}
{error && <ErrorAlert description={error} />}
{submissionError ? (
<ErrorAlert description={submissionError} />
) : (
error && <ErrorAlert description={error} />
)}
</form>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions src/components/Claim/Link/views/BankFlowManager.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
try {
const addBankAccountResponse = await addBankAccount(payload)
if (addBankAccountResponse.error) {
setError(addBankAccountResponse.error)
return { error: addBankAccountResponse.error }
}
if (addBankAccountResponse.data?.id) {
Expand Down Expand Up @@ -316,9 +315,15 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
}
if (!senderInfo.bridgeCustomerId) throw new Error('Sender bridge customer ID not found')

const threeLetterCountryCode = getCountryCodeForWithdraw(selectedCountry.id)
const payloadWithCountry = {
...payload,
country: selectedCountry.id,
countryCode: threeLetterCountryCode,
address: {
...payload.address,
country: threeLetterCountryCode,
},
country: threeLetterCountryCode,
}
Comment on lines +318 to 327
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify top-level country field is still part of AddBankAccountPayload

You’re now setting:

  • countryCode: threeLetterCountryCode
  • address.country: threeLetterCountryCode
  • country: threeLetterCountryCode (top-level)

If the API no longer expects country, this may trigger invalid_parameters with source "country". If redundant, drop it:

                 const payloadWithCountry = {
                     ...payload,
                     countryCode: threeLetterCountryCode,
                     address: {
                         ...payload.address,
                         country: threeLetterCountryCode,
                     },
-                    country: threeLetterCountryCode,
                 }

Run to confirm the payload shape:


🏁 Script executed:

#!/bin/bash
# Locate AddBankAccountPayload and usages of top-level `country`
rg -nC2 'export\s+type\s+AddBankAccountPayload|export\s+interface\s+AddBankAccountPayload' src
rg -nC2 '\bAddBankAccountPayload\b' src | sed -n '1,200p'
rg -nP '\bcountry\s*:' src/app/actions/types --glob '!**/*.test.*'

Length of output: 6451


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="src/app/actions/types/users.types.ts"
echo "=== inspecting: $file ==="
if [ ! -f "$file" ]; then
  echo "FILE_NOT_FOUND: $file"
  exit 0
fi

echo "----- file contents (first 400 lines) -----"
sed -n '1,400p' "$file" || true

echo
echo "----- grep for 'country' in that file (with context) -----"
rg -n --hidden --no-ignore-vcs '\bcountry\b' "$file" -n -C2 || true

echo
echo "----- locations referencing AddBankAccountPayload in src (context) -----"
rg -n --hidden --no-ignore-vcs '\bAddBankAccountPayload\b' src -C2 || true

echo
echo "----- grep for 'country' occurrences across src (lines only) -----"
rg -n --hidden --no-ignore-vcs '\bcountry\s*[:?]' src || true

Length of output: 13643


Remove top-level country from payload — not part of AddBankAccountPayload

AddBankAccountPayload (src/app/actions/types/users.types.ts) defines countryCode and address.country but does NOT include a top-level country; sending it may trigger API validation errors. Remove the top-level country field.

Location: src/components/Claim/Link/views/BankFlowManager.view.tsx (around lines 318–327)

                 const payloadWithCountry = {
                     ...payload,
                     countryCode: threeLetterCountryCode,
                     address: {
                         ...payload.address,
                         country: threeLetterCountryCode,
                     },
-                    country: threeLetterCountryCode,
                 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const threeLetterCountryCode = getCountryCodeForWithdraw(selectedCountry.id)
const payloadWithCountry = {
...payload,
country: selectedCountry.id,
countryCode: threeLetterCountryCode,
address: {
...payload.address,
country: threeLetterCountryCode,
},
country: threeLetterCountryCode,
}
const threeLetterCountryCode = getCountryCodeForWithdraw(selectedCountry.id)
const payloadWithCountry = {
...payload,
countryCode: threeLetterCountryCode,
address: {
...payload.address,
country: threeLetterCountryCode,
},
}
🤖 Prompt for AI Agents
In src/components/Claim/Link/views/BankFlowManager.view.tsx around lines
318-327, the payload construction adds a top-level "country" property which is
not part of AddBankAccountPayload and may fail API validation; remove the
top-level "country" key and only set countryCode and address.country (keep
spreading payload.address and payload otherwise intact) so the resulting payload
contains countryCode and address.country but no top-level country field.


const externalAccountResponse = await createBridgeExternalAccountForGuest(
Expand Down Expand Up @@ -358,7 +363,6 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
return {}
} catch (e: any) {
const errorString = ErrorHandler(e)
setError(errorString)
Sentry.captureException(e)
return { error: errorString }
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sdkErrorHandler.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const ErrorHandler = (error: any) => {
} else if (error.toString().includes('The operation either timed out or was not allowed')) {
return 'Please confirm the transaction.'
} else {
return 'Something failed. Please try again.'
return 'There was an issue with your request. Please contact support.'
}
}
}
Loading