Skip to content

fix: update tokens controllers to use selectedAccountId instead of selectedAddress - #4219

Merged
montelaidev merged 27 commits into
mainfrom
fix/ap381/update-tokens-controllers-to-use-internal-accounts
Jun 20, 2024
Merged

fix: update tokens controllers to use selectedAccountId instead of selectedAddress#4219
montelaidev merged 27 commits into
mainfrom
fix/ap381/update-tokens-controllers-to-use-internal-accounts

Conversation

@montelaidev

@montelaidevmontelaidev commented Apr 26, 2024

Copy link
Copy Markdown
Contributor

Explanation

This PR updates the selectedAccount to selectedAccountId in the token controllers

References

Fixeshttps://github.com/MetaMask/accounts-planning/issues/381

Changelog

@metamask/assets-controllers

  • BREAKING:
    • TokenBalancesController messenger must allow the action AccountsController:getSelectedAccount and remove PreferencesController:getState.
    • TokenDetectionController messenger must allow the action AccountsController:getAccount.
    • TokenDetectionController messenger must allow the event AccountsController:selectedEvmAccountChange and remove AccountsController:selectedAccountChange.
    • TokenDetectionController removes selectedAddress constructor argument.
    • TokenRatesController messenger must allow the action AccountsController:getAccount, AccountsController:getSelectedAccount and remove PreferencesController:getState.
    • TokenRatesController messenger must allow the event AccountsController:selectedEvmAccountChange and remove PreferencesController:stateChange.
    • TokensController messenger must allow the action AccountsController:getAccount, AccountsController:getSelectedAccount.
    • TokensController messenger must allow the event AccountsController:selectedEvmAccountChange.
    • TokensController removes selectedAddress constructor argument.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@montelaidev

Copy link
Copy Markdown
ContributorAuthor

@metamaskbot publish-preview

@montelaidev
montelaidevforce-pushed the fix/ap381/update-tokens-controllers-to-use-internal-accounts branch from 78ef3b5 to 6c0595dCompareApril 29, 2024 08:24
@montelaidev

Copy link
Copy Markdown
ContributorAuthor

@metamaskbot publish-preview

1 similar comment
@montelaidev

Copy link
Copy Markdown
ContributorAuthor

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

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

Expand for full list of packages and versions.
{
"@metamask-previews/accounts-controller": "13.0.0-preview-cb17e99",
"@metamask-previews/address-book-controller": "4.0.1-preview-cb17e99",
"@metamask-previews/announcement-controller": "6.1.0-preview-cb17e99",
"@metamask-previews/approval-controller": "6.0.1-preview-cb17e99",
"@metamask-previews/assets-controllers": "28.0.0-preview-cb17e99",
"@metamask-previews/base-controller": "5.0.1-preview-cb17e99",
"@metamask-previews/build-utils": "2.0.1-preview-cb17e99",
"@metamask-previews/composable-controller": "6.0.1-preview-cb17e99",
"@metamask-previews/controller-utils": "9.1.0-preview-cb17e99",
"@metamask-previews/ens-controller": "10.0.1-preview-cb17e99",
"@metamask-previews/eth-json-rpc-provider": "3.0.1-preview-cb17e99",
"@metamask-previews/gas-fee-controller": "15.1.0-preview-cb17e99",
"@metamask-previews/json-rpc-engine": "8.0.1-preview-cb17e99",
"@metamask-previews/json-rpc-middleware-stream": "7.0.1-preview-cb17e99",
"@metamask-previews/keyring-controller": "15.0.0-preview-cb17e99",
"@metamask-previews/logging-controller": "3.0.1-preview-cb17e99",
"@metamask-previews/message-manager": "8.0.1-preview-cb17e99",
"@metamask-previews/name-controller": "6.0.1-preview-cb17e99",
"@metamask-previews/network-controller": "18.1.0-preview-cb17e99",
"@metamask-previews/notification-controller": "5.0.1-preview-cb17e99",
"@metamask-previews/permission-controller": "9.0.2-preview-cb17e99",
"@metamask-previews/permission-log-controller": "2.0.1-preview-cb17e99",
"@metamask-previews/phishing-controller": "9.0.1-preview-cb17e99",
"@metamask-previews/polling-controller": "6.0.1-preview-cb17e99",
"@metamask-previews/preferences-controller": "10.0.0-preview-cb17e99",
"@metamask-previews/queued-request-controller": "0.9.0-preview-cb17e99",
"@metamask-previews/rate-limit-controller": "5.0.1-preview-cb17e99",
"@metamask-previews/selected-network-controller": "12.0.1-preview-cb17e99",
"@metamask-previews/signature-controller": "15.0.0-preview-cb17e99",
"@metamask-previews/transaction-controller": "28.1.0-preview-cb17e99",
"@metamask-previews/user-operation-controller": "8.0.1-preview-cb17e99"
}

@montelaidev

Copy link
Copy Markdown
ContributorAuthor

@montelaidev
montelaidevforce-pushed the fix/ap381/update-tokens-controllers-to-use-internal-accounts branch from cb17e99 to 1e319a0CompareJune 5, 2024 12:51
@montelaidevmontelaidev self-assigned this Jun 5, 2024
@montelaidev
montelaidev marked this pull request as ready for review June 5, 2024 16:11
@montelaidev
montelaidev requested review from a team, ccharly and gantunesrJune 5, 2024 16:11
*/
constructor({
selectedAddress,
selectedAccountId,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similar comment as here — what are your thoughts on using the messenger to get the current value of this later on in the constructor rather than having the controller take this as an argument?

onPreferencesStateChange,
selectedAccountId,
getInternalAccount,
onSelectedAccountChange,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similar comment as above, but in addition, instead of continuing with the callback pattern is it possible to listen to the AccountsController:selectedAccountChange event instead?

constructor({
chainId: initialChainId,
selectedAddress,
selectedAccountId,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Similar comment as above.

Comment threadpackages/assets-controllers/jest.config.js Outdated
Comment threadpackages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenBalancesController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment on lines +277 to +280
const selectedAccount = this.messagingSystem.call(
'AccountsController:getAccount',
this.#selectedAccountId,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
constselectedAccount=this.messagingSystem.call(
'AccountsController:getAccount',
this.#selectedAccountId,
);
constselectedAddress=this.#getSelectedAddress();

And use selectedAddress afterward

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WDYT about this suggestion ⬆️?

@montelaidevmontelaidev mentioned this pull request Jun 18, 2024
Comment threadpackages/assets-controllers/jest.config.js Outdated
Comment threadpackages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenRatesController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenRatesController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenRatesController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment threadtests/mocks.txt Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.ts Outdated
Comment on lines +277 to +280
const selectedAccount = this.messagingSystem.call(
'AccountsController:getAccount',
this.#selectedAccountId,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WDYT about this suggestion ⬆️?

@montelaidev

Copy link
Copy Markdown
ContributorAuthor

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

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

Expand for full list of packages and versions.
{
"@metamask-previews/accounts-controller": "17.0.0-preview-8ab89f22",
"@metamask-previews/address-book-controller": "5.0.0-preview-8ab89f22",
"@metamask-previews/announcement-controller": "7.0.0-preview-8ab89f22",
"@metamask-previews/approval-controller": "7.0.0-preview-8ab89f22",
"@metamask-previews/assets-controllers": "33.0.0-preview-8ab89f22",
"@metamask-previews/base-controller": "6.0.0-preview-8ab89f22",
"@metamask-previews/build-utils": "3.0.0-preview-8ab89f22",
"@metamask-previews/chain-controller": "0.1.0-preview-8ab89f22",
"@metamask-previews/composable-controller": "7.0.0-preview-8ab89f22",
"@metamask-previews/controller-utils": "11.0.0-preview-8ab89f22",
"@metamask-previews/ens-controller": "12.0.0-preview-8ab89f22",
"@metamask-previews/eth-json-rpc-provider": "4.0.0-preview-8ab89f22",
"@metamask-previews/gas-fee-controller": "17.0.0-preview-8ab89f22",
"@metamask-previews/json-rpc-engine": "9.0.0-preview-8ab89f22",
"@metamask-previews/json-rpc-middleware-stream": "8.0.0-preview-8ab89f22",
"@metamask-previews/keyring-controller": "17.1.0-preview-8ab89f22",
"@metamask-previews/logging-controller": "5.0.0-preview-8ab89f22",
"@metamask-previews/message-manager": "10.0.0-preview-8ab89f22",
"@metamask-previews/name-controller": "8.0.0-preview-8ab89f22",
"@metamask-previews/network-controller": "19.0.0-preview-8ab89f22",
"@metamask-previews/notification-controller": "6.0.0-preview-8ab89f22",
"@metamask-previews/notification-services-controller": "0.0.0-preview-8ab89f22",
"@metamask-previews/permission-controller": "10.0.0-preview-8ab89f22",
"@metamask-previews/permission-log-controller": "3.0.0-preview-8ab89f22",
"@metamask-previews/phishing-controller": "10.0.0-preview-8ab89f22",
"@metamask-previews/polling-controller": "8.0.0-preview-8ab89f22",
"@metamask-previews/preferences-controller": "13.0.0-preview-8ab89f22",
"@metamask-previews/profile-sync-controller": "0.0.0-preview-8ab89f22",
"@metamask-previews/queued-request-controller": "0.12.0-preview-8ab89f22",
"@metamask-previews/rate-limit-controller": "6.0.0-preview-8ab89f22",
"@metamask-previews/selected-network-controller": "15.0.2-preview-8ab89f22",
"@metamask-previews/signature-controller": "18.0.0-preview-8ab89f22",
"@metamask-previews/transaction-controller": "33.0.0-preview-8ab89f22",
"@metamask-previews/user-operation-controller": "12.0.0-preview-8ab89f22"
}

Comment threadpackages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenDetectionController.ts Outdated
Comment threadpackages/assets-controllers/src/TokenRatesController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokenRatesController.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated
Comment threadpackages/assets-controllers/src/TokensController.test.ts Outdated

@ccharlyccharly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job :) this was a big one! :)

@montelaidev
montelaidev merged commit ca683e8 into mainJun 20, 2024
@montelaidev
montelaidev deleted the fix/ap381/update-tokens-controllers-to-use-internal-accounts branch June 20, 2024 13:18
@montelaidev

Copy link
Copy Markdown
ContributorAuthor

@metamaskbot publish-preview

mcmire pushed a commit that referenced this pull request Jun 20, 2024
…lectedAddress (#4219)
## Explanation
This PR updates the `selectedAccount` to `selectedAccountId` in the
token controllers
## References
FixesMetaMask/accounts-planning#381
## Changelog
### `@metamask/assets-controllers`
- **BREAKING**: `TokenBalancesController` update
`PreferencesConrtollerGetStateAction` to
`AccountsControllerGetSelectedAccountAction`
- **BREAKING**: `TokenDetectionController` change `selectedAddress` to
`selectedAccountId`
- **ADDED**: `TokenDetectionController` add `getAccountAction`
- **BREAKING**: `TokenRatesController` change `selectedAddress` to
`selectedAccountId`
- **BREAKING**: `onPreferencesStateChange` arg removed and
`getInternalAccount` and `onSelectedAccountChange` added in
`TokenRatesController`
- **ADDED**: `getAccountAction` added in`TokensController` - **BREAKING**: Changed `selectedAddress` to `selectedAccountId` and
`PreferencesControllerStateChangeEvent` to
`AccountsControllerSelectedEvmAccountChangeEvent` in the
`TokensController`
- **ADDED**: `getAccountAction` added in`TokensController` ## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
@montelaidevmontelaidev mentioned this pull request Jun 25, 2024
3 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@montelaidev@mcmire@ccharly@gantunesr