Skip to content

Commit f8c4c8a

Browse files
bergarcessahar-fehriamitabh94mcmire
authored
chore: rename state and add methods to preferences controller to match already patchede code (#6707)
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> Adds the missing non-nft related changes of the mobile client patch to the repo. https://github.com/MetaMask/metamask-mobile/blob/main/patches/%40metamask%2Bpreferences-controller%2B18.4.0.patch With this PR, the `@metamask/preferences-controller` patch on mobile can be removed completely. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> * Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-1308 ## 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 communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [X] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes --------- Co-authored-by: sahar-fehri <sahar.fehri@consensys.net> Co-authored-by: Amitabh Aggarwal <aggarwal.amitabh@gmail.com> Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
1 parent 654158c commit f8c4c8a

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

packages/preferences-controller/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Add a new controller state property: `tokenNetworkFilter` ([#6707](https://github.com/MetaMask/core/pull/6707))
13+
- Add a new controller method: `setTokenNetworkFilter` ([#6707](https://github.com/MetaMask/core/pull/6707))
1214
- Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6525](https://github.com/MetaMask/core/pull/6525))
1315

1416
### Changed
1517

16-
- **BREAKING:** Rename `openSeaEnabled` to `displayNftMedia` ([#4774](https://github.com/MetaMask/core/pull/4774))
17-
- **BREAKING:** Rename `setOpenSeaEnabled` to `setDisplayNftMedia` ([#4774](https://github.com/MetaMask/core/pull/4774))
18+
- **BREAKING:** Rename controller state property from `useMultiRpcMigration` to `showMultiRpcModal` ([#6707](https://github.com/MetaMask/core/pull/6707))
19+
- **BREAKING:** Rename controller method from `setUseMultiRpcMigration` to `setShowMultiRpcModal` ([#6707](https://github.com/MetaMask/core/pull/6707))
20+
- **BREAKING:** Rename controller state property from `openSeaEnabled` to `displayNftMedia` ([#4774](https://github.com/MetaMask/core/pull/4774))
21+
- **BREAKING:** Rename controller method from `setOpenSeaEnabled` to `setDisplayNftMedia` ([#4774](https://github.com/MetaMask/core/pull/4774))
1822
- Bump `@metamask/controller-utils` from `^11.12.0` to `^11.14.0` ([#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629))
1923
- Bump `@metamask/base-controller` from `^8.1.0` to `^8.4.0` ([#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465), [#6632](https://github.com/MetaMask/core/pull/6632))
2024
- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))

packages/preferences-controller/src/PreferencesController.test.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('PreferencesController', () => {
3030
smartAccountOptInForAccounts: [],
3131
isIpfsGatewayEnabled: true,
3232
useTransactionSimulations: true,
33-
useMultiRpcMigration: true,
33+
showMultiRpcModal: true,
3434
showIncomingTransactions: Object.values(
3535
ETHERSCAN_SUPPORTED_CHAIN_IDS,
3636
).reduce(
@@ -49,6 +49,7 @@ describe('PreferencesController', () => {
4949
},
5050
privacyMode: false,
5151
dismissSmartAccountSuggestionEnabled: false,
52+
tokenNetworkFilter: {},
5253
});
5354
});
5455

@@ -448,14 +449,23 @@ describe('PreferencesController', () => {
448449

449450
it('should set useMultiRpcMigration', () => {
450451
const controller = setupPreferencesController();
451-
controller.setUseMultiRpcMigration(true);
452-
expect(controller.state.useMultiRpcMigration).toBe(true);
452+
controller.setShowMultiRpcModal(true);
453+
expect(controller.state.showMultiRpcModal).toBe(true);
453454
});
454455

455456
it('should set useMultiRpcMigration is false value is passed', () => {
456457
const controller = setupPreferencesController();
457-
controller.setUseMultiRpcMigration(false);
458-
expect(controller.state.useMultiRpcMigration).toBe(false);
458+
controller.setShowMultiRpcModal(false);
459+
expect(controller.state.showMultiRpcModal).toBe(false);
460+
});
461+
462+
it('sets tokenNetworkFilter', () => {
463+
const controller = setupPreferencesController();
464+
controller.setTokenNetworkFilter({ '0x1': true, '0xa': false });
465+
expect(controller.state.tokenNetworkFilter).toStrictEqual({
466+
'0x1': true,
467+
'0xa': false,
468+
});
459469
});
460470

461471
it('should set featureFlags', () => {
@@ -615,6 +625,7 @@ describe('PreferencesController', () => {
615625
"0xfa": true,
616626
"0xfa2": true,
617627
},
628+
"showMultiRpcModal": true,
618629
"showTestNetworks": false,
619630
"smartAccountOptIn": true,
620631
"smartAccountOptInForAccounts": Array [],
@@ -623,7 +634,6 @@ describe('PreferencesController', () => {
623634
"order": "dsc",
624635
"sortCallback": "stringNumeric",
625636
},
626-
"useMultiRpcMigration": true,
627637
"useNftDetection": false,
628638
"useSafeChainsListValidation": true,
629639
"useTokenDetection": true,
@@ -677,16 +687,17 @@ describe('PreferencesController', () => {
677687
"0xfa": true,
678688
"0xfa2": true,
679689
},
690+
"showMultiRpcModal": true,
680691
"showTestNetworks": false,
681692
"smartAccountOptIn": true,
682693
"smartAccountOptInForAccounts": Array [],
683694
"smartTransactionsOptInStatus": true,
695+
"tokenNetworkFilter": Object {},
684696
"tokenSortConfig": Object {
685697
"key": "tokenFiatAmount",
686698
"order": "dsc",
687699
"sortCallback": "stringNumeric",
688700
},
689-
"useMultiRpcMigration": true,
690701
"useNftDetection": false,
691702
"useSafeChainsListValidation": true,
692703
"useTokenDetection": true,
@@ -740,16 +751,17 @@ describe('PreferencesController', () => {
740751
"0xfa": true,
741752
"0xfa2": true,
742753
},
754+
"showMultiRpcModal": true,
743755
"showTestNetworks": false,
744756
"smartAccountOptIn": true,
745757
"smartAccountOptInForAccounts": Array [],
746758
"smartTransactionsOptInStatus": true,
759+
"tokenNetworkFilter": Object {},
747760
"tokenSortConfig": Object {
748761
"key": "tokenFiatAmount",
749762
"order": "dsc",
750763
"sortCallback": "stringNumeric",
751764
},
752-
"useMultiRpcMigration": true,
753765
"useNftDetection": false,
754766
"useSafeChainsListValidation": true,
755767
"useTokenDetection": true,
@@ -802,16 +814,17 @@ describe('PreferencesController', () => {
802814
"0xfa": true,
803815
"0xfa2": true,
804816
},
817+
"showMultiRpcModal": true,
805818
"showTestNetworks": false,
806819
"smartAccountOptIn": true,
807820
"smartAccountOptInForAccounts": Array [],
808821
"smartTransactionsOptInStatus": true,
822+
"tokenNetworkFilter": Object {},
809823
"tokenSortConfig": Object {
810824
"key": "tokenFiatAmount",
811825
"order": "dsc",
812826
"sortCallback": "stringNumeric",
813827
},
814-
"useMultiRpcMigration": true,
815828
"useNftDetection": false,
816829
"useSafeChainsListValidation": true,
817830
"useTokenDetection": true,

packages/preferences-controller/src/PreferencesController.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export type PreferencesState = {
120120
/**
121121
* Controls whether Multi rpc modal is displayed or not
122122
*/
123-
useMultiRpcMigration: boolean;
123+
showMultiRpcModal: boolean;
124124
/**
125125
* Controls whether to use the safe chains list validation
126126
*/
@@ -147,6 +147,10 @@ export type PreferencesState = {
147147
* @deprecated This preference is deprecated and will be removed in the future.
148148
*/
149149
smartAccountOptInForAccounts: Hex[];
150+
/**
151+
* Controls token filtering controls
152+
*/
153+
tokenNetworkFilter: Record<string, boolean>;
150154
};
151155

152156
const metadata = {
@@ -240,7 +244,7 @@ const metadata = {
240244
anonymous: true,
241245
usedInUi: true,
242246
},
243-
useMultiRpcMigration: {
247+
showMultiRpcModal: {
244248
includeInStateLogs: true,
245249
persist: true,
246250
anonymous: true,
@@ -282,6 +286,12 @@ const metadata = {
282286
anonymous: true,
283287
usedInUi: true,
284288
},
289+
tokenNetworkFilter: {
290+
includeInStateLogs: true,
291+
persist: true,
292+
anonymous: false,
293+
usedInUi: true,
294+
},
285295
};
286296

287297
const name = 'PreferencesController';
@@ -352,7 +362,7 @@ export function getDefaultPreferencesState(): PreferencesState {
352362
showTestNetworks: false,
353363
useNftDetection: false,
354364
useTokenDetection: true,
355-
useMultiRpcMigration: true,
365+
showMultiRpcModal: true,
356366
smartTransactionsOptInStatus: true,
357367
useTransactionSimulations: true,
358368
useSafeChainsListValidation: true,
@@ -365,6 +375,7 @@ export function getDefaultPreferencesState(): PreferencesState {
365375
dismissSmartAccountSuggestionEnabled: false,
366376
smartAccountOptIn: true,
367377
smartAccountOptInForAccounts: [],
378+
tokenNetworkFilter: {},
368379
};
369380
}
370381

@@ -652,13 +663,13 @@ export class PreferencesController extends BaseController<
652663
/**
653664
* Toggle multi rpc migration modal.
654665
*
655-
* @param useMultiRpcMigration - Boolean indicating if the multi rpc modal will be displayed or not.
666+
* @param showMultiRpcModal - Boolean indicating if the multi rpc modal will be displayed or not.
656667
*/
657-
setUseMultiRpcMigration(useMultiRpcMigration: boolean) {
668+
setShowMultiRpcModal(showMultiRpcModal: boolean) {
658669
this.update((state) => {
659-
state.useMultiRpcMigration = useMultiRpcMigration;
660-
if (!useMultiRpcMigration) {
661-
state.useMultiRpcMigration = false;
670+
state.showMultiRpcModal = showMultiRpcModal;
671+
if (!showMultiRpcModal) {
672+
state.showMultiRpcModal = false;
662673
}
663674
});
664675
}
@@ -755,6 +766,17 @@ export class PreferencesController extends BaseController<
755766
state.smartAccountOptInForAccounts = accounts;
756767
});
757768
}
769+
770+
/**
771+
* Set the token network filter configuration setting.
772+
*
773+
* @param tokenNetworkFilter - Object describing token network filter configuration.
774+
*/
775+
setTokenNetworkFilter(tokenNetworkFilter: Record<string, boolean>) {
776+
this.update((state) => {
777+
state.tokenNetworkFilter = tokenNetworkFilter;
778+
});
779+
}
758780
}
759781

760782
export default PreferencesController;

0 commit comments

Comments
 (0)