mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
persist user traits for comparison (#16506)
This commit is contained in:
parent
dbf49b1fe2
commit
557b6edf4f
@ -76,6 +76,8 @@ const exceptionsToFilter = {
|
|||||||
* @property {Array} [eventsBeforeMetricsOptIn] - Array of queued events added before
|
* @property {Array} [eventsBeforeMetricsOptIn] - Array of queued events added before
|
||||||
* a user opts into metrics.
|
* a user opts into metrics.
|
||||||
* @property {object} [traits] - Traits that are not derived from other state keys.
|
* @property {object} [traits] - Traits that are not derived from other state keys.
|
||||||
|
* @property {Record<string any>} [previousUserTraits] - The user traits the last
|
||||||
|
* time they were computed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default class MetaMetricsController {
|
export default class MetaMetricsController {
|
||||||
@ -685,7 +687,7 @@ export default class MetaMetricsController {
|
|||||||
* @returns {MetaMetricsTraits | null} traits that have changed since last update
|
* @returns {MetaMetricsTraits | null} traits that have changed since last update
|
||||||
*/
|
*/
|
||||||
_buildUserTraitsObject(metamaskState) {
|
_buildUserTraitsObject(metamaskState) {
|
||||||
const { traits } = this.store.getState();
|
const { traits, previousUserTraits } = this.store.getState();
|
||||||
/** @type {MetaMetricsTraits} */
|
/** @type {MetaMetricsTraits} */
|
||||||
const currentTraits = {
|
const currentTraits = {
|
||||||
[TRAITS.ADDRESS_BOOK_ENTRIES]: sum(
|
[TRAITS.ADDRESS_BOOK_ENTRIES]: sum(
|
||||||
@ -722,17 +724,17 @@ export default class MetaMetricsController {
|
|||||||
[TRAITS.TOKEN_DETECTION_ENABLED]: metamaskState.useTokenDetection,
|
[TRAITS.TOKEN_DETECTION_ENABLED]: metamaskState.useTokenDetection,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!this.previousTraits) {
|
if (!previousUserTraits) {
|
||||||
this.previousTraits = currentTraits;
|
this.store.updateState({ previousUserTraits: currentTraits });
|
||||||
return currentTraits;
|
return currentTraits;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.previousTraits && !isEqual(this.previousTraits, currentTraits)) {
|
if (previousUserTraits && !isEqual(previousUserTraits, currentTraits)) {
|
||||||
const updates = pickBy(
|
const updates = pickBy(
|
||||||
currentTraits,
|
currentTraits,
|
||||||
(v, k) => !isEqual(this.previousTraits[k], v),
|
(v, k) => !isEqual(previousUserTraits[k], v),
|
||||||
);
|
);
|
||||||
this.previousTraits = currentTraits;
|
this.store.updateState({ previousUserTraits: currentTraits });
|
||||||
return updates;
|
return updates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user