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

Refactor AccountSelector #2779

Closed
wants to merge 9 commits into from
Closed

Conversation

GuillaumeRx
Copy link
Contributor

@GuillaumeRx GuillaumeRx commented Oct 1, 2024

This refactors the AccountSelector:

  • the state format for this component has changed to an object with an id and address key.
  • Adds a new optional prop switchGlobalAccount that defaults to false. It allows the component to switch the global selected account of the Extension to be switched on selection of an account.
  • Adds a new optional prop hideExternalAccounts that defaults to false. It allows the component to hide the accounts that are not owned by the snap.
  • Makes selectedAccount prop optional. If it's not provided we will get the selected account in the AccountsController, if it is we will try to get the address related to this account and if it doesn't exist we will throw an error.
  • Makes the chainIds prop optional.

@GuillaumeRx GuillaumeRx requested a review from a team as a code owner October 1, 2024 14:13
@GuillaumeRx GuillaumeRx force-pushed the gr/account-id-account-selector branch from 9de797f to a205ba6 Compare October 1, 2024 14:28
Copy link

codecov bot commented Oct 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.44%. Comparing base (ecbac90) to head (17a7ea6).
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2779   +/-   ##
=======================================
  Coverage   94.43%   94.44%           
=======================================
  Files         483      483           
  Lines       10297    10310   +13     
  Branches     1568     1571    +3     
=======================================
+ Hits         9724     9737   +13     
  Misses        573      573           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GuillaumeRx GuillaumeRx force-pushed the gr/account-id-account-selector branch 3 times, most recently from 4c25571 to dbb84a2 Compare October 2, 2024 12:53
Copy link

socket-security bot commented Oct 2, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/bignumber.js@9.1.2, npm/@types/uuid@8.3.4, npm/utf8@3.0.0, npm/hash-base@3.1.0, npm/aes-js@3.1.2, npm/bs58@4.0.1, npm/node-addon-api@2.0.2, npm/bech32@2.0.0, npm/blakejs@1.2.1, npm/scrypt-js@3.0.1, npm/bs58check@2.1.2, npm/ethereum-cryptography@0.1.3, npm/ethereumjs-util@7.1.5, npm/rlp@2.2.7, npm/secp256k1@4.0.3, npm/crc@3.8.0, npm/keccak@3.0.4, npm/@keystonehq/base-eth-keyring@0.14.1, npm/@keystonehq/bc-ur-registry-eth@0.19.1, npm/hdkey@2.1.0, npm/rlp@3.0.0, npm/@keystonehq/bc-ur-registry@0.6.4, npm/cbor-sync@1.0.4, npm/jsbi@3.2.5, npm/ethereumjs-wallet@1.0.2, npm/jsonschema@1.4.1, npm/@metamask/slip44@3.1.0, npm/@types/pbkdf2@3.1.2, npm/@types/secp256k1@4.0.6, npm/@metamask/obs-store@9.0.0, npm/@metamask/browser-passworder@4.3.0, npm/@types/uuid@9.0.8, npm/@keystonehq/alias-sampling@0.1.2, npm/async-mutex@0.5.0, npm/@ngraveio/bc-ur@1.1.13, npm/@keystonehq/metamask-airgapped-keyring@0.14.1, npm/@metamask/utils@8.5.0, npm/base-x@3.0.10, npm/@metamask/snaps-utils@7.8.1, npm/node-gyp-build@4.8.2, npm/@metamask/message-manager@10.1.1, npm/@metamask/eth-snap-keyring@4.3.6, npm/@metamask/keyring-api@8.1.3, npm/@metamask/eth-hd-keyring@7.0.4, npm/@metamask/eth-simple-keyring@6.0.5, npm/@metamask/keyring-controller@17.2.2, npm/@metamask/accounts-controller@18.2.2, npm/@metamask/snaps-controllers@9.10.0, npm/@metamask/snaps-rpc-methods@11.3.0, npm/@metamask/snaps-sdk@6.7.0, npm/@metamask/snaps-utils@8.3.0

View full report↗︎

Next steps

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/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

@GuillaumeRx GuillaumeRx force-pushed the gr/account-id-account-selector branch from dbb84a2 to 2d24433 Compare October 2, 2024 14:30
Copy link

socket-security bot commented Oct 3, 2024

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

Package New capabilities Transitives Size Publisher
npm/@metamask/accounts-controller@18.2.2 Transitive: environment, filesystem, network +53 24.4 MB metamaskbot
npm/@metamask/keyring-controller@17.2.2 Transitive: environment, filesystem, network +66 17.5 MB metamaskbot

View full report↗︎

@GuillaumeRx
Copy link
Contributor Author

@SocketSecurity ignore-all these depedencies are pulled by packages we own or are packages we own

Comment on lines +147 to +150
assert(
account,
`Account with ID ${element.props.selectedAccount} not found.`,
);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just return undefined or null in that case?

Copy link
Contributor Author

@GuillaumeRx GuillaumeRx Oct 3, 2024

Choose a reason for hiding this comment

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

I prefer to throw because we then don't know which account to select in the UI since it always need to have an account selected

@GuillaumeRx GuillaumeRx closed this Oct 8, 2024
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