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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@
"node_modules/(?!(@wagmi|wagmi|viem|@viem|@squirrel-labs)/)"
],
"moduleNameMapper": {
"\\.(svg|png|jpg|jpeg|gif)$": "jest-transform-stub",
"^@/(.*)$": "<rootDir>/src/$1",
"^wagmi/chains$": "<rootDir>/src/utils/__mocks__/wagmi.ts",
"^@squirrel-labs/peanut-sdk$": "<rootDir>/src/utils/__mocks__/peanut-sdk.ts",
"^next/cache$": "<rootDir>/src/utils/__mocks__/next-cache.ts",
"\\.(svg|png|jpg|jpeg|gif)$": "jest-transform-stub"
"^next/cache$": "<rootDir>/src/utils/__mocks__/next-cache.ts"
},
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.ts"
Expand Down
14 changes: 11 additions & 3 deletions src/app/(mobile-ui)/withdraw/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<WithdrawStep>(initialStep)

Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/utils/bridge.utils.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
Loading