Skip to content

Conversation

@montelaidev
Copy link
Contributor

@montelaidev montelaidev commented Apr 26, 2024

Explanation

This PR updates the selectedAccount to selectedAccountId in the token controllers

References

Fixes https://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
Contributor Author

@metamaskbot publish-preview

@montelaidev montelaidev force-pushed the fix/ap381/update-tokens-controllers-to-use-internal-accounts branch from 78ef3b5 to 6c0595d Compare April 29, 2024 08:24
@montelaidev
Copy link
Contributor Author

@metamaskbot publish-preview

1 similar comment
@montelaidev
Copy link
Contributor Author

@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-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
Contributor Author

@montelaidev montelaidev force-pushed the fix/ap381/update-tokens-controllers-to-use-internal-accounts branch from cb17e99 to 1e319a0 Compare June 5, 2024 12:51
@montelaidev montelaidev 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 gantunesr June 5, 2024 16:11
*/
constructor({
selectedAddress,
selectedAccountId,
Copy link
Contributor

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
Contributor

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
Contributor

Choose a reason for hiding this comment

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

Similar comment as above.

@montelaidev montelaidev requested a review from gantunesr June 14, 2024 07:37
Comment on lines 277 to 280
const selectedAccount = this.messagingSystem.call(
'AccountsController:getAccount',
this.#selectedAccountId,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const selectedAccount = this.messagingSystem.call(
'AccountsController:getAccount',
this.#selectedAccountId,
);
const selectedAddress = this.#getSelectedAddress();

And use selectedAddress afterward

Copy link
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 montelaidev mentioned this pull request Jun 18, 2024
Comment on lines 277 to 280
const selectedAccount = this.messagingSystem.call(
'AccountsController:getAccount',
this.#selectedAccountId,
);
Copy link
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
Contributor Author

@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-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"
}

Copy link
Contributor

@ccharly ccharly left a comment

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 main Jun 20, 2024
@montelaidev montelaidev deleted the fix/ap381/update-tokens-controllers-to-use-internal-accounts branch June 20, 2024 13:18
@montelaidev
Copy link
Contributor Author

@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

Fixes MetaMask/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
@montelaidev montelaidev mentioned this pull request Jun 25, 2024
3 tasks
Sign up for free to 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.

5 participants