Skip to content

Commit

Permalink
feat(multi-srp): add number_of_hd_entropies user trait
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykLucka committed Feb 19, 2025
1 parent fad21cd commit fe06ffe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/scripts/controllers/metametrics-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
keyrings: [],
});

expect(traits).toStrictEqual({
Expand Down Expand Up @@ -1555,6 +1556,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
keyrings: [],
});

const updatedTraits = controller._buildUserTraitsObject({
Expand Down Expand Up @@ -1614,6 +1616,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
keyrings: [],
});

expect(updatedTraits).toStrictEqual({
Expand Down Expand Up @@ -1681,6 +1684,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
keyrings: [],
});

const updatedTraits = controller._buildUserTraitsObject({
Expand Down Expand Up @@ -1730,6 +1734,7 @@ describe('MetaMetricsController', function () {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
custodyAccountDetails: {},
///: END:ONLY_INCLUDE_IF
keyrings: [],
});
expect(updatedTraits).toStrictEqual(null);
});
Expand Down
18 changes: 18 additions & 0 deletions app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import Analytics from '../lib/segment/analytics';
import { ENVIRONMENT } from '../../../development/build/constants';
///: END:ONLY_INCLUDE_IF

import { KeyringType } from '../../../shared/constants/keyring';
import type {
PreferencesControllerState,
PreferencesControllerGetStateAction,
Expand Down Expand Up @@ -175,6 +176,7 @@ export type MetaMaskState = {
};
};
///: END:ONLY_INCLUDE_IF
keyrings: { type: string; accounts: string[] }[];
};

/**
Expand Down Expand Up @@ -1209,6 +1211,9 @@ export default class MetaMetricsController extends BaseController<
[MetaMetricsUserTrait.NumberOfTokens]: this.#getNumberOfTokens(
metamaskState.allTokens,
),
[MetaMetricsUserTrait.NumberOfHDEntropies]:
this.#getNumberOfHDEntropies(metamaskState) ??
previousUserTraits?.number_of_hd_entropies,
[MetaMetricsUserTrait.OpenSeaApiEnabled]: metamaskState.openSeaEnabled,
[MetaMetricsUserTrait.ThreeBoxEnabled]: false, // deprecated, hard-coded as false
[MetaMetricsUserTrait.Theme]: metamaskState.theme || 'default',
Expand Down Expand Up @@ -1335,6 +1340,19 @@ export default class MetaMetricsController extends BaseController<
}, 0);
}

/**
* Returns the number of HD Entropies the user has.
*
* @param metamaskState
*/
#getNumberOfHDEntropies(metamaskState: MetaMaskState): number {
return (
metamaskState.keyrings?.filter(
(keyring) => keyring.type === KeyringType.hdKeyTree,
).length ?? 0
);
}

/**
* Calls segment.identify with given user traits
*
Expand Down
8 changes: 8 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ export type MetaMetricsUserTraits = {
* accounts.
*/
number_of_tokens?: number;
/**
* The number of HD Entropies the user has.
*/
number_of_hd_entropies?: number;
/**
* Does the user have the OpenSea API enabled?
*/
Expand Down Expand Up @@ -541,6 +545,10 @@ export enum MetaMetricsUserTrait {
* Identified when the number of tokens change.
*/
NumberOfTokens = 'number_of_tokens',
/**
* Identified when the user has HD Entropies
*/
NumberOfHDEntropies = 'number_of_hd_entropies',
/**
* Identified when the OpenSea API is enabled.
*/
Expand Down

0 comments on commit fe06ffe

Please sign in to comment.