Low-balance push notifications + Safari payment history pagination fix - #716
Merged
Dev-AdeTutu merged 2 commits intoAug 25, 2026
Merged
Conversation
Add browser push notifications for low meter balance and fix payment
history pagination breaking after scroll in Safari.
- Backend: SQLite-backed push subscription store, VAPID-based Web Push
sender, and /api/push/{config,subscribe,unsubscribe} endpoints.
- Backend: dynamic low-balance threshold (10% of trailing 7-day typical
weekly usage, falling back to LOW_BALANCE_THRESHOLD when no history
exists), wired into the IoT bridge's low-balance check and exposed on
the meter balance endpoint.
- Frontend: service worker (public/sw.js) that renders push
notifications with a "Top Up" action routing to /pay, and a
pushService that requests notification permission on first dashboard
visit and subscribes once a meter's balance crosses the low-balance
threshold.
- Frontend: rewired payment history pagination to use the URL page
param as the source of truth with explicit Prev/Next handlers
instead of scroll/IntersectionObserver-driven state, fixing Safari
pagination becoming unresponsive after scrolling past 50 rows.
- Fixed a pre-existing build failure on /history and
/dashboard/provider (useSearchParams used without a Suspense
boundary) that was breaking `next build`.
|
@Onomebello Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
This PR delivers two user-facing improvements:
Problem
Users only discovered low balances after manually checking dashboards, causing avoidable service interruptions. In addition, payment history pagination could become non-functional after scrolling in Safari, with no API request fired and URL page state not updating consistently.
What Changed
Frontend
/historyand/dashboard/provideruseduseSearchParams()without aSuspenseboundary, which madenext buildfail with a prerender/export error (unrelated to this PR's business logic, but blocking any build that touches these routes). Wrapped both pages' bodies inSuspenseso the build succeeds again.Backend
GET /api/push/configPOST /api/push/subscribePOST /api/push/unsubscribethreshold = 10% of typical weekly usage (last 7 days)LOW_BALANCE_THRESHOLDwhen insufficient history exists.Docs / Config
.env.example.Files of Interest
src/app/history/page.tsxsrc/app/dashboard/user/page.tsxsrc/services/pushService.tspublic/sw.jspublic/icons/push-warning.svgpublic/icons/push-badge.svg../backend/src/routes/pushSubscriptions.ts../backend/src/lib/pushNotifications.ts../backend/src/lib/pushSubscriptions.ts../backend/src/iot/bridge.ts../backend/src/lib/usageEvents.ts../backend/src/routes/meters.ts../backend/src/index.tsTesting / Validation
cd backend && npm run build.web-push).cd frontend && npx tsc --noEmit, excluding pre-existing test-file type errors from missing Jest type defs, unrelated to this change).cd frontend && npm run build, exit code 0) after the Suspense fix.frontend/npm testrun: pre-existing failures inOfflinePaymentModal.test.tsxandAllowlistPanel.test.tsx(missing unrelated modules@/hooks/useOffline,@/services/allowlistService) are unaffected by this change; all other suites pass (19/19 tests).Operational Notes
WEB_PUSH_VAPID_SUBJECTWEB_PUSH_VAPID_PUBLIC_KEYWEB_PUSH_VAPID_PRIVATE_KEYRisk Assessment
Follow-ups
Add targeted unit/integration tests for:
this pr closes [Feature] Add browser push notifications for low balance alerts #701
this pr closes [Bug] Payment history pagination breaks with infinite scroll #702