mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Swaps: Add anonymized tracking for HW wallet and HW wallet type (#11063)
This commit is contained in:
parent
3a6966ac8a
commit
cfe1ea2bea
@ -15,6 +15,12 @@
|
|||||||
"provider": {
|
"provider": {
|
||||||
"chainId": "0x4"
|
"chainId": "0x4"
|
||||||
},
|
},
|
||||||
|
"keyrings": [
|
||||||
|
{
|
||||||
|
"type": "Ledger Hardware",
|
||||||
|
"accounts": ["0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc"]
|
||||||
|
}
|
||||||
|
],
|
||||||
"identities": {
|
"identities": {
|
||||||
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
|
"0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc": {
|
||||||
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
|
"address": "0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc",
|
||||||
|
@ -54,6 +54,7 @@ import {
|
|||||||
getSwapsDefaultToken,
|
getSwapsDefaultToken,
|
||||||
getCurrentChainId,
|
getCurrentChainId,
|
||||||
isHardwareWallet,
|
isHardwareWallet,
|
||||||
|
getHardwareWalletType,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
import {
|
import {
|
||||||
ERROR_FETCHING_QUOTES,
|
ERROR_FETCHING_QUOTES,
|
||||||
@ -483,6 +484,8 @@ export const fetchQuotesAndSetQuoteState = (
|
|||||||
|
|
||||||
dispatch(setFromToken(selectedFromToken));
|
dispatch(setFromToken(selectedFromToken));
|
||||||
|
|
||||||
|
const hardwareWalletUsed = isHardwareWallet(state);
|
||||||
|
const hardwareWalletType = getHardwareWalletType(state);
|
||||||
metaMetricsEvent({
|
metaMetricsEvent({
|
||||||
event: 'Quotes Requested',
|
event: 'Quotes Requested',
|
||||||
category: 'swaps',
|
category: 'swaps',
|
||||||
@ -493,6 +496,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,
|
||||||
anonymizedData: true,
|
anonymizedData: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -563,6 +568,8 @@ export const fetchQuotesAndSetQuoteState = (
|
|||||||
response_time: Date.now() - fetchStartTime,
|
response_time: Date.now() - fetchStartTime,
|
||||||
best_quote_source: newSelectedQuote.aggregator,
|
best_quote_source: newSelectedQuote.aggregator,
|
||||||
available_quotes: Object.values(fetchedQuotes)?.length,
|
available_quotes: Object.values(fetchedQuotes)?.length,
|
||||||
|
is_hardware_wallet: hardwareWalletUsed,
|
||||||
|
hardware_wallet_type: hardwareWalletType,
|
||||||
anonymizedData: true,
|
anonymizedData: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -85,6 +85,16 @@ export function isHardwareWallet(state) {
|
|||||||
return keyring.type.includes('Hardware');
|
return keyring.type.includes('Hardware');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a HW wallet type, e.g. "Ledger Hardware"
|
||||||
|
* @param {Object} state
|
||||||
|
* @returns {String|undefined}
|
||||||
|
*/
|
||||||
|
export function getHardwareWalletType(state) {
|
||||||
|
const keyring = getCurrentKeyring(state);
|
||||||
|
return keyring.type.includes('Hardware') ? keyring.type : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function getAccountType(state) {
|
export function getAccountType(state) {
|
||||||
const currentKeyring = getCurrentKeyring(state);
|
const currentKeyring = getCurrentKeyring(state);
|
||||||
const type = currentKeyring && currentKeyring.type;
|
const type = currentKeyring && currentKeyring.type;
|
||||||
|
@ -15,6 +15,44 @@ describe('Selectors', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#isHardwareWallet', () => {
|
||||||
|
it('returns false if it is not a HW wallet', () => {
|
||||||
|
mockState.metamask.keyrings[0].type = 'Simple Key Pair';
|
||||||
|
expect(selectors.isHardwareWallet(mockState)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true if it is a Ledger HW wallet', () => {
|
||||||
|
mockState.metamask.keyrings[0].type = 'Ledger Hardware';
|
||||||
|
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true if it is a Trezor HW wallet', () => {
|
||||||
|
mockState.metamask.keyrings[0].type = 'Trezor Hardware';
|
||||||
|
expect(selectors.isHardwareWallet(mockState)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#getHardwareWalletType', () => {
|
||||||
|
it('returns undefined if it is not a HW wallet', () => {
|
||||||
|
mockState.metamask.keyrings[0].type = 'Simple Key Pair';
|
||||||
|
expect(selectors.getHardwareWalletType(mockState)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns "Ledger Hardware" if it is a Ledger HW wallet', () => {
|
||||||
|
mockState.metamask.keyrings[0].type = 'Ledger Hardware';
|
||||||
|
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
||||||
|
'Ledger Hardware',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns "Trezor Hardware" if it is a Trezor HW wallet', () => {
|
||||||
|
mockState.metamask.keyrings[0].type = 'Trezor Hardware';
|
||||||
|
expect(selectors.getHardwareWalletType(mockState)).toBe(
|
||||||
|
'Trezor Hardware',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('returns selected identity', () => {
|
it('returns selected identity', () => {
|
||||||
expect(selectors.getSelectedIdentity(mockState)).toStrictEqual({
|
expect(selectors.getSelectedIdentity(mockState)).toStrictEqual({
|
||||||
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
|
||||||
|
Loading…
Reference in New Issue
Block a user