Skip to content

Conversation

fabiobozzo
Copy link
Contributor

@fabiobozzo fabiobozzo commented Aug 19, 2025

Explanation

What is the current state and why does it need to change?

Currently, the MultichainAccountService has no mechanism to manage provider states based on user preferences like the "basic functionality" toggle. When users disable advanced features (basic functionality OFF), all providers (EVM, Solana, Bitcoin, etc.) remain active and continue creating multichain accounts, which goes against the user's preference for a simplified wallet experience.

The extension's PreferencesController manages the basic functionality toggle (useExternalServices), but there was no way to communicate this state change to the core MultichainAccountService to disable non-essential providers.

What is the solution and how does it work?

This PR introduces a clean provider state management system that allows clients to control which providers are active based on user preferences:

  1. Provider-Level Disable Mechanism: Added setDisabled(disabled: boolean) method to BaseAccountProvider. Providers now can / should check this.isDisabled in their createAccounts methods and return empty arrays when disabled, preventing new account creation.

  2. EvmAccountProvider could be disabled, for other reasons in the future, but does not depend on basic functionality, at all.

  3. Added setBasicFunctionality({ enabled: boolean }) method to MultichainAccountService that:

    • Calls setDisabled(!enabled) on all providers
    • Triggers wallet alignment when basic functionality is enabled to ensure account groups are complete
  4. Extension Integration: The extension's PreferencesController now calls this method when the basic functionality toggle changes.

References

Alignment method provided by: #6326

Stories:

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 communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

Copy link
Contributor

@hmalik88 hmalik88 left a comment

Choose a reason for hiding this comment

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

I think we also need to make sure we return an empty array or throw for getAccounts and getAccount based on isDisabled.

@fabiobozzo fabiobozzo marked this pull request as ready for review August 20, 2025 09:23
@fabiobozzo fabiobozzo requested review from a team as code owners August 20, 2025 09:23
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

*
* @param enabled - Whether basic functionality is enabled.
*/
async setBasicFunctionality(enabled: boolean): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

IDK if we should have this as part of the public API 🤔

My initial idea was to have the "account provider wrapper" to "react" to some events (or maybe a runtime callback) and adapt each of their methods to return all accounts or no accounts (based on the "basic functionality flag").

Though, I haven't checked of this was done on both clients, so maybe it's not that easy to do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something to discuss @ccharly . It's an architectural decision, and I chose the simplest path (multichain account service was already available to both places where basicFunctionality is toggled in extension and mobile).

Are you suggesting we use MultichainAccountServiceMessenger to dispatch a MultichainAccountServiceSetBasicFunctionalityAction ? I'm not sure how to get a ref to that messenger in mobile tbh.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, let's be pragmatic here and keep your implementation for now. It's simple enough and does get the job done, so that's ok! 👍

We can re-visit that later once we have a bit more time.

@fabiobozzo fabiobozzo requested a review from ccharly August 26, 2025 13:44
@fabiobozzo
Copy link
Contributor Author

@metamaskbot publish-preview

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/account-tree-controller": "0.10.0-preview-6a91767a",
  "@metamask-previews/accounts-controller": "33.0.0-preview-6a91767a",
  "@metamask-previews/address-book-controller": "6.1.1-preview-6a91767a",
  "@metamask-previews/announcement-controller": "7.0.3-preview-6a91767a",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-6a91767a",
  "@metamask-previews/approval-controller": "7.1.3-preview-6a91767a",
  "@metamask-previews/assets-controllers": "74.1.0-preview-6a91767a",
  "@metamask-previews/base-controller": "8.2.0-preview-6a91767a",
  "@metamask-previews/bridge-controller": "41.2.0-preview-6a91767a",
  "@metamask-previews/bridge-status-controller": "40.1.0-preview-6a91767a",
  "@metamask-previews/build-utils": "3.0.3-preview-6a91767a",
  "@metamask-previews/chain-agnostic-permission": "1.1.1-preview-6a91767a",
  "@metamask-previews/composable-controller": "11.0.0-preview-6a91767a",
  "@metamask-previews/controller-utils": "11.12.0-preview-6a91767a",
  "@metamask-previews/delegation-controller": "0.7.0-preview-6a91767a",
  "@metamask-previews/earn-controller": "6.0.0-preview-6a91767a",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-6a91767a",
  "@metamask-previews/ens-controller": "17.0.1-preview-6a91767a",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-6a91767a",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-6a91767a",
  "@metamask-previews/foundryup": "1.0.1-preview-6a91767a",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-6a91767a",
  "@metamask-previews/gator-permissions-controller": "0.0.0-preview-6a91767a",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-6a91767a",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-6a91767a",
  "@metamask-previews/keyring-controller": "23.0.0-preview-6a91767a",
  "@metamask-previews/logging-controller": "6.0.4-preview-6a91767a",
  "@metamask-previews/message-manager": "12.0.2-preview-6a91767a",
  "@metamask-previews/messenger": "0.1.0-preview-6a91767a",
  "@metamask-previews/multichain-account-service": "0.5.0-preview-6a91767a",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-6a91767a",
  "@metamask-previews/multichain-network-controller": "0.12.0-preview-6a91767a",
  "@metamask-previews/multichain-transactions-controller": "5.0.0-preview-6a91767a",
  "@metamask-previews/name-controller": "8.0.3-preview-6a91767a",
  "@metamask-previews/network-controller": "24.1.0-preview-6a91767a",
  "@metamask-previews/network-enablement-controller": "0.4.0-preview-6a91767a",
  "@metamask-previews/notification-services-controller": "17.0.0-preview-6a91767a",
  "@metamask-previews/permission-controller": "11.0.6-preview-6a91767a",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-6a91767a",
  "@metamask-previews/phishing-controller": "13.1.0-preview-6a91767a",
  "@metamask-previews/polling-controller": "14.0.0-preview-6a91767a",
  "@metamask-previews/preferences-controller": "19.0.0-preview-6a91767a",
  "@metamask-previews/profile-sync-controller": "24.0.0-preview-6a91767a",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-6a91767a",
  "@metamask-previews/remote-feature-flag-controller": "1.7.0-preview-6a91767a",
  "@metamask-previews/sample-controllers": "1.0.0-preview-6a91767a",
  "@metamask-previews/seedless-onboarding-controller": "3.0.0-preview-6a91767a",
  "@metamask-previews/selected-network-controller": "23.0.0-preview-6a91767a",
  "@metamask-previews/shield-controller": "0.0.0-preview-6a91767a",
  "@metamask-previews/signature-controller": "33.0.0-preview-6a91767a",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-6a91767a",
  "@metamask-previews/transaction-controller": "60.1.0-preview-6a91767a",
  "@metamask-previews/user-operation-controller": "39.0.0-preview-6a91767a"
}

@fabiobozzo
Copy link
Contributor Author

@metamaskbot publish-preview

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/account-tree-controller": "0.10.0-preview-970969ca",
  "@metamask-previews/accounts-controller": "33.0.0-preview-970969ca",
  "@metamask-previews/address-book-controller": "6.1.1-preview-970969ca",
  "@metamask-previews/announcement-controller": "7.0.3-preview-970969ca",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-970969ca",
  "@metamask-previews/approval-controller": "7.1.3-preview-970969ca",
  "@metamask-previews/assets-controllers": "74.1.0-preview-970969ca",
  "@metamask-previews/base-controller": "8.2.0-preview-970969ca",
  "@metamask-previews/bridge-controller": "41.3.0-preview-970969ca",
  "@metamask-previews/bridge-status-controller": "40.2.0-preview-970969ca",
  "@metamask-previews/build-utils": "3.0.3-preview-970969ca",
  "@metamask-previews/chain-agnostic-permission": "1.1.1-preview-970969ca",
  "@metamask-previews/composable-controller": "11.0.0-preview-970969ca",
  "@metamask-previews/controller-utils": "11.12.0-preview-970969ca",
  "@metamask-previews/delegation-controller": "0.7.0-preview-970969ca",
  "@metamask-previews/earn-controller": "6.0.0-preview-970969ca",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-970969ca",
  "@metamask-previews/ens-controller": "17.0.1-preview-970969ca",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-970969ca",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-970969ca",
  "@metamask-previews/foundryup": "1.0.1-preview-970969ca",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-970969ca",
  "@metamask-previews/gator-permissions-controller": "0.0.0-preview-970969ca",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-970969ca",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-970969ca",
  "@metamask-previews/keyring-controller": "23.0.0-preview-970969ca",
  "@metamask-previews/logging-controller": "6.0.4-preview-970969ca",
  "@metamask-previews/message-manager": "12.0.2-preview-970969ca",
  "@metamask-previews/messenger": "0.1.0-preview-970969ca",
  "@metamask-previews/multichain-account-service": "0.5.0-preview-970969ca",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-970969ca",
  "@metamask-previews/multichain-network-controller": "0.12.0-preview-970969ca",
  "@metamask-previews/multichain-transactions-controller": "5.0.0-preview-970969ca",
  "@metamask-previews/name-controller": "8.0.3-preview-970969ca",
  "@metamask-previews/network-controller": "24.1.0-preview-970969ca",
  "@metamask-previews/network-enablement-controller": "0.4.0-preview-970969ca",
  "@metamask-previews/notification-services-controller": "17.0.0-preview-970969ca",
  "@metamask-previews/permission-controller": "11.0.6-preview-970969ca",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-970969ca",
  "@metamask-previews/phishing-controller": "13.1.0-preview-970969ca",
  "@metamask-previews/polling-controller": "14.0.0-preview-970969ca",
  "@metamask-previews/preferences-controller": "19.0.0-preview-970969ca",
  "@metamask-previews/profile-sync-controller": "24.0.0-preview-970969ca",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-970969ca",
  "@metamask-previews/remote-feature-flag-controller": "1.7.0-preview-970969ca",
  "@metamask-previews/sample-controllers": "1.0.0-preview-970969ca",
  "@metamask-previews/seedless-onboarding-controller": "3.0.0-preview-970969ca",
  "@metamask-previews/selected-network-controller": "23.0.0-preview-970969ca",
  "@metamask-previews/shield-controller": "0.1.0-preview-970969ca",
  "@metamask-previews/signature-controller": "33.0.0-preview-970969ca",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-970969ca",
  "@metamask-previews/transaction-controller": "60.1.0-preview-970969ca",
  "@metamask-previews/user-operation-controller": "39.0.0-preview-970969ca"
}

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.

LGTM!

@fabiobozzo fabiobozzo enabled auto-merge (squash) August 27, 2025 12:08
@fabiobozzo fabiobozzo merged commit 7caad8b into main Aug 27, 2025
231 checks passed
@fabiobozzo fabiobozzo deleted the feat/MUL-343-trigger-multichain-alignment branch August 27, 2025 12:17
github-merge-queue bot pushed a commit to MetaMask/metamask-mobile that referenced this pull request Sep 3, 2025
…18472)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Add multichain account provider state management when basic
functionality toggle changes on mobile.

When users toggle the "Basic Functionality" setting on mobile, account
providers need to be managed appropriately - non-EVM providers should be
disabled when basic functionality is OFF, and all providers should be
enabled with wallet alignment when basic functionality is ON.

## **Changelog**

CHANGELOG entry: null

This PR integrates with the
`MultichainAccountService.setBasicFunctionality()` method to:
- Update provider disabled states based on basic functionality
preference
- Trigger multichain wallet alignment when basic functionality is
enabled

1. **BasicFunctionalityModal** - Main settings toggle modal
2. **ConfirmTurnOnBackupAndSyncModal** - Backup & sync confirmation flow

Both now call
`Engine.context.MultichainAccountService.setBasicFunctionality({ enabled
})` after updating Redux state.

## **Related issues**

[MUL-343](https://consensyssoftware.atlassian.net/browse/MUL-343)

Relates to: MetaMask/metamask-extension#35190,
MetaMask/core#6332

## **Manual testing steps**

Scenario: user enables basic functionality from settings
Given basic functionality is currently disabled
And user is in Settings > Security & Privacy > Basic Functionality

When user toggles "Basic Functionality" to ON
Then Redux state updates to basicFunctionalityEnabled: true
And MultichainAccountService.setBasicFunctionality is called with
enabled: true
And console shows "MultichainAccountService: Setting basic functionality
enabled"
And console shows "Triggered wallet alignment..."
And all multichain account providers are enabled

---

Scenario: user disables basic functionality from settings  
Given basic functionality is currently enabled
And user is in Settings > Security & Privacy > Basic Functionality

When user toggles "Basic Functionality" to OFF
Then confirmation modal appears
When user confirms the action
Then Redux state updates to basicFunctionalityEnabled: false  
And MultichainAccountService.setBasicFunctionality is called with
enabled: false
And console shows "MultichainAccountService: Setting basic functionality
disabled"
And EVM provider remains active
And non-EVM providers (Solana, etc.) are disabled

---

Scenario: user enables basic functionality via backup sync flow
Given basic functionality is disabled
And user is in backup & sync confirmation modal

When user confirms "Turn On" 
Then MultichainAccountService.setBasicFunctionality is called with
enabled: true
And providers are enabled and alignment is triggered

## **Screenshots/Recordings**

<img width="1127" height="1011" alt="image"
src="https://github.com/user-attachments/assets/f5be2102-1b18-4b70-aee6-f36223d1be82"
/>


## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] 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-mobile/blob/main/.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.

[MUL-343]:
https://consensyssoftware.atlassian.net/browse/MUL-343?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
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.

5 participants