@@ -5,30 +5,115 @@ import SpClubCongratsPopup from '../SpClubCongratsPopup';
55import SimpleLoadingRing from '../SimpleLoadingRing' ;
66import { joinSpClub } from '../../api' ;
77import { useDaemonContext } from '../../providers/DaemonProvider' ;
8+ import { getSpClubMemberId } from '../../services/wallets' ;
9+ import { isPassportValid } from '../../utils/utils' ;
810
911export default function SpClub ( ) {
1012 const [ isOpen , setIsOpen ] = useState < boolean > ( false ) ;
11- const [ walletAddress , setWalletAddress ] = useState ( '' ) ;
1213 const [ isCongratsPopupOpen , setIsCongratsPopupOpen ] = useState < boolean > ( false ) ;
1314 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
15+ const [ memberId , setMemberId ] = useState < string > ( '0' ) ;
16+ const [ referrer , setReferrer ] = useState < string > ( '' ) ;
1417
1518 const { profiles } = useDaemonContext ( ) ;
1619
20+ const fetchMemberIdWithRetry = async ( startTime = Date . now ( ) ) : Promise < string | null > => {
21+ const _memberId = await getSpClubMemberId ( profiles [ 0 ] ) ;
22+
23+ if ( _memberId . toString ( ) !== '0' ) {
24+ return _memberId . toString ( ) ;
25+ }
26+
27+ if ( Date . now ( ) - startTime >= 60000 ) { // Stop after 1 minute
28+ return null ;
29+ }
30+
31+ await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
32+ return fetchMemberIdWithRetry ( startTime ) ; // Recursive call with startTime
33+ } ;
34+
1735 const handleJoinClub = async ( ) => {
1836 setIsLoading ( true )
1937
2038 try {
21- const result = await joinSpClub ( profiles [ 0 ] , profiles [ 1 ] ) ;
39+ const result = await joinSpClub ( profiles [ 0 ] , profiles [ 1 ] , referrer ) ;
2240
23- if ( result !== false )
41+ if ( result !== false ) {
42+ const _memberId = await fetchMemberIdWithRetry ( )
43+
44+ if ( _memberId === null ) throw new Error ( "Couldn't fetch memberId" )
45+
46+ setMemberId ( _memberId ) ;
2447 setIsCongratsPopupOpen ( true )
48+ }
2549 } catch ( error ) {
2650 console . log ( error ) ;
2751 }
2852
2953 setTimeout ( ( ) => setIsLoading ( false ) , 2000 )
3054 }
3155
56+ const renderCardContent = ( ) => {
57+ if ( profiles ?. [ 0 ] ?. spClub ?. memberId && profiles ?. [ 0 ] ?. spClub ?. memberId !== '0' ) {
58+ return (
59+ < div className = "info-wrapper" style = { {
60+ gap : '16px'
61+ } } >
62+ < div >
63+ < p style = { { fontSize : '14px' , color : '#FFFFFF' } } > Member ID</ p >
64+ < p style = { { fontSize : '16px' , color : '#989899' } } > { profiles ?. [ 0 ] ?. spClub ?. memberId . toString ( ) } </ p >
65+ </ div >
66+
67+ {
68+ profiles ?. [ 0 ] ?. spClub ?. inviter &&
69+ < div >
70+ < p style = { { fontSize : '14px' , color : '#FFFFFF' } } > Inviter</ p >
71+ < p style = { { fontSize : '16px' , color : '#989899' } } > { profiles ?. [ 0 ] ?. spClub ?. inviter ?. toString ( ) } </ p >
72+ </ div >
73+ }
74+
75+ {
76+ ! isPassportValid ( parseInt ( profiles ?. [ 0 ] ?. spClub ?. expires ) ) &&
77+ < div style = { { display : 'flex' , alignItems : 'center' , width : '100%' } } >
78+ < p style = { { fontSize : '16px' , color : '#FFFFFF' , textAlign : 'center' } } > Passport Expired.</ p >
79+ < p style = { { fontSize : '12px' , color : '#989899' , textAlign : 'center' } } > Buy another passport to reactivate your club membership.</ p >
80+ </ div >
81+ }
82+ </ div >
83+ )
84+ }
85+
86+ return (
87+ < div className = "info-wrapper" style = { { gap : '24px' } } >
88+ < div >
89+ < p > Input you inviter's wallet address</ p >
90+ < input value = { referrer } onChange = { ( e ) => setReferrer ( e . target . value ) } placeholder = "wallet address" style = { { color : '#FFFFFF' } } />
91+ </ div >
92+
93+ < div style = { { width : '100%' , display : 'flex' , justifyContent : 'center' , gap : '24px' , flexDirection : 'row' , alignItems : 'center' } } >
94+ < div style = { { width : '100%' , height : '1px' , background : '#FFFFFF' } } />
95+
96+ < div >
97+ < p style = { { fontSize : '20px' } } > or</ p >
98+ </ div >
99+
100+ < div style = { { width : '100%' , height : '1px' , background : '#FFFFFF' } } />
101+
102+ </ div >
103+
104+ < div style = { { width : '100%' } } >
105+ < p style = { { width : '100%' , textAlign : 'center' , fontSize : '16px' } } > Get Silent Pass Passport and join the club</ p >
106+ </ div >
107+
108+ < button style = { { cursor : 'pointer' } } onClick = { handleJoinClub } >
109+ { isLoading ? < SimpleLoadingRing /> :
110+ < p > Join Club</ p >
111+ }
112+ </ button >
113+ </ div >
114+ )
115+ }
116+
32117 return (
33118 < >
34119 < div className = { `account-wrapper referral-program ${ isOpen ? 'active' : '' } ` } >
@@ -40,39 +125,14 @@ export default function SpClub() {
40125 </ div >
41126 </ div >
42127 < div className = "info-card" >
43- < div className = "info-wrapper" >
44- < div >
45- < p > Input you inviter wallet address</ p >
46- < input value = { walletAddress } onChange = { ( e ) => setWalletAddress ( e . target . value ) } placeholder = "wallet address" />
47- </ div >
48-
49- < div style = { { width : '100%' , display : 'flex' , justifyContent : 'center' , gap : '24px' , flexDirection : 'row' , alignItems : 'center' } } >
50- < div style = { { width : '100%' , height : '1px' , background : '#FFFFFF' } } />
51-
52- < div >
53- < p style = { { fontSize : '20px' } } > or</ p >
54- </ div >
55-
56- < div style = { { width : '100%' , height : '1px' , background : '#FFFFFF' } } />
57128
58- </ div >
59-
60- < div style = { { width : '100%' } } >
61- < p style = { { width : '100%' , textAlign : 'center' , fontSize : '16px' } } > Get Silent Pass Passport and join the club</ p >
62- </ div >
63-
64- < button onClick = { handleJoinClub } >
65- { isLoading ? < SimpleLoadingRing /> :
66- < p > Join Club</ p >
67- }
68- </ button >
69- </ div >
129+ { renderCardContent ( ) }
70130 </ div >
71131 </ div >
72132
73133 {
74134 isCongratsPopupOpen && (
75- < SpClubCongratsPopup setIsCongratsPopupOpen = { setIsCongratsPopupOpen } />
135+ < SpClubCongratsPopup setIsCongratsPopupOpen = { setIsCongratsPopupOpen } memberId = { memberId } />
76136 )
77137 }
78138 </ >
0 commit comments