Skip to content

Conversation

@nicosampler
Copy link

@nicosampler nicosampler commented Jan 11, 2026

⚠️ Proof of Concept: Client-Side Notifications (PWA)

Status: Experimental / Do Not Merge

Motivation

This PR explores a feature I believe would be a valuable addition to the Morpho app: automated user notifications. As a user, I want to be alerted about critical changes to my positions - such as a Health Factor dropping below a specific threshold or a significant dip in APY for supplied assets - without constantly monitoring the interface.

While there are existing solutions that solve this via server-side monitoring and messaging layers (Email, Telegram, etc.), they typically require sacrificing privacy by sharing user data with a centralized service.

Proposed Solution

I propose a privacy-first, client-side solution leveraging Progressive Web App (PWA) capabilities and Service Workers.
By converting the Morpho app into a PWA, we can run background processes locally on the user's device. This allows for:

  • Anonymity: No need to register an email or link a wallet. Users can simply track an address (Watch Mode).
  • Local Execution: All checks happen in the browser's background thread, preserving data sovereignty.
  • Native Experience: Notifications are delivered via the system's native notification center (desktop or mobile).

Future UX Vision

While this PR focuses on the underlying architecture, I envision the final implementation featuring a "Notification Center" (e.g., a Bell icon in the header).
This UI component would allow users to:

  • Global enabling/disabling of notifications.
  • Granularly toggle specific alert types (e.g., "Notify me if HF < X" or "Notify me if Supply APY < Y%").
  • Configure different thresholds for different notifications.
  • Configure the frequency of checks to balance battery life/data usage.
  • Manage permissions directly from the interface.

Implementation Overview

This PR demonstrates the feasibility of this architecture through three main steps:

  1. PWA Transformation: Configures the dApp to be installable and register a Service Worker.
  2. Notification Architecture: Defines the base architecture to make app notifications work in the background.
  3. Feature Implementation: Implements the Health Factor notification logic.

Technical Notes, Trade-offs & Workarounds

  • Viem Compatibility: I encountered issues using viem directly within the Service Worker due to restricted dynamic imports in that environment.
    • Workaround: I utilized the Multicall contract triggered via a raw RPC eth_call. This required adjustments to the wagmi-config.
  • Code Duplication: Due to the Service Worker's inability to access React Context or Hooks, some logic from the borrow-subpage hooks had to be duplicated/re-implemented for the worker context. A future refactor would be needed to abstract this shared logic into pure TS functions compatible with both environments.
  • Hardcoded Thresholds: For testing purposes, the Health Factor threshold is currently hardcoded to 5. This allows testing the notification flow by taking a real, low-risk loan (high HF) and still receiving the alert immediately.
  • File Structure: Some logic has been placed within existing files for simplicity. In a production-ready version, this code should be modularized into dedicated services.
  • Permissions UX: Currently, permission requests are triggered immediately upon load for demonstration purposes. Ideally, this should be moved to a user action (toggle) to avoid intrusive UX patterns.
  • RPC Scalability: Running frequent eth_call polling from every client's background worker could strain public RPC endpoints. A production version could allow the user to input their own custom RPC URL to avoid rate limits.

- Integrated VitePWA plugin in vite.config.ts with a manifest for the Morpho Lite app.
- Updated package.json to include vite-plugin-pwa dependency.
- Included InstallBanner component in header.tsx for user installation prompts.
@vercel
Copy link

vercel bot commented Jan 11, 2026

@nicosampler is attempting to deploy a commit to the Morpho Association Team on Vercel.

A member of the Team first needs to authorize it.

@nicosampler nicosampler force-pushed the user-notifications branch 2 times, most recently from 88169fd to 33c34b2 Compare January 12, 2026 01:30
- Added a PWAProvider to manage PWA installation and notification permissions.
- Refactored InstallBanner to use the new usePWA hook.
- Implemented a service worker for user notifications.
- Added demo jobs to handle health factors and market yields (no real functionality, only to show how it could work).
- Created utility functions for sending notifications and managing job states in the service worker.
- Replaced the existing job handlers for health factors and market yields with new implementations.
- Introduced a dedicated handler for health factor checks, which calculates and monitors health factors for user positions.
- Updated the service worker to utilize the new health factor handler and adjusted job scheduling intervals.
- Added a new job for market yield checks, with a placeholder for future implementation.
- Removed obsolete job files and notification utility functions to streamline the user notifications architecture.
@nicosampler nicosampler changed the title feat(lite): add native user notifications feat(lite): ⚠️ Proof of Concept: Client-Side Notifications (PWA) Jan 12, 2026
@nicosampler nicosampler marked this pull request as ready for review January 12, 2026 02:18
@nicosampler
Copy link
Author

Hello @garethfuller @haydenshively @cashd 👋🏾

Sorry to tag you directly! As an external contributor, I wasn't sure of the best channel to introduce this idea to the team. I would love to hear your opinions on this approach whenever you have a moment.

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.

1 participant