Skip to content

feat: Web Push notification integration (PWA) - #460

Open
only1isaac wants to merge 1 commit into
FinChippay:masterfrom
only1isaac:feature/push-notification-integration-377
Open

feat: Web Push notification integration (PWA)#460
only1isaac wants to merge 1 commit into
FinChippay:masterfrom
only1isaac:feature/push-notification-integration-377

Conversation

@only1isaac

Copy link
Copy Markdown
Contributor

Summary

Implements full Web Push notification support for the Finchippay PWA, addressing all acceptance criteria from issue #377.

Changes

Frontend

  • frontend/public/sw.js — push and notificationclick event handlers already present; confirmed working with new subscription flow
  • frontend/lib/pushNotifications.ts (NEW) — requestPermission(), subscribeUser(publicKey), unsubscribeUser(publicKey), isSubscribed() helpers; converts VAPID key via urlBase64ToUint8Array
  • frontend/components/PushNotificationPrompt.tsx (NEW) — Gentle opt-in banner shown after wallet connection; "Enable" / "Not Now" buttons; dismisses to localStorage so it doesn't re-nag
  • frontend/pages/_app.tsx — Imports and renders PushNotificationPrompt in AppShellInner (below InstallBanner)
  • frontend/.env.example — Added NEXT_PUBLIC_VAPID_PUBLIC_KEY

Backend

  • backend/src/services/pushService.js (NEW) — web-push powered VAPID sender; addSubscription / removeSubscription / sendNotification; auto-cleans expired (HTTP 410) subscriptions
  • backend/src/routes/push.js (NEW) — Three endpoints: GET /api/push/vapid-public-key, POST /api/push/subscribe, POST /api/push/unsubscribe; Zod validation + strictLimiter
  • backend/src/server.js — Mounts push routes at /api/push
  • backend/migrations/009_push_subscriptions.js (NEW) — Creates push_subscriptions table with public_key, endpoint, p256dh, auth, unique constraint on (public_key, endpoint)
  • backend/package.json — Added web-push@^3.6.7
  • backend/.env.example — Added VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY, VAPID_SUBJECT

Push Notification Triggers

  • backend/src/services/tipsService.js — Fires push to creator on tip receipt
  • backend/src/services/eventIndexer.js — Fires push for contract events: tip, escrow_create, escrow_claim, stream_open, stream_claim

Docs

  • ENV.md — Documented all VAPID backend and frontend env vars

Tests

  • backend/__tests__/pushService.test.js (NEW) — 21 passing tests covering addSubscription, removeSubscription, sendNotification (including 410 cleanup), and all three push route endpoints

Acceptance Criteria

Criteria Status
Users can enable push notifications from a prompt in the app ✅ PushNotificationPrompt in AppShellInner
Push notifications received when app is closed ✅ Service worker push handler + VAPID backend
Notification click opens app to relevant page ✅ notificationclick navigates to data.url
Subscriptions stored server-side and cleaned up on unsubscribe push_subscriptions table + remove endpoint
VAPID keys configurable via env vars ✅ VAPID_PUBLIC/PRIVATE_KEY + VAPID_SUBJECT
CI: backend tests cover push service ✅ 21 tests passing

Testing

Generate VAPID keys:

npx web-push generate-vapid-keys

Add to backend/.env and frontend/.env.local, then connect a wallet — the notification prompt will appear.

Closes #377

- Add push event and notificationclick handlers to service worker (sw.js)
- Create frontend/lib/pushNotifications.ts: requestPermission, subscribeUser,
  unsubscribeUser, isSubscribed helpers with VAPID key support
- Create frontend/components/PushNotificationPrompt.tsx: gentle opt-in prompt
  shown after wallet connect; respects user choice with localStorage dismiss
- Integrate PushNotificationPrompt into AppShellInner (_app.tsx)
- Create backend/src/services/pushService.js: web-push VAPID sender with
  addSubscription, removeSubscription, sendNotification; auto-removes
  expired (HTTP 410) subscriptions
- Create backend/src/routes/push.js: POST /api/push/subscribe,
  POST /api/push/unsubscribe, GET /api/push/vapid-public-key
- Mount push routes at /api/push in server.js
- Add migration 009_push_subscriptions.js: push_subscriptions table with
  public_key, endpoint, p256dh, auth columns and unique constraint
- Trigger push notifications on: tip received (tipsService), escrow_create,
  escrow_claim, stream_open, stream_claim contract events (eventIndexer)
- Add VAPID_PUBLIC_KEY, VAPID_PRIVATE_KEY, VAPID_SUBJECT to backend .env.example
- Add NEXT_PUBLIC_VAPID_PUBLIC_KEY to frontend .env.example
- Document all VAPID env vars in ENV.md
- Add 21 passing backend tests covering pushService and push routes

Closes FinChippay#377
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

@only1isaac is attempting to deploy a commit to the Topmatrixmor2014 Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[New] Push Notification Integration with Service Worker

1 participant