Skip to content

Pass localized snap name to SubjectMetadataController #2157

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

Merged
merged 6 commits into from
Feb 5, 2024
Merged
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
15 changes: 13 additions & 2 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
VirtualFile,
NpmSnapFileNames,
OnNameLookupResponseStruct,
getLocalizedSnapManifest,
} from '@metamask/snaps-utils';
import type { Json, NonEmptyArray, SemVerRange } from '@metamask/utils';
import {
Expand Down Expand Up @@ -2515,7 +2516,7 @@ export class SnapController extends BaseController<
} = files;

assertIsSnapManifest(manifest.result);
const { version, proposedName } = manifest.result;
const { version } = manifest.result;

const sourceCode = sourceCodeFile.toString();

Expand Down Expand Up @@ -2546,6 +2547,8 @@ export class SnapController extends BaseController<
},
];

const localizedFiles = localizationFiles.map((file) => file.result);

const snap: Snap = {
// Restore relevant snap state if it exists
...existingSnap,
Expand All @@ -2566,7 +2569,7 @@ export class SnapController extends BaseController<
version,
versionHistory,
auxiliaryFiles,
localizationFiles: localizationFiles.map((file) => file.result),
localizationFiles: localizedFiles,
};

// If the snap was blocked, it isn't any longer
Expand All @@ -2586,6 +2589,14 @@ export class SnapController extends BaseController<
}
}

// In case the Snap uses a localized manifest, we need to get the
// proposed name from the localized manifest.
const { proposedName } = getLocalizedSnapManifest(
manifest.result,
'en',
localizedFiles,
);

this.messagingSystem.call('SubjectMetadataController:addSubjectMetadata', {
subjectType: SubjectType.Snap,
name: proposedName,
Expand Down