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), Object.values(metamaskState.addressBook).map(size),
), ),
[TRAITS.LEDGER_CONNECTION_TYPE]: metamaskState.ledgerTransportType, [TRAITS.LEDGER_CONNECTION_TYPE]: metamaskState.ledgerTransportType,
[TRAITS.NUMBER_OF_ACCOUNTS]: Object.values(metamaskState.identities)
.length,
[TRAITS.NETWORKS_ADDED]: metamaskState.frequentRpcListDetail.map( [TRAITS.NETWORKS_ADDED]: metamaskState.frequentRpcListDetail.map(
(rpc) => rpc.chainId, (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( [TRAITS.NUMBER_OF_NFT_COLLECTIONS]: this._getNumberOfNFtCollection(
metamaskState, metamaskState,
), ),
[TRAITS.OPENSEA_API_ENABLED]: metamaskState.openSeaEnabled,
[TRAITS.THREE_BOX_ENABLED]: metamaskState.threeBoxSyncingAllowed,
}; };
if (!this.previousTraits) { if (!this.previousTraits) {

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

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

Loading…
Cancel
Save