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 integration sdk #9673

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Jonathansoufer
Copy link
Contributor

@Jonathansoufer Jonathansoufer commented May 17, 2024

Description

This PR implements all the REDUX flows (Actions, Reducers, Sagas, Controllers usage) to power Notifications UI.

Related issues

Fixes: N/A

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@Jonathansoufer Jonathansoufer self-assigned this May 17, 2024
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link

socket-security bot commented May 22, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None +2 1.49 MB jonnyman9

View full report↗︎

Copy link

socket-security bot commented May 22, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSource
New author npm/[email protected]

View full report↗︎

Next steps

What is new author?

A new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.

Scrutinize new collaborator additions to packages because they now have the ability to publish code into your dependency tree. Packages should avoid frequent or unnecessary additions or changes to publishing rights.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

@Jonathansoufer Jonathansoufer marked this pull request as ready for review May 22, 2024 10:59
@Jonathansoufer Jonathansoufer requested a review from a team as a code owner May 22, 2024 10:59
@@ -1,12 +1,14 @@
import { ACTIONS } from '../../reducers/notification';
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are shipping notification it would be cool to refactor this to use the slice pattern with RTK we have some examples on the codebase like this one:

import { PayloadAction, createSlice } from '@reduxjs/toolkit';

It would be cool to instead of the action and reducer we have a single file with the slice instead, in typescript, let me know your thoughts!

Copy link
Contributor

Choose a reason for hiding this comment

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

@tommasini what is the benefit of this slice pattern?

@owencraston owencraston added the DO-NOT-MERGE Pull requests that should not be merged label May 22, 2024
app/core/Engine.ts Outdated Show resolved Hide resolved
return type === NETWORK_TYPES.RPC ? rpcUrl : type;
},
getCurrentChainId: () => networkController.state.providerConfig.chainId,
environment: process.env.METAMASK_ENVIRONMENT,
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have a default case here? I am not sure how reliable this value is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, this is also implemented here and used everywhere within the app through the call of const providerConfig = useSelector(selectProviderConfig);. What do you advice?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was referring to process.env.METAMASK_ENVIRONMENT

Copy link
Contributor

Choose a reason for hiding this comment

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

If its too much trouble than its okay.

* @returns An object containing:
* - `createSession`: A function to initiate the session creation process.
*/
function useCreateSession(): {
Copy link
Contributor

Choose a reason for hiding this comment

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

I really love the hooks that you have created. I strongly encourage you to write some basic hook tests using renderHook. This goes for all of the hooks in the new hooks folder. Here is an example in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this already here. Is there any other approach you're suggesting?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I did not see this before. This is great. I guess I was looking for a specific useCreateSession.test.ts file but this work. I think having individual test files is cleaner and easier to maintain as we scale but I do not feel strongly about it.

export type AccountType = InternalAccount & {
balance: string;
keyring: KeyringType;
label: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am pretty sure that the InternalAccount object has the label (defined as name) under the metadata object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. On the extension notification's implementation they are using name and label here. So I don't know if on purpose or by mistake. Meanwhile, I'll put the question to the Notification's team.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can confirm that the account name (same as label) is already available on the InternalAccounts object. In my opinion we should rely on this object as much as possible for accounts related work. The balance will need to be added but we can get the label from metadata. The type is also available on this interface but it has support for non evm account type so if we want to limit it to only evm we can use KeyringType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO-NOT-MERGE Pull requests that should not be merged team-notifications Notifications team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants