1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

remove rpc urls from metrics (#16710)

This commit is contained in:
Brad Decker 2022-11-30 10:52:25 -05:00 committed by GitHub
parent dd0844e200
commit b3895b6840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 57 deletions

View File

@ -91,8 +91,6 @@ export default class MetaMetricsController {
* networkDidChange event emitted by the networkController
* @param {Function} options.getCurrentChainId - Gets the current chain id from the
* network controller
* @param {Function} options.getNetworkIdentifier - Gets the current network
* identifier from the network controller
* @param {string} options.version - The version of the extension
* @param {string} options.environment - The environment the extension is running in
* @param {string} options.extension - webextension-polyfill
@ -104,7 +102,6 @@ export default class MetaMetricsController {
preferencesStore,
onNetworkDidChange,
getCurrentChainId,
getNetworkIdentifier,
version,
environment,
initState,
@ -120,7 +117,6 @@ export default class MetaMetricsController {
};
const prefState = preferencesStore.getState();
this.chainId = getCurrentChainId();
this.network = getNetworkIdentifier();
this.locale = prefState.currentLocale.replace('_', '-');
this.version =
environment === 'production' ? version : `${version}-${environment}`;
@ -150,7 +146,6 @@ export default class MetaMetricsController {
onNetworkDidChange(() => {
this.chainId = getCurrentChainId();
this.network = getNetworkIdentifier();
});
this.segment = segment;
@ -470,7 +465,6 @@ export default class MetaMetricsController {
properties: {
params,
locale: this.locale,
network: this.network,
chain_id: this.chainId,
environment_type: environmentType,
},
@ -668,7 +662,6 @@ export default class MetaMetricsController {
value,
currency,
category,
network: properties?.network ?? this.network,
locale: this.locale,
chain_id: properties?.chain_id ?? this.chainId,
environment_type: environmentType,

View File

@ -8,7 +8,11 @@ import {
TRAITS,
} from '../../../shared/constants/metametrics';
import waitUntilCalled from '../../../test/lib/wait-until-called';
import { CHAIN_IDS, CURRENCY_SYMBOLS } from '../../../shared/constants/network';
import {
CHAIN_IDS,
CURRENCY_SYMBOLS,
NETWORK_TYPES,
} from '../../../shared/constants/network';
import * as Utils from '../lib/util';
import MetaMetricsController from './metametrics';
import { NETWORK_EVENTS } from './network';
@ -16,7 +20,6 @@ import { NETWORK_EVENTS } from './network';
const segment = createSegmentMock(2, 10000);
const VERSION = '0.0.1-test';
const NETWORK = 'Mainnet';
const FAKE_CHAIN_ID = '0x1338';
const LOCALE = 'en_US';
const TEST_META_METRICS_ID = '0xabc';
@ -46,7 +49,6 @@ const DEFAULT_TEST_CONTEXT = {
const DEFAULT_SHARED_PROPERTIES = {
chain_id: FAKE_CHAIN_ID,
locale: LOCALE.replace('_', '-'),
network: NETWORK,
environment_type: 'background',
};
@ -64,7 +66,7 @@ const DEFAULT_PAGE_PROPERTIES = {
function getMockNetworkController(
chainId = FAKE_CHAIN_ID,
provider = { type: NETWORK },
provider = { type: NETWORK_TYPES.MAINNET },
) {
let networkStore = { chainId, provider };
const on = sinon.stub().withArgs(NETWORK_EVENTS.NETWORK_DID_CHANGE);
@ -130,8 +132,6 @@ function getMetaMetricsController({
} = {}) {
return new MetaMetricsController({
segment: segmentInstance || segment,
getNetworkIdentifier:
networkController.getNetworkIdentifier.bind(networkController),
getCurrentChainId:
networkController.getCurrentChainId.bind(networkController),
onNetworkDidChange: networkController.on.bind(
@ -178,7 +178,6 @@ describe('MetaMetricsController', function () {
});
const metaMetricsController = getMetaMetricsController();
assert.strictEqual(metaMetricsController.version, VERSION);
assert.strictEqual(metaMetricsController.network, NETWORK);
assert.strictEqual(metaMetricsController.chainId, FAKE_CHAIN_ID);
assert.strictEqual(
metaMetricsController.state.participateInMetaMetrics,
@ -203,14 +202,12 @@ describe('MetaMetricsController', function () {
const metaMetricsController = getMetaMetricsController({
networkController,
});
assert.strictEqual(metaMetricsController.network, NETWORK);
networkController.store.updateState({
provider: {
type: 'NEW_NETWORK',
},
chainId: '0xaab',
});
assert.strictEqual(metaMetricsController.network, 'NEW_NETWORK');
assert.strictEqual(metaMetricsController.chainId, '0xaab');
});
@ -219,7 +216,6 @@ describe('MetaMetricsController', function () {
const metaMetricsController = getMetaMetricsController({
preferencesStore,
});
assert.strictEqual(metaMetricsController.network, NETWORK);
preferencesStore.updateState({
currentLocale: 'en_UK',
});

View File

@ -289,13 +289,6 @@ async function addEthereumChainHandler(
}),
);
let rpcUrlOrigin;
try {
rpcUrlOrigin = new URL(firstValidRPCUrl).origin;
} catch {
// ignore
}
sendMetrics({
event: 'Custom Network Added',
category: EVENT.CATEGORIES.NETWORK,
@ -305,18 +298,9 @@ async function addEthereumChainHandler(
properties: {
chain_id: _chainId,
network_name: _chainName,
// Including network to override the default network
// property included in all events. For RPC type networks
// the MetaMetrics controller uses the rpcUrl for the network
// property.
network: rpcUrlOrigin,
symbol: ticker,
block_explorer_url: firstValidBlockExplorerUrl,
source: EVENT.SOURCE.TRANSACTION.DAPP,
},
sensitiveProperties: {
rpc_url: rpcUrlOrigin,
},
});
// Once the network has been added, the requested is considered successful

View File

@ -2121,29 +2121,18 @@ export default class MetamaskController extends EventEmitter {
},
);
let rpcUrlOrigin;
try {
rpcUrlOrigin = new URL(rpcUrl).origin;
} catch {
// ignore
}
this.metaMetricsController.trackEvent({
event: 'Custom Network Added',
category: EVENT.CATEGORIES.NETWORK,
referrer: {
url: rpcUrlOrigin,
url: ORIGIN_METAMASK,
},
properties: {
chain_id: chainId,
network_name: chainName,
network: rpcUrlOrigin,
symbol: ticker,
block_explorer_url: blockExplorerUrl,
source: EVENT.SOURCE.NETWORK.POPULAR_NETWORK_LIST,
},
sensitiveProperties: {
rpc_url: rpcUrlOrigin,
},
actionId,
});
}

View File

@ -42,6 +42,7 @@ import {
FEATURED_RPCS,
} from '../../../../../shared/constants/network';
import { decimalToHex } from '../../../../../shared/lib/transactions-controller-utils';
import { ORIGIN_METAMASK } from '../../../../../shared/constants/app';
/**
* Attempts to convert the given chainId to a decimal string, for display
@ -530,29 +531,18 @@ const NetworksForm = ({
}
if (addNewNetwork) {
let rpcUrlOrigin;
try {
rpcUrlOrigin = new URL(rpcUrl).origin;
} catch {
// error
}
trackEvent({
event: 'Custom Network Added',
category: EVENT.CATEGORIES.NETWORK,
referrer: {
url: rpcUrlOrigin,
url: ORIGIN_METAMASK,
},
properties: {
chain_id: addHexPrefix(Number(chainId).toString(16)),
network_name: networkName,
network: rpcUrlOrigin,
symbol: ticker,
block_explorer_url: blockExplorerUrl,
source: EVENT.SOURCE.NETWORK.CUSTOM_NETWORK_FORM,
},
sensitiveProperties: {
rpc_url: rpcUrlOrigin,
},
});
dispatch(setNewNetworkAdded(networkName));
history.push(DEFAULT_ROUTE);