From d22f04cb7c0dfa7e6ea2e855c730dcd306dd3a57 Mon Sep 17 00:00:00 2001 From: Omgiri01 <157702026+Omgiri01@users.noreply.github.com> Date: Tue, 2 Jun 2026 16:44:22 +0530 Subject: [PATCH] feat: Add transaction history page showing on-chain and demo SoroSave records --- src/app/history/page.tsx | 296 ++++++++++++++++++++++++++++++++++++++ src/components/Navbar.tsx | 6 + 2 files changed, 302 insertions(+) create mode 100644 src/app/history/page.tsx diff --git a/src/app/history/page.tsx b/src/app/history/page.tsx new file mode 100644 index 0000000..2d93a90 --- /dev/null +++ b/src/app/history/page.tsx @@ -0,0 +1,296 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { Navbar } from "@/components/Navbar"; +import { useWallet } from "@/app/providers"; + +interface Transaction { + id: string; + hash: string; + timestamp: string; + type: "Contribution" | "Payout" | "Group Join" | "Stellar Payment" | "Contract Invocation" | "Unknown"; + amount?: string; + successful: boolean; + memo?: string; +} + +export default function HistoryPage() { + const { address, isConnected } = useWallet(); + const [transactions, setTransactions] = useState([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + const [useDemoData, setUseDemoData] = useState(false); + + // SoroSave specific mock/demo transactions + const demoTransactions: Transaction[] = [ + { + id: "1", + hash: "7f7112ea1bc8328131e5fb5958619d854e4889c1682390a1e5cb5958619d854e", + timestamp: new Date(Date.now() - 3600000 * 2).toISOString(), // 2 hours ago + type: "Contribution", + amount: "50 XLM", + successful: true, + memo: "SoroSave Contribution - Cycle 2", + }, + { + id: "2", + hash: "82ea1bc8328131e5fb5958619d854e4889c1682390a1e5cb5958619d854e7f711", + timestamp: new Date(Date.now() - 3600000 * 24).toISOString(), // 1 day ago + type: "Group Join", + amount: "10 XLM", + successful: true, + memo: "SoroSave Join - Chit Fund Alpha", + }, + { + id: "3", + hash: "31e5fb5958619d854e4889c1682390a1e5cb5958619d854e7f71182ea1bc8328", + timestamp: new Date(Date.now() - 3600000 * 48).toISOString(), // 2 days ago + type: "Payout", + amount: "300 XLM", + successful: true, + memo: "SoroSave Payout - Cycle 1 Winner", + }, + ]; + + useEffect(() => { + if (!isConnected || !address || useDemoData) { + if (useDemoData) { + setTransactions(demoTransactions); + } else { + setTransactions([]); + } + return; + } + + const fetchHistory = async () => { + setLoading(true); + setError(null); + try { + const response = await fetch( + `https://horizon-testnet.stellar.org/accounts/${address}/transactions?order=desc&limit=20` + ); + if (!response.ok) { + throw new Error("Failed to fetch transaction history from Horizon."); + } + const data = await response.json(); + const records = data._embedded.records; + + const parsedTxs: Transaction[] = records.map((record: any) => { + let type: Transaction["type"] = "Contract Invocation"; + let amount = undefined; + + // Parse transaction details + if (record.memo) { + if (record.memo.toLowerCase().includes("contribution")) { + type = "Contribution"; + } else if (record.memo.toLowerCase().includes("payout")) { + type = "Payout"; + } else if (record.memo.toLowerCase().includes("join")) { + type = "Group Join"; + } + } + + // Format timestamp + const timestamp = record.created_at; + + return { + id: record.id, + hash: record.hash, + timestamp, + type, + amount, + successful: record.successful, + memo: record.memo, + }; + }); + + setTransactions(parsedTxs); + } catch (err: any) { + console.error("Error fetching transactions:", err); + setError("Could not retrieve live on-chain history. Showing demo transactions instead."); + setTransactions(demoTransactions); + } finally { + setLoading(false); + } + }; + + fetchHistory(); + }, [address, isConnected, useDemoData]); + + return ( + <> + +
+
+
+

+ Transaction History +

+

+ Review your on-chain interactions, contributions, and SoroSave payouts. +

+
+ {isConnected && ( +
+ +
+ )} +
+ + {!isConnected ? ( +
+ +

Wallet not connected

+

+ Please connect your Freighter wallet in the navigation bar to view your transaction history. +

+
+ ) : loading ? ( +
+
+
+ ) : error && transactions.length === 0 ? ( +
+
+
+ +
+
+

{error}

+
+
+
+ ) : transactions.length === 0 ? ( +
+ +

No transactions yet

+

+ This account does not have any transactions on Stellar Testnet yet. You can toggled the "Show Demo SoroSave Data" button above to view sample transactions. +

+
+ ) : ( +
+ +
+ )} +
+ + ); +} diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 2d673aa..9b1e5b3 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -25,6 +25,12 @@ export function Navbar() { > Create Group + + History +