mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
ConfirmImportToken: update metrics logic (#13775)
This commit is contained in:
parent
063a15c085
commit
e4181ec581
@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
import React, { useCallback, useContext, useEffect } from 'react';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
@ -9,9 +9,9 @@ import Button from '../../components/ui/button';
|
|||||||
import Identicon from '../../components/ui/identicon';
|
import Identicon from '../../components/ui/identicon';
|
||||||
import TokenBalance from '../../components/ui/token-balance';
|
import TokenBalance from '../../components/ui/token-balance';
|
||||||
import { I18nContext } from '../../contexts/i18n';
|
import { I18nContext } from '../../contexts/i18n';
|
||||||
|
import { MetaMetricsContext as NewMetaMetricsContext } from '../../contexts/metametrics.new';
|
||||||
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
import { getMostRecentOverviewPage } from '../../ducks/history/history';
|
||||||
import { getPendingTokens } from '../../ducks/metamask/metamask';
|
import { getPendingTokens } from '../../ducks/metamask/metamask';
|
||||||
import { useNewMetricEvent } from '../../hooks/useMetricEvent';
|
|
||||||
import { addTokens, clearPendingTokens } from '../../store/actions';
|
import { addTokens, clearPendingTokens } from '../../store/actions';
|
||||||
|
|
||||||
const getTokenName = (name, symbol) => {
|
const getTokenName = (name, symbol) => {
|
||||||
@ -22,24 +22,11 @@ const ConfirmImportToken = () => {
|
|||||||
const t = useContext(I18nContext);
|
const t = useContext(I18nContext);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const trackEvent = useContext(NewMetaMetricsContext);
|
||||||
|
|
||||||
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
|
const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage);
|
||||||
const pendingTokens = useSelector(getPendingTokens);
|
const pendingTokens = useSelector(getPendingTokens);
|
||||||
|
|
||||||
const [addedToken, setAddedToken] = useState({});
|
|
||||||
|
|
||||||
const trackTokenAddedEvent = useNewMetricEvent({
|
|
||||||
event: 'Token Added',
|
|
||||||
category: 'Wallet',
|
|
||||||
sensitiveProperties: {
|
|
||||||
token_symbol: addedToken.symbol,
|
|
||||||
token_contract_address: addedToken.address,
|
|
||||||
token_decimal_precision: addedToken.decimals,
|
|
||||||
unlisted: addedToken.unlisted,
|
|
||||||
source: addedToken.isCustom ? 'custom' : 'list',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleAddTokens = useCallback(async () => {
|
const handleAddTokens = useCallback(async () => {
|
||||||
await dispatch(addTokens(pendingTokens));
|
await dispatch(addTokens(pendingTokens));
|
||||||
|
|
||||||
@ -47,8 +34,19 @@ const ConfirmImportToken = () => {
|
|||||||
const firstTokenAddress = addedTokenValues?.[0].address?.toLowerCase();
|
const firstTokenAddress = addedTokenValues?.[0].address?.toLowerCase();
|
||||||
|
|
||||||
addedTokenValues.forEach((pendingToken) => {
|
addedTokenValues.forEach((pendingToken) => {
|
||||||
setAddedToken({ ...pendingToken });
|
trackEvent({
|
||||||
|
event: 'Token Added',
|
||||||
|
category: 'Wallet',
|
||||||
|
sensitiveProperties: {
|
||||||
|
token_symbol: pendingToken.symbol,
|
||||||
|
token_contract_address: pendingToken.address,
|
||||||
|
token_decimal_precision: pendingToken.decimals,
|
||||||
|
unlisted: pendingToken.unlisted,
|
||||||
|
source: pendingToken.isCustom ? 'custom' : 'list',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch(clearPendingTokens());
|
dispatch(clearPendingTokens());
|
||||||
|
|
||||||
if (firstTokenAddress) {
|
if (firstTokenAddress) {
|
||||||
@ -56,13 +54,7 @@ const ConfirmImportToken = () => {
|
|||||||
} else {
|
} else {
|
||||||
history.push(mostRecentOverviewPage);
|
history.push(mostRecentOverviewPage);
|
||||||
}
|
}
|
||||||
}, [dispatch, history, mostRecentOverviewPage, pendingTokens]);
|
}, [dispatch, history, mostRecentOverviewPage, pendingTokens, trackEvent]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (Object.keys(addedToken).length) {
|
|
||||||
trackTokenAddedEvent();
|
|
||||||
}
|
|
||||||
}, [addedToken, trackTokenAddedEvent]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Object.keys(pendingTokens).length === 0) {
|
if (Object.keys(pendingTokens).length === 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user