feat: Yield Dashboard with Real-Time Oracle Price Feeds and Charting#159
Open
ZuLu0890 wants to merge 1 commit into
Open
feat: Yield Dashboard with Real-Time Oracle Price Feeds and Charting#159ZuLu0890 wants to merge 1 commit into
ZuLu0890 wants to merge 1 commit into
Conversation
…griTrust-Protocol#82) Implements a real-time yield dashboard providing farmers with: - Live oracle price feeds via WebSocket (wss://oracle.agritrust.io/ws/prices) - Interactive OHLC charting with time range selector (recharts) - Farm-level KPI grid with SVG sparklines and trend indicators - Configurable price threshold alerts with browser notifications - Offline IndexedDB cache with staleness detection - Signal-based reactive store architecture (createSignal/createComputed) New files (11): - src/types/prices.ts — price, OHLC, alert, KPI, WebSocket message types - src/services/priceCache.ts — IndexedDB offline cache - src/stores/priceFeedStore.ts — signal-based reactive store - src/hooks/usePriceFeed.ts — WebSocket hook with auto-reconnect - src/hooks/useAlertConfig.ts — alert CRUD with localStorage persistence - src/components/dashboard/Sparkline.tsx — SVG sparkline mini-chart - src/components/dashboard/PriceFeedCard.tsx — crop price display - src/components/dashboard/PriceChart.tsx — OHLC chart with volume - src/components/dashboard/KpiGrid.tsx — farm KPI metrics grid - src/components/dashboard/YieldDashboard.tsx — main integration page - src/components/dashboard/__tests__/yieldDashboard.test.tsx — 28 tests Modified (4): - app/dashboard/page.tsx — dynamic import + FeatureGate - vitest.config.ts — @ path alias for tests - package.json — fix react-leaflet version CI: ESLint clean, TypeScript clean, 28/28 tests passing Closes AgriTrust-Protocol#82
Author
|
Done, the CI failures are from the main repo project, Please check and compare |
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.
PR: Yield Dashboard with Real-Time Oracle Price Feeds and Charting
Closes #82
Summary
Implements a real-time yield dashboard providing farmers with live oracle price feeds, interactive OHLC charting, farm-level KPIs with sparklines, configurable price threshold alerts (browser notifications), offline IndexedDB caching, and connection health monitoring — all built on the project's existing signal-based reactive architecture.
Changes at a Glance
src/types/prices.tssrc/services/priceCache.tssrc/stores/priceFeedStore.tssrc/hooks/usePriceFeed.ts,src/hooks/useAlertConfig.tsSparkline.tsx,PriceFeedCard.tsx,PriceChart.tsx,KpiGrid.tsx,YieldDashboard.tsxsrc/components/dashboard/__tests__/yieldDashboard.test.tsxapp/dashboard/page.tsx,vitest.config.ts,package.json,package-lock.jsonArchitecture
Data Flow
certificationStore.tspattern usingcreateSignal/createComputedfromsrc/services/reactive/. Components subscribe viauseSignal()for tear-free concurrent rendering.idblibrary (matchingindexedDbStore.tsconventions) for offline persistence of price maps and OHLC historical data.rechartsdependency (matchingTelemetryChart.tsx/YieldHistogram.tsxpatterns) withResponsiveContainerfor responsive sizing.YieldDashboardis dynamically imported vianext/dynamicwithssr: falseand gated behind the existingFeatureGate('analytics').Feature Details
1. Real-Time Price Feeds (
usePriceFeed.ts)wss://oracle.agritrust.io/ws/pricesvia WebSocketerrorif no heartbeat received in 20sprice_updatemessage, evaluates all enabled alerts and triggersNotificationAPIuseOnlineStatus; when offline, closes WebSocket and serves cached datadisconnected → connecting → connected / reconnecting / error2. Price Feed Cards (
PriceFeedCard.tsx)role="button",tabIndex={0},Enter/Spaceto select3. OHLC Price Chart (
PriceChart.tsx)ResponsiveContainerfilling parent container4. Farm-Level KPIs (
KpiGrid.tsx, computed inpriceFeedStore.ts)5. Price Alerts (
useAlertConfig.ts)NotificationAPI when threshold is breached6. Offline Mode (
priceCache.ts)idb7. SVG Sparklines (
Sparkline.tsx)useId()for unique gradient IDs — no SVG ID collisionsTechnical Invariants Met
usePriceFeedsubscribes via WebSocket; merges intopriceMap$signalrechartswithisAnimationActive={false}for 60fps interactionsohlcData$signal keyed by pair; merged and cached in IndexedDBdataFreshness$computed signal; amber "Stale" badge onPriceFeedCardpriceCache.tspersists to IndexedDB; stale indicator when offlineuseAlertConfigwith localStorage persistence and Notification APINotificationAPI inusePriceFeedmessage handlerCI Verification
Test Coverage
MockWebSocketclass, fake-indexeddb, rechartsResponsiveContainermockFiles Changed
New Files (11)
src/types/prices.tsPriceTick,PriceMap,OHLCBar,PriceAlert,FarmKpi,DataFreshness,PriceFeedWSMessage(discriminated union),ConnectionStatesrc/services/priceCache.tsidb:cachePriceMap(),getCachedPriceMap(),cacheOHLCBars(),getCachedOHLCBars()src/stores/priceFeedStore.tspriceMap$,connectionState$,alerts$,ohlcData$,dataFreshness$(computed),kpis$(computed)src/hooks/usePriceFeed.tssrc/hooks/useAlertConfig.tssrc/components/dashboard/Sparkline.tsxuseId()for unique IDssrc/components/dashboard/PriceFeedCard.tsxsrc/components/dashboard/PriceChart.tsxsrc/components/dashboard/KpiGrid.tsxsrc/components/dashboard/YieldDashboard.tsxsrc/components/dashboard/__tests__/yieldDashboard.test.tsxModified Files (4)
app/dashboard/page.tsxYieldDashboardimport behindFeatureGate('analytics')vitest.config.tsresolve.aliasfor@→ project root@/path aliasespackage.jsonreact-leafletversion^4.2.2→^4.2.1npm installpackage-lock.jsonKnown Gaps / Future Work
These are acknowledged with
TODOcomments inYieldDashboard.tsx:/api/insurance/policiesendpoint./api/settlements/pendingendpoint.emailNotificationsEnabledtoggle exists in the UI but no email-sending service is wired up. Requires email provider integration (SendGrid, SES, etc.).InternationalizedTextkeys (dashboard.yield.title,dashboard.yield.livePrices,dashboard.priceChart.title,dashboard.kpi.noData) need to be registered in the i18n translation system.Testing Instructions
Screenshots
Dashboard layout: