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

fix: Don't show third party notice for preinstalled Snaps #27319

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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,7 +20,11 @@ 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 {
getPermissions,
getPreinstalledSnaps,
getSnapMetadata,
} from '../../../../selectors';
import { useOriginMetadata } from '../../../../hooks/useOriginMetadata';
import { isSnapId } from '../../../../helpers/utils/snaps';
import { SnapIcon } from '../../../../components/app/snaps/snap-icon';
Expand All @@ -36,12 +40,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this would make us skip the third party notice if multiple Snaps are installed where one is preinstalled? That seems wrong to me 🤔

const [isShowingSnapsPrivacyWarning, setIsShowingSnapsPrivacyWarning] =
useState(!isPreinstalled && !snapsInstallPrivacyWarningShown);

const onCancel = useCallback(() => {
rejectConnection(request.metadata.id);
}, [request, rejectConnection]);
Expand All @@ -55,8 +70,6 @@ export default function SnapsConnect({
}
}, [request, approveConnection]);

const snaps = getDedupedSnaps(request, currentPermissions);

const SnapsConnectContent = () => {
let trimmedOrigin = (useOriginMetadata(origin) || {})?.hostname;
const { name } = useSelector((state) =>
Expand All @@ -68,11 +81,6 @@ export default function SnapsConnect({
trimmedOrigin = name;
}

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 @@ -1572,6 +1572,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
Loading