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

fix: update transaction controllers to use selected account #4244

Conversation

montelaidev
Copy link
Contributor

@montelaidev montelaidev commented May 2, 2024

Explanation

This pr updates the transaction controller to use account id from the InternalAccount instead of an address

References

Related to https://github.com/MetaMask/accounts-planning/issues/381

Changelog

@metamask/transaction-controller

  • BREAKING: getSelectedAddress is replaced with getSelectedAccount in the TransactionController
  • BREAKING: getCurrentAccount returns an InternalAccount instead of a string in the IncomingTransactionHelper

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

Fixes https://github.com/MetaMask/accounts-planning/issues/381

@montelaidev
Copy link
Contributor Author

@metamaskbot publish-preview

Copy link
Contributor

github-actions bot commented May 2, 2024

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-0e5df333",
  "@metamask-previews/address-book-controller": "4.0.1-preview-0e5df333",
  "@metamask-previews/announcement-controller": "6.1.0-preview-0e5df333",
  "@metamask-previews/approval-controller": "6.0.1-preview-0e5df333",
  "@metamask-previews/assets-controllers": "28.0.0-preview-0e5df333",
  "@metamask-previews/base-controller": "5.0.2-preview-0e5df333",
  "@metamask-previews/build-utils": "2.0.1-preview-0e5df333",
  "@metamask-previews/composable-controller": "6.0.1-preview-0e5df333",
  "@metamask-previews/controller-utils": "9.1.0-preview-0e5df333",
  "@metamask-previews/ens-controller": "10.0.1-preview-0e5df333",
  "@metamask-previews/eth-json-rpc-provider": "3.0.1-preview-0e5df333",
  "@metamask-previews/gas-fee-controller": "15.1.0-preview-0e5df333",
  "@metamask-previews/json-rpc-engine": "8.0.1-preview-0e5df333",
  "@metamask-previews/json-rpc-middleware-stream": "7.0.1-preview-0e5df333",
  "@metamask-previews/keyring-controller": "15.0.0-preview-0e5df333",
  "@metamask-previews/logging-controller": "3.0.1-preview-0e5df333",
  "@metamask-previews/message-manager": "8.0.1-preview-0e5df333",
  "@metamask-previews/name-controller": "6.0.1-preview-0e5df333",
  "@metamask-previews/network-controller": "18.1.0-preview-0e5df333",
  "@metamask-previews/notification-controller": "5.0.1-preview-0e5df333",
  "@metamask-previews/permission-controller": "9.0.2-preview-0e5df333",
  "@metamask-previews/permission-log-controller": "2.0.1-preview-0e5df333",
  "@metamask-previews/phishing-controller": "9.0.2-preview-0e5df333",
  "@metamask-previews/polling-controller": "6.0.1-preview-0e5df333",
  "@metamask-previews/preferences-controller": "10.0.0-preview-0e5df333",
  "@metamask-previews/queued-request-controller": "0.9.0-preview-0e5df333",
  "@metamask-previews/rate-limit-controller": "5.0.1-preview-0e5df333",
  "@metamask-previews/selected-network-controller": "12.0.1-preview-0e5df333",
  "@metamask-previews/signature-controller": "15.0.0-preview-0e5df333",
  "@metamask-previews/transaction-controller": "28.1.1-preview-0e5df333",
  "@metamask-previews/user-operation-controller": "8.0.1-preview-0e5df333"
}

@montelaidev montelaidev force-pushed the fix/ap381/update-transaction-controllers-to-use-selectedAccountId branch from 0e5df33 to b874e4c Compare June 3, 2024 14:36
@montelaidev montelaidev marked this pull request as ready for review June 3, 2024 14:44
@montelaidev montelaidev requested a review from a team as a code owner June 3, 2024 14:44
@montelaidev montelaidev changed the title Fix: [WIP] update transaction controllers to use selected account fix: update transaction controllers to use selected account Jun 3, 2024
ccharly
ccharly previously approved these changes Jun 3, 2024
@montelaidev montelaidev requested a review from a team June 4, 2024 07:47
@@ -1035,7 +1036,7 @@ export class TransactionController extends BaseController<
if (origin) {
await validateTransactionOrigin(
await this.getPermittedAccounts(origin),
this.getSelectedAddress(),
this.getSelectedAccount().address,
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this controller takes a function that allows for getting the currently selected account. However, this is an old pattern and we are slowly trying to move all controllers to use the messenger pattern for intercommunication.

Since you're making a breaking change anyway, what are your thoughts on extending the TransactionControllerMessenger to allow the AccountsController:getSelectedAccount action? You can do this by importing AccountsControllerGetSelectedAccountAction from @metamask/accounts-controller and adding it to AllowedActions. Then you can remove the getSelectedAccount option from the constructor altogether and replace this line with:

Suggested change
this.getSelectedAccount().address,
this.messagingSystem.call('AccountsController:getSelectedAccount').address,

@@ -52,6 +52,7 @@
"@metamask/controller-utils": "^11.0.0",
"@metamask/eth-query": "^4.0.0",
"@metamask/gas-fee-controller": "^17.0.0",
"@metamask/keyring-api": "6.4.0",
Copy link
Contributor

@legobeat legobeat Jun 4, 2024

Choose a reason for hiding this comment

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

Noting that this is a type-only import and not under peerDependencies, this is a something that could be moved to devDependencies?

(If strict compatibility with the imported class is required, that indicates to me that it could also be a candidate for peerDependencies, if introducing that requirement here is indeed intended)

Copy link
Contributor

@mcmire mcmire Jun 5, 2024

Choose a reason for hiding this comment

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

Looking at the emitted type declaration file, it looks like the @metamask/keyring-api shows up there, so I believe this needs to be in dependencies, not devDependencies or peerDependencies so that it doesn't create a TypeScript error on build. Right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated, it looks like this is missing a ^:

Suggested change
"@metamask/keyring-api": "6.4.0",
"@metamask/keyring-api": "^6.4.0",

Copy link
Contributor

@legobeat legobeat Jun 6, 2024

Choose a reason for hiding this comment

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

@mcmire I may be missing something but it seems to me that if we just consider the peerDependencies aspect in isolation, it should also be here.
And if the peerDependencies is satisifed, then there should be no TypeScript error on build, and therefore no need for dependencies since the types will be provided by the peerDependencies entry?

Copy link
Contributor

@legobeat legobeat Jun 6, 2024

Choose a reason for hiding this comment

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

I'm thinking if it's not added in peerDependencies, using code may run the risk of getting inconsistent type-checking results or plain incompatibilities, due to using the wrong version of @metamask/keyring-api for its type-checking?

Specifically here, it would be wrt the getSelectedAccount constructor option.

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've removed the callback and used the messaging system instead to get the selected account. @metamask/keyring-api can just be a dev dependency for the tests.

@@ -99,6 +143,11 @@ const setupController = async (
givenOptions: Partial<
ConstructorParameters<typeof TransactionController>[0]
> = {},
mockData: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We named it mocks in our previous PRs! So we could rename it if you want

@montelaidev montelaidev merged commit f28d7a1 into main Jun 7, 2024
113 checks passed
@montelaidev montelaidev deleted the fix/ap381/update-transaction-controllers-to-use-selectedAccountId branch June 7, 2024 15:20
legobeat pushed a commit that referenced this pull request Jun 11, 2024
This pr updates the transaction controller to use account id from the
InternalAccount instead of an address

Related to MetaMask/accounts-planning#381

- **BREAKING**: `getSelectedAddress` is replaced with
`getSelectedAccount` in the `TransactionController`
- **BREAKING**: `getCurrentAccount` returns an `InternalAccount` instead
of a `string` in the `IncomingTransactionHelper`

- [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

Fixes MetaMask/accounts-planning#381

---------

Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
legobeat pushed a commit that referenced this pull request Jun 11, 2024
This pr updates the transaction controller to use account id from the
InternalAccount instead of an address

Related to MetaMask/accounts-planning#381

- **BREAKING**: `getSelectedAddress` is replaced with
`getSelectedAccount` in the `TransactionController`
- **BREAKING**: `getCurrentAccount` returns an `InternalAccount` instead
of a `string` in the `IncomingTransactionHelper`

- [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

Fixes MetaMask/accounts-planning#381

---------

Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
legobeat pushed a commit that referenced this pull request Jun 11, 2024
This pr updates the transaction controller to use account id from the
InternalAccount instead of an address

Related to MetaMask/accounts-planning#381

- **BREAKING**: `getSelectedAddress` is replaced with
`getSelectedAccount` in the `TransactionController`
- **BREAKING**: `getCurrentAccount` returns an `InternalAccount` instead
of a `string` in the `IncomingTransactionHelper`

- [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

Fixes MetaMask/accounts-planning#381

---------

Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
Gudahtt added a commit to MetaMask/metamask-extension that referenced this pull request Jul 25, 2024
The `@metamask/transaction-controller` package has been updated from v32 to
v34. The `@metamask/user-operation-controller` package had to be bumped as
well to avoid new peer dependency warnings.

Primarily the only breaking changes in these ranges were peer dependency
updates and an update to the minimum supported Node.js version. The new
peer dependencies did not introduce any new warnings, they are all met. This
update has resolved some pre-existing peer dependency warnings.

The only functional change required was this update to the
TransactionController in v33.0.0:

```
- **BREAKING:** The `TransactionController` messenger must now allow the `AccountsController:getSelectedAccount` action ([#4244](MetaMask/core#4244))

...

- **BREAKING:** Remove `getSelectedAddress` option from `TransactionController` ([#4244](MetaMask/core#4244))
  - The AccountsController is used to get the currently selected address automatically.
```

That change has been applied.

See the full changelogs here:
* [`@metamask/transaction-controller`](https://github.com/MetaMask/core/blob/%40metamask/transaction-controller%4034.0.0/packages/transaction-controller/CHANGELOG.md)
* [`@metamask/user-operation-controller`](https://github.com/MetaMask/core/blob/%40metamask/user-operation-controller%4013.0.0/packages/user-operation-controller/CHANGELOG.md)

This helps unblock #9372
Gudahtt added a commit to MetaMask/metamask-extension that referenced this pull request Jul 25, 2024
## **Description**

The `@metamask/transaction-controller` package has been updated from v32
to v34. The `@metamask/user-operation-controller` package had to be
bumped as well to avoid new peer dependency warnings.

Primarily the only breaking changes in these ranges were peer dependency
updates and an update to the minimum supported Node.js version. The new
peer dependencies did not introduce any new warnings, they are all met.
This update has resolved some pre-existing peer dependency warnings.

The only functional change required was this update to the
TransactionController in v33.0.0:

```
- **BREAKING:** The `TransactionController` messenger must now allow the `AccountsController:getSelectedAccount` action ([#4244](MetaMask/core#4244))

...

- **BREAKING:** Remove `getSelectedAddress` option from `TransactionController` ([#4244](MetaMask/core#4244))
  - The AccountsController is used to get the currently selected address automatically.
```

That change has been applied.

See the full changelogs here:
*
[`@metamask/transaction-controller`](https://github.com/MetaMask/core/blob/%40metamask/transaction-controller%4034.0.0/packages/transaction-controller/CHANGELOG.md)
*
[`@metamask/user-operation-controller`](https://github.com/MetaMask/core/blob/%40metamask/user-operation-controller%4013.0.0/packages/user-operation-controller/CHANGELOG.md)

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26124?quickstart=1)

## **Related issues**

This helps unblock #9372

## **Manual testing steps**

N/A

## **Screenshots/Recordings**

N/A

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
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.

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
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