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

Add support for localised Snap manifests #21909

Merged
merged 69 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
dbdfb88
Add support for localised Snap manifests
Mrtenz Nov 21, 2023
cfb868f
Update LavaMoat policies
metamaskbot Nov 21, 2023
dd1f514
Remove unused import
Mrtenz Nov 21, 2023
cb5bb9a
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Jan 25, 2024
25caea4
remove snaps metadata constant
hmalik88 Jan 25, 2024
0236821
add fence
hmalik88 Jan 25, 2024
c631e4f
update useTransactionInsights with a new selector
hmalik88 Jan 25, 2024
8ada300
fixed fences and regenerated lavamoat policies
hmalik88 Jan 25, 2024
8b00de0
more fixes
hmalik88 Jan 26, 2024
33c0eba
remove prop
hmalik88 Jan 26, 2024
b75b0c3
lint fix
hmalik88 Jan 26, 2024
217b38c
remove unused message
hmalik88 Jan 26, 2024
dad9c75
fix selector
hmalik88 Jan 26, 2024
588b84a
remove unused messages
hmalik88 Jan 26, 2024
285c6a0
fix fence
hmalik88 Jan 26, 2024
1891d3e
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Jan 30, 2024
efa8c11
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Feb 1, 2024
316c85a
revert fence change
hmalik88 Feb 5, 2024
6a0db9d
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Feb 5, 2024
b5b8573
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Feb 6, 2024
045ece9
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Feb 7, 2024
b8d6a4a
remove upstreamed code
hmalik88 Feb 7, 2024
31502d2
add snaps metadata selector
hmalik88 Feb 7, 2024
a3c5c2e
fix selector
hmalik88 Feb 7, 2024
7bf2143
remove unused import
hmalik88 Feb 8, 2024
238da7d
add guard to selector
hmalik88 Feb 15, 2024
7e9c8ce
reorder selectors
hmalik88 Feb 15, 2024
939d1d8
revert changes
hmalik88 Feb 19, 2024
f539710
revert more changes
hmalik88 Feb 19, 2024
d40b561
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Feb 19, 2024
de1e717
revert permission utils
hmalik88 Feb 19, 2024
3e28af6
update
hmalik88 Mar 12, 2024
985804c
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 12, 2024
7b613ed
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 12, 2024
14b121d
lint fix
hmalik88 Mar 13, 2024
32cf174
update with getSnapName func
hmalik88 Mar 13, 2024
e82615d
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 13, 2024
1ee0cca
revert messages
hmalik88 Mar 13, 2024
b033b59
revert lavamoat policies
hmalik88 Mar 13, 2024
6cc9085
fix lint error, regenerate lavamoat policies
hmalik88 Mar 13, 2024
73d32c1
address PR comments
hmalik88 Mar 13, 2024
9d1b806
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 13, 2024
fffaff8
use correct selector
hmalik88 Mar 13, 2024
5a11aed
update snap keyring with new getSnapName func
hmalik88 Mar 14, 2024
f52db29
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 14, 2024
2d70bfb
update policies
hmalik88 Mar 14, 2024
cdcd78c
lint fix
hmalik88 Mar 14, 2024
55b3acb
update snapshot
hmalik88 Mar 14, 2024
07c3d2d
update implementation to accomodate for non-snap origins
hmalik88 Mar 14, 2024
a46262e
update selector usage
hmalik88 Mar 14, 2024
01380e8
applying pr suggestions
hmalik88 Mar 14, 2024
33dd279
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 14, 2024
6154ffc
add missing param
hmalik88 Mar 14, 2024
dbe9557
update mockstore
hmalik88 Mar 14, 2024
4d98e62
fix mock store for error template store
hmalik88 Mar 14, 2024
c387e6e
update mock store for success template
hmalik88 Mar 14, 2024
0a47e49
update snap permission list test with mock store
hmalik88 Mar 14, 2024
2de1e50
some more fixes
hmalik88 Mar 14, 2024
3372577
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 14, 2024
ba2c90d
update getSnapName functions to fallback to snap id
hmalik88 Mar 14, 2024
e24df44
test fixes
hmalik88 Mar 14, 2024
fd0fd07
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 14, 2024
81e7a48
update selector test
hmalik88 Mar 14, 2024
07b8470
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 14, 2024
0003a3e
refactor per PR comments
hmalik88 Mar 15, 2024
4e3eaca
Merge branch 'develop' into mrtenz/manifest-localisation
hmalik88 Mar 15, 2024
f259765
lint fix
hmalik88 Mar 15, 2024
90f06b6
pass subject origin to permission descriptions for future use
hmalik88 Mar 15, 2024
3d69eb5
fix prop usage
hmalik88 Mar 15, 2024
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
8 changes: 5 additions & 3 deletions app/scripts/lib/snap-keyring/snap-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES } from '../../../../shared/cons
import { t } from '../../translate';
import MetamaskController from '../../metamask-controller';
import { IconName } from '../../../../ui/components/component-library/icon';
import { getSnapName } from './utils/getSnapName';
import { isBlockedUrl } from './utils/isBlockedUrl';
import { showSuccess, showError } from './utils/showResult';
import { SnapKeyringBuilderMessenger } from './types';
Expand Down Expand Up @@ -40,6 +39,8 @@ export const getAccountsBySnapId = async (
* @param setSelectedAccountHelper - A function to update current selected account.
* @param removeAccountHelper - A function to help remove an account based on its address.
* @param trackEvent - A function to track MetaMetrics events.
* @param getSnapName - A function to get a snap's localized
* (or non-localized if there are no localization files) name from its manifest.
* @returns The constructed SnapKeyring builder instance with the following methods:
* - `saveState`: Persists all keyrings in the keyring controller.
* - `addAccount`: Initiates the process of adding an account with user confirmation and handling the user input.
Expand All @@ -55,6 +56,7 @@ export const snapKeyringBuilder = (
payload: Record<string, any>,
options?: Record<string, any>,
) => void,
getSnapName: (snapId: string) => string,
) => {
const builder = (() => {
return new SnapKeyring(getSnapController() as any, {
Expand Down Expand Up @@ -111,7 +113,7 @@ export const snapKeyringBuilder = (
snapId: string,
handleUserInput: (accepted: boolean) => Promise<void>,
) => {
const snapName = getSnapName(controllerMessenger, snapId);
const snapName = getSnapName(snapId);
const { id: addAccountApprovalId } = controllerMessenger.call(
'ApprovalController:startFlow',
);
Expand Down Expand Up @@ -237,7 +239,7 @@ export const snapKeyringBuilder = (
snapId: string,
handleUserInput: (accepted: boolean) => Promise<void>,
) => {
const snapName = getSnapName(controllerMessenger, snapId);
const snapName = getSnapName(snapId);
const { id: removeAccountApprovalId } = controllerMessenger.call(
'ApprovalController:startFlow',
);
Expand Down
90 changes: 0 additions & 90 deletions app/scripts/lib/snap-keyring/utils/getSnapName.test.ts

This file was deleted.

14 changes: 0 additions & 14 deletions app/scripts/lib/snap-keyring/utils/getSnapName.ts

This file was deleted.

34 changes: 33 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ import {
TransactionType,
} from '@metamask/transaction-controller';

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import {
getLocalizedSnapManifest,
stripSnapPrefix,
} from '@metamask/snaps-utils';
///: END:ONLY_INCLUDE_IF

///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils';
///: END:ONLY_INCLUDE_IF
Expand Down Expand Up @@ -989,7 +996,6 @@ export default class MetamaskController extends EventEmitter {
'PhishingController:test',
'PhishingController:maybeUpdateState',
'KeyringController:getAccounts',
'SubjectMetadataController:getSubjectMetadata',
'AccountsController:setSelectedAccount',
'AccountsController:getAccountByAddress',
],
Expand All @@ -1003,6 +1009,31 @@ export default class MetamaskController extends EventEmitter {
await this.accountsController.updateAccounts();
};

const getSnapName = (id) => {
if (!id) {
return null;
}

const currentLocale = this.getLocale();
const { snaps } = this.snapController.state;
const snap = snaps[id];

if (!snap) {
return stripSnapPrefix(id);
}

if (snap.localizationFiles) {
const localizedManifest = getLocalizedSnapManifest(
snap.manifest,
currentLocale,
snap.localizationFiles,
);
return localizedManifest.proposedName;
}

return snap.manifest.proposedName;
};

additionalKeyrings.push(
snapKeyringBuilder(
snapKeyringBuildMessenger,
Expand All @@ -1011,6 +1042,7 @@ export default class MetamaskController extends EventEmitter {
(address) => this.preferencesController.setSelectedAddress(address),
(address) => this.removeAccount(address),
this.metaMetricsController.trackEvent.bind(this.metaMetricsController),
getSnapName,
),
);

Expand Down
43 changes: 0 additions & 43 deletions shared/constants/snaps.ts

This file was deleted.

Loading
Loading