MetaMetrics: Identify 'nft_autodetection_enabled' & 'opensea_api_enabled' (#14367)

* MetaMetrics: alphabetize traits

* MetaMetrics: identify nft_autodetection_enabled

* MetaMetrics: identify opensea_api_enabled

* metametrics.test: alphabetize traits

* metametrics.test: add new traits
- nft_autodetection_enabled
- opensea_api_enabled

* MetaMetrics: @property use string literals

* MetaMetrics.test: update with openSeaEnabled & useCollectibleDetection

* MetaMetrics: alphabetize

* MetaMetrics: update MetaMetricsTraits @typedef
- add nft_autodetection_enabled
- add opensea_api_enabled
feature/default_network_editable
Ariella Vu 3 years ago committed by GitHub
parent eed6ae2b8c
commit e7bb8e2663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/scripts/controllers/metametrics.js
  2. 63
      app/scripts/controllers/metametrics.test.js
  3. 10
      shared/constants/metametrics.js

@ -548,15 +548,17 @@ export default class MetaMetricsController {
Object.values(metamaskState.addressBook).map(size),
),
[TRAITS.LEDGER_CONNECTION_TYPE]: metamaskState.ledgerTransportType,
[TRAITS.NUMBER_OF_ACCOUNTS]: Object.values(metamaskState.identities)
.length,
[TRAITS.NETWORKS_ADDED]: metamaskState.frequentRpcListDetail.map(
(rpc) => rpc.chainId,
),
[TRAITS.THREE_BOX_ENABLED]: metamaskState.threeBoxSyncingAllowed,
[TRAITS.NFT_AUTODETECTION_ENABLED]: metamaskState.useCollectibleDetection,
[TRAITS.NUMBER_OF_ACCOUNTS]: Object.values(metamaskState.identities)
.length,
[TRAITS.NUMBER_OF_NFT_COLLECTIONS]: this._getNumberOfNFtCollection(
metamaskState,
),
[TRAITS.OPENSEA_API_ENABLED]: metamaskState.openSeaEnabled,
[TRAITS.THREE_BOX_ENABLED]: metamaskState.threeBoxSyncingAllowed,
};
if (!this.previousTraits) {

@ -613,12 +613,10 @@ describe('MetaMetricsController', function () {
it('should return full user traits object on first call', function () {
const metaMetricsController = getMetaMetricsController();
const traits = metaMetricsController._buildUserTraitsObject({
frequentRpcListDetail: [
{ chainId: MAINNET_CHAIN_ID },
{ chainId: ROPSTEN_CHAIN_ID },
],
ledgerTransportType: 'web-hid',
identities: [{}, {}],
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
allCollectibles: {
'0xac706cE8A9BF27Afecf080fB298d0ee13cfb978A': {
56: [
@ -645,19 +643,25 @@ describe('MetaMetricsController', function () {
],
},
},
frequentRpcListDetail: [
{ chainId: MAINNET_CHAIN_ID },
{ chainId: ROPSTEN_CHAIN_ID },
],
identities: [{}, {}],
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
threeBoxSyncingAllowed: false,
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
useCollectibleDetection: false,
});
assert.deepEqual(traits, {
[TRAITS.ADDRESS_BOOK_ENTRIES]: 3,
[TRAITS.LEDGER_CONNECTION_TYPE]: 'web-hid',
[TRAITS.NETWORKS_ADDED]: [MAINNET_CHAIN_ID, ROPSTEN_CHAIN_ID],
[TRAITS.NFT_AUTODETECTION_ENABLED]: false,
[TRAITS.NUMBER_OF_ACCOUNTS]: 2,
[TRAITS.NUMBER_OF_NFT_COLLECTIONS]: 3,
[TRAITS.OPENSEA_API_ENABLED]: true,
[TRAITS.THREE_BOX_ENABLED]: false,
});
});
@ -665,67 +669,76 @@ describe('MetaMetricsController', function () {
it('should return only changed traits object on subsequent calls', function () {
const metaMetricsController = getMetaMetricsController();
metaMetricsController._buildUserTraitsObject({
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
frequentRpcListDetail: [
{ chainId: MAINNET_CHAIN_ID },
{ chainId: ROPSTEN_CHAIN_ID },
],
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
identities: [{}, {}],
threeBoxSyncingAllowed: false,
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
useCollectibleDetection: false,
});
const updatedTraits = metaMetricsController._buildUserTraitsObject({
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }, { address: '0x1' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
frequentRpcListDetail: [
{ chainId: MAINNET_CHAIN_ID },
{ chainId: ROPSTEN_CHAIN_ID },
],
ledgerTransportType: 'web-hid',
openSeaEnabled: false,
identities: [{}, {}, {}],
threeBoxSyncingAllowed: false,
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }, { address: '0x1' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
useCollectibleDetection: false,
});
assert.deepEqual(updatedTraits, {
[TRAITS.ADDRESS_BOOK_ENTRIES]: 4,
[TRAITS.NUMBER_OF_ACCOUNTS]: 3,
[TRAITS.OPENSEA_API_ENABLED]: false,
});
});
it('should return null if no traits changed', function () {
const metaMetricsController = getMetaMetricsController();
metaMetricsController._buildUserTraitsObject({
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
frequentRpcListDetail: [
{ chainId: MAINNET_CHAIN_ID },
{ chainId: ROPSTEN_CHAIN_ID },
],
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
identities: [{}, {}],
threeBoxSyncingAllowed: false,
useCollectibleDetection: true,
});
const updatedTraits = metaMetricsController._buildUserTraitsObject({
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
});
const updatedTraits = metaMetricsController._buildUserTraitsObject({
frequentRpcListDetail: [
{ chainId: MAINNET_CHAIN_ID },
{ chainId: ROPSTEN_CHAIN_ID },
],
ledgerTransportType: 'web-hid',
openSeaEnabled: true,
identities: [{}, {}],
threeBoxSyncingAllowed: false,
addressBook: {
[MAINNET_CHAIN_ID]: [{ address: '0x' }],
[ROPSTEN_CHAIN_ID]: [{ address: '0x' }, { address: '0x0' }],
},
useCollectibleDetection: true,
});
assert.equal(updatedTraits, null);

@ -164,10 +164,14 @@
* trait
* @property {'networks_added'} NETWORKS_ADDED - when user modifies networks
* we identify the networks_added trait
* @property {'nft_autodetection_enabled'} NFT_AUTODETECTION_ENABLED - when Autodetect NFTs
* feature is toggled we identify the nft_autodetection_enabled trait
* @property {'number_of_accounts'} NUMBER_OF_ACCOUNTS - when identities
* change, we identify the new number_of_accounts trait
* @property {'number_of_nft_collections'} NUMBER_OF_NFT_COLLECTIONS - user
* trait for number of unique NFT addresses
* @property {'opensea_api_enabled'} OPENSEA_API_ENABLED - when the OpenSea API is enabled
* we identify the opensea_api_enabled trait
* @property {'three_box_enabled'} THREE_BOX_ENABLED - when 3box feature is
* toggled we identify the 3box_enabled trait
*/
@ -181,8 +185,10 @@ export const TRAITS = {
ADDRESS_BOOK_ENTRIES: 'address_book_entries',
LEDGER_CONNECTION_TYPE: 'ledger_connection_type',
NETWORKS_ADDED: 'networks_added',
NFT_AUTODETECTION_ENABLED: 'nft_autodetection_enabled',
NUMBER_OF_ACCOUNTS: 'number_of_accounts',
NUMBER_OF_NFT_COLLECTIONS: 'number_of_nft_collections',
OPENSEA_API_ENABLED: 'opensea_api_enabled',
THREE_BOX_ENABLED: 'three_box_enabled',
};
@ -194,10 +200,14 @@ export const TRAITS = {
* type of ledger connection set by user preference.
* @property {Array<string>} [networks_added] - An array consisting of chainIds
* that indicate the networks a user has added to their MetaMask.
* @property {number} [nft_autodetection_enabled] - does the user have the
* use collection/nft detection enabled?
* @property {number} [number_of_accounts] - A number representing the number
* of identities(accounts) added to the user's MetaMask.
* @property {number} [number_of_nft_collections] - A number representing the
* amount of different NFT collections the user possesses an NFT from.
* @property {boolean} [opensea_api_enabled] - does the user have the OpenSea
* API enabled?
* @property {boolean} [three_box_enabled] - does the user have 3box sync
* enabled?
*/

Loading…
Cancel
Save