1- import React , { useState } from 'react' ;
1+ import React , { useState , useEffect } from 'react' ;
22import {
33 Box ,
44 Typography ,
@@ -11,7 +11,9 @@ import {
1111 DialogContent ,
1212 DialogActions ,
1313 TextField ,
14- LinearProgress
14+ LinearProgress ,
15+ CircularProgress ,
16+ Alert
1517} from '@mui/material' ;
1618import { styled } from '@mui/material/styles' ;
1719import {
@@ -21,6 +23,8 @@ import {
2123 TrendingUp as TrendingIcon ,
2224 EmojiEvents as TrophyIcon ,
2325} from '@mui/icons-material' ;
26+ import VaultService from '../services/VaultService' ;
27+ import { Guild as GuildType } from '../types' ;
2428
2529const GuildCard = styled ( Card ) ( ( { theme } ) => ( {
2630 background : 'rgba(255, 255, 255, 0.08)' ,
@@ -121,39 +125,40 @@ const GuildSection: React.FC = () => {
121125 const [ createDialogOpen , setCreateDialogOpen ] = useState ( false ) ;
122126 const [ newGuildName , setNewGuildName ] = useState ( '' ) ;
123127 const [ newGuildDescription , setNewGuildDescription ] = useState ( '' ) ;
128+ const [ guilds , setGuilds ] = useState < Guild [ ] > ( [ ] ) ;
129+ const [ loading , setLoading ] = useState ( true ) ;
130+ const [ error , setError ] = useState < string | null > ( null ) ;
131+
132+ const vaultService = VaultService . getInstance ( ) ;
124133
125- const [ guilds ] = useState < Guild [ ] > ( [
126- {
127- id : '1' ,
128- name : 'Diamond Traders' ,
129- description : 'Elite traders focused on high-volume trading and maximum rewards' ,
130- members : 24 ,
131- maxMembers : 50 ,
132- totalReferrals : 156 ,
133- milestone : { current : 156 , target : 200 , reward : 'Exclusive Diamond NFT' } ,
134- isJoined : false ,
135- } ,
136- {
137- id : '2' ,
138- name : 'DeFi Warriors' ,
139- description : 'DeFi enthusiasts building the future of decentralized finance' ,
140- members : 18 ,
141- maxMembers : 30 ,
142- totalReferrals : 89 ,
143- milestone : { current : 89 , target : 100 , reward : 'Team Jackpot Bonus' } ,
144- isJoined : true ,
145- } ,
146- {
147- id : '3' ,
148- name : 'Solana Seekers' ,
149- description : 'Solana ecosystem pioneers seeking the best opportunities' ,
150- members : 31 ,
151- maxMembers : 40 ,
152- totalReferrals : 203 ,
153- milestone : { current : 203 , target : 250 , reward : 'Premium Guild Status' } ,
154- isJoined : false ,
155- } ,
156- ] ) ;
134+ useEffect ( ( ) => {
135+ loadGuilds ( ) ;
136+ } , [ ] ) ;
137+
138+ const loadGuilds = async ( ) => {
139+ try {
140+ setLoading ( true ) ;
141+ const guildsData = await vaultService . getGuilds ( ) ;
142+ // Transform the data to match our local interface
143+ const transformedGuilds : Guild [ ] = guildsData . map ( guild => ( {
144+ id : guild . id ,
145+ name : guild . name ,
146+ description : guild . description ,
147+ members : guild . members . length ,
148+ maxMembers : guild . maxMembers ,
149+ totalReferrals : guild . totalReferrals ,
150+ milestone : guild . milestone ,
151+ isJoined : Math . random ( ) > 0.7 , // Mock join status
152+ } ) ) ;
153+ setGuilds ( transformedGuilds ) ;
154+ setError ( null ) ;
155+ } catch ( err ) {
156+ setError ( 'Failed to load guilds' ) ;
157+ console . error ( 'Error loading guilds:' , err ) ;
158+ } finally {
159+ setLoading ( false ) ;
160+ }
161+ } ;
157162
158163 const handleCreateGuild = ( ) => {
159164 // Mock guild creation
@@ -183,85 +188,99 @@ const GuildSection: React.FC = () => {
183188 </ CreateGuildButton >
184189 </ SectionHeader >
185190
186- < Typography variant = "body2" color = "text.secondary" paragraph >
191+ < Typography variant = "body2" color = "text.secondary" sx = { { mb : 2 } } >
187192 Join or create a guild to pool referral bonuses and unlock team-based vault jackpots!
188193 </ Typography >
189194
190- < div style = { { display : 'flex' , flexDirection : 'column' , gap : 16 } } >
191- { guilds . map ( ( guild ) => (
192- < GuildItem key = { guild . id } >
193- < CardContent >
194- < Box display = "flex" justifyContent = "space-between" alignItems = "flex-start" mb = { 2 } >
195- < Box >
196- < Typography variant = "h6" gutterBottom >
197- { guild . name }
198- { guild . isJoined && (
199- < Chip
200- size = "small"
201- label = "JOINED"
202- sx = { {
203- ml : 1 ,
204- background : 'linear-gradient(135deg, #4ECDC4, #44B7B8)' ,
205- color : '#fff' ,
206- fontWeight : 'bold'
207- } }
208- />
209- ) }
210- </ Typography >
211- < Typography variant = "body2" color = "text.secondary" >
212- { guild . description }
213- </ Typography >
195+ { loading ? (
196+ < Box display = "flex" justifyContent = "center" py = { 4 } >
197+ < CircularProgress sx = { { color : '#FFD700' } } />
198+ </ Box >
199+ ) : error ? (
200+ < Alert severity = "error" sx = { { mb : 2 } } >
201+ { error }
202+ </ Alert >
203+ ) : guilds . length === 0 ? (
204+ < Typography variant = "body2" color = "text.secondary" textAlign = "center" py = { 4 } >
205+ No guilds available. Create the first one!
206+ </ Typography >
207+ ) : (
208+ < div style = { { display : 'flex' , flexDirection : 'column' , gap : 16 } } >
209+ { guilds . map ( ( guild ) => (
210+ < GuildItem key = { guild . id } >
211+ < CardContent >
212+ < Box display = "flex" justifyContent = "space-between" alignItems = "flex-start" mb = { 2 } >
213+ < Box >
214+ < Typography variant = "h6" gutterBottom >
215+ { guild . name }
216+ { guild . isJoined && (
217+ < Chip
218+ size = "small"
219+ label = "JOINED"
220+ sx = { {
221+ ml : 1 ,
222+ background : 'linear-gradient(135deg, #4ECDC4, #44B7B8)' ,
223+ color : '#fff' ,
224+ fontWeight : 'bold'
225+ } }
226+ />
227+ ) }
228+ </ Typography >
229+ < Typography variant = "body2" color = "text.secondary" >
230+ { guild . description }
231+ </ Typography >
232+ </ Box >
233+ { ! guild . isJoined && (
234+ < JoinGuildButton
235+ size = "small"
236+ onClick = { ( ) => handleJoinGuild ( guild . id ) }
237+ >
238+ Join
239+ </ JoinGuildButton >
240+ ) }
214241 </ Box >
215- { ! guild . isJoined && (
216- < JoinGuildButton
217- size = "small"
218- onClick = { ( ) => handleJoinGuild ( guild . id ) }
219- >
220- Join
221- </ JoinGuildButton >
222- ) }
223- </ Box >
224242
225- < Box display = "flex" gap = { 2 } mb = { 2 } >
226- < Box display = "flex" alignItems = "center" gap = { 0.5 } >
227- < PeopleIcon sx = { { fontSize : 16 , color : '#FFD700' } } />
228- < Typography variant = "caption" >
229- { guild . members } /{ guild . maxMembers }
230- </ Typography >
231- </ Box >
232- < Box display = "flex" alignItems = "center" gap = { 0.5 } >
233- < TrendingIcon sx = { { fontSize : 16 , color : '#FFD700' } } />
234- < Typography variant = "caption" >
235- { guild . totalReferrals } referrals
236- </ Typography >
243+ < Box display = "flex" gap = { 2 } mb = { 2 } >
244+ < Box display = "flex" alignItems = "center" gap = { 0.5 } >
245+ < PeopleIcon sx = { { fontSize : 16 , color : '#FFD700' } } />
246+ < Typography variant = "caption" >
247+ { guild . members } /{ guild . maxMembers }
248+ </ Typography >
249+ </ Box >
250+ < Box display = "flex" alignItems = "center" gap = { 0.5 } >
251+ < TrendingIcon sx = { { fontSize : 16 , color : '#FFD700' } } />
252+ < Typography variant = "caption" >
253+ { guild . totalReferrals } referrals
254+ </ Typography >
255+ </ Box >
237256 </ Box >
238- </ Box >
239257
240- < Box >
241- < Box display = "flex" justifyContent = "space-between" alignItems = "center" mb = { 1 } >
242- < Typography variant = "caption" color = "text.secondary" >
243- Milestone Progress
244- </ Typography >
245- < RewardBadge
246- size = "small"
247- icon = { < TrophyIcon /> }
248- label = { guild . milestone . reward }
249- />
258+ < Box >
259+ < Box display = "flex" justifyContent = "space-between" alignItems = "center" mb = { 1 } >
260+ < Typography variant = "caption" color = "text.secondary" >
261+ Milestone Progress
262+ </ Typography >
263+ < RewardBadge
264+ size = "small"
265+ icon = { < TrophyIcon /> }
266+ label = { guild . milestone . reward }
267+ />
268+ </ Box >
269+ < GuildProgress >
270+ < LinearProgress
271+ variant = "determinate"
272+ value = { ( guild . milestone . current / guild . milestone . target ) * 100 }
273+ />
274+ < Typography variant = "caption" color = "text.secondary" sx = { { mt : 0.5 , display : 'block' } } >
275+ { guild . milestone . current } /{ guild . milestone . target }
276+ </ Typography >
277+ </ GuildProgress >
250278 </ Box >
251- < GuildProgress >
252- < LinearProgress
253- variant = "determinate"
254- value = { ( guild . milestone . current / guild . milestone . target ) * 100 }
255- />
256- < Typography variant = "caption" color = "text.secondary" sx = { { mt : 0.5 , display : 'block' } } >
257- { guild . milestone . current } /{ guild . milestone . target }
258- </ Typography >
259- </ GuildProgress >
260- </ Box >
261- </ CardContent >
262- </ GuildItem >
263- ) ) }
264- </ div >
279+ </ CardContent >
280+ </ GuildItem >
281+ ) ) }
282+ </ div >
283+ ) }
265284
266285 { /* Create Guild Dialog */ }
267286 < Dialog
0 commit comments