metamask-extension icon indicating copy to clipboard operation
metamask-extension copied to clipboard

Convert MMIController to a non-controller (without renaming it)

Open mcmire opened this issue 1 year ago • 1 comments

What is this about?

Following the Wallet Framework team's OKRs for Q3 2024, we want to bring MMIController up to date with our latest controller patterns.

After review, it turns out that MMIController does not have any state and therefore should not inherit from BaseController (or anything, for that matter).

Scenario

No response

Design

No response

Technical Details

No response

Threat Modeling Framework

No response

Acceptance Criteria

  • A constant called name exists which holds the namespace for actions and events.
  • MMIController does not inherit from a superclass (it does not have state, so it is not a controller).
    • super() is removed from the constructor.
    • MMIController uses this.messagingSystem to refer to the messenger instead of this.messenger for consistency with controllers.
    • MMIController no longer takes metaMetricsController as a constructor option.
      • It no longer reads the state directly from this controller, but uses the MetaMetricsController:getState action through the messenger to do so instead.
    • MMIController no longer takes networkController as a constructor option.
      • It no longer reads the state directly from this controller, but uses the NetworkController:getState action through the messenger to do so instead.
      • It no longer calls setActiveNetwork directly on the controller, but calls the NetworkController:setActiveNetwork messenger action instead.
      • It no longer calls setProviderType on the controller — this method is deprecated — but calls the NetworkController:setActiveNetwork messenger action instead.
    • MMIController still takes mmiConfigurationController, keyringController, preferencesController, appStateController, transactionUpdateController, custodyController, permissionController, and signatureController as well as getState, getPendingNonce, updateTransactionHash, setChannelId, and setConnectionRequest. In theory we should use the messenger for these, but we'd need to add actions to the corresponding controllers to support this, and this would be too much work.
  • Supporting types exist.
    • The MMIControllerActions and MMIControllerEvents types exist.
    • The AllowedActions and AllowedEvents types exist.
    • The MMIControllerMessenger type exists and expects AccountsController:getAccountByAddress, AccountsController:setAccountName, AccountsController:listAccounts, AccountsController:getSelectedAccount, and AccountsController:setSelectedAccount.
    • The type of the messagingSystem property is corrected from any.
  • The tests are updated to follow suit.
    • ❌ The use of beforeEach is not corrected, as this would take too long. We can solve this in another PR.
  • MMIController is not renamed, as it would mess with the diff too much. We can do this in a different PR.

Stakeholder review needed before the work gets merged

  • [X] Engineering (needed in most cases)
  • [ ] Design
  • [ ] Product
  • [ ] QA (automation tests are required to pass before merging PRs but not all changes are covered by automation tests - please review if QA is needed beyond automation tests)
  • [ ] Security
  • [ ] Legal
  • [ ] Marketing
  • [ ] Management (please specify)
  • [ ] Other (please specify)

References

  • https://github.com/MetaMask/core/issues/1509

mcmire avatar Jul 18 '24 03:07 mcmire

We should tag the MMI team to discuss further if this feels like the right path forward.

desi avatar Jul 25 '24 15:07 desi

The below part of the ticket is not covered at the moment because MetaMetricsController:getState doesn't exist yet!

MMIController no longer takes metaMetricsController as a constructor option.
It no longer reads the state directly from this controller, but uses the MetaMetricsController:getState action through the messenger to do so instead.

kanthesha avatar Oct 21 '24 12:10 kanthesha

As we don't have state, we do not need a MMIControllerActions and also MMIControllerEvents. These two will be removed from the Acceptance Criteria.

The MMIControllerActions and MMIControllerEvents types exist.

kanthesha avatar Oct 21 '24 16:10 kanthesha