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

Support watching assets on a specific account #1124

Merged
merged 9 commits into from
Mar 30, 2023

Conversation

Cal-L
Copy link
Contributor

@Cal-L Cal-L commented Mar 8, 2023

Support watching assets on a specific account

The purpose of the changes to is allow a user to store a watched asset to the token states in the TokensController. Why is this needed? The introduction of the Permission System on mobile now allows users to interact with Dapps using accounts that are different than what is active on their wallet screen. This dynamic makes it possible for users to watch assets under the active Dapp account, which may be different than the active wallet account. As a result, we needed to enable passing of an account address to both the watchAsset and addToken method, that would allow for storing of tokens under specific account addresses. All of the listed changes below is backwards compatible and code that uses the TokensController will not need to change.

Description

  • CHANGED:

    • TokensController.watchAsset
      • Added optional interactingAddress: string parameter with the definition of The address of the account that is requesting to watch the asset.
    • TokensController.acceptWatchAsset
      • Now passes an account address (interactingAddress: string || selectedAddress: string) into TokensController.addToken under the ERC20 switch condition.
    • TokensController.addToken
      • If interactingAddress is defined and is not equal to selectedAddress, this method will function the same way but will not update tokens, ignoredTokens, detectedTokens token states.
      • If interactingAddress is not defined, this method will use the selectedAddress and function the same way.
    • SuggestedAssetMeta type
      • Added optional interactingAddress?: string property. This is only populated if interactingAddress is passed into TokensController.watchAsset.

Checklist

  • Tests are included if applicable
  • Any added code is fully documented

Issue

Resolves #???

@Cal-L Cal-L changed the title Patch/5773 improve watch asset Support watching assets on specific accounts Mar 8, 2023
@Cal-L Cal-L changed the title Support watching assets on specific accounts Support watching assets on a specific account Mar 8, 2023
@Cal-L Cal-L marked this pull request as ready for review March 9, 2023 03:23
@Cal-L Cal-L requested a review from a team as a code owner March 9, 2023 03:23
asset,
id: this._generateRandomId(),
status: SuggestedAssetStatus.pending as SuggestedAssetStatus.pending,
time: Date.now(),
type,
};
if (interactingAddress) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO - Provide selectedAddress as fallback to ensure that suggestedAssetMeta always has an interactingAddress

tommasini
tommasini previously approved these changes Mar 22, 2023
Copy link
Contributor

@tommasini tommasini left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gudahtt
Copy link
Member

Gudahtt commented Mar 23, 2023

Hmm, I hadn't realized before that EIP-747 relied upon the current selected account. I guess we'll need to update https://eips.ethereum.org/EIPS/eip-747 to work more effectively with scenarios where multiple accounts are connected.

@adonesky1
Copy link
Contributor

Hmm, I hadn't realized before that EIP-747 relied upon the current selected account. I guess we'll need to update https://eips.ethereum.org/EIPS/eip-747 to work more effectively with scenarios where multiple accounts are connected.

we're discussing related topics in context of adding support for adding NFTs via wallet_watchAsset and architecting changes with multichain in mind. @Cal-L perhaps you should join us to discuss this work in our meeting tomorrow?

Gudahtt
Gudahtt previously approved these changes Mar 23, 2023
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM! Left one suggestion for improved test coverage, and Cal your pending TODO comment looks worth pursing as well, but we don't need to block on that.

@Cal-L Cal-L dismissed stale reviews from Gudahtt and tommasini via c38d0ec March 28, 2023 23:34
@Cal-L Cal-L force-pushed the patch/5773-improve-watch-asset branch from c38d0ec to cb2d3d9 Compare March 28, 2023 23:44
@Cal-L Cal-L marked this pull request as draft March 29, 2023 17:23
@Cal-L
Copy link
Contributor Author

Cal-L commented Mar 29, 2023

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask/address-book-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/announcement-controller": "3.0.0-preview.cb2d3d9",
  "@metamask/approval-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/assets-controllers": "5.0.0-preview.cb2d3d9",
  "@metamask/base-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/composable-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/controller-utils": "3.0.0-preview.cb2d3d9",
  "@metamask/ens-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/gas-fee-controller": "4.0.0-preview.cb2d3d9",
  "@metamask/keyring-controller": "4.0.0-preview.cb2d3d9",
  "@metamask/message-manager": "2.0.0-preview.cb2d3d9",
  "@metamask/network-controller": "5.0.0-preview.cb2d3d9",
  "@metamask/notification-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/permission-controller": "3.0.0-preview.cb2d3d9",
  "@metamask/phishing-controller": "3.0.0-preview.cb2d3d9",
  "@metamask/preferences-controller": "2.1.0-preview.cb2d3d9",
  "@metamask/rate-limit-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/subject-metadata-controller": "2.0.0-preview.cb2d3d9",
  "@metamask/transaction-controller": "4.0.0-preview.cb2d3d9"
}

@Cal-L Cal-L marked this pull request as ready for review March 29, 2023 20:40
@Cal-L Cal-L force-pushed the patch/5773-improve-watch-asset branch from cb2d3d9 to eb5cab8 Compare March 30, 2023 04:57
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@Cal-L Cal-L merged commit 9952d5f into main Mar 30, 2023
@Cal-L Cal-L deleted the patch/5773-improve-watch-asset branch March 30, 2023 19:44
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 25, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 25, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 25, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 25, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 25, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 26, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 26, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 26, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 26, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 27, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 27, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 27, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Jul 27, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 3, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 16, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 16, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 17, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 18, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 18, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 22, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
Gudahtt added a commit to MetaMask/metamask-mobile that referenced this pull request Aug 22, 2023
The `@metamask/assets-controllers` patch added as part of the
permission system implementation [1] has been updated to more closely
match how the feature was implemented upstream [2]. It should be
functionally equivalent.

This relates to MetaMask/mobile-planning#877

[1]: #5062
[2]: MetaMask/core#1124
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Add interactingAddress property to SuggestedAssetMetaBase type

* Allow passing an account address to watchAsset

* Pass interacting account address into addToken from acceptWatchAsset

* Support adding token to an account that is not the active wallet account

* Rename detection fields to interacting to support more cases

* Create test for watching an asset under a specific account address

* Create test for storing a watched asset under a specific account address

* Use selectedAddress as fallback for interacting address

* Fix TokensController tests
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Add interactingAddress property to SuggestedAssetMetaBase type

* Allow passing an account address to watchAsset

* Pass interacting account address into addToken from acceptWatchAsset

* Support adding token to an account that is not the active wallet account

* Rename detection fields to interacting to support more cases

* Create test for watching an asset under a specific account address

* Create test for storing a watched asset under a specific account address

* Use selectedAddress as fallback for interacting address

* Fix TokensController 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.

4 participants