diff --git a/src/app/groups/[id]/page.tsx b/src/app/groups/[id]/page.tsx index 02ab880..deb1b90 100644 --- a/src/app/groups/[id]/page.tsx +++ b/src/app/groups/[id]/page.tsx @@ -1,133 +1,63 @@ -"use client"; +import { useState, useEffect } from 'react'; +import { RoundProgress } from '@/components/RoundProgress'; +import { Contract } from '@stellar/stellar-sdk'; +import { SorobanRpc } from '@stellar/stellar-sdk'; -import { Navbar } from "@/components/Navbar"; -import { MemberList } from "@/components/MemberList"; -import { RoundProgress } from "@/components/RoundProgress"; -import { ContributeModal } from "@/components/ContributeModal"; -import { useState } from "react"; -import { formatAmount, GroupStatus } from "@sorosave/sdk"; - -// TODO: Fetch real data from contract -const MOCK_GROUP = { - id: 1, - name: "Lagos Savings Circle", - admin: "GABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFG", - token: "CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HHGCYSC", - contributionAmount: 1000000000n, - cycleLength: 604800, - maxMembers: 5, - members: [ - "GABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFG", - "GEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJ", - "GIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMN", - ], - payoutOrder: [ - "GABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFG", - "GEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJ", - "GIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMN", - ], - currentRound: 1, - totalRounds: 3, - status: GroupStatus.Active, - createdAt: 1700000000, -}; +interface GroupPageProps { + params: { id: string } +} -export default function GroupDetailPage() { - const [showContributeModal, setShowContributeModal] = useState(false); - const group = MOCK_GROUP; +export default function GroupPage({ params }: GroupPageProps) { + const [roundData, setRoundData] = useState({ + currentRound: 0, + totalRounds: 0, + contributionsReceived: 0, + totalMembers: 0, + isComplete: false + }); + + useEffect(() => { + const fetchRoundData = async () => { + try { + const server = new SorobanRpc.Server(process.env.NEXT_PUBLIC_RPC_URL!); + const contract = new Contract(process.env.NEXT_PUBLIC_CONTRACT_ID!); + + // Poll for round data every 10 seconds + const interval = setInterval(async () => { + const roundInfo = await server.getContractState(contract, 'round_info'); + const members = await server.getContractState(contract, 'members'); + + setRoundData({ + currentRound: roundInfo.current_round, + totalRounds: roundInfo.total_rounds, + contributionsReceived: roundInfo.contributions_received, + totalMembers: members.length, + isComplete: roundInfo.is_complete + }); + + if (roundInfo.is_complete) { + clearInterval(interval); + } + }, 10000); + + return () => clearInterval(interval); + } catch (error) { + console.error('Error fetching round data:', error); + } + }; + + fetchRoundData(); + }, [params.id]); return ( - <> - -
-
-

{group.name}

-

- {formatAmount(group.contributionAmount)} tokens per cycle -

-
- -
-
- - - -
- -
-
-

- Actions -

-
- {group.status === GroupStatus.Active && ( - - )} - {group.status === GroupStatus.Forming && ( - - )} -
-
- -
-

- Group Info -

-
-
-
Status
-
{group.status}
-
-
-
Members
-
- {group.members.length}/{group.maxMembers} -
-
-
-
Cycle
-
- {group.cycleLength / 86400} days -
-
-
-
Pot Size
-
- {formatAmount( - group.contributionAmount * BigInt(group.members.length) - )}{" "} - tokens -
-
-
-
-
-
-
- - setShowContributeModal(false)} +
+

Group Details

+ - +
); -} +} \ No newline at end of file