Skip to content

Commit

Permalink
fix: Don't show third party notice for preinstalled Snaps (#27319)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

We show a third party notice when installing or connecting to a Snap for
the first time. Preinstalled Snaps are first party Snaps however, so we
don't need to show the warning for these Snaps. I've implemented some
logic that checks if the requested Snap is a preinstalled Snap, and only
show the third party notice if it's not.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27319?quickstart=1)

Fixes: MetaMask/MetaMask-planning#3325.

Assuming you have not accepted the third party notice before:

1. Go to [the Test Snaps
page](https://metamask.github.io/snaps/test-snaps/latest/)
2. Connect to the preinstalled Snap, and verify the notice is _not_
shown
3. Connect to any other Snap, and verify that the notice _is_ shown

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
Mrtenz committed Sep 24, 2024
1 parent bdc819a commit 9fbf6d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
28 changes: 18 additions & 10 deletions ui/pages/permissions-connect/snaps/snaps-connect/snaps-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ import SnapConnectCell from '../../../../components/app/snaps/snap-connect-cell/
import { getDedupedSnaps } from '../../../../helpers/utils/util';
import PulseLoader from '../../../../components/ui/pulse-loader/pulse-loader';
import SnapPrivacyWarning from '../../../../components/app/snaps/snap-privacy-warning/snap-privacy-warning';
import { getPermissions, getSnapMetadata } from '../../../../selectors';
import SnapAvatar from '../../../../components/app/snaps/snap-avatar/snap-avatar';
import {
getPermissions,
getPreinstalledSnaps,
getSnapMetadata,
} from '../../../../selectors';
import { useOriginMetadata } from '../../../../hooks/useOriginMetadata';

export default function SnapsConnect({
Expand All @@ -35,12 +39,23 @@ export default function SnapsConnect({
const t = useI18nContext();
const { origin } = targetSubjectMetadata;
const [isLoading, setIsLoading] = useState(false);
const [isShowingSnapsPrivacyWarning, setIsShowingSnapsPrivacyWarning] =
useState(!snapsInstallPrivacyWarningShown);

const currentPermissions = useSelector((state) =>
getPermissions(state, request?.metadata?.origin),
);

const preinstalledSnaps = useSelector(getPreinstalledSnaps);

const snaps = getDedupedSnaps(request, currentPermissions);
const snapId = snaps[0];
const { name: snapName } = useSelector((state) =>
getSnapMetadata(state, snapId),
);

const isPreinstalled = Object.keys(preinstalledSnaps).includes(snapId);
const [isShowingSnapsPrivacyWarning, setIsShowingSnapsPrivacyWarning] =
useState(!isPreinstalled && !snapsInstallPrivacyWarningShown);

const onCancel = useCallback(() => {
rejectConnection(request.metadata.id);
}, [request, rejectConnection]);
Expand All @@ -54,16 +69,9 @@ export default function SnapsConnect({
}
}, [request, approveConnection]);

const snaps = getDedupedSnaps(request, currentPermissions);

const SnapsConnectContent = () => {
const { hostname: trimmedOrigin } = useOriginMetadata(origin) || {};

const snapId = snaps[0];
const { name: snapName } = useSelector((state) =>
getSnapMetadata(state, snapId),
);

if (isLoading) {
return (
<Box
Expand Down
12 changes: 12 additions & 0 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,18 @@ export const getEnabledSnaps = createDeepEqualSelector(getSnaps, (snaps) => {
}, {});
});

export const getPreinstalledSnaps = createDeepEqualSelector(
getSnaps,
(snaps) => {
return Object.values(snaps).reduce((acc, snap) => {
if (snap.preinstalled) {
acc[snap.id] = snap;
}
return acc;
}, {});
},
);

export const getInsightSnaps = createDeepEqualSelector(
getEnabledSnaps,
getPermissionSubjects,
Expand Down

0 comments on commit 9fbf6d9

Please sign in to comment.