Skip to content

feat(notifications): implement real-time on-chain sale notifications (#9) - #19

Open
Simultech369 wants to merge 1 commit into
Crate-Protocol:mainfrom
Simultech369:feat/sale-notifications
Open

feat(notifications): implement real-time on-chain sale notifications (#9)#19
Simultech369 wants to merge 1 commit into
Crate-Protocol:mainfrom
Simultech369:feat/sale-notifications

Conversation

@Simultech369

Copy link
Copy Markdown

Summary of Changes

This pull request resolves #9 by implementing an on-chain event-driven notification subsystem for producers in crate-frontend, complete with Soroban RPC event polling, cursor persistence, navbar dropdown indicators, and real-time sale toasts.

🎯 Key Implementations

  1. Soroban Event Poller & Notification State Hook (src/hooks/useNotifications.ts)

    • Implements useNotifications hook polling Soroban RPC getEvents for purchase_license and withdraw_earnings topics.
    • Persists the last processed ledger cursor in localStorage (crate_events_cursor_${address}).
    • Scopes notification records and read/unread state per connected wallet address (crate_notifications_${address}).
    • Gracefully no-ops when contract ID or wallet connection is absent.
  2. Navbar Notification Dropdown (src/components/NotificationDropdown.tsx)

    • Bell icon button with dynamic unread count badge.
    • Dropdown panel showing relative time ago (Just now, 5m ago, 2d ago), sample title, amount in XLM, unread indicators, "Mark read" and "Clear" actions.
  3. In-App Toast Alerts

    • Automatically surfaces in-app toast notifications with audio/visual flair when a new license purchase is detected on-chain while connected.
  4. Testing & Validation (src/__tests__/notifications.test.ts)

    • Unit tests covering per-wallet storage isolation, read/unread state toggles, and cursor advancing.

🧪 Verification & Testing

  • npx vitest run:

…rate-Protocol#9)

- Create useNotifications hook with Soroban RPC event polling (getEvents)
- Add persisted cursor and notification state scoped per connected wallet
- Implement NotificationDropdown with unread badge, relative timestamps, and mark as read actions
- Integrate real-time toast alerts on incoming sales
- Add unit tests verifying persistence, read state toggles, and cursor updates
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.

feat: real-time on-chain sale notifications for producers

1 participant