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 22 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

Caution

Test run failed

St.
Category Percentage Covered / Total
🟡 Statements
74.24% (+0.13% 🔼)
14691/19789
🔴 Branches
51.88% (+0.18% 🔼)
3508/6762
🔴 Functions
57.33% (+0.22% 🔼)
2085/3637
🟡 Lines
75.77% (+0.13% 🔼)
13328/17589
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / useNotificationsTokenVersion.ts
100% 92.31% 100% 100%
🟢
... / useNotificationsRenewal.ts
100% 94.44% 100% 100%
🟢
... / constants.ts
100% 100% 100% 100%
🟢
... / useShowNotificationsRenewalMessage.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / safe-migrations.ts
97.44% (-0.13% 🔻)
88.89% (+1.39% 🔼)
100%
97.3% (-0.14% 🔻)
🔴
... / GlobalPushNotifications.tsx
61.97% (-0.41% 🔻)
39.71% 58.73%
59.04% (-0.42% 🔻)
🟡
... / index.tsx
61.54% (-21.79% 🔻)
0% (-66.67% 🔻)
0% (-66.67% 🔻)
66.67% (-21.57% 🔻)
🔴
... / index.tsx
32.69% (-2.72% 🔻)
0% 0%
35.42% (-3.22% 🔻)

Test suite run failed

Failed tests: 5/1782. Failed suites: 3/240.
  ● ConfirmationView › should display a confirmation screen for a SETTINGS_CHANGE transaction

    expect(received).toMatchSnapshot()

    Snapshot name: `ConfirmationView should display a confirmation screen for a SETTINGS_CHANGE transaction 1`

    - Snapshot  - 9
    + Received  + 9

    @@ -121,19 +121,19 @@
              style="--Paper-shadow: none;"
            >
              <h3
                class="MuiAccordion-heading css-cy7rkm-MuiAccordion-heading"
              >
    -           <div
    +           <button
                  aria-expanded="false"
    -             class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-6csn7x-MuiButtonBase-root-MuiAccordionSummary-root"
    +             class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-10sjung-MuiButtonBase-root-MuiAccordionSummary-root"
                  data-testid="decoded-tx-summary"
    -             role="button"
                  tabindex="0"
    +             type="button"
                >
    -             <div
    -               class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1pnrdlh-MuiAccordionSummary-content"
    +             <span
    +               class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1r0e0ir-MuiAccordionSummary-content"
                  >
                    Advanced details
                    <span
                      class=""
                      data-mui-internal-clone-element="true"
    @@ -146,12 +146,12 @@
                    </span>
                    <div
                      class="MuiBox-root css-i9gxme"
                    />
                    addOwnerWithThreshold
    -             </div>
    -             <div
    +             </span>
    +             <span
                    class="MuiAccordionSummary-expandIconWrapper css-1wqf3nl-MuiAccordionSummary-expandIconWrapper"
                  >
                    <svg
                      aria-hidden="true"
                      class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1dhtbeh-MuiSvgIcon-root"
    @@ -161,12 +161,12 @@
                    >
                      <path
                        d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"
                      />
                    </svg>
    -             </div>
    -           </div>
    +             </span>
    +           </button>
              </h3>
              <div
                class="MuiCollapse-root MuiCollapse-vertical MuiCollapse-hidden css-cwrbtg-MuiCollapse-root"
                style="min-height: 0px;"
              >

      116 |     )
      117 |
    > 118 |     expect(container).toMatchSnapshot()
          |                       ^
      119 |   })
      120 |
      121 |   it("should display a confirmation with method call when the transaction type is not found in the ConfirmationView's mapper", () => {

      at Object.toMatchSnapshot (src/components/tx/confirmation-views/ConfirmationView.test.tsx:118:23)

  ● ConfirmationView › should display a confirmation with method call when the transaction type is not found in the ConfirmationView's mapper

    expect(received).toMatchSnapshot()

    Snapshot name: `ConfirmationView should display a confirmation with method call when the transaction type is not found in the ConfirmationView's mapper 1`

    - Snapshot  - 9
    + Received  + 9

    @@ -10,19 +10,19 @@
              style="--Paper-shadow: none;"
            >
              <h3
                class="MuiAccordion-heading css-cy7rkm-MuiAccordion-heading"
              >
    -           <div
    +           <button
                  aria-expanded="false"
    -             class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-6csn7x-MuiButtonBase-root-MuiAccordionSummary-root"
    +             class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-10sjung-MuiButtonBase-root-MuiAccordionSummary-root"
                  data-testid="decoded-tx-summary"
    -             role="button"
                  tabindex="0"
    +             type="button"
                >
    -             <div
    -               class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1pnrdlh-MuiAccordionSummary-content"
    +             <span
    +               class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1r0e0ir-MuiAccordionSummary-content"
                  >
                    Advanced details
                    <span
                      class=""
                      data-mui-internal-clone-element="true"
    @@ -35,12 +35,12 @@
                    </span>
                    <div
                      class="MuiBox-root css-i9gxme"
                    />
                    addOwnerWithThreshold
    -             </div>
    -             <div
    +             </span>
    +             <span
                    class="MuiAccordionSummary-expandIconWrapper css-1wqf3nl-MuiAccordionSummary-expandIconWrapper"
                  >
                    <svg
                      aria-hidden="true"
                      class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1dhtbeh-MuiSvgIcon-root"
    @@ -50,12 +50,12 @@
                    >
                      <path
                        d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"
                      />
                    </svg>
    -             </div>
    -           </div>
    +             </span>
    +           </button>
              </h3>
              <div
                class="MuiCollapse-root MuiCollapse-vertical MuiCollapse-hidden css-cwrbtg-MuiCollapse-root"
                style="min-height: 0px;"
              >

      131 |     )
      132 |
    > 133 |     expect(container).toMatchSnapshot()
          |                       ^
      134 |   })
      135 | })
      136 |

      at Object.toMatchSnapshot (src/components/tx/confirmation-views/ConfirmationView.test.tsx:133:23)


  ● SignOrExecute › should display a confirmation screen

    expect(received).toMatchSnapshot()

    Snapshot name: `SignOrExecute should display a confirmation screen 1`

    - Snapshot  - 9
    + Received  + 9

    @@ -17,19 +17,19 @@
                  style="--Paper-shadow: none;"
                >
                  <h3
                    class="MuiAccordion-heading css-cy7rkm-MuiAccordion-heading"
                  >
    -               <div
    +               <button
                      aria-expanded="false"
    -                 class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-6csn7x-MuiButtonBase-root-MuiAccordionSummary-root"
    +                 class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-10sjung-MuiButtonBase-root-MuiAccordionSummary-root"
                      data-testid="decoded-tx-summary"
    -                 role="button"
                      tabindex="0"
    +                 type="button"
                    >
    -                 <div
    -                   class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1pnrdlh-MuiAccordionSummary-content"
    +                 <span
    +                   class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1r0e0ir-MuiAccordionSummary-content"
                      >
                        Advanced details
                        <span
                          class=""
                          data-mui-internal-clone-element="true"
    @@ -41,12 +41,12 @@
                          />
                        </span>
                        <div
                          class="MuiBox-root css-i9gxme"
                        />
    -                 </div>
    -                 <div
    +                 </span>
    +                 <span
                        class="MuiAccordionSummary-expandIconWrapper css-1wqf3nl-MuiAccordionSummary-expandIconWrapper"
                      >
                        <svg
                          aria-hidden="true"
                          class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1dhtbeh-MuiSvgIcon-root"
    @@ -56,12 +56,12 @@
                        >
                          <path
                            d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"
                          />
                        </svg>
    -                 </div>
    -               </div>
    +                 </span>
    +               </button>
                  </h3>
                  <div
                    class="MuiCollapse-root MuiCollapse-vertical MuiCollapse-hidden css-cwrbtg-MuiCollapse-root"
                    style="min-height: 0px;"
                  >

      54 |
      55 |     expect(getByTestId('sign-btn')).toBeInTheDocument()
    > 56 |     expect(container).toMatchSnapshot()
         |                       ^
      57 |   })
      58 |
      59 |   it('should display an error screen', async () => {

      at Object.toMatchSnapshot (src/components/tx/SignOrExecuteForm/__tests__/SignOrExecute.test.tsx:56:23)

  ● SignOrExecute › should display an error screen

    expect(received).toMatchSnapshot()

    Snapshot name: `SignOrExecute should display an error screen 1`

    - Snapshot  - 9
    + Received  + 9

    @@ -17,19 +17,19 @@
                  style="--Paper-shadow: none;"
                >
                  <h3
                    class="MuiAccordion-heading css-cy7rkm-MuiAccordion-heading"
                  >
    -               <div
    +               <button
                      aria-expanded="false"
    -                 class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-6csn7x-MuiButtonBase-root-MuiAccordionSummary-root"
    +                 class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-10sjung-MuiButtonBase-root-MuiAccordionSummary-root"
                      data-testid="decoded-tx-summary"
    -                 role="button"
                      tabindex="0"
    +                 type="button"
                    >
    -                 <div
    -                   class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1pnrdlh-MuiAccordionSummary-content"
    +                 <span
    +                   class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1r0e0ir-MuiAccordionSummary-content"
                      >
                        Advanced details
                        <span
                          class=""
                          data-mui-internal-clone-element="true"
    @@ -41,12 +41,12 @@
                          />
                        </span>
                        <div
                          class="MuiBox-root css-i9gxme"
                        />
    -                 </div>
    -                 <div
    +                 </span>
    +                 <span
                        class="MuiAccordionSummary-expandIconWrapper css-1wqf3nl-MuiAccordionSummary-expandIconWrapper"
                      >
                        <svg
                          aria-hidden="true"
                          class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1dhtbeh-MuiSvgIcon-root"
    @@ -56,12 +56,12 @@
                        >
                          <path
                            d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"
                          />
                        </svg>
    -                 </div>
    -               </div>
    +                 </span>
    +               </button>
                  </h3>
                  <div
                    class="MuiCollapse-root MuiCollapse-vertical MuiCollapse-hidden css-cwrbtg-MuiCollapse-root"
                    style="min-height: 0px;"
                  >

      73 |
      74 |     expect(container.querySelector('sign-btn')).not.toBeInTheDocument()
    > 75 |     expect(container).toMatchSnapshot()
         |                       ^
      76 |   })
      77 | })
      78 |

      at Object.toMatchSnapshot (src/components/tx/SignOrExecuteForm/__tests__/SignOrExecute.test.tsx:75:23)


  ● BatchTransactions › should render a list of batch transactions

    expect(received).toMatchSnapshot()

    Snapshot name: `BatchTransactions should render a list of batch transactions 1`

    - Snapshot  - 9
    + Received  + 9

    @@ -15,18 +15,18 @@
              style="--Paper-shadow: none;"
            >
              <h3
                class="MuiAccordion-heading css-cy7rkm-MuiAccordion-heading"
              >
    -           <div
    +           <button
                  aria-expanded="false"
    -             class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-6csn7x-MuiButtonBase-root-MuiAccordionSummary-root"
    -             role="button"
    +             class="MuiButtonBase-root MuiAccordionSummary-root MuiAccordionSummary-gutters accordion css-10sjung-MuiButtonBase-root-MuiAccordionSummary-root"
                  tabindex="0"
    +             type="button"
                >
    -             <div
    -               class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1pnrdlh-MuiAccordionSummary-content"
    +             <span
    +               class="MuiAccordionSummary-content MuiAccordionSummary-contentGutters css-1r0e0ir-MuiAccordionSummary-content"
                  >
                    <div
                      class="MuiBox-root css-mvjamn"
                    >
                      <div
    @@ -58,12 +58,12 @@
                             
                          </b>
                        </span>
                      </div>
                    </div>
    -             </div>
    -             <div
    +             </span>
    +             <span
                    class="MuiAccordionSummary-expandIconWrapper css-1wqf3nl-MuiAccordionSummary-expandIconWrapper"
                  >
                    <svg
                      aria-hidden="true"
                      class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1dhtbeh-MuiSvgIcon-root"
    @@ -73,12 +73,12 @@
                    >
                      <path
                        d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z"
                      />
                    </svg>
    -             </div>
    -           </div>
    +             </span>
    +           </button>
              </h3>
              <div
                class="MuiCollapse-root MuiCollapse-vertical MuiCollapse-hidden css-cwrbtg-MuiCollapse-root"
                style="min-height: 0px;"
              >

      10 |     const { container, getByText } = render(<BatchTransactions />)
      11 |
    > 12 |     expect(container).toMatchSnapshot()
         |                       ^
      13 |     expect(getByText('GnosisSafeProxy')).toBeDefined()
      14 |   })
      15 | })

      at Object.toMatchSnapshot (src/components/tx/confirmation-views/BatchTransactions/BatchTransactions.test.tsx:12:23)

Report generated by 🧪jest coverage report action from c93846d

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.21 KB (🟡 +142 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.57 KB (🟡 +1.96 KB) 1.09 MB
/balances 29.88 KB (🟡 +176 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.38 KB (🟢 -75 B) 1.07 MB
/new-safe/create 25.52 KB (🟢 -74 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.91 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.82 KB (🟡 +92 B) 1.07 MB
/share/safe-app 7.56 KB (🟢 -5 B) 1.05 MB
/stake 618 B (🟢 -1 B) 1.04 MB
/swap 764 B (🟡 +4 B) 1.04 MB
/terms 12.93 KB (🟡 +1 B) 1.05 MB
/transactions 99.47 KB (🟡 +2.9 KB) 1.14 MB
/transactions/history 99.43 KB (🟡 +2.9 KB) 1.14 MB
/transactions/messages 60.26 KB (🟡 +1.96 KB) 1.1 MB
/transactions/msg 56.51 KB (🟡 +1.96 KB) 1.1 MB
/transactions/queue 49.37 KB (🟡 +1.97 KB) 1.09 MB
/transactions/tx 48.73 KB (🟡 +1.96 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
Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 🚀

Copy link

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!
Looks good but some tests are failing. Nvm, it's the GitHub Action itself not the tests.

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