-
Notifications
You must be signed in to change notification settings - Fork 13
Bugfix/wrong currency #935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
62e3c7e
cf6d4b6
c49c972
2444603
a9a69ab
b5eb1d7
5c4a838
67e54d4
ffaf281
8bd8c5b
26c68d2
801351d
5610675
100b862
01bc540
a546e00
63900e5
0456983
f0f3c04
b6e044e
cc9b57a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ import EmptyState from '@/components/Global/EmptyStates/EmptyState' | |
import { UserDetailsForm, type UserDetailsFormData } from '@/components/AddMoney/UserDetailsForm' | ||
import { updateUserById } from '@/app/actions/users' | ||
import AddMoneyBankDetails from '@/components/AddMoney/components/AddMoneyBankDetails' | ||
import { getDisplayCurrencySymbol } from '@/utils/currency' | ||
import { getOnrampCurrencyConfig, getCurrencySymbol, getMinimumAmount } from '@/utils/bridge.utils' | ||
|
||
type AddStep = 'inputAmount' | 'kyc' | 'loading' | 'collectUserDetails' | 'showDetails' | ||
|
||
|
@@ -76,6 +78,21 @@ export default function OnrampBankPage() { | |
return formattedBalance | ||
}, [balance]) | ||
|
||
const currencyConfig = useMemo(() => { | ||
if (!selectedCountry?.id) return null | ||
const { currency } = getOnrampCurrencyConfig(selectedCountry.id) | ||
return { | ||
code: currency.toUpperCase(), | ||
symbol: getCurrencySymbol(currency), | ||
price: 1, // For bridge currencies, we use 1:1 with the amount entered | ||
} | ||
}, [selectedCountry?.id]) | ||
|
||
const minimumAmount = useMemo(() => { | ||
if (!selectedCountry?.id) return 1 | ||
return getMinimumAmount(selectedCountry.id) | ||
}, [selectedCountry?.id]) | ||
|
||
useEffect(() => { | ||
if (user === null) return // wait for user to be fetched | ||
if (step === 'loading') { | ||
|
@@ -119,14 +136,14 @@ export default function OnrampBankPage() { | |
setError({ showError: true, errorMessage: 'Please enter a valid number.' }) | ||
return false | ||
} | ||
if (amount && amount < 1) { | ||
setError({ showError: true, errorMessage: 'Minimum deposit is 1.' }) | ||
if (amount && amount < minimumAmount) { | ||
setError({ showError: true, errorMessage: `Minimum deposit is ${minimumAmount}.` }) | ||
return false | ||
} | ||
setError({ showError: false, errorMessage: '' }) | ||
return true | ||
}, | ||
[setError] | ||
[setError, minimumAmount] | ||
) | ||
|
||
const handleTokenAmountChange = useCallback( | ||
|
@@ -328,6 +345,16 @@ export default function OnrampBankPage() { | |
setTokenValue={handleTokenAmountChange} | ||
walletBalance={peanutWalletBalance} | ||
hideCurrencyToggle | ||
currency={ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no default to usd? does undefined make sense here? |
||
selectedCountry | ||
? { | ||
code: getOnrampCurrencyConfig(selectedCountry.id).currency, | ||
symbol: getCurrencySymbol(getOnrampCurrencyConfig(selectedCountry.id).currency), | ||
price: 1, | ||
} | ||
: undefined | ||
} | ||
hideBalance={true} | ||
/> | ||
<div className="flex items-center gap-2 text-xs text-grey-1"> | ||
<Icon name="info" width={16} height={16} /> | ||
|
@@ -339,7 +366,7 @@ export default function OnrampBankPage() { | |
onClick={handleAmountContinue} | ||
disabled={ | ||
!parseFloat(rawTokenAmount) || | ||
parseFloat(rawTokenAmount) < 1 || | ||
parseFloat(rawTokenAmount) < minimumAmount || | ||
error.showError || | ||
isCreatingOnramp | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ import { useRouter, useParams } from 'next/navigation' | |
import { useEffect, useState, useMemo } from 'react' | ||
import { countryCodeMap, countryData } from '@/components/AddMoney/consts' | ||
import { formatCurrencyAmount } from '@/utils/currency' | ||
import { formatBankAccountDisplay } from '@/utils/format.utils' | ||
import Icon from '@/components/Global/Icon' | ||
import { getCurrencySymbol, getOnrampCurrencyConfig } from '@/utils/bridge.utils' | ||
|
||
export interface IOnrampData { | ||
transferId?: string | ||
|
@@ -62,6 +64,8 @@ export default function AddMoneyBankDetails() { | |
return countryCode?.toLowerCase() || 'us' | ||
}, [currentCountryDetails]) | ||
|
||
const onrampCurrency = getOnrampCurrencyConfig(currentCountryDetails?.id || 'US').currency | ||
|
||
useEffect(() => { | ||
// If no amount is set, redirect back to add money page | ||
if (!amountToOnramp || parseFloat(amountToOnramp) <= 0) { | ||
|
@@ -82,13 +86,37 @@ export default function AddMoneyBankDetails() { | |
}, [amountToOnramp, router]) | ||
|
||
const generateBankDetails = async () => { | ||
const formattedAmount = formatCurrencyAmount(amountToOnramp, currentCountryDetails?.currency || 'USD') | ||
const bankDetails = `Bank Transfer Details: | ||
const formattedAmount = formatCurrencyAmount(amountToOnramp, onrampCurrency) | ||
const isMexico = currentCountryDetails?.id === 'MX' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: this will likely have to be reworked when we add more geos |
||
|
||
let bankDetails = `Bank Transfer Details: | ||
Amount: ${formattedAmount} | ||
Bank Name: ${onrampData?.depositInstructions?.bankName || 'Loading...'} | ||
Bank Address: ${onrampData?.depositInstructions?.bankAddress || 'Loading...'} | ||
Account Number: ${onrampData?.depositInstructions?.bankAccountNumber || 'Loading...'} | ||
Routing Number: ${onrampData?.depositInstructions?.bankRoutingNumber || 'Loading...'} | ||
Bank Name: ${onrampData?.depositInstructions?.bankName || 'Loading...'}` | ||
|
||
// Only include Bank Address for non-Mexico countries since Mexico doesn't return IBAN/BIC or equivalent | ||
if (!isMexico) { | ||
bankDetails += ` | ||
Bank Address: ${onrampData?.depositInstructions?.bankAddress || 'Loading...'}` | ||
|
||
const accountLabel = onrampData?.depositInstructions?.bankAccountNumber ? 'Account Number' : 'IBAN' | ||
const routingLabel = onrampData?.depositInstructions?.bankRoutingNumber ? 'Routing Number' : 'BIC' | ||
const accountValue = | ||
onrampData?.depositInstructions?.bankAccountNumber || | ||
(onrampData?.depositInstructions?.iban | ||
? formatBankAccountDisplay(onrampData.depositInstructions.iban, 'iban') | ||
: null) || | ||
'Loading...' | ||
const routingValue = | ||
onrampData?.depositInstructions?.bankRoutingNumber || | ||
onrampData?.depositInstructions?.bic || | ||
'Loading...' | ||
|
||
bankDetails += ` | ||
${accountLabel}: ${accountValue} | ||
${routingLabel}: ${routingValue}` | ||
} | ||
|
||
bankDetails += ` | ||
Deposit Message: ${onrampData?.depositInstructions?.depositMessage || 'Loading...'} | ||
|
||
Please use these details to complete your bank transfer.` | ||
|
@@ -117,37 +145,43 @@ Please use these details to complete your bank transfer.` | |
amount={amountToOnramp} | ||
tokenSymbol={PEANUT_WALLET_TOKEN_SYMBOL} | ||
countryCodeForFlag={countryCodeForFlag} | ||
currencySymbol={getCurrencySymbol(onrampCurrency)} | ||
/> | ||
|
||
<Card className="rounded-sm"> | ||
<PaymentInfoRow | ||
label={'Amount'} | ||
value={formatCurrencyAmount(amountToOnramp, currentCountryDetails?.currency || 'USD')} | ||
/> | ||
<PaymentInfoRow label={'Amount'} value={formatCurrencyAmount(amountToOnramp, onrampCurrency)} /> | ||
<PaymentInfoRow | ||
label={'Bank Name'} | ||
value={onrampData?.depositInstructions?.bankName || 'Loading...'} | ||
/> | ||
<PaymentInfoRow | ||
label={'Bank Address'} | ||
value={onrampData?.depositInstructions?.bankAddress || 'Loading...'} | ||
/> | ||
<PaymentInfoRow | ||
label={onrampData?.depositInstructions?.bankAccountNumber ? 'Account Number' : 'IBAN'} | ||
value={ | ||
onrampData?.depositInstructions?.bankAccountNumber || | ||
onrampData?.depositInstructions?.iban || | ||
'Loading...' | ||
} | ||
/> | ||
<PaymentInfoRow | ||
label={onrampData?.depositInstructions?.bankRoutingNumber ? 'Routing Number' : 'BIC'} | ||
value={ | ||
onrampData?.depositInstructions?.bankRoutingNumber || | ||
onrampData?.depositInstructions?.bic || | ||
'Loading...' | ||
} | ||
/> | ||
{currentCountryDetails?.id !== 'MX' && ( | ||
<PaymentInfoRow | ||
label={'Bank Address'} | ||
value={onrampData?.depositInstructions?.bankAddress || 'Loading...'} | ||
/> | ||
)} | ||
{currentCountryDetails?.id !== 'MX' && ( | ||
<PaymentInfoRow | ||
label={onrampData?.depositInstructions?.bankAccountNumber ? 'Account Number' : 'IBAN'} | ||
value={ | ||
onrampData?.depositInstructions?.bankAccountNumber || | ||
(onrampData?.depositInstructions?.iban | ||
? formatBankAccountDisplay(onrampData.depositInstructions.iban, 'iban') | ||
: null) || | ||
'N/A' | ||
} | ||
/> | ||
)} | ||
{currentCountryDetails?.id !== 'MX' && ( | ||
<PaymentInfoRow | ||
label={onrampData?.depositInstructions?.bankRoutingNumber ? 'Routing Number' : 'BIC'} | ||
value={ | ||
onrampData?.depositInstructions?.bankRoutingNumber || | ||
onrampData?.depositInstructions?.bic || | ||
'N/A' | ||
} | ||
/> | ||
)} | ||
<PaymentInfoRow | ||
hideBottomBorder | ||
label={'Deposit Message'} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2063,6 +2063,8 @@ export const countryCodeMap: { [key: string]: string } = { | |
USA: 'US', | ||
} | ||
|
||
const enabledBankTransferCountries = new Set([...Object.keys(countryCodeMap), 'US']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix country code format inconsistency in enabledBankTransferCountries. The set mixes 3-letter country codes from -const enabledBankTransferCountries = new Set([...Object.keys(countryCodeMap), 'US'])
+const enabledBankTransferCountries = new Set([...Object.keys(countryCodeMap), 'USA']) Also verify that all country codes in the logic below use consistent formatting with this set. 🤖 Prompt for AI Agents
|
||
|
||
countryData.forEach((country) => { | ||
if (country.type === 'country') { | ||
const countryCode = country.id | ||
|
@@ -2115,7 +2117,7 @@ countryData.forEach((country) => { | |
...DEFAULT_BANK_WITHDRAW_METHOD, | ||
id: `${countryCode.toLowerCase()}-default-bank-withdraw`, | ||
path: `/withdraw/${countryCode.toLowerCase()}/bank`, | ||
isSoon: countryCode === 'MX', | ||
isSoon: !enabledBankTransferCountries.has(countryCode), | ||
}) | ||
} | ||
|
||
|
@@ -2129,6 +2131,9 @@ countryData.forEach((country) => { | |
const newMethod = { ...m } | ||
if (newMethod.id === 'bank-transfer-add') { | ||
newMethod.path = `/add-money/${country.path}/bank` | ||
newMethod.isSoon = !enabledBankTransferCountries.has(countryCode) | ||
} else { | ||
newMethod.isSoon = true | ||
} | ||
return newMethod | ||
}) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||
import { getCurrencySymbol } from './bridge.utils' | ||||||
|
||||||
// Helper function to get currency symbol based on code | ||||||
export const getDisplayCurrencySymbol = (code?: string, fallbackSymbol: string = '$'): string => { | ||||||
if (!code) return fallbackSymbol | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
||||||
const upperCode = code.toUpperCase() | ||||||
|
||||||
switch (upperCode) { | ||||||
|
@@ -15,14 +16,20 @@ export const getDisplayCurrencySymbol = (code?: string, fallbackSymbol: string = | |||||
return '£' | ||||||
case 'JPY': | ||||||
return '¥' | ||||||
case 'MXN': | ||||||
return 'MX$' | ||||||
case 'BRL': | ||||||
return 'R$' | ||||||
case 'CAD': | ||||||
return 'CA$' | ||||||
default: | ||||||
return upperCode // Return the currency code itself as fallback (e.g., "CAD", "CHF") | ||||||
return upperCode // Return the currency code itself as fallback (e.g., "CHF") | ||||||
} | ||||||
} | ||||||
|
||||||
// Simple currency amount formatter | ||||||
export const formatCurrencyAmount = (amount: string | number, currencyCode: string): string => { | ||||||
const symbol = getDisplayCurrencySymbol(currencyCode) | ||||||
const symbol = getCurrencySymbol(currencyCode) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function inconsistency may cause validation issues. Using The functions should use consistent currency support. Consider:
- const symbol = getCurrencySymbol(currencyCode)
+ const symbol = getDisplayCurrencySymbol(currencyCode) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount | ||||||
|
||||||
if (isNaN(numAmount)) return `${symbol}0` | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.