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: Show correct origins when snaps use wallet_requestSnaps #26715

Merged
merged 18 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 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.

18 changes: 18 additions & 0 deletions test/data/mock-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,24 @@
"parentCapability": "snap_getBip44Entropy"
}
}
},
"https://snaps.metamask.io": {
"origin": "https://snaps.metamask.io",
"permissions": {
"wallet_snap": {
"caveats": [
{
"type": "snapIds",
"value": {
"npm:@metamask/test-snap-bip44": {}
}
}
],
"date": 1718117256761,
"id": "sBxmdvnow7QiN9aS4uSdn",
"invoker": "https://snaps.metamask.io"
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const SnapMetadataModal = ({ snapId, isOpen, onClose }) => {
: undefined;

const installOrigin = useOriginMetadata(installInfo?.origin);
const isSnapRequesting =
installInfo?.origin?.startsWith('local:') ||
installInfo?.origin?.startsWith('npm:');

const snapPrefix = getSnapPrefix(snapId);
const packageName = stripSnapPrefix(snapId);
Expand Down Expand Up @@ -161,7 +164,11 @@ export const SnapMetadataModal = ({ snapId, isOpen, onClose }) => {
</Tooltip>
)}
</Box>
<Text ellipsis>{installOrigin.host}</Text>
<Text ellipsis>
{isSnapRequesting
? stripSnapPrefix(installInfo.origin)
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
: installOrigin.host}
</Text>
</Box>
)}
<Box
Expand Down
13 changes: 11 additions & 2 deletions ui/pages/permissions-connect/snaps/snap-install/snap-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export default function SnapInstall({
const hasError = !requestState.loading && requestState.error;
const isLoading = requestState.loading;

// we already have access to the requesting snap's metadata
const isOriginSnap =
request?.metadata?.dappOrigin?.startsWith('local:') ||
request?.metadata?.dappOrigin?.startsWith('npm:');

const warnings = getSnapInstallWarnings(
requestState?.permissions ?? {},
t,
Expand Down Expand Up @@ -111,11 +116,15 @@ export default function SnapInstall({
flexDirection={FlexDirection.Column}
backgroundColor={BackgroundColor.backgroundAlternative}
>
{isLoading || hasError ? (
{(isLoading || hasError) && !isOriginSnap ? (
<PermissionConnectHeader origin={origin} iconUrl={iconUrl} />
) : (
<SnapAuthorshipHeader
snapId={targetSubjectMetadata.origin}
snapId={
isLoading && isOriginSnap
? request?.metadata?.dappOrigin
: targetSubjectMetadata.origin
}
onCancel={onCancel}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export default function SnapsConnect({
const snaps = getDedupedSnaps(request, currentPermissions);

const SnapsConnectContent = () => {
const { hostname: trimmedOrigin } = useOriginMetadata(origin) || {};
let trimmedOrigin = (useOriginMetadata(origin) || {})?.name;
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved

if (origin?.startsWith('local:') || origin?.startsWith('npm:')) {
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
trimmedOrigin = targetSubjectMetadata.name;
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
}

const snapId = snaps[0];
const { name: snapName } = useSelector((state) =>
Expand Down
13 changes: 12 additions & 1 deletion ui/pages/snaps/snap-view/snap-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ function SnapSettings({ snapId, initRemove, resetInitRemove }) {
}
};

const connectedTitle = () => {
hmalik88 marked this conversation as resolved.
Show resolved Hide resolved
const hasSnap = (subject) =>
subject.origin.startsWith('local:') || subject.origin.startsWith('npm:');
if (connectedSubjects.every((subject) => hasSnap(subject))) {
return t('connectedSnaps');
} else if (connectedSubjects.some((subject) => hasSnap(subject))) {
return t('connectedSitesAndSnaps');
}
return t('connectedSites');
};

useEffect(() => {
if (initRemove) {
setIsShowingRemoveWarning(true);
Expand Down Expand Up @@ -167,7 +178,7 @@ function SnapSettings({ snapId, initRemove, resetInitRemove }) {
</Box>
<Box className="snap-view__content__connected-sites" marginTop={12}>
<Text variant={TextVariant.bodyLgMedium} marginBottom={2}>
{t('connectedSites')}
{connectedTitle()}
</Text>
<ConnectedSitesList
connectedSubjects={connectedSubjects}
Expand Down