Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 57 additions & 127 deletions src/app/groups/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Navbar />
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
<div className="mb-8">
<h1 className="text-2xl font-bold text-gray-900">{group.name}</h1>
<p className="text-gray-600 mt-1">
{formatAmount(group.contributionAmount)} tokens per cycle
</p>
</div>

<div className="grid lg:grid-cols-3 gap-6">
<div className="lg:col-span-2 space-y-6">
<RoundProgress
currentRound={group.currentRound}
totalRounds={group.totalRounds}
contributionsReceived={1}
totalMembers={group.members.length}
/>

<MemberList
members={group.members}
admin={group.admin}
payoutOrder={group.payoutOrder}
currentRound={group.currentRound}
/>
</div>

<div className="space-y-4">
<div className="bg-white rounded-xl shadow-sm border p-6">
<h3 className="text-lg font-semibold text-gray-900 mb-4">
Actions
</h3>
<div className="space-y-3">
{group.status === GroupStatus.Active && (
<button
onClick={() => setShowContributeModal(true)}
className="w-full bg-primary-600 text-white py-3 rounded-lg font-medium hover:bg-primary-700 transition-colors"
>
Contribute
</button>
)}
{group.status === GroupStatus.Forming && (
<button className="w-full bg-blue-600 text-white py-3 rounded-lg font-medium hover:bg-blue-700 transition-colors">
Join Group
</button>
)}
</div>
</div>

<div className="bg-white rounded-xl shadow-sm border p-6">
<h3 className="text-sm font-semibold text-gray-900 mb-3">
Group Info
</h3>
<dl className="space-y-2 text-sm">
<div className="flex justify-between">
<dt className="text-gray-500">Status</dt>
<dd className="font-medium text-gray-900">{group.status}</dd>
</div>
<div className="flex justify-between">
<dt className="text-gray-500">Members</dt>
<dd className="font-medium text-gray-900">
{group.members.length}/{group.maxMembers}
</dd>
</div>
<div className="flex justify-between">
<dt className="text-gray-500">Cycle</dt>
<dd className="font-medium text-gray-900">
{group.cycleLength / 86400} days
</dd>
</div>
<div className="flex justify-between">
<dt className="text-gray-500">Pot Size</dt>
<dd className="font-medium text-gray-900">
{formatAmount(
group.contributionAmount * BigInt(group.members.length)
)}{" "}
tokens
</dd>
</div>
</dl>
</div>
</div>
</div>
</main>

<ContributeModal
groupId={group.id}
contributionAmount={group.contributionAmount}
isOpen={showContributeModal}
onClose={() => setShowContributeModal(false)}
<div className="container mx-auto px-4 py-8">
<h1 className="text-2xl font-bold mb-6">Group Details</h1>
<RoundProgress
currentRound={roundData.currentRound}
totalRounds={roundData.totalRounds}
contributionsReceived={roundData.contributionsReceived}
totalMembers={roundData.totalMembers}
/>
</>
</div>
);
}
}