Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export PEANUT_API_URL=""
export PEANUT_API_URL="https://api.staging.peanut.to"
# export PEANUT_API_URL="http://127.0.0.1:5000/" # If running api locally
export PROMO_LIST={}
export PEANUT_API_KEY=""
export BRIDGE_API_KEY=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import * as consts from '@/constants'

export async function POST(request: NextRequest) {
try {
const { bankAccount } = await request.json()
const { bankAccountNumber } = await request.json()
const apiKey = process.env.PEANUT_API_KEY

if (!bankAccount || !apiKey) {
if (!bankAccountNumber || !apiKey) {
return new NextResponse('Bad Request: missing required parameters', { status: 400 })
}

const response = await fetch(`${consts.PEANUT_API_URL}/validate-bank-number`, {
const response = await fetch(`${consts.PEANUT_API_URL}/validate-bank-account-number`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'api-key': apiKey,
},
body: JSON.stringify({
bankNumber: bankAccount,
bankAccountNumber,
}),
})

Expand Down
2 changes: 1 addition & 1 deletion src/components/Cashout/Components/Initial.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const InitialCashoutView = ({
console.error('Invalid bank account')
setErrorState({
showError: true,
errorMessage: 'Invalid bank account. Please make sure your account is supported',
errorMessage: 'Invalid bank account. Reach out to support if you need help.',
})
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Global/KYCComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export const GlobalKYCComponent = ({ intialStep, offrampForm, setOfframpForm, on
return (
<div>
<div className="flex w-full flex-col items-center justify-center gap-6 px-2 text-center">
<p className="w-full text-h8 font-normal">After KYC, you can cashout straight to your bank account!</p>
<p className="w-full text-h8 font-normal">Regulations require us to verify your identity.</p>
<Steps
variant={'circles'}
orientation="vertical"
Expand Down
2 changes: 1 addition & 1 deletion src/constants/general.consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ipfsProviderArray = [
'https://gw3.io/ipfs/',
]

export const PEANUT_API_URL = process.env.PEANUT_API_URL || 'https://api.peanut.to'
export const PEANUT_API_URL = (process.env.PEANUT_API_URL || 'https://api.peanut.to').replace(/\/$/, '') // remove any accidental trailing slash
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using URL constructor for robust URL handling.

While removing trailing slashes is good practice, consider using the URL constructor for more robust URL handling and validation:

-export const PEANUT_API_URL = (process.env.PEANUT_API_URL || 'https://api.peanut.to').replace(/\/$/, '') // remove any accidental trailing slash
+export const PEANUT_API_URL = (() => {
+  try {
+    const url = new URL(process.env.PEANUT_API_URL || 'https://api.peanut.to');
+    return url.href.replace(/\/$/, '');
+  } catch (e) {
+    console.error('Invalid PEANUT_API_URL format');
+    return 'https://api.peanut.to';
+  }
+})()

This approach provides several benefits:

  1. Validates URL format
  2. Handles malformed URLs gracefully
  3. Still maintains the trailing slash removal
📝 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
export const PEANUT_API_URL = (process.env.PEANUT_API_URL || 'https://api.peanut.to').replace(/\/$/, '') // remove any accidental trailing slash
export const PEANUT_API_URL = (() => {
try {
const url = new URL(process.env.PEANUT_API_URL || 'https://api.peanut.to');
return url.href.replace(/\/$/, '');
} catch (e) {
console.error('Invalid PEANUT_API_URL format');
return 'https://api.peanut.to';
}
})()

export const next_proxy_url = '/api/proxy'

export const supportedWalletconnectChains = <{ chainId: string; name: string }[]>[
Expand Down
6 changes: 3 additions & 3 deletions src/utils/cashout.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,14 @@ export function getChainIdFromBridgeChainName(chainName: string): string | undef
}

export async function validateBankAccount(bankAccount: string): Promise<boolean> {
bankAccount = bankAccount.replace(/\s/g, '')
const response = await fetch(`/api/peanut/iban/validate-bank-account`, {
const bankAccountNumber = bankAccount.replace(/\s/g, '')
const response = await fetch(`/api/peanut/iban/validate-bank-account-number`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
bankAccount,
bankAccountNumber,
}),
})

Expand Down