Skip to content

Commit

Permalink
Add privacy setting to disable external name sources (#21045)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalsh0 authored Oct 3, 2023
1 parent 04aae35 commit ab0fdee
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 13 deletions.
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.

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
});
15 changes: 12 additions & 3 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,9 @@ export default class MetamaskController extends EventEmitter {
);

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

this.nameController = new NameController({
messenger: this.controllerMessenger.getRestricted({
name: 'NameController',
Expand All @@ -1548,9 +1551,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 @@ -2404,6 +2407,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
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,81 @@ exports[`Security Tab should match snapshot 1`] = `
</div>
</div>
</div>
<span
class="settings-page__security-tab-sub-header"
>
Signature requests
</span>
<div
class="settings-page__content-padded"
>
<div
class="mm-box settings-page__content-row mm-box--display-flex mm-box--gap-4 mm-box--flex-direction-row mm-box--justify-content-space-between"
>
<div
class="settings-page__content-item"
>
<span>
Suggest address names
</span>
<div
class="settings-page__content-description"
>
We pull data from third parties like Etherscan, Infura, and Lens Protocol, to suggest names for addresses on signatures requests. Turning on name suggestions exposes your IP address to these third parties.
</div>
</div>
<div
class="settings-page__content-item-col"
data-testid="useExternalNameSources"
>
<label
class="toggle-button toggle-button--off"
tabindex="0"
>
<div
style="display: flex; width: 52px; align-items: center; justify-content: flex-start; position: relative; cursor: pointer; background-color: transparent; border: 0px; padding: 0px; user-select: none;"
>
<div
style="width: 40px; height: 24px; padding: 0px; border-radius: 26px; display: flex; align-items: center; justify-content: center; background-color: rgb(242, 244, 246);"
>
<div
style="font-size: 11px; display: flex; align-items: center; justify-content: center; font-family: 'Helvetica Neue', Helvetica, sans-serif; position: relative; color: rgb(250, 250, 250); margin-top: auto; margin-bottom: auto; line-height: 0; opacity: 0; width: 26px; height: 20px; left: 4px;"
/>
<div
style="font-size: 11px; display: flex; align-items: center; justify-content: center; font-family: 'Helvetica Neue', Helvetica, sans-serif; position: relative; color: rgba(255, 255, 255, 0.6); bottom: 0px; margin-top: auto; margin-bottom: auto; padding-right: 5px; line-height: 0; width: 26px; height: 20px; opacity: 1;"
/>
</div>
<div
style="position: absolute; height: 100%; top: 0px; left: 0px; display: flex; flex: 1; align-self: stretch; align-items: center; justify-content: flex-start;"
>
<div
style="width: 18px; height: 18px; display: flex; align-self: center; box-shadow: none; border-radius: 50%; box-sizing: border-box; position: relative; background-color: rgb(106, 115, 125); left: 3px;"
/>
</div>
<input
style="border: 0px; height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; width: 1px;"
type="checkbox"
value="false"
/>
</div>
<div
class="toggle-button__status"
>
<span
class="toggle-button__label-off"
>
Off
</span>
<span
class="toggle-button__label-on"
>
On
</span>
</div>
</label>
</div>
</div>
</div>
<span
class="settings-page__security-tab-sub-header"
>
Expand Down
56 changes: 56 additions & 0 deletions ui/pages/settings/security-tab/security-tab.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export default class SecurityTab extends PureComponent {
setUseCurrencyRateCheck: PropTypes.func.isRequired,
useAddressBarEnsResolution: PropTypes.bool.isRequired,
setUseAddressBarEnsResolution: PropTypes.func.isRequired,
///: BEGIN:ONLY_INCLUDE_IN(petnames)
useExternalNameSources: PropTypes.bool.isRequired,
setUseExternalNameSources: PropTypes.func.isRequired,
///: END:ONLY_INCLUDE_IN
};

state = {
Expand Down Expand Up @@ -813,6 +817,43 @@ export default class SecurityTab extends PureComponent {
);
}

///: BEGIN:ONLY_INCLUDE_IN(petnames)
renderExternalNameSourcesToggle() {
const { t } = this.context;
const { useExternalNameSources, setUseExternalNameSources } = this.props;

return (
<Box
ref={this.settingsRefs[13]}
className="settings-page__content-row"
display={Display.Flex}
flexDirection={FlexDirection.Row}
justifyContent={JustifyContent.spaceBetween}
gap={4}
>
<div className="settings-page__content-item">
<span>{t('externalNameSourcesSetting')}</span>
<div className="settings-page__content-description">
{t('externalNameSourcesSettingDescription')}
</div>
</div>

<div
className="settings-page__content-item-col"
data-testid="useExternalNameSources"
>
<ToggleButton
value={useExternalNameSources}
onToggle={(value) => setUseExternalNameSources(!value)}
offLabel={t('off')}
onLabel={t('on')}
/>
</div>
</Box>
);
}
///: END:ONLY_INCLUDE_IN

render() {
const { warning } = this.props;

Expand All @@ -835,6 +876,7 @@ export default class SecurityTab extends PureComponent {
<div className="settings-page__content-padded">
{this.renderPhishingDetectionToggle()}
</div>

<div>
<span className="settings-page__security-tab-sub-header">
{this.context.t('smartContracts')}
Expand All @@ -843,6 +885,7 @@ export default class SecurityTab extends PureComponent {
<div className="settings-page__content-padded">
{this.renderUse4ByteResolutionToggle()}
</div>

<span className="settings-page__security-tab-sub-header">
{this.context.t('transactions')}
</span>
Expand Down Expand Up @@ -870,6 +913,19 @@ export default class SecurityTab extends PureComponent {
{this.renderNftDetectionToggle()}
</div>

{
///: BEGIN:ONLY_INCLUDE_IN(petnames)
}
<span className="settings-page__security-tab-sub-header">
{this.context.t('settingsSubHeadingSignatures')}
</span>
<div className="settings-page__content-padded">
{this.renderExternalNameSourcesToggle()}
</div>
{
///: END:ONLY_INCLUDE_IN
}

<span className="settings-page__security-tab-sub-header">
{this.context.t('metrics')}
</span>
Expand Down
14 changes: 14 additions & 0 deletions ui/pages/settings/security-tab/security-tab.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
setUseNftDetection,
setUse4ByteResolution,
setUseSafeChainsListValidation,
///: BEGIN:ONLY_INCLUDE_IN(petnames)
setUseExternalNameSources,
///: END:ONLY_INCLUDE_IN
} from '../../../store/actions';
import { getAllNetworks } from '../../../selectors';
import SecurityTab from './security-tab.component';
Expand All @@ -37,6 +40,9 @@ const mapStateToProps = (state) => {
openSeaEnabled,
useNftDetection,
use4ByteResolution,
///: BEGIN:ONLY_INCLUDE_IN(petnames)
useExternalNameSources,
///: END:ONLY_INCLUDE_IN
} = metamask;

const allNetworks = getAllNetworks(state);
Expand All @@ -56,6 +62,9 @@ const mapStateToProps = (state) => {
openSeaEnabled,
useNftDetection,
use4ByteResolution,
///: BEGIN:ONLY_INCLUDE_IN(petnames)
useExternalNameSources,
///: END:ONLY_INCLUDE_IN
};
};

Expand All @@ -80,6 +89,11 @@ const mapDispatchToProps = (dispatch) => {
setUse4ByteResolution: (value) => {
return dispatch(setUse4ByteResolution(value));
},
///: BEGIN:ONLY_INCLUDE_IN(petnames)
setUseExternalNameSources: (value) => {
return dispatch(setUseExternalNameSources(value));
},
///: END:ONLY_INCLUDE_IN
};
};

Expand Down
10 changes: 10 additions & 0 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4449,6 +4449,16 @@ export async function setAddSnapAccountEnabled(value: boolean): Promise<void> {
}
///: END:ONLY_INCLUDE_IN

///: BEGIN:ONLY_INCLUDE_IN(petnames)
export function setUseExternalNameSources(val: boolean): void {
try {
submitRequestToBackground('setUseExternalNameSources', [val]);
} catch (error) {
logErrorWithMessage(error);
}
}
///: END:ONLY_INCLUDE_IN

export function setFirstTimeUsedNetwork(chainId: string) {
return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]);
}
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3029,12 +3029,12 @@ __metadata:
linkType: hard

"@jest/expect@npm:^29.1.2":
version: 29.1.2
resolution: "@jest/expect@npm:29.1.2"
version: 29.6.2
resolution: "@jest/expect@npm:29.6.2"
dependencies:
expect: "npm:^29.1.2"
jest-snapshot: "npm:^29.1.2"
checksum: 7bb80bf176f39becdbd2ef54be615c3e7010f3230ccc419f22c97fa5b66e0fa14bb6b05019840d01cd1892e42be8158bea4c94487f05da1dd2b85a4ac097dd15
expect: "npm:^29.6.2"
jest-snapshot: "npm:^29.6.2"
checksum: 2beed96e3d24945a72aa2ae4843c99f4c631564569258fdde6746fae3efcbfbff96dbf92ed28d6531299bd12b2766075bacaaae88ebf84b99316e77151b43a9f
languageName: node
linkType: hard

Expand Down Expand Up @@ -16386,7 +16386,7 @@ __metadata:
languageName: node
linkType: hard

"expect@npm:^29.0.0, expect@npm:^29.1.2, expect@npm:^29.6.2":
"expect@npm:^29.0.0, expect@npm:^29.6.2":
version: 29.6.2
resolution: "expect@npm:29.6.2"
dependencies:
Expand Down Expand Up @@ -16678,13 +16678,13 @@ __metadata:
linkType: hard

"fast-xml-parser@npm:^4.1.3":
version: 4.2.5
resolution: "fast-xml-parser@npm:4.2.5"
version: 4.2.4
resolution: "fast-xml-parser@npm:4.2.4"
dependencies:
strnum: "npm:^1.0.5"
bin:
fxparser: src/cli/cli.js
checksum: 4be7ebe24d6a9a60c278e1423cd86a7da9a77ec64c95563e2c552363caf7a777e0c87c9de1255c2f4e8dea9bce8905dc2bdc58a34e9f2b73c4693654456ad284
checksum: 157f64a142d37f2c937d5308d62668119e40218dab41a07d1a9563c3f92663c81fd08db0efc9fe484e0bc4dfea59827f319adc510426ff9b97c83a779d511b6f
languageName: node
linkType: hard

Expand Down Expand Up @@ -21456,7 +21456,7 @@ __metadata:
languageName: node
linkType: hard

"jest-snapshot@npm:^29.1.2":
"jest-snapshot@npm:^29.1.2, jest-snapshot@npm:^29.6.2":
version: 29.6.2
resolution: "jest-snapshot@npm:29.6.2"
dependencies:
Expand Down

0 comments on commit ab0fdee

Please sign in to comment.