mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
User trait - number of nft collections (#14377)
* Add new user trait for 'Number of NFT collections'. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> FIx JS DOC Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Arrange TRAITS in alphabetical order Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> Unit Tests for allCollectibles traits tracking. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> change cid to chainId Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * invert condition Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * jsdoc - alphabetical order Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * change {string} to the literal {number_of_nft_collections} Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Optimize _getNumberOfNFTs Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
This commit is contained in:
parent
637a960d3c
commit
9bd391a35f
@ -540,6 +540,9 @@ export default class MetaMetricsController {
|
||||
(rpc) => rpc.chainId,
|
||||
),
|
||||
[TRAITS.THREE_BOX_ENABLED]: metamaskState.threeBoxSyncingAllowed,
|
||||
[TRAITS.NUMBER_OF_NFT_COLLECTIONS]: this._getNumberOfNFtCollection(
|
||||
metamaskState,
|
||||
),
|
||||
};
|
||||
|
||||
if (!this.previousTraits) {
|
||||
@ -581,6 +584,25 @@ export default class MetaMetricsController {
|
||||
}, {});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} metamaskState
|
||||
* @returns number of unique collectible addresses
|
||||
*/
|
||||
_getNumberOfNFtCollection(metamaskState) {
|
||||
const { allCollectibles } = metamaskState;
|
||||
if (!allCollectibles) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const allAddresses = Object.values(allCollectibles)
|
||||
.flatMap((chainCollectibles) => Object.values(chainCollectibles))
|
||||
.flat()
|
||||
.map((collectible) => collectible.address);
|
||||
const unique = [...new Set(allAddresses)];
|
||||
return unique.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls segment.identify with given user traits
|
||||
*
|
||||
|
@ -619,14 +619,41 @@ describe('MetaMetricsController', function () {
|
||||
],
|
||||
ledgerTransportType: 'web-hid',
|
||||
identities: [{}, {}],
|
||||
allCollectibles: {
|
||||
'0xac706cE8A9BF27Afecf080fB298d0ee13cfb978A': {
|
||||
56: [
|
||||
{
|
||||
address: '0xd2cea331e5f5d8ee9fb1055c297795937645de91',
|
||||
tokenId: '100',
|
||||
},
|
||||
{
|
||||
address: '0xd2cea331e5f5d8ee9fb1055c297795937645de91',
|
||||
tokenId: '101',
|
||||
},
|
||||
{
|
||||
address: '0x7488d2ce5deb26db021285b50b661d655eb3d3d9',
|
||||
tokenId: '99',
|
||||
},
|
||||
],
|
||||
},
|
||||
'0xe04AB39684A24D8D4124b114F3bd6FBEB779cacA': {
|
||||
69: [
|
||||
{
|
||||
address: '0x63d646bc7380562376d5de205123a57b1718184d',
|
||||
tokenId: '14',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
threeBoxSyncingAllowed: false,
|
||||
});
|
||||
|
||||
assert.deepEqual(traits, {
|
||||
[TRAITS.THREE_BOX_ENABLED]: false,
|
||||
[TRAITS.LEDGER_CONNECTION_TYPE]: 'web-hid',
|
||||
[TRAITS.NUMBER_OF_ACCOUNTS]: 2,
|
||||
[TRAITS.NETWORKS_ADDED]: [MAINNET_CHAIN_ID, ROPSTEN_CHAIN_ID],
|
||||
[TRAITS.NUMBER_OF_ACCOUNTS]: 2,
|
||||
[TRAITS.NUMBER_OF_NFT_COLLECTIONS]: 3,
|
||||
[TRAITS.THREE_BOX_ENABLED]: false,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -162,6 +162,8 @@
|
||||
* identify the networks_added trait
|
||||
* @property {string} [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 {string} [THREE_BOX_ENABLED] - when 3box feature is toggled we
|
||||
* identify the 3box_enabled trait
|
||||
*/
|
||||
@ -173,9 +175,10 @@
|
||||
|
||||
export const TRAITS = {
|
||||
LEDGER_CONNECTION_TYPE: 'ledger_connection_type',
|
||||
THREE_BOX_ENABLED: 'three_box_enabled',
|
||||
NUMBER_OF_ACCOUNTS: 'number_of_accounts',
|
||||
NETWORKS_ADDED: 'networks_added',
|
||||
NUMBER_OF_ACCOUNTS: 'number_of_accounts',
|
||||
NUMBER_OF_NFT_COLLECTIONS: 'number_of_nft_collections',
|
||||
THREE_BOX_ENABLED: 'three_box_enabled',
|
||||
};
|
||||
|
||||
// Mixpanel converts the zero address value to a truly anonymous event, which
|
||||
|
Loading…
Reference in New Issue
Block a user