From 095cc94ed041e9246cedd980170cdd167266277f Mon Sep 17 00:00:00 2001 From: Olusegun Akintayo Date: Thu, 21 Apr 2022 22:29:39 +0400 Subject: [PATCH] Add new token added event (duplicating the existing event structure) when collectible is manually added (#14279) * Add new token added event (duplicating the existing event structure) when auto detection occurs for NFTs Set source property to detected on the new token added event, --- ui/pages/add-collectible/add-collectible.js | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ui/pages/add-collectible/add-collectible.js b/ui/pages/add-collectible/add-collectible.js index c768403eb..ed8dde133 100644 --- a/ui/pages/add-collectible/add-collectible.js +++ b/ui/pages/add-collectible/add-collectible.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useContext, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import { util } from '@metamask/controllers'; @@ -17,6 +17,7 @@ import ActionableMessage from '../../components/ui/actionable-message'; import PageContainer from '../../components/ui/page-container'; import { addCollectibleVerifyOwnership, + getTokenStandardAndDetails, removeToken, setNewCollectibleAddedMessage, } from '../../store/actions'; @@ -24,6 +25,8 @@ import FormField from '../../components/ui/form-field'; import { getIsMainnet, getUseCollectibleDetection } from '../../selectors'; import { getCollectiblesDetectionNoticeDismissed } from '../../ducks/metamask/metamask'; import CollectiblesDetectionNotice from '../../components/app/collectibles-detection-notice'; +import { MetaMetricsContext } from '../../contexts/metametrics'; +import { ASSET_TYPES } from '../../../shared/constants/transaction'; export default function AddCollectible() { const t = useI18nContext(); @@ -47,6 +50,7 @@ export default function AddCollectible() { const [tokenId, setTokenId] = useState(''); const [disabled, setDisabled] = useState(true); const [collectibleAddFailed, setCollectibleAddFailed] = useState(false); + const trackEvent = useContext(MetaMetricsContext); const handleAddCollectible = async () => { try { @@ -65,6 +69,26 @@ export default function AddCollectible() { ); } dispatch(setNewCollectibleAddedMessage('success')); + + const tokenDetails = await getTokenStandardAndDetails( + address, + null, + tokenId.toString(), + ); + + trackEvent({ + event: 'Token Added', + category: 'Wallet', + sensitiveProperties: { + token_contract_address: address, + token_symbol: tokenDetails?.symbol, + tokenId: tokenId.toString(), + asset_type: ASSET_TYPES.COLLECTIBLE, + token_standard: tokenDetails?.standard, + source: 'custom', + }, + }); + history.push(DEFAULT_ROUTE); };