1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Swaps: Add more anonymized tracking for HW wallet and HW wallet type (#11087)

This commit is contained in:
Daniel 2021-05-13 21:26:08 +02:00 committed by Dan Miller
parent 120efc6dab
commit 79e79e9212
7 changed files with 81 additions and 1 deletions

View File

@ -24,6 +24,24 @@ export const createSwapsMockStore = () => {
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': 2, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': 2,
'0x1111111111111111111111111111111111111111': 0.1, '0x1111111111111111111111111111111111111111': 0.1,
}, },
identities: {
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': {
address: '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825',
name: 'Send Account 1',
},
'0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb': {
address: '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
name: 'Send Account 2',
},
'0x2f8d4a878cfa04a6e60d46362f5644deab66572d': {
address: '0x2f8d4a878cfa04a6e60d46362f5644deab66572d',
name: 'Send Account 3',
},
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
name: 'Send Account 4',
},
},
accounts: { accounts: {
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': { '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
@ -35,6 +53,21 @@ export const createSwapsMockStore = () => {
}, },
}, },
selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
keyringTypes: ['Simple Key Pair', 'HD Key Tree'],
keyrings: [
{
type: 'HD Key Tree',
accounts: [
'0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
'c5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'2f8d4a878cfa04a6e60d46362f5644deab66572d',
],
},
{
type: 'Simple Key Pair',
accounts: ['0xd85a4b6a394794842887b8284293d69163007bbb'],
},
],
frequentRpcListDetail: [], frequentRpcListDetail: [],
tokens: [ tokens: [
{ {

View File

@ -545,6 +545,8 @@ export const fetchQuotesAndSetQuoteState = (
request_type: balanceError ? 'Quote' : 'Order', request_type: balanceError ? 'Quote' : 'Order',
slippage: maxSlippage, slippage: maxSlippage,
custom_slippage: maxSlippage !== 2, custom_slippage: maxSlippage !== 2,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
}); });
dispatch(setSwapsErrorKey(QUOTES_NOT_AVAILABLE_ERROR)); dispatch(setSwapsErrorKey(QUOTES_NOT_AVAILABLE_ERROR));
@ -685,6 +687,8 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
performance_savings: usedQuote.savings?.performance, performance_savings: usedQuote.savings?.performance,
fee_savings: usedQuote.savings?.fee, fee_savings: usedQuote.savings?.fee,
median_metamask_fee: usedQuote.savings?.medianMetaMaskFee, median_metamask_fee: usedQuote.savings?.medianMetaMaskFee,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: getHardwareWalletType(state),
}; };
metaMetricsEvent({ metaMetricsEvent({

View File

@ -9,6 +9,10 @@ import {
getApproveTxParams, getApproveTxParams,
prepareToLeaveSwaps, prepareToLeaveSwaps,
} from '../../../ducks/swaps/swaps'; } from '../../../ducks/swaps/swaps';
import {
isHardwareWallet,
getHardwareWalletType,
} from '../../../selectors/selectors';
import { import {
DEFAULT_ROUTE, DEFAULT_ROUTE,
BUILD_QUOTE_ROUTE, BUILD_QUOTE_ROUTE,
@ -34,6 +38,8 @@ export default function AwaitingSignatures() {
const fetchParams = useSelector(getFetchParams); const fetchParams = useSelector(getFetchParams);
const { destinationTokenInfo, sourceTokenInfo } = fetchParams?.metaData || {}; const { destinationTokenInfo, sourceTokenInfo } = fetchParams?.metaData || {};
const approveTxParams = useSelector(getApproveTxParams); const approveTxParams = useSelector(getApproveTxParams);
const hardwareWalletUsed = useSelector(isHardwareWallet);
const hardwareWalletType = useSelector(getHardwareWalletType);
const needsTwoConfirmations = Boolean(approveTxParams); const needsTwoConfirmations = Boolean(approveTxParams);
const awaitingSignaturesEvent = useNewMetricEvent({ const awaitingSignaturesEvent = useNewMetricEvent({
@ -46,6 +52,8 @@ export default function AwaitingSignatures() {
request_type: fetchParams?.balanceError ? 'Quote' : 'Order', request_type: fetchParams?.balanceError ? 'Quote' : 'Order',
slippage: fetchParams?.slippage, slippage: fetchParams?.slippage,
custom_slippage: fetchParams?.slippage === 2, custom_slippage: fetchParams?.slippage === 2,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
category: 'swaps', category: 'swaps',
}); });

View File

@ -13,6 +13,8 @@ import {
getCurrentCurrency, getCurrentCurrency,
getRpcPrefsForCurrentProvider, getRpcPrefsForCurrentProvider,
getUSDConversionRate, getUSDConversionRate,
isHardwareWallet,
getHardwareWalletType,
} from '../../../selectors'; } from '../../../selectors';
import { import {
@ -95,6 +97,8 @@ export default function AwaitingSwap({
feeinUnformattedFiat = renderableNetworkFees.rawNetworkFees; feeinUnformattedFiat = renderableNetworkFees.rawNetworkFees;
} }
const hardwareWalletUsed = useSelector(isHardwareWallet);
const hardwareWalletType = useSelector(getHardwareWalletType);
const quotesExpiredEvent = useNewMetricEvent({ const quotesExpiredEvent = useNewMetricEvent({
event: 'Quotes Timed Out', event: 'Quotes Timed Out',
sensitiveProperties: { sensitiveProperties: {
@ -105,6 +109,8 @@ export default function AwaitingSwap({
slippage: fetchParams?.slippage, slippage: fetchParams?.slippage,
custom_slippage: fetchParams?.slippage === 2, custom_slippage: fetchParams?.slippage === 2,
gas_fees: feeinUnformattedFiat, gas_fees: feeinUnformattedFiat,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
category: 'swaps', category: 'swaps',
}); });

View File

@ -13,6 +13,8 @@ import {
getSelectedAccount, getSelectedAccount,
getCurrentChainId, getCurrentChainId,
getIsSwapsChain, getIsSwapsChain,
isHardwareWallet,
getHardwareWalletType,
} from '../../selectors/selectors'; } from '../../selectors/selectors';
import { import {
getQuotes, getQuotes,
@ -184,6 +186,8 @@ export default function Swap() {
}; };
}, [dispatch, chainId]); }, [dispatch, chainId]);
const hardwareWalletUsed = useSelector(isHardwareWallet);
const hardwareWalletType = useSelector(getHardwareWalletType);
const exitedSwapsEvent = useNewMetricEvent({ const exitedSwapsEvent = useNewMetricEvent({
event: 'Exited Swaps', event: 'Exited Swaps',
category: 'swaps', category: 'swaps',
@ -195,6 +199,8 @@ export default function Swap() {
slippage: fetchParams?.slippage, slippage: fetchParams?.slippage,
custom_slippage: fetchParams?.slippage !== 2, custom_slippage: fetchParams?.slippage !== 2,
current_screen: pathname.match(/\/swaps\/(.+)/u)[1], current_screen: pathname.match(/\/swaps\/(.+)/u)[1],
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
}); });
const exitEventRef = useRef(); const exitEventRef = useRef();

View File

@ -10,6 +10,10 @@ import {
getFetchParams, getFetchParams,
getQuotesFetchStartTime, getQuotesFetchStartTime,
} from '../../../ducks/swaps/swaps'; } from '../../../ducks/swaps/swaps';
import {
isHardwareWallet,
getHardwareWalletType,
} from '../../../selectors/selectors';
import { I18nContext } from '../../../contexts/i18n'; import { I18nContext } from '../../../contexts/i18n';
import { MetaMetricsContext } from '../../../contexts/metametrics.new'; import { MetaMetricsContext } from '../../../contexts/metametrics.new';
import Mascot from '../../../components/ui/mascot'; import Mascot from '../../../components/ui/mascot';
@ -67,6 +71,8 @@ export default function LoadingSwapsQuotes({
const fetchParams = useSelector(getFetchParams); const fetchParams = useSelector(getFetchParams);
const quotesFetchStartTime = useSelector(getQuotesFetchStartTime); const quotesFetchStartTime = useSelector(getQuotesFetchStartTime);
const hardwareWalletUsed = useSelector(isHardwareWallet);
const hardwareWalletType = useSelector(getHardwareWalletType);
const quotesRequestCancelledEventConfig = { const quotesRequestCancelledEventConfig = {
event: 'Quotes Request Cancelled', event: 'Quotes Request Cancelled',
category: 'swaps', category: 'swaps',
@ -78,6 +84,8 @@ export default function LoadingSwapsQuotes({
slippage: fetchParams?.slippage, slippage: fetchParams?.slippage,
custom_slippage: fetchParams?.slippage !== 2, custom_slippage: fetchParams?.slippage !== 2,
response_time: Date.now() - quotesFetchStartTime, response_time: Date.now() - quotesFetchStartTime,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
}; };

View File

@ -39,6 +39,8 @@ import {
getSwapsDefaultToken, getSwapsDefaultToken,
getCurrentChainId, getCurrentChainId,
getNativeCurrency, getNativeCurrency,
isHardwareWallet,
getHardwareWalletType,
} from '../../../selectors'; } from '../../../selectors';
import { toPrecisionWithoutTrailingZeros } from '../../../helpers/utils/util'; import { toPrecisionWithoutTrailingZeros } from '../../../helpers/utils/util';
import { getTokens } from '../../../ducks/metamask/metamask'; import { getTokens } from '../../../ducks/metamask/metamask';
@ -330,6 +332,8 @@ export default function ViewQuote() {
available_quotes: numberOfQuotes, available_quotes: numberOfQuotes,
}; };
const hardwareWalletUsed = useSelector(isHardwareWallet);
const hardwareWalletType = useSelector(getHardwareWalletType);
const allAvailableQuotesOpened = useNewMetricEvent({ const allAvailableQuotesOpened = useNewMetricEvent({
event: 'All Available Quotes Opened', event: 'All Available Quotes Opened',
category: 'swaps', category: 'swaps',
@ -340,6 +344,8 @@ export default function ViewQuote() {
usedQuote?.aggregator === topQuote?.aggregator usedQuote?.aggregator === topQuote?.aggregator
? null ? null
: usedQuote?.aggregator, : usedQuote?.aggregator,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
}); });
const quoteDetailsOpened = useNewMetricEvent({ const quoteDetailsOpened = useNewMetricEvent({
@ -352,6 +358,8 @@ export default function ViewQuote() {
usedQuote?.aggregator === topQuote?.aggregator usedQuote?.aggregator === topQuote?.aggregator
? null ? null
: usedQuote?.aggregator, : usedQuote?.aggregator,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
}); });
const editSpendLimitOpened = useNewMetricEvent({ const editSpendLimitOpened = useNewMetricEvent({
@ -362,13 +370,20 @@ export default function ViewQuote() {
custom_spend_limit_set: originalApproveAmount === approveAmount, custom_spend_limit_set: originalApproveAmount === approveAmount,
custom_spend_limit_amount: custom_spend_limit_amount:
originalApproveAmount === approveAmount ? null : approveAmount, originalApproveAmount === approveAmount ? null : approveAmount,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
}, },
}); });
const bestQuoteReviewedEvent = useNewMetricEvent({ const bestQuoteReviewedEvent = useNewMetricEvent({
event: 'Best Quote Reviewed', event: 'Best Quote Reviewed',
category: 'swaps', category: 'swaps',
sensitiveProperties: { ...eventObjectBase, network_fees: feeInFiat }, sensitiveProperties: {
...eventObjectBase,
network_fees: feeInFiat,
is_hardware_wallet: hardwareWalletUsed,
hardware_wallet_type: hardwareWalletType,
},
}); });
useEffect(() => { useEffect(() => {
if ( if (