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

feat: preferences controller to base controller v2 #27398

Merged
merged 64 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3da007e
upgrade preferences controller to base controller v2
kanthesha Sep 20, 2024
be16a89
fixed dependencies of PreferencesController
kanthesha Sep 23, 2024
9187999
Merge branch 'develop' into feat/upgrade-preferences-controller-to-v2
kanthesha Sep 23, 2024
788e141
preferencescontroller dependencies
kanthesha Sep 23, 2024
30aa0a7
metamask-controller and tests updated
kanthesha Sep 23, 2024
5069931
OnPreferencesStateChange added to MetaMetrix
kanthesha Sep 24, 2024
d1e0d83
listener updated
kanthesha Sep 24, 2024
5195082
fix re-publishing preferences state
kanthesha Sep 24, 2024
6ee82ed
test e2e
kanthesha Sep 25, 2024
b88fcc6
preferences dependencies updated
kanthesha Sep 25, 2024
54294df
update eslintrc
kanthesha Sep 25, 2024
0e1077a
preferences.js and preferences.test.js removed
kanthesha Sep 25, 2024
11e0d3a
pref state change updated
kanthesha Sep 25, 2024
dada0d4
privacy snapshot updated
kanthesha Sep 26, 2024
efda3a4
preferences controller updated
kanthesha Sep 26, 2024
c874699
removed new entries in privacy snapshot
kanthesha Sep 26, 2024
51e8886
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Sep 26, 2024
e141165
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Sep 26, 2024
9d9291f
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Sep 26, 2024
7c80640
preferences controller test coverage improved
kanthesha Sep 27, 2024
06b165e
Merge branch 'feat/preferences-controller-to-base-controller-v2' of g…
kanthesha Sep 27, 2024
14e05ba
resolve merge conflict
kanthesha Oct 1, 2024
077a4be
include Mechele suggestions
kanthesha Oct 1, 2024
1b1dc70
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 1, 2024
d5c6579
PreferencesController lint fix
kanthesha Oct 1, 2024
5e9b867
Merge branch 'feat/preferences-controller-to-base-controller-v2' of g…
kanthesha Oct 1, 2024
957eec9
anonymous of controller metadata updated based on sentry-state.ts
kanthesha Oct 1, 2024
1483091
replace any with Json in snapRegistryList
kanthesha Oct 1, 2024
792d82d
lint fix
kanthesha Oct 2, 2024
b30d1d7
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 2, 2024
3f07cec
warning message moved to state declaration
kanthesha Oct 2, 2024
09cec04
initLangCode removed, networkConfigurationsByChainId by messenger and…
kanthesha Oct 4, 2024
4eb1ae7
resolve merge conflict
kanthesha Oct 4, 2024
c1b84cd
remove unneccesary check
kanthesha Oct 4, 2024
2314923
remove default export from PreferencesController
kanthesha Oct 4, 2024
241ec77
resolve merge conflict
kanthesha Oct 4, 2024
25b9104
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 4, 2024
a734fb2
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
mikesposito Oct 8, 2024
6d54c24
extend core PreferencesController state
kanthesha Oct 8, 2024
67ec4fa
Merge branch 'feat/preferences-controller-to-base-controller-v2' of g…
kanthesha Oct 8, 2024
5d59442
Update LavaMoat policies
metamaskbot Oct 8, 2024
adda932
default preferences updated
kanthesha Oct 9, 2024
e42bc59
resolve merge conflict and defaults of e2e tests updated
kanthesha Oct 9, 2024
78d6ebc
Merge branch 'feat/preferences-controller-to-base-controller-v2' of g…
kanthesha Oct 9, 2024
28242b5
remove passing onboardingController to account tracker
kanthesha Oct 9, 2024
243bf79
update e2e tests
kanthesha Oct 9, 2024
d2a3e5e
update e2e tests
kanthesha Oct 9, 2024
d25bf35
update e2e tests
kanthesha Oct 9, 2024
5e2856c
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 9, 2024
31ca2fc
update e2e tests
kanthesha Oct 9, 2024
24ce5f8
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 9, 2024
936a4a9
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 10, 2024
ea9583d
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 10, 2024
a4c1952
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 10, 2024
3f0011e
fix current locale
kanthesha Oct 11, 2024
a1a4a0f
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
cryptodev-2s Oct 12, 2024
a8b0c53
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 14, 2024
37b1d31
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 14, 2024
0eb3dc5
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 14, 2024
c7abe9b
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
kanthesha Oct 14, 2024
0c94e58
Merge branch 'feat/preferences-controller-to-base-controller-v2' of g…
kanthesha Oct 14, 2024
e0f925e
resolve merge conflict
kanthesha Oct 14, 2024
fc7958b
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 14, 2024
5dcdc42
Merge branch 'develop' into feat/preferences-controller-to-base-contr…
kanthesha Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ module.exports = {
'app/scripts/controllers/swaps/**/*.test.ts',
'app/scripts/controllers/metametrics.test.js',
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/controllers/preferences.test.js',
'app/scripts/controllers/preferences-controller.test.ts',
'app/scripts/lib/**/*.test.js',
'app/scripts/metamask-controller.test.js',
'app/scripts/migrations/*.test.js',
Expand Down
5 changes: 2 additions & 3 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function maybeDetectPhishing(theController) {
return {};
}

const prefState = theController.preferencesController.store.getState();
const prefState = theController.preferencesController.state;
if (!prefState.usePhishDetect) {
return {};
}
Expand Down Expand Up @@ -758,8 +758,7 @@ export function setupController(
controller.preferencesController,
),
getUseAddressBarEnsResolution: () =>
controller.preferencesController.store.getState()
.useAddressBarEnsResolution,
controller.preferencesController.state.useAddressBarEnsResolution,
provider: controller.provider,
});

Expand Down
23 changes: 15 additions & 8 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class AppStateController extends EventEmitter {
isUnlocked,
initState,
onInactiveTimeout,
preferencesStore,
preferencesController,
messenger,
extension,
} = opts;
Expand Down Expand Up @@ -85,12 +85,18 @@ export default class AppStateController extends EventEmitter {
this.waitingForUnlock = [];
addUnlockListener(this.handleUnlock.bind(this));

preferencesStore.subscribe(({ preferences }) => {
const currentState = this.store.getState();
if (currentState.timeoutMinutes !== preferences.autoLockTimeLimit) {
this._setInactiveTimeout(preferences.autoLockTimeLimit);
}
});
messenger.subscribe(
'PreferencesController:stateChange',
({ preferences }) => {
const currentState = this.store.getState();
if (
preferences &&
currentState.timeoutMinutes !== preferences.autoLockTimeLimit
) {
this._setInactiveTimeout(preferences.autoLockTimeLimit);
}
},
);

messenger.subscribe(
'KeyringController:qrKeyringStateChange',
Expand All @@ -100,7 +106,8 @@ export default class AppStateController extends EventEmitter {
}),
);

const { preferences } = preferencesStore.getState();
const { preferences } = preferencesController.state;
cryptodev-2s marked this conversation as resolved.
Show resolved Hide resolved

this._setInactiveTimeout(preferences.autoLockTimeLimit);

this.messagingSystem = messenger;
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/controllers/app-state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ describe('AppStateController', () => {
initState,
onInactiveTimeout: jest.fn(),
showUnlockRequest: jest.fn(),
preferencesStore: {
subscribe: jest.fn(),
getState: jest.fn(() => ({
preferencesController: {
state: {
preferences: {
autoLockTimeLimit: 0,
},
})),
},
},
messenger: {
call: jest.fn(() => ({
Expand Down
17 changes: 9 additions & 8 deletions app/scripts/controllers/metametrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ export default class MetaMetricsController {
* @param {object} options
* @param {object} options.segment - an instance of analytics for tracking
* events that conform to the new MetaMetrics tracking plan.
* @param {object} options.preferencesStore - The preferences controller store, used
* to access and subscribe to preferences that will be attached to events
* @param {object} options.preferencesControllerState - The state of preferences controller
* @param {Function} options.onPreferencesStateChange - Used to attach a listener to the
* stateChange event emitted by the PreferencesController
* @param {Function} options.onNetworkDidChange - Used to attach a listener to the
* networkDidChange event emitted by the networkController
* @param {Function} options.getCurrentChainId - Gets the current chain id from the
Expand All @@ -128,7 +129,8 @@ export default class MetaMetricsController {
*/
constructor({
segment,
preferencesStore,
preferencesControllerState,
onPreferencesStateChange,
onNetworkDidChange,
getCurrentChainId,
version,
Expand All @@ -144,16 +146,15 @@ export default class MetaMetricsController {
captureException(err);
}
};
const prefState = preferencesStore.getState();
this.chainId = getCurrentChainId();
this.locale = prefState.currentLocale.replace('_', '-');
this.locale = preferencesControllerState.currentLocale.replace('_', '-');
this.version =
environment === 'production' ? version : `${version}-${environment}`;
this.extension = extension;
this.environment = environment;

///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
this.selectedAddress = prefState.selectedAddress;
this.selectedAddress = preferencesControllerState.selectedAddress;
///: END:ONLY_INCLUDE_IF

const abandonedFragments = omitBy(initState?.fragments, 'persist');
Expand All @@ -177,8 +178,8 @@ export default class MetaMetricsController {
},
});

preferencesStore.subscribe(({ currentLocale }) => {
this.locale = currentLocale.replace('_', '-');
onPreferencesStateChange(({ currentLocale }) => {
this.locale = currentLocale?.replace('_', '-');
});

onNetworkDidChange(() => {
Expand Down
49 changes: 24 additions & 25 deletions app/scripts/controllers/metametrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,6 @@ const DEFAULT_PAGE_PROPERTIES = {
...DEFAULT_SHARED_PROPERTIES,
};

function getMockPreferencesStore({ currentLocale = LOCALE } = {}) {
let preferencesStore = {
currentLocale,
};
const subscribe = jest.fn();
const updateState = (newState) => {
preferencesStore = { ...preferencesStore, ...newState };
subscribe.mock.calls[0][0](preferencesStore);
};
return {
getState: jest.fn().mockReturnValue(preferencesStore),
updateState,
subscribe,
};
}

const SAMPLE_PERSISTED_EVENT = {
id: 'testid',
persist: true,
Expand Down Expand Up @@ -117,7 +101,10 @@ function getMetaMetricsController({
participateInMetaMetrics = true,
metaMetricsId = TEST_META_METRICS_ID,
marketingCampaignCookieId = null,
preferencesStore = getMockPreferencesStore(),
preferencesControllerState = { currentLocale: LOCALE },
onPreferencesStateChange = () => {
// do nothing
},
getCurrentChainId = () => FAKE_CHAIN_ID,
onNetworkDidChange = () => {
// do nothing
Expand All @@ -128,7 +115,8 @@ function getMetaMetricsController({
segment: segmentInstance || segment,
getCurrentChainId,
onNetworkDidChange,
preferencesStore,
preferencesControllerState,
onPreferencesStateChange,
version: '0.0.1',
environment: 'test',
initState: {
Expand Down Expand Up @@ -209,11 +197,16 @@ describe('MetaMetricsController', function () {
});

it('should update when preferences changes', function () {
const preferencesStore = getMockPreferencesStore();
let subscribeListener;
const onPreferencesStateChange = (listener) => {
subscribeListener = listener;
};
const metaMetricsController = getMetaMetricsController({
preferencesStore,
preferencesControllerState: { currentLocale: LOCALE },
onPreferencesStateChange,
});
preferencesStore.updateState({ currentLocale: 'en_UK' });

subscribeListener({ currentLocale: 'en_UK' });
expect(metaMetricsController.locale).toStrictEqual('en-UK');
});
});
Expand Down Expand Up @@ -732,9 +725,11 @@ describe('MetaMetricsController', function () {

it('should track a page view if isOptInPath is true and user not yet opted in', function () {
const metaMetricsController = getMetaMetricsController({
preferencesStore: getMockPreferencesStore({
preferencesControllerState: {
currentLocale: LOCALE,
participateInMetaMetrics: null,
}),
},
onPreferencesStateChange: jest.fn(),
});
const spy = jest.spyOn(segment, 'page');
metaMetricsController.trackPage(
Expand All @@ -746,6 +741,7 @@ describe('MetaMetricsController', function () {
},
{ isOptInPath: true },
);

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(
{
Expand All @@ -765,9 +761,11 @@ describe('MetaMetricsController', function () {

it('multiple trackPage call with same actionId should result in same messageId being sent to segment', function () {
const metaMetricsController = getMetaMetricsController({
preferencesStore: getMockPreferencesStore({
preferencesControllerState: {
currentLocale: LOCALE,
participateInMetaMetrics: null,
}),
},
onPreferencesStateChange: jest.fn(),
});
const spy = jest.spyOn(segment, 'page');
metaMetricsController.trackPage(
Expand All @@ -790,6 +788,7 @@ describe('MetaMetricsController', function () {
},
{ isOptInPath: true },
);

expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenCalledWith(
{
Expand Down
13 changes: 6 additions & 7 deletions app/scripts/controllers/mmi-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ describe('MMIController', function () {
});

metaMetricsController = new MetaMetricsController({
preferencesStore: {
getState: jest.fn().mockReturnValue({ currentLocale: 'en' }),
subscribe: jest.fn(),
preferencesControllerState: {
currentLocale: 'en'
},
onPreferencesStateChange: jest.fn(),
getCurrentChainId: jest.fn(),
onNetworkDidChange: jest.fn(),
});
Expand Down Expand Up @@ -245,13 +245,12 @@ describe('MMIController', function () {
initState: {},
onInactiveTimeout: jest.fn(),
showUnlockRequest: jest.fn(),
preferencesStore: {
subscribe: jest.fn(),
getState: jest.fn(() => ({
preferencesController: {
state: {
preferences: {
autoLockTimeLimit: 0,
},
})),
},
},
messenger: mockMessenger,
}),
Expand Down
Loading