feat: live TVL and user metrics with 24h sparkline and /api/stats#12
Open
ijeoma270 wants to merge 1 commit into
Open
feat: live TVL and user metrics with 24h sparkline and /api/stats#12ijeoma270 wants to merge 1 commit into
ijeoma270 wants to merge 1 commit into
Conversation
Closes SmartDropLabs#7 - src/lib/stats.ts — fetchStats() queries the factory contract via Soroban RPC (stubbed with clear TODO) and falls back to plausible demo data until contracts are deployed; also exports StatsData type and formatUsd helper - src/app/api/stats/route.ts — GET /api/stats with Next.js 60-second revalidation so all clients share a cached response without hammering RPC - src/hooks/useStats.ts — react-query hook (refetchInterval: 60 s) that calls /api/stats when running in server mode; falls back to fetchStats() directly when the route is unavailable (static GitHub Pages export) - src/components/Sparkline/Sparkline.tsx — dependency-free SVG sparkline component with optional fill area and latest-point dot indicator - src/app/page.tsx — replaces hardcoded "30,738 / $302M / 213" with live data from useStats(); adds skeleton loading state, "Demo" badge (with tooltip) while contracts are undeployed, sparkline on the TVL card, and a "Last Updated" relative-time panel - next.config.ts — output: "export" now conditional on NEXT_EXPORT=true so the API route is active in server/Vercel deployments while GitHub Pages CI continues to produce the static out/ directory - deploy-github-pages.yml — sets NEXT_EXPORT=true in the build step
Contributor
|
Let me review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7
What changed
New files
src/lib/stats.tsfetchStats()— data layer; queries factory contract (stubbed with TODO for when it's deployed), falls back to realistic demo data; exportsStatsDatatypesrc/app/api/stats/route.tsGET /api/statswith 60-second Next.js revalidation — all clients share one cached responsesrc/hooks/useStats.tsuseStats()react-query hook; polls every 60 s; tries/api/statsfirst, falls back to directfetchStats()call so it works in static export toosrc/components/Sparkline/Sparkline.tsxModified files
src/app/page.tsx— replaces hardcoded30,738 / $302M / 213with live data fromuseStats(); adds Chakra skeleton loading state;Demobadge (with tooltip explaining contracts not yet deployed) on the TVL card; 24h SVG sparkline inline with TVL value; third panel swapped to "Last Updated" with relative-time label (just now,2m ago, …)next.config.ts—output: "export"now conditional onNEXT_EXPORT=true; unset = server mode, API routes active (Vercel /next start).github/workflows/deploy-github-pages.yml— addsNEXT_EXPORT: "true"to the build step so GitHub Pages CI still produces the staticout/directoryArchitecture
Wiring real data
When the factory contract is deployed, replace the TODO block in
src/lib/stats.tswith:The
Demobadge and its tooltip disappear automatically oncesource: "live"is returned.How to test