mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
[FLASK] Fix crash when requesting unknown snap permission (#18447)
This commit is contained in:
parent
c52d2131d3
commit
40628da3b4
@ -9,24 +9,13 @@ export default function UpdateSnapPermissionList({
|
|||||||
approvedPermissions,
|
approvedPermissions,
|
||||||
revokedPermissions,
|
revokedPermissions,
|
||||||
newPermissions,
|
newPermissions,
|
||||||
|
targetSubjectMetadata,
|
||||||
}) {
|
}) {
|
||||||
const t = useI18nContext();
|
const t = useI18nContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box paddingTop={1}>
|
<Box paddingTop={1}>
|
||||||
{getWeightedPermissions(t, newPermissions).map((permission, index) => {
|
{getWeightedPermissions(t, newPermissions, targetSubjectMetadata).map(
|
||||||
return (
|
|
||||||
<PermissionCell
|
|
||||||
title={permission.label}
|
|
||||||
description={permission.description}
|
|
||||||
weight={permission.weight}
|
|
||||||
avatarIcon={permission.leftIcon}
|
|
||||||
dateApproved={permission?.permissionValue?.date}
|
|
||||||
key={`${permission.permissionName}-${index}`}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
{getWeightedPermissions(t, approvedPermissions).map(
|
|
||||||
(permission, index) => {
|
(permission, index) => {
|
||||||
return (
|
return (
|
||||||
<PermissionCell
|
<PermissionCell
|
||||||
@ -40,7 +29,23 @@ export default function UpdateSnapPermissionList({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
{getWeightedPermissions(t, revokedPermissions).map(
|
{getWeightedPermissions(
|
||||||
|
t,
|
||||||
|
approvedPermissions,
|
||||||
|
targetSubjectMetadata,
|
||||||
|
).map((permission, index) => {
|
||||||
|
return (
|
||||||
|
<PermissionCell
|
||||||
|
title={permission.label}
|
||||||
|
description={permission.description}
|
||||||
|
weight={permission.weight}
|
||||||
|
avatarIcon={permission.leftIcon}
|
||||||
|
dateApproved={permission?.permissionValue?.date}
|
||||||
|
key={`${permission.permissionName}-${index}`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{getWeightedPermissions(t, revokedPermissions, targetSubjectMetadata).map(
|
||||||
(permission, index) => {
|
(permission, index) => {
|
||||||
return (
|
return (
|
||||||
<PermissionCell
|
<PermissionCell
|
||||||
@ -72,4 +77,5 @@ UpdateSnapPermissionList.propTypes = {
|
|||||||
* New permissions that are being requested
|
* New permissions that are being requested
|
||||||
*/
|
*/
|
||||||
newPermissions: PropTypes.object.isRequired,
|
newPermissions: PropTypes.object.isRequired,
|
||||||
|
targetSubjectMetadata: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
@ -5,12 +5,16 @@ import { useI18nContext } from '../../../hooks/useI18nContext';
|
|||||||
import PermissionCell from '../permission-cell';
|
import PermissionCell from '../permission-cell';
|
||||||
import Box from '../../ui/box';
|
import Box from '../../ui/box';
|
||||||
|
|
||||||
export default function PermissionsConnectPermissionList({ permissions }) {
|
export default function PermissionsConnectPermissionList({
|
||||||
|
permissions,
|
||||||
|
targetSubjectMetadata,
|
||||||
|
}) {
|
||||||
const t = useI18nContext();
|
const t = useI18nContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box paddingTop={2} paddingBottom={2}>
|
<Box paddingTop={2} paddingBottom={2}>
|
||||||
{getWeightedPermissions(t, permissions).map((permission, index) => {
|
{getWeightedPermissions(t, permissions, targetSubjectMetadata).map(
|
||||||
|
(permission, index) => {
|
||||||
return (
|
return (
|
||||||
<PermissionCell
|
<PermissionCell
|
||||||
title={permission.label}
|
title={permission.label}
|
||||||
@ -21,11 +25,13 @@ export default function PermissionsConnectPermissionList({ permissions }) {
|
|||||||
key={`${permission.permissionName}-${index}`}
|
key={`${permission.permissionName}-${index}`}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
},
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PermissionsConnectPermissionList.propTypes = {
|
PermissionsConnectPermissionList.propTypes = {
|
||||||
permissions: PropTypes.object.isRequired,
|
permissions: PropTypes.object.isRequired,
|
||||||
|
targetSubjectMetadata: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
@ -409,6 +409,7 @@ export const getPermissionDescription = ({
|
|||||||
t,
|
t,
|
||||||
permissionName,
|
permissionName,
|
||||||
permissionValue,
|
permissionValue,
|
||||||
|
targetSubjectMetadata,
|
||||||
}) => {
|
}) => {
|
||||||
let value = PERMISSION_DESCRIPTIONS[UNKNOWN_PERMISSION];
|
let value = PERMISSION_DESCRIPTIONS[UNKNOWN_PERMISSION];
|
||||||
|
|
||||||
@ -416,7 +417,12 @@ export const getPermissionDescription = ({
|
|||||||
value = PERMISSION_DESCRIPTIONS[permissionName];
|
value = PERMISSION_DESCRIPTIONS[permissionName];
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = value({ t, permissionName, permissionValue });
|
const result = value({
|
||||||
|
t,
|
||||||
|
permissionName,
|
||||||
|
permissionValue,
|
||||||
|
targetSubjectMetadata,
|
||||||
|
});
|
||||||
if (!Array.isArray(result)) {
|
if (!Array.isArray(result)) {
|
||||||
return [{ ...result, permissionName, permissionValue }];
|
return [{ ...result, permissionName, permissionValue }];
|
||||||
}
|
}
|
||||||
@ -434,14 +440,20 @@ export const getPermissionDescription = ({
|
|||||||
*
|
*
|
||||||
* @param {Function} t - The translation function
|
* @param {Function} t - The translation function
|
||||||
* @param {object} permissions - The permissions object.
|
* @param {object} permissions - The permissions object.
|
||||||
|
* @param {object} targetSubjectMetadata - The subject metadata.
|
||||||
* @returns {PermissionLabelObject[]}
|
* @returns {PermissionLabelObject[]}
|
||||||
*/
|
*/
|
||||||
export function getWeightedPermissions(t, permissions) {
|
export function getWeightedPermissions(t, permissions, targetSubjectMetadata) {
|
||||||
return Object.entries(permissions)
|
return Object.entries(permissions)
|
||||||
.reduce(
|
.reduce(
|
||||||
(target, [permissionName, permissionValue]) =>
|
(target, [permissionName, permissionValue]) =>
|
||||||
target.concat(
|
target.concat(
|
||||||
getPermissionDescription({ t, permissionName, permissionValue }),
|
getPermissionDescription({
|
||||||
|
t,
|
||||||
|
permissionName,
|
||||||
|
permissionValue,
|
||||||
|
targetSubjectMetadata,
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
|
@ -123,6 +123,7 @@ export default function SnapInstall({
|
|||||||
</Text>
|
</Text>
|
||||||
<PermissionsConnectPermissionList
|
<PermissionsConnectPermissionList
|
||||||
permissions={requestState.permissions || {}}
|
permissions={requestState.permissions || {}}
|
||||||
|
targetSubjectMetadata={targetSubjectMetadata}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -135,6 +135,7 @@ export default function SnapUpdate({
|
|||||||
approvedPermissions={approvedPermissions}
|
approvedPermissions={approvedPermissions}
|
||||||
revokedPermissions={revokedPermissions}
|
revokedPermissions={revokedPermissions}
|
||||||
newPermissions={newPermissions}
|
newPermissions={newPermissions}
|
||||||
|
targetSubjectMetadata={targetSubjectMetadata}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -1,29 +1,18 @@
|
|||||||
import { isObject } from '@metamask/utils';
|
import { getPermissionDescription } from '../../../helpers/utils/permission';
|
||||||
import { PERMISSION_DESCRIPTIONS } from '../../../helpers/utils/permission';
|
|
||||||
|
|
||||||
export function getSnapInstallWarnings(permissions, targetSubjectMetadata, t) {
|
export function getSnapInstallWarnings(permissions, targetSubjectMetadata, t) {
|
||||||
const weightOneWarnings = Object.entries(permissions).reduce(
|
const weightOneWarnings = Object.entries(permissions).reduce(
|
||||||
(filteredWarnings, [permissionName, permissionValue]) => {
|
(filteredWarnings, [permissionName, permissionValue]) => {
|
||||||
const permissionDescription = PERMISSION_DESCRIPTIONS[permissionName]({
|
const permissionDescription = getPermissionDescription({
|
||||||
t,
|
t,
|
||||||
|
permissionName,
|
||||||
permissionValue,
|
permissionValue,
|
||||||
targetSubjectMetadata,
|
targetSubjectMetadata,
|
||||||
});
|
});
|
||||||
if (Array.isArray(permissionDescription)) {
|
|
||||||
permissionDescription.forEach((description) => {
|
return filteredWarnings.concat(
|
||||||
if (description.weight === 1) {
|
permissionDescription.filter((description) => description.weight === 1),
|
||||||
const { id, message } = description;
|
);
|
||||||
filteredWarnings.push({ id, message });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (
|
|
||||||
isObject(permissionDescription) &&
|
|
||||||
permissionDescription.weight === 1
|
|
||||||
) {
|
|
||||||
const { id, message } = permissionDescription;
|
|
||||||
filteredWarnings.push({ id, message });
|
|
||||||
}
|
|
||||||
return filteredWarnings;
|
|
||||||
},
|
},
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
@ -35,6 +35,7 @@ import {
|
|||||||
getSubjectsWithSnapPermission,
|
getSubjectsWithSnapPermission,
|
||||||
getPermissions,
|
getPermissions,
|
||||||
getPermissionSubjects,
|
getPermissionSubjects,
|
||||||
|
getTargetSubjectMetadata,
|
||||||
} from '../../../../selectors';
|
} from '../../../../selectors';
|
||||||
import { formatDate } from '../../../../helpers/utils/util';
|
import { formatDate } from '../../../../helpers/utils/util';
|
||||||
|
|
||||||
@ -65,6 +66,9 @@ function ViewSnap() {
|
|||||||
(state) => snap && getPermissions(state, snap.id),
|
(state) => snap && getPermissions(state, snap.id),
|
||||||
);
|
);
|
||||||
const subjects = useSelector((state) => getPermissionSubjects(state));
|
const subjects = useSelector((state) => getPermissionSubjects(state));
|
||||||
|
const targetSubjectMetadata = useSelector((state) =>
|
||||||
|
getTargetSubjectMetadata(state, snap?.id),
|
||||||
|
);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const onToggle = () => {
|
const onToggle = () => {
|
||||||
@ -180,6 +184,7 @@ function ViewSnap() {
|
|||||||
<Box width={BLOCK_SIZES.FULL}>
|
<Box width={BLOCK_SIZES.FULL}>
|
||||||
<PermissionsConnectPermissionList
|
<PermissionsConnectPermissionList
|
||||||
permissions={permissions ?? {}}
|
permissions={permissions ?? {}}
|
||||||
|
targetSubjectMetadata={targetSubjectMetadata}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user