Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

refactor: cleanup notifications system #3926

Merged
merged 5 commits into from
Jun 8, 2022
Merged

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented May 30, 2022

What it solves

An introduction to safe-global/safe-pm#83

How this PR fixes it

The current notification system has been refactored:

  • Notistack upgraded to the newest MUI4-supporting version.
  • System has been simplified: the new actions are showNotification, close/closeAllNotification(s) and delete/deleteAllNotification(s) and the syntax follows Notistack as closely as possible.
  • Immutable has been removed from the notifications store.
  • Notifications are now cached for later retrieval.

None of the above adjustments should yet reflect/alter the UI in it's current state.

How to test it

Interact with the Safe and observe notifications functioning as before.

One notable notification to check, which includes an onClick handler, is dispatched when the Safe requires an update. I removed some unnecessary code that is responsible for address book interaction notifications. They should still work as before as well.

@iamacook iamacook requested review from katspaugh and usame-algan May 30, 2022 12:32
@iamacook iamacook self-assigned this May 30, 2022
@github-actions
Copy link

CLA Assistant Lite All Contributors have signed the CLA.

Comment on lines +23 to +72
const notificationsReducer = handleActions<NotificationsState, Notification | KeyPayload>(
{
[NOTIFICATION_ACTIONS.SHOW]: (state, { payload }: Action<Notification>) => {
// getNotificationsFromTxType can return `null` notifications
return payload ? [...state, payload] : state
},
[NOTIFICATION_ACTIONS.CLOSE]: (state, { payload }: Action<KeyPayload>) => {
return state.map((notification) => {
return notification.options?.key === payload.key ? { ...notification, dismissed: true } : notification
})
},
[NOTIFICATION_ACTIONS.CLOSE_ALL]: (state) => {
return state.map((notification) => ({ ...notification, dismissed: true }))
},
[NOTIFICATION_ACTIONS.DELETE]: (state, { payload }: Action<KeyPayload>) => {
return state.filter((notification) => notification.options?.key !== payload.key)
},
[NOTIFICATION_ACTIONS.DELETE_ALL]: () => {
return []
},
},
[],
)

export const showNotification = (
payload: Pick<Notification, 'message' | 'options'>,
): ThunkAction<SnackbarKey, AppReduxState, undefined, AnyAction> => {
return (dispatch): SnackbarKey => {
const action = createAction<Notification>(NOTIFICATION_ACTIONS.SHOW)

const key = payload.options?.key || Math.random().toString(32).slice(2)

dispatch(
action({
...payload,
options: { ...payload.options, key },
}),
)

return key
}
}
export const closeNotification = createAction<KeyPayload>(NOTIFICATION_ACTIONS.CLOSE)
export const closeAllNotifications = createAction(NOTIFICATION_ACTIONS.CLOSE_ALL)
export const deleteNotification = createAction<KeyPayload>(NOTIFICATION_ACTIONS.DELETE)
export const deleteAllNotifications = createAction(NOTIFICATION_ACTIONS.DELETE_ALL)

export const selectNotifications = (state: AppReduxState): NotificationsState => {
return state[NOTIFICATIONS_REDUCER_ID]
}
Copy link
Member Author

Choose a reason for hiding this comment

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

After working on web-core, it really doesn't make sense to separate these into separate files in my opinion.

@github-actions
Copy link

github-actions bot commented May 30, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 2 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

Deployment links

Mainnet     🟣 Polygon     🟠 Rinkeby

@coveralls
Copy link

coveralls commented May 30, 2022

Pull Request Test Coverage Report for Build 2460417343

  • 59 of 121 (48.76%) changed or added relevant lines in 20 files are covered.
  • 25 unchanged lines in 7 files lost coverage.
  • Overall coverage decreased (-0.3%) to 36.594%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/logic/safe/store/actions/TxMultiSender.ts 0 1 0.0%
src/logic/wallets/onboard.ts 0 1 0.0%
src/routes/opening/index.tsx 0 1 0.0%
src/routes/safe/components/AddressBook/ExportEntriesModal/index.tsx 0 1 0.0%
src/routes/safe/components/Apps/hooks/appList/useRemoteSafeApps.ts 0 1 0.0%
src/routes/safe/components/Settings/ManageOwners/EditOwnerModal/index.tsx 0 1 0.0%
src/routes/safe/components/Settings/SafeDetails/index.tsx 0 1 0.0%
src/routes/safe/components/Transactions/TxList/hooks/useActionButtonsHandlers.ts 0 1 0.0%
src/logic/notifications/txNotificationBuilder.tsx 13 15 86.67%
src/logic/wallets/store/middleware/index.ts 0 2 0.0%
Files with Coverage Reduction New Missed Lines %
src/routes/safe/components/Apps/components/SafeAppCard/SafeAppCard.tsx 1 78.46%
src/logic/safe/store/middleware/notificationsMiddleware.ts 2 13.0%
src/routes/safe/components/Apps/components/AppsList.tsx 2 80.33%
src/routes/safe/components/Apps/components/SearchInputCard.tsx 2 36.36%
src/routes/safe/components/Apps/components/NoAppsFound.tsx 4 42.86%
src/routes/safe/components/Apps/index.tsx 5 0%
src/routes/safe/components/Apps/hooks/appList/useAppList.ts 9 54.29%
Totals Coverage Status
Change from base Build 2398030745: -0.3%
Covered Lines: 3845
Relevant Lines: 9543

💛 - Coveralls

@katspaugh
Copy link
Member

Good refactoring, but it broke some of the notifications. I tested only the address book ones.

Screenshot 2022-06-07 at 10 41 57

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.

Also something is wrong with error styles.

Screenshot 2022-06-07 at 11 20 16

@iamacook
Copy link
Member Author

iamacook commented Jun 7, 2022

@katspaugh, seems like both were CSS selector issues and these should now be addressed.

@iamacook iamacook requested a review from katspaugh June 7, 2022 14:19
@francovenica
Copy link
Contributor

francovenica commented Jun 8, 2022

Checked all the notifications I could find and they look fine.

Regarding

One notable notification to check, which includes an onClick handler, is dispatched when the Safe requires an update. I removed some unnecessary code that is responsible for address book interaction notifications. They should still work as before as well.

I tried to use safes that are 1.0.0 or 1.1.1 and I didn't get any notification, not when accessing it nor when I upgrade them. So I'm not sure how to check this one

@iamacook
Copy link
Member Author

iamacook commented Jun 8, 2022

Regarding

One notable notification to check, which includes an onClick handler, is dispatched when the Safe requires an update. I removed some unnecessary code that is responsible for address book interaction notifications. They should still work as before as well.

I tried to use safes that are 1.0.0 or 1.1.1 and I didn't get any notification, not when accessing it nor when I upgrade them. So I'm not sure how to check this one

I've adjusted the action that shows the update notification. If you:

a) have an older Safe open and connect to an owner
b) switch to an older Safe whilst connected to an owner

the notification should be displayed. Clicking on it should take you to the details settings where you can update the Safe.

@francovenica
Copy link
Contributor

Ok, the notification is there.
I've checked that shows up when you load a safe with an outdated version (today is any < v1.3.0) or if you switch from one that is already up to date to one outdated. Also the notification only shows up if you are owner of the safe, so non-owners or disconnected users don't see the notification. Connecting to the app with the owner of an outdated safe while being having it loaded also shows the notification, which is correct.

Looks good to me
image

@iamacook iamacook merged commit 8fa5a8a into dev Jun 8, 2022
@iamacook iamacook deleted the refactor/notifications branch June 8, 2022 10:46
@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants