diff --git a/package.json b/package.json index a3f28f673..f19df87e4 100644 --- a/package.json +++ b/package.json @@ -137,11 +137,11 @@ "node_modules/(?!(@wagmi|wagmi|viem|@viem|@squirrel-labs)/)" ], "moduleNameMapper": { + "\\.(svg|png|jpg|jpeg|gif)$": "jest-transform-stub", "^@/(.*)$": "/src/$1", "^wagmi/chains$": "/src/utils/__mocks__/wagmi.ts", "^@squirrel-labs/peanut-sdk$": "/src/utils/__mocks__/peanut-sdk.ts", - "^next/cache$": "/src/utils/__mocks__/next-cache.ts", - "\\.(svg|png|jpg|jpeg|gif)$": "jest-transform-stub" + "^next/cache$": "/src/utils/__mocks__/next-cache.ts" }, "setupFilesAfterEnv": [ "/jest.setup.ts" diff --git a/src/app/(mobile-ui)/withdraw/page.tsx b/src/app/(mobile-ui)/withdraw/page.tsx index 3aaef1b1f..ed7ef7959 100644 --- a/src/app/(mobile-ui)/withdraw/page.tsx +++ b/src/app/(mobile-ui)/withdraw/page.tsx @@ -10,6 +10,7 @@ import { useWithdrawFlow } from '@/context/WithdrawFlowContext' import { useWallet } from '@/hooks/wallet/useWallet' import { tokenSelectorContext } from '@/context/tokenSelector.context' import { formatAmount } from '@/utils' +import { getCountryFromAccount } from '@/utils/bridge.utils' import { useRouter } from 'next/navigation' import { useCallback, useEffect, useMemo, useState, useRef, useContext } from 'react' import { formatUnits } from 'viem' @@ -27,12 +28,12 @@ export default function WithdrawPage() { error, setUsdAmount, selectedMethod, + selectedBankAccount, setSelectedMethod, setShowAllWithdrawMethods, } = useWithdrawFlow() - // FIXED FLOW: Only crypto gets amount input on main page, countries route directly - const initialStep: WithdrawStep = selectedMethod ? 'inputAmount' : 'selectMethod' + const initialStep: WithdrawStep = selectedMethod || selectedBankAccount ? 'inputAmount' : 'selectMethod' const [step, setStep] = useState(initialStep) @@ -179,7 +180,14 @@ export default function WithdrawPage() { setUsdAmount(usdVal.toString()) // Route based on selected method type - if (selectedMethod.type === 'crypto') { + if (selectedBankAccount) { + const country = getCountryFromAccount(selectedBankAccount) + if (country) { + router.push(`/withdraw/${country.path}/bank`) + } else { + throw new Error('Failed to get country from bank account') + } + } else if (selectedMethod.type === 'crypto') { router.push('/withdraw/crypto') } else if (selectedMethod.type === 'manteca') { // Route directly to Manteca with method and country params diff --git a/src/utils/bridge.utils.ts b/src/utils/bridge.utils.ts index 4aa1eeaca..6e07d2fad 100644 --- a/src/utils/bridge.utils.ts +++ b/src/utils/bridge.utils.ts @@ -1,3 +1,6 @@ +import { countryData as ALL_METHODS_DATA, CountryData } from '@/components/AddMoney/consts' +import { Account, AccountType } from '@/interfaces' + export interface CurrencyConfig { currency: string paymentRail: string @@ -76,3 +79,17 @@ export const getPaymentRailDisplayName = (paymentRail: string): string => { } return displayNames[paymentRail] || paymentRail.toUpperCase() } + +export function getCountryFromAccount(account: Account): CountryData | undefined { + const threeLetterCountryCode = (account.details.countryCode ?? '').toUpperCase() + + let countryInfo + if (account.type === AccountType.US) { + countryInfo = ALL_METHODS_DATA.find((c) => c.id === 'US') + } else { + countryInfo = account.details.countryName + ? ALL_METHODS_DATA.find((c) => c.path.toLowerCase() === account.details.countryName?.toLowerCase()) + : ALL_METHODS_DATA.find((c) => c.id === threeLetterCountryCode) + } + return countryInfo +}