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/[country]/bank/page.tsx b/src/app/(mobile-ui)/withdraw/[country]/bank/page.tsx index 85218f9b3..8d01d563f 100644 --- a/src/app/(mobile-ui)/withdraw/[country]/bank/page.tsx +++ b/src/app/(mobile-ui)/withdraw/[country]/bank/page.tsx @@ -41,8 +41,8 @@ export default function WithdrawBankPage() { )?.currencyCode useEffect(() => { - if (!bankAccount && !amountToWithdraw) { - // If no bank account AND no amount, go back to main page + if (!amountToWithdraw) { + // If no amount, go back to main page router.replace('/withdraw') } else if (!bankAccount && amountToWithdraw) { // If amount is set but no bank account, go to country method selection diff --git a/src/app/(mobile-ui)/withdraw/page.tsx b/src/app/(mobile-ui)/withdraw/page.tsx index 3aaef1b1f..0f4a94dd4 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,11 +28,11 @@ 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 [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 @@ -210,8 +218,6 @@ export default function WithdrawPage() { }, [rawTokenAmount, maxDecimalAmount, error.showError, selectedTokenData?.price]) if (step === 'inputAmount') { - const methodTitle = selectedMethod?.title || selectedMethod?.countryPath || 'Selected method' - return (
= ({ pageTitle={pageTitle} onPrev={onBackClick || defaultBackNavigation} savedAccounts={savedAccounts} - onAccountClick={(account, path) => { + onAccountClick={(account, _path) => { setSelectedBankAccount(account) - - // FIXED: For withdraw flow, route to saved account path - if (flow === 'withdraw') { - if (account.type === AccountType.MANTECA) { - router.push( - `/withdraw/manteca?country=${account.details.countryName}&destination=${account.identifier}` - ) - } else { - router.push(path) - } - return + setSelectedMethod({ + type: account.type === AccountType.MANTECA ? 'manteca' : 'bridge', + countryPath: account.details.countryName, + title: 'To Bank', + }) + if (account.type === AccountType.MANTECA) { + router.push( + `/withdraw/manteca?country=${account.details.countryName}&destination=${account.identifier}` + ) } - - // Original add flow - router.push(path) }} onSelectNewMethodClick={() => setShouldShowAllMethods(true)} /> 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 +}