@@ -10,12 +10,10 @@ import Image, { type StaticImageData } from 'next/image'
1010import { useParams , useRouter , useSearchParams } from 'next/navigation'
1111import EmptyState from '../Global/EmptyStates/EmptyState'
1212import { useAuth } from '@/context/authContext'
13- import { useEffect , useMemo , useRef , useState } from 'react'
13+ import { useMemo , useRef , useState } from 'react'
1414import { DynamicBankAccountForm , type IBankAccountDetails } from './DynamicBankAccountForm'
1515import { addBankAccount } from '@/app/actions/users'
16- import { type BridgeKycStatus } from '@/utils/bridge-accounts.utils'
1716import { type AddBankAccountPayload } from '@/app/actions/types/users.types'
18- import { useWebSocket } from '@/hooks/useWebSocket'
1917import { useWithdrawFlow } from '@/context/WithdrawFlowContext'
2018import { type Account } from '@/interfaces'
2119import { getCountryCodeForWithdraw } from '@/utils/withdraw.utils'
@@ -64,28 +62,11 @@ const AddWithdrawCountriesList = ({ flow }: AddWithdrawCountriesListProps) => {
6462 const [ view , setView ] = useState < 'list' | 'form' > ( flow === 'withdraw' && amountToWithdraw ? 'form' : 'list' )
6563 const [ isKycModalOpen , setIsKycModalOpen ] = useState ( false )
6664 const formRef = useRef < { handleSubmit : ( ) => void } > ( null )
67- const [ liveKycStatus , setLiveKycStatus ] = useState < BridgeKycStatus | undefined > (
68- user ?. user ?. bridgeKycStatus as BridgeKycStatus
69- )
7065 const [ isSupportedTokensModalOpen , setIsSupportedTokensModalOpen ] = useState ( false )
7166
72- const { isUserBridgeKycUnderReview } = useKycStatus ( )
67+ const { isUserKycApproved , isUserBridgeKycUnderReview } = useKycStatus ( )
7368 const [ showKycStatusModal , setShowKycStatusModal ] = useState ( false )
7469
75- useWebSocket ( {
76- username : user ?. user . username ?? undefined ,
77- autoConnect : ! ! user ?. user . username ,
78- onKycStatusUpdate : ( newStatus ) => {
79- setLiveKycStatus ( newStatus as BridgeKycStatus )
80- } ,
81- } )
82-
83- useEffect ( ( ) => {
84- if ( user ?. user . bridgeKycStatus ) {
85- setLiveKycStatus ( user . user . bridgeKycStatus as BridgeKycStatus )
86- }
87- } , [ user ?. user . bridgeKycStatus ] )
88-
8970 const countryPathParts = Array . isArray ( params . country ) ? params . country : [ params . country ]
9071 const isBankPage = countryPathParts [ countryPathParts . length - 1 ] === 'bank'
9172 const countrySlugFromUrl = isBankPage ? countryPathParts . slice ( 0 , - 1 ) . join ( '-' ) : countryPathParts . join ( '-' )
@@ -100,14 +81,12 @@ const AddWithdrawCountriesList = ({ flow }: AddWithdrawCountriesListProps) => {
10081 ) : Promise < { error ?: string } > => {
10182 // re-fetch user to ensure we have the latest KYC status
10283 // (the multi-phase flow may have completed but websocket/state not yet propagated)
103- const freshUser = await fetchUser ( )
104- const currentKycStatus = freshUser ?. user ?. bridgeKycStatus || liveKycStatus || user ?. user . bridgeKycStatus
105- const isUserKycVerified = currentKycStatus === 'approved'
84+ await fetchUser ( )
10685
10786 // scenario (1): happy path: if the user has already completed kyc, we can add the bank account directly
10887 // email and name are now collected by sumsub — no need to check them here
109- if ( isUserKycVerified ) {
110- const currentAccountIds = new Set ( ( freshUser ?. accounts ?? user ?. accounts ?? [ ] ) . map ( ( acc ) => acc . id ) )
88+ if ( isUserKycApproved ) {
89+ const currentAccountIds = new Set ( ( user ?. accounts ?? [ ] ) . map ( ( acc ) => acc . id ) )
11190
11291 const result = await addBankAccount ( payload )
11392 if ( result . error ) {
@@ -149,7 +128,7 @@ const AddWithdrawCountriesList = ({ flow }: AddWithdrawCountriesListProps) => {
149128
150129 // scenario (2): if the user hasn't completed kyc yet
151130 // name and email are now collected by sumsub sdk — no need to save them beforehand
152- if ( ! isUserKycVerified ) {
131+ if ( ! isUserKycApproved ) {
153132 await sumsubFlow . handleInitiateKyc ( 'STANDARD' )
154133 }
155134
0 commit comments