1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 23:14:56 +01:00
metamask-extension/ui/pages/permissions-connect/flask/util.js
Frederik Bolding 4eb8e50800
[FLASK] snaps-skunkworks@0.21.0 (#15889)
* snaps-skunkworks@0.21.0

* Update policy files

* Regen policies again

* Fix tests

* Simplify selector

* Fix flaky test

* Update iframe execution env

* Move snap install warnings to util

* Add basic copy for snap_getBip32PublicKey

* Update permission icon

* Update E2Es

* Fix lint

* Fix locale strings
2022-09-23 12:39:54 +02:00

39 lines
1.3 KiB
JavaScript

import { flatMap } from '@metamask/snap-utils';
import { coinTypeToProtocolName } from '../../../helpers/utils/util';
export function getSnapInstallWarnings(permissions, targetSubjectMetadata, t) {
const bip32EntropyPermissions =
permissions &&
Object.entries(permissions)
.filter(([key]) => key === 'snap_getBip32Entropy')
.map(([, value]) => value);
const bip44EntropyPermissions =
permissions &&
Object.entries(permissions)
.filter(([key]) => key === 'snap_getBip44Entropy')
.map(([, value]) => value);
return [
...flatMap(bip32EntropyPermissions, (permission, i) =>
permission.caveats[0].value.map(({ path, curve }) => ({
id: `key-access-bip32-${path.join('/')}-${curve}-${i}`,
message: t('snapInstallWarningKeyAccess', [
targetSubjectMetadata.name,
`${path.join('/')} (${curve})`,
]),
})),
),
...flatMap(bip44EntropyPermissions, (permission, i) =>
permission.caveats[0].value.map(({ coinType }) => ({
id: `key-access-bip44-${coinType}-${i}`,
message: t('snapInstallWarningKeyAccess', [
targetSubjectMetadata.name,
coinTypeToProtocolName(coinType) ||
t('unrecognizedProtocol', [coinType]),
]),
})),
),
];
}