Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: notifications renewal [SW-631] #4699

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Open

Conversation

tmjssz
Copy link
Collaborator

@tmjssz tmjssz commented Dec 20, 2024

What it solves

Resolves SW-631

Displays a message prompting users to re-register their token with the new notification service.

Token Versioning

  • Introduces versioning for Firebase tokens, stored in local storage for each Safe.
  • Stores the latest token version for the corresponding Safes during a new token registration.

Warning Mechanism

  • Displays a warning on the notifications settings page for Safes with no version or outdated token versions.
  • Shows a one-time notification pop-up for affected Safes.

Token Renewal

  • When the user clicks the CTA:
    • If a specific Safe is loaded: tokens for all Safes with active notifications on the current Safe's chain are renewed.
    • On the global preferences page: tokens for all Safes across all chains are renewed.

Feature Flag

All logic is gated by the RENEW_NOTIFICATIONS_TOKEN feature flag.

How this PR fixes it

  • Added a new NotificationRenewal component to handle the renewal of notifications with a user interface for signing messages.
  • Introduced a new hook useNotificationsRenewal to manage the renewal of notifications, including functions to check if renewal is needed and to perform the renewal.
  • Added a hook useNotificationsTokenVersion to manage the token versions for notifications in local storage and to check if the renewal feature is enabled.
  • Updated the registration logic to set the token version to V2 upon successful registration.
  • Integrated the useNotificationsRenewal hook to show the renewal message when the app is opened.
  • Included the NotificationRenewal component in the push notifications settings page.
  • Merge Safes that need to be registered with those that need renewal on global settings page.

Additional changes

  • The notification link is enhanced to support a click handler for custom actions. This is needed to trigger the token renewal process from that link directly.
  • Update firebase dependency to version 11.1.0

How to test it

For a specific Safe

  1. Load a Safe with enabled push notifications
  2. Connect a wallet
  3. After connecting the wallet, a notification renewal pop-up should appear
  4. Navigate to the push notifications settings page for the current Safe
  5. Observe a warning indicating the need to renew the token at the top of the page
  6. Click on the "Sign" button in the pop-up or on the settings page
  7. Approve the signing request in your connected wallet
  8. Token should be renewed for all the the current chain's Safes that are enabled for push notifications
  9. The warning on settings page should disappear
  10. The pop-up should not be displayed again on page refresh

For the global settings

  1. Load the app and connect a signer who owns at least one Safe with enabled push notifications
  2. Navigate to the global push notifications settings page
  3. Observe a token renewal warning displayed at the top of the global settings page
  4. Clicking the CTA should renew the notifications for all the Safes selected (for each chain a message needs to be signed)

Screenshots

notifications-renewal-warning.mp4
Screenshot 2024-12-20 at 17 40 46

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

Copy link

Copy link

github-actions bot commented Dec 20, 2024

Copy link

github-actions bot commented Dec 20, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
74.04% (-0.05% 🔻)
14642/19777
🔴 Branches
51.43% (-0.2% 🔻)
3481/6769
🔴 Functions
56.97% (-0.1% 🔻)
2072/3637
🟡 Lines
75.57% (-0.06% 🔻)
13285/17579
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟡
... / useNotificationsTokenVersion.ts
73.33% 38.46% 60% 71.43%
🟡
... / useNotificationsRenewal.ts
69.35% 21.43% 46.67% 71.19%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / GlobalPushNotifications.tsx
61.97% (-0.41% 🔻)
39.71% 58.73%
59.04% (-0.42% 🔻)
🟢
... / useNotificationPreferences.ts
86.81% (+0.45% 🔼)
50% (+10% 🔼)
75.76% (-4.89% 🔻)
87.06% (+1.52% 🔼)
🟢
... / logic.ts
85% (-13.04% 🔻)
40% (-40% 🔻)
83.33% (-16.67% 🔻)
85.45% (-12.42% 🔻)
🔴
... / index.tsx
32.69% (-2.72% 🔻)
0% 0%
35.42% (-3.22% 🔻)

Test suite run success

1752 tests passing in 237 suites.

Report generated by 🧪jest coverage report action from 79b6be6

@katspaugh
Copy link
Member

@tmjssz please rebase to the new dev, the src folder got moved to apps/web.

@tmjssz tmjssz force-pushed the feat/notifications-renewal branch from 79b6be6 to f7aa0b5 Compare December 20, 2024 16:44
Copy link

github-actions bot commented Dec 20, 2024

Coverage report for apps/web

St.
Category Percentage Covered / Total
🟡 Statements
74.04% (-0.05% 🔻)
14642/19777
🔴 Branches
51.43% (-0.19% 🔻)
3481/6769
🔴 Functions
56.97% (-0.1% 🔻)
2072/3637
🟡 Lines
75.57% (-0.05% 🔻)
13285/17579
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟡
... / useNotificationsTokenVersion.ts
73.33% 38.46% 60% 71.43%
🟡
... / useNotificationsRenewal.ts
69.35% 21.43% 46.67% 71.19%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / GlobalPushNotifications.tsx
61.97% (-0.41% 🔻)
39.71% 58.73%
59.04% (-0.42% 🔻)
🟢
... / useNotificationPreferences.ts
86.81% (+0.45% 🔼)
50% (+10% 🔼)
75.76% (-4.89% 🔻)
87.06% (+1.52% 🔼)
🟢
... / logic.ts
85% (-13.04% 🔻)
40% (-40% 🔻)
83.33% (-16.67% 🔻)
85.45% (-12.42% 🔻)
🔴
... / index.tsx
32.69% (-2.72% 🔻)
0% 0%
35.42% (-3.22% 🔻)

Test suite run success

1752 tests passing in 237 suites.

Report generated by 🧪jest coverage report action from 1bae52d

Copy link

github-actions bot commented Dec 20, 2024

📦 Next.js Bundle Analysis for @safe-global/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 1.04 MB (🟡 +53.07 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Thirty-two Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/ 508 B (🟢 -2 B) 1.04 MB
/address-book 23.07 KB (🟡 +4 B) 1.06 MB
/apps 35.8 KB (🟡 +2.08 KB) 1.08 MB
/apps/custom 33.87 KB (🟡 +2.08 KB) 1.07 MB
/apps/open 55.59 KB (🟡 +1.98 KB) 1.1 MB
/balances 29.74 KB (🟡 +38 B) 1.07 MB
/balances/nfts 9.52 KB (🟢 -24 B) 1.05 MB
/bridge 2.56 KB (🟡 +1 B) 1.04 MB
/cookie 8.77 KB (🟡 +1 B) 1.05 MB
/home 61.38 KB (🟡 +2.12 KB) 1.1 MB
/new-safe/advanced-create 26.39 KB (🟢 -68 B) 1.07 MB
/new-safe/create 25.52 KB (🟢 -67 B) 1.07 MB
/new-safe/load 6.08 KB (🟢 -5 B) 1.05 MB
/privacy 14.57 KB (🟡 +2 B) 1.05 MB
/settings/appearance 2.25 KB (🟡 +2 B) 1.04 MB
/settings/environment-variables 3.27 KB (🟢 -1 B) 1.04 MB
/settings/modules 4.06 KB (🟡 +1 B) 1.04 MB
/settings/notifications 6.41 KB (🟢 -14.9 KB) 1.05 MB
/settings/safe-apps 20.35 KB (🟡 +2.08 KB) 1.06 MB
/settings/security 2.34 KB (🟡 +1 B) 1.04 MB
/settings/setup 30.69 KB (🟢 -46 B) 1.07 MB
/share/safe-app 7.56 KB (🟢 -5 B) 1.05 MB
/stake 618 B (🟢 -1 B) 1.04 MB
/swap 759 B (🟢 -1 B) 1.04 MB
/terms 12.93 KB (🟡 +1 B) 1.05 MB
/transactions 98.66 KB (🟡 +2.09 KB) 1.14 MB
/transactions/history 98.62 KB (🟡 +2.09 KB) 1.14 MB
/transactions/messages 60.27 KB (🟡 +1.97 KB) 1.1 MB
/transactions/msg 56.52 KB (🟡 +1.97 KB) 1.1 MB
/transactions/queue 49.38 KB (🟡 +1.98 KB) 1.09 MB
/transactions/tx 48.74 KB (🟡 +1.98 KB) 1.09 MB
/welcome/accounts 409 B (🟡 +2 B) 1.04 MB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@tmjssz tmjssz force-pushed the feat/notifications-renewal branch from 5f9ea3d to 1bae52d Compare December 21, 2024 14:17
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.

2 participants