Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add privacy setting to disable external name sources #21045

Merged
merged 42 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f41e25f
Add petnames metrics
matthewwalsh0 Sep 20, 2023
d8d2bd3
Update metrics
matthewwalsh0 Sep 21, 2023
75b3827
Add user trait
matthewwalsh0 Sep 21, 2023
be83db9
Fix linting
matthewwalsh0 Sep 21, 2023
1c4d20f
Merge branch 'develop' into feat/petnames-metrics
matthewwalsh0 Sep 21, 2023
97761f7
Merge branch 'develop' into feat/petnames-metrics
matthewwalsh0 Sep 21, 2023
3b8d34b
Remove proposed name from name component
matthewwalsh0 Sep 25, 2023
cece879
Fix name clearing
matthewwalsh0 Sep 25, 2023
c834ed3
Update name controller
matthewwalsh0 Sep 26, 2023
a89cda4
Add settings toggle to disable external name providers
matthewwalsh0 Sep 26, 2023
edd5403
Update name controller
matthewwalsh0 Sep 26, 2023
233be51
Update name controller
matthewwalsh0 Sep 27, 2023
eed4d40
Update yarn lock
matthewwalsh0 Sep 27, 2023
897d278
Merge branch 'develop' into feat/petnames-metrics
matthewwalsh0 Sep 27, 2023
4db917e
Display checksum addresses
matthewwalsh0 Sep 27, 2023
f1e5778
Update name controller
matthewwalsh0 Sep 27, 2023
18566b8
Add unit tests
matthewwalsh0 Sep 27, 2023
5e701d0
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 27, 2023
3b332f6
Fix linting
matthewwalsh0 Sep 27, 2023
37d52f1
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 27, 2023
7062cc8
Fix unit tests
matthewwalsh0 Sep 27, 2023
e0e324f
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 27, 2023
881e17a
Update text
matthewwalsh0 Sep 28, 2023
0609838
Update name controller
matthewwalsh0 Sep 28, 2023
7f2a158
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 28, 2023
eeb00a2
Merge branch 'develop' into feat/petnames-metrics
matthewwalsh0 Sep 29, 2023
52e3c71
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 29, 2023
0504df9
Send open metric after proposed names are loaded
matthewwalsh0 Sep 29, 2023
f93fd5e
Use released name controller
matthewwalsh0 Sep 29, 2023
9ade0d0
Skip displayed metric if part of modal
matthewwalsh0 Sep 29, 2023
24cbc7d
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 29, 2023
8d1c873
Update policies
matthewwalsh0 Sep 29, 2023
b2e05a9
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 29, 2023
633a467
Fix E2E test
matthewwalsh0 Sep 29, 2023
59013c3
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 29, 2023
b11e751
Update snapshot
matthewwalsh0 Sep 29, 2023
5f67213
Fix unit test
matthewwalsh0 Sep 29, 2023
a585e1e
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 29, 2023
35cd3ac
Refactor E2E tests
matthewwalsh0 Sep 29, 2023
b596e4e
Merge branch 'develop' into feat/petnames-metrics
matthewwalsh0 Sep 29, 2023
d70efc7
Merge branch 'feat/petnames-metrics' into feat/external-name-sources-…
matthewwalsh0 Sep 30, 2023
bad1b19
Merge branch 'develop' into feat/external-name-sources-toggle
matthewwalsh0 Oct 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions app/scripts/controllers/metametrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { ObservableStore } from '@metamask/obs-store';
import { bufferToHex, keccak } from 'ethereumjs-util';
import { v4 as uuidv4 } from 'uuid';
import { NameType } from '@metamask/name-controller';
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
import {
METAMETRICS_ANONYMOUS_ID,
Expand Down Expand Up @@ -800,6 +801,10 @@ export default class MetaMetricsController {
///: END:ONLY_INCLUDE_IN
[MetaMetricsUserTrait.SecurityProviders]:
metamaskState.transactionSecurityCheckEnabled ? ['opensea'] : [],
///: BEGIN:ONLY_INCLUDE_IN(petnames)
[MetaMetricsUserTrait.PetnameAddressCount]:
this._getPetnameAddressCount(metamaskState),
///: END:ONLY_INCLUDE_IN
};

if (!previousUserTraits) {
Expand Down Expand Up @@ -1076,4 +1081,29 @@ export default class MetaMetricsController {
};
this.segment[eventType](modifiedPayload, modifiedCallback);
}

/**
* Returns the total number of Ethereum addresses with saved petnames,
* including all chain ID variations.
*
* @param {object} metamaskState
* @returns {number}
*/
_getPetnameAddressCount(metamaskState) {
const addressNames = metamaskState.names?.[NameType.ETHEREUM_ADDRESS] ?? {};

return Object.keys(addressNames).reduce((totalCount, address) => {
const addressEntry = addressNames[address];

const addressNameCount = Object.keys(addressEntry).reduce(
(count, chainId) => {
const hasName = Boolean(addressEntry[chainId].name?.length);
return count + (hasName ? 1 : 0);
},
0,
);

return totalCount + addressNameCount;
}, 0);
}
}
36 changes: 36 additions & 0 deletions app/scripts/controllers/metametrics.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { strict as assert } from 'assert';
import sinon from 'sinon';
import { toHex } from '@metamask/controller-utils';
import { NameType } from '@metamask/name-controller';
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
import { createSegmentMock } from '../lib/segment';
import {
Expand Down Expand Up @@ -1028,6 +1029,38 @@ describe('MetaMetricsController', function () {
useTokenDetection: true,
desktopEnabled: false,
security_providers: [],
names: {
[NameType.ETHEREUM_ADDRESS]: {
'0x123': {
'0x1': {
name: 'Test 1',
},
'0x2': {
name: 'Test 2',
},
'0x3': {
name: null,
},
},
'0x456': {
'0x1': {
name: 'Test 3',
},
},
'0x789': {
'0x1': {
name: null,
},
},
},
otherType: {
otherValue: {
otherVariation: {
name: 'Test 4',
},
},
},
},
});

assert.deepEqual(traits, {
Expand Down Expand Up @@ -1056,6 +1089,9 @@ describe('MetaMetricsController', function () {
[MetaMetricsUserTrait.MmiAccountAddress]: null,
[MetaMetricsUserTrait.MmiIsCustodian]: false,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(petnames)
[MetaMetricsUserTrait.PetnameAddressCount]: 3,
///: END:ONLY_INCLUDE_IN
});
});

Expand Down
16 changes: 16 additions & 0 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ export default class PreferencesController {
snapsAddSnapAccountModalDismissed: false,
///: END:ONLY_INCLUDE_IN
isLineaMainnetReleased: false,
///: BEGIN:ONLY_INCLUDE_IN(petnames)
useExternalNameSources: true,
///: END:ONLY_INCLUDE_IN
...opts.initState,
};

Expand Down Expand Up @@ -261,6 +264,19 @@ export default class PreferencesController {
}
///: END:ONLY_INCLUDE_IN

///: BEGIN:ONLY_INCLUDE_IN(petnames)
/**
* Setter for the `useExternalNameSources` property
*
* @param {boolean} useExternalNameSources - Whether or not to use external name providers in the name controller.
*/
setUseExternalNameSources(useExternalNameSources) {
this.store.updateState({
useExternalNameSources,
});
}
///: END:ONLY_INCLUDE_IN

/**
* Setter for the `advancedGasFee` property
*
Expand Down
17 changes: 17 additions & 0 deletions app/scripts/controllers/preferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,21 @@ describe('preferences controller', () => {
});
});
});

///: BEGIN:ONLY_INCLUDE_IN(petnames)
describe('setUseExternalNameSources', () => {
it('should default to true', () => {
expect(
preferencesController.store.getState().useExternalNameSources,
).toStrictEqual(true);
});

it('should set the useExternalNameSources property in state', () => {
preferencesController.setUseExternalNameSources(false);
expect(
preferencesController.store.getState().useExternalNameSources,
).toStrictEqual(false);
});
});
///: END:ONLY_INCLUDE_IN
});
6 changes: 3 additions & 3 deletions app/scripts/lib/SnapsNameProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('SnapsNameProvider', () => {
const response = await provider.getProposedNames({
value: VALUE_MOCK,
type: NameType.ETHEREUM_ADDRESS,
chainId: CHAIN_ID_MOCK,
variation: CHAIN_ID_MOCK,
});

expect(response).toStrictEqual({
Expand Down Expand Up @@ -193,7 +193,7 @@ describe('SnapsNameProvider', () => {
const response = await provider.getProposedNames({
value: VALUE_MOCK,
type: NameType.ETHEREUM_ADDRESS,
chainId: CHAIN_ID_MOCK,
variation: CHAIN_ID_MOCK,
});

expect(response).toStrictEqual({
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('SnapsNameProvider', () => {
const response = await provider.getProposedNames({
value: VALUE_MOCK,
type: NameType.ETHEREUM_ADDRESS,
chainId: CHAIN_ID_MOCK,
variation: CHAIN_ID_MOCK,
});

expect(response).toStrictEqual({
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/SnapsNameProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class SnapsNameProvider implements NameProvider {
snap: TruncatedSnap,
request: NameProviderRequest,
): Promise<{ sourceId: string; result: NameProviderSourceResult }> {
const { chainId: chainIdHex, value } = request;
const { variation: chainIdHex, value } = request;
const sourceId = snap.id;
const chainIdDecimal = parseInt(chainIdHex, 16);

Expand Down
16 changes: 12 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1538,8 +1538,10 @@ export default class MetamaskController extends EventEmitter {
);

///: BEGIN:ONLY_INCLUDE_IN(petnames)
const isExternalNameSourcesEnabled = () =>
this.preferencesController.store.getState().useExternalNameSources;

this.nameController = new NameController({
getChainId: () => this.networkController.state.providerConfig.chainId,
messenger: this.controllerMessenger.getRestricted({
name: 'NameController',
allowedActions: [],
Expand All @@ -1550,9 +1552,9 @@ export default class MetamaskController extends EventEmitter {
this.ensController,
),
}),
new EtherscanNameProvider({}),
new TokenNameProvider({}),
new LensNameProvider(),
new EtherscanNameProvider({ isEnabled: isExternalNameSourcesEnabled }),
new TokenNameProvider({ isEnabled: isExternalNameSourcesEnabled }),
new LensNameProvider({ isEnabled: isExternalNameSourcesEnabled }),
new SnapsNameProvider({
messenger: this.controllerMessenger.getRestricted({
name: 'SnapsNameProvider',
Expand Down Expand Up @@ -2403,6 +2405,12 @@ export default class MetamaskController extends EventEmitter {
preferencesController,
),
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(petnames)
setUseExternalNameSources:
preferencesController.setUseExternalNameSources.bind(
preferencesController,
),
///: END:ONLY_INCLUDE_IN
setIpfsGateway: preferencesController.setIpfsGateway.bind(
preferencesController,
),
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,22 @@
"fetch": true
},
"packages": {
"@metamask/base-controller": true
"@metamask/base-controller": true,
"@metamask/name-controller>@metamask/utils": true,
"eth-json-rpc-filters>async-mutex": true
}
},
"@metamask/name-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/key-tree>@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true,
"superstruct": true
}
},
"@metamask/network-controller": {
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/desktop/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,22 @@
"fetch": true
},
"packages": {
"@metamask/base-controller": true
"@metamask/base-controller": true,
"@metamask/name-controller>@metamask/utils": true,
"eth-json-rpc-filters>async-mutex": true
}
},
"@metamask/name-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/key-tree>@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true,
"superstruct": true
}
},
"@metamask/network-controller": {
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,22 @@
"fetch": true
},
"packages": {
"@metamask/base-controller": true
"@metamask/base-controller": true,
"@metamask/name-controller>@metamask/utils": true,
"eth-json-rpc-filters>async-mutex": true
}
},
"@metamask/name-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/key-tree>@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true,
"superstruct": true
}
},
"@metamask/network-controller": {
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,22 @@
"fetch": true
},
"packages": {
"@metamask/base-controller": true
"@metamask/base-controller": true,
"@metamask/name-controller>@metamask/utils": true,
"eth-json-rpc-filters>async-mutex": true
}
},
"@metamask/name-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/key-tree>@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true,
"superstruct": true
}
},
"@metamask/network-controller": {
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,22 @@
"fetch": true
},
"packages": {
"@metamask/base-controller": true
"@metamask/base-controller": true,
"@metamask/name-controller>@metamask/utils": true,
"eth-json-rpc-filters>async-mutex": true
}
},
"@metamask/name-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/key-tree>@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true,
"superstruct": true
}
},
"@metamask/network-controller": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
"@metamask/logo": "^3.1.1",
"@metamask/message-manager": "^7.3.0",
"@metamask/metamask-eth-abis": "^3.0.0",
"@metamask/name-controller": "^1.0.0",
"@metamask/name-controller": "^3.0.0",
"@metamask/network-controller": "^12.2.0",
"@metamask/notification-controller": "^3.0.0",
"@metamask/obs-store": "^8.1.0",
Expand Down
Loading
Loading