diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..bffb357 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "next/core-web-vitals" +} diff --git a/next.config.ts b/next.config.mjs similarity index 86% rename from next.config.ts rename to next.config.mjs index f0a914d..9b7c761 100644 --- a/next.config.ts +++ b/next.config.mjs @@ -1,6 +1,5 @@ -import type { NextConfig } from "next"; - -const nextConfig: NextConfig = { +/** @type {import('next').NextConfig} */ +const nextConfig = { reactStrictMode: true, env: { NEXT_PUBLIC_STELLAR_NETWORK: process.env.NEXT_PUBLIC_STELLAR_NETWORK || "testnet", diff --git a/package.json b/package.json index 87c6767..f207c68 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "@radix-ui/react-dropdown-menu": "^2.1.0", "@radix-ui/react-tabs": "^1.1.0", "@radix-ui/react-toast": "^1.2.0", - "@radix-ui/react-badge": "^1.0.0", "class-variance-authority": "^0.7.0" }, "devDependencies": { diff --git a/src/components/dashboard/treasury-chart.tsx b/src/components/dashboard/treasury-chart.tsx index 5660554..a60e76c 100644 --- a/src/components/dashboard/treasury-chart.tsx +++ b/src/components/dashboard/treasury-chart.tsx @@ -30,11 +30,24 @@ const MOCK_DATA: ChartDataPoint[] = [ { period: "C8", totalContributions: 850_000_000_000, loansOutstanding: 80_000_000_000 }, ]; -async function fetchContributionData(): Promise { +async function fetchContributionData(groupId?: string): Promise { try { - const res = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/api/contributions` - ); + let url = `${process.env.NEXT_PUBLIC_API_URL}/api/contributions`; + + if (groupId) { + url = `${process.env.NEXT_PUBLIC_API_URL}/api/groups/${groupId}/contributions`; + } else { + const groupsRes = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/groups`); + if (groupsRes.ok) { + const groups = await groupsRes.json(); + if (Array.isArray(groups) && groups.length > 0) { + const firstGroupId = groups[0].id; + url = `${process.env.NEXT_PUBLIC_API_URL}/api/groups/${firstGroupId}/contributions`; + } + } + } + + const res = await fetch(url); if (!res.ok) throw new Error("Failed to fetch contributions"); const data: unknown = await res.json(); if (!Array.isArray(data) || data.length === 0) throw new Error("Empty contributions"); @@ -44,23 +57,29 @@ async function fetchContributionData(): Promise { } } -export function TreasuryChart() { - const { data = MOCK_DATA, isLoading } = useQuery({ - queryKey: ["treasury-chart"], - queryFn: fetchContributionData, +interface TreasuryChartProps { + groupId?: string; +} + +export function TreasuryChart({ groupId }: TreasuryChartProps) { + const { data = MOCK_DATA, isLoading } = useQuery({ + queryKey: ["treasury-chart", groupId], + queryFn: () => fetchContributionData(groupId), refetchInterval: 60_000, staleTime: 30_000, }); - const hasData = data.length > 0; + const hasData = data && data.length > 0; return (
-

- Treasury Overview -

+
+

+ Treasury Overview +

+
{isLoading ? ( -
+
@@ -70,70 +89,75 @@ export function TreasuryChart() {

No contribution data yet

-

+

Start contributing to your cooperative to see treasury growth here.

+
) : ( - - - - - - - - - - - - - - - `$${formatAmount(v)}`} - /> - [ - `$${formatAmount(value)}`, - name, - ]} - /> - - - - +
+ + + + + + + + + + + + + + + `$${formatAmount(v)}`} + /> + [ + `$${formatAmount(value)}`, + name, + ]} + /> + + + + +
)}
); diff --git a/src/hooks/use-wallet.ts b/src/hooks/use-wallet.ts index f8530fe..708a116 100644 --- a/src/hooks/use-wallet.ts +++ b/src/hooks/use-wallet.ts @@ -4,16 +4,18 @@ import { useState, useCallback } from "react"; import { StellarWalletsKit, WalletNetwork, + allowAllModules, FREIGHTER_ID, - LOBSTR_ID, - xBullWalletId, } from "@creit.tech/stellar-wallets-kit"; -const kit = new StellarWalletsKit({ - network: WalletNetwork.TESTNET, - selectedWalletId: FREIGHTER_ID, - wallets: [FREIGHTER_ID, LOBSTR_ID, xBullWalletId], -}); +let kit: StellarWalletsKit | null = null; +if (typeof window !== "undefined") { + kit = new StellarWalletsKit({ + network: WalletNetwork.TESTNET, + selectedWalletId: FREIGHTER_ID, + modules: allowAllModules(), + }); +} export function useWallet() { const [address, setAddress] = useState(null); @@ -21,13 +23,17 @@ export function useWallet() { const [error, setError] = useState(null); const connect = useCallback(async () => { + if (!kit) { + setError("Wallet kit is not initialized"); + return; + } setIsConnecting(true); setError(null); try { await kit.openModal({ onWalletSelected: async (option) => { - kit.setWallet(option.id); - const { address: addr } = await kit.getAddress(); + kit!.setWallet(option.id); + const { address: addr } = await kit!.getAddress(); setAddress(addr); }, }); @@ -44,6 +50,7 @@ export function useWallet() { const signTransaction = useCallback(async (xdr: string) => { if (!address) throw new Error("Wallet not connected"); + if (!kit) throw new Error("Wallet kit is not initialized"); const { signedTxXdr } = await kit.signTransaction(xdr, { address, networkPassphrase: WalletNetwork.TESTNET, diff --git a/src/lib/stellar.ts b/src/lib/stellar.ts index b05b840..a30e038 100644 --- a/src/lib/stellar.ts +++ b/src/lib/stellar.ts @@ -25,7 +25,7 @@ export const SOROBAN_RPC_URL = export const server = new SorobanRpc.Server(SOROBAN_RPC_URL); export const networkPassphrase = - STELLAR_NETWORK === "MAINNET" + STELLAR_NETWORK === "PUBLIC" ? Networks.PUBLIC : Networks.TESTNET;