Skip to content

Commit 05070b7

Browse files
authored
Merge pull request #1283 from peanutprotocol/fix/withdraw-recent-methods
fix: correctly route recent methods
2 parents c45b2e4 + 3dabf06 commit 05070b7

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@
137137
"node_modules/(?!(@wagmi|wagmi|viem|@viem|@squirrel-labs)/)"
138138
],
139139
"moduleNameMapper": {
140+
"\\.(svg|png|jpg|jpeg|gif)$": "jest-transform-stub",
140141
"^@/(.*)$": "<rootDir>/src/$1",
141142
"^wagmi/chains$": "<rootDir>/src/utils/__mocks__/wagmi.ts",
142143
"^@squirrel-labs/peanut-sdk$": "<rootDir>/src/utils/__mocks__/peanut-sdk.ts",
143-
"^next/cache$": "<rootDir>/src/utils/__mocks__/next-cache.ts",
144-
"\\.(svg|png|jpg|jpeg|gif)$": "jest-transform-stub"
144+
"^next/cache$": "<rootDir>/src/utils/__mocks__/next-cache.ts"
145145
},
146146
"setupFilesAfterEnv": [
147147
"<rootDir>/jest.setup.ts"

src/app/(mobile-ui)/withdraw/page.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useWithdrawFlow } from '@/context/WithdrawFlowContext'
1010
import { useWallet } from '@/hooks/wallet/useWallet'
1111
import { tokenSelectorContext } from '@/context/tokenSelector.context'
1212
import { formatAmount } from '@/utils'
13+
import { getCountryFromAccount } from '@/utils/bridge.utils'
1314
import { useRouter } from 'next/navigation'
1415
import { useCallback, useEffect, useMemo, useState, useRef, useContext } from 'react'
1516
import { formatUnits } from 'viem'
@@ -27,12 +28,12 @@ export default function WithdrawPage() {
2728
error,
2829
setUsdAmount,
2930
selectedMethod,
31+
selectedBankAccount,
3032
setSelectedMethod,
3133
setShowAllWithdrawMethods,
3234
} = useWithdrawFlow()
3335

34-
// FIXED FLOW: Only crypto gets amount input on main page, countries route directly
35-
const initialStep: WithdrawStep = selectedMethod ? 'inputAmount' : 'selectMethod'
36+
const initialStep: WithdrawStep = selectedMethod || selectedBankAccount ? 'inputAmount' : 'selectMethod'
3637

3738
const [step, setStep] = useState<WithdrawStep>(initialStep)
3839

@@ -179,7 +180,14 @@ export default function WithdrawPage() {
179180
setUsdAmount(usdVal.toString())
180181

181182
// Route based on selected method type
182-
if (selectedMethod.type === 'crypto') {
183+
if (selectedBankAccount) {
184+
const country = getCountryFromAccount(selectedBankAccount)
185+
if (country) {
186+
router.push(`/withdraw/${country.path}/bank`)
187+
} else {
188+
throw new Error('Failed to get country from bank account')
189+
}
190+
} else if (selectedMethod.type === 'crypto') {
183191
router.push('/withdraw/crypto')
184192
} else if (selectedMethod.type === 'manteca') {
185193
// Route directly to Manteca with method and country params

src/utils/bridge.utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { countryData as ALL_METHODS_DATA, CountryData } from '@/components/AddMoney/consts'
2+
import { Account, AccountType } from '@/interfaces'
3+
14
export interface CurrencyConfig {
25
currency: string
36
paymentRail: string
@@ -76,3 +79,17 @@ export const getPaymentRailDisplayName = (paymentRail: string): string => {
7679
}
7780
return displayNames[paymentRail] || paymentRail.toUpperCase()
7881
}
82+
83+
export function getCountryFromAccount(account: Account): CountryData | undefined {
84+
const threeLetterCountryCode = (account.details.countryCode ?? '').toUpperCase()
85+
86+
let countryInfo
87+
if (account.type === AccountType.US) {
88+
countryInfo = ALL_METHODS_DATA.find((c) => c.id === 'US')
89+
} else {
90+
countryInfo = account.details.countryName
91+
? ALL_METHODS_DATA.find((c) => c.path.toLowerCase() === account.details.countryName?.toLowerCase())
92+
: ALL_METHODS_DATA.find((c) => c.id === threeLetterCountryCode)
93+
}
94+
return countryInfo
95+
}

0 commit comments

Comments
 (0)