Skip to content

Commit

Permalink
Add action for revoking dynamic permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Jul 5, 2023
1 parent dc9c3e6 commit 88a96a2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,10 @@ export default class MetamaskController extends EventEmitter {
this.notificationController.markRead(ids);
}

revokeDynamicSnapPermissions(permissions) {
// TODO
}

///: END:ONLY_INCLUDE_IN

/**
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/snaps/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export const ExcludedSnapEndowments = Object.freeze({
'endowment:long-running is deprecated. For more information please see https://github.com/MetaMask/snaps-monorepo/issues/945.',
///: END:ONLY_INCLUDE_IN
});

export const DynamicSnapPermissions = Object.freeze(['eth_accounts']);
32 changes: 20 additions & 12 deletions ui/components/app/permission-cell/permission-cell-options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useRef } from 'react';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
import Box from '../../ui/box';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { IconName, ButtonIcon, Text } from '../../component-library';
Expand All @@ -9,13 +10,18 @@ import {
TextVariant,
} from '../../../helpers/constants/design-system';
import Popover from '../../ui/popover/popover.component';
import { DynamicSnapPermissions } from '../../../../shared/constants/snaps/permissions';
import { revokeDynamicSnapPermissions } from '../../../store/actions';

export const PermissionCellOptions = ({ permissionName, description }) => {
const t = useI18nContext();
const dispatch = useDispatch();
const ref = useRef(false);
const [showOptions, setShowOptions] = useState(false);
const [showDetails, setShowDetails] = useState(false);

const isRevokable = DynamicSnapPermissions.includes(permissionName);

const handleOpen = () => {
setShowOptions(true);
};
Expand All @@ -36,7 +42,7 @@ export const PermissionCellOptions = ({ permissionName, description }) => {

const handleRevokePermission = () => {
setShowOptions(false);
// TODO
dispatch(revokeDynamicSnapPermissions([permissionName]));
};

return (
Expand All @@ -58,17 +64,19 @@ export const PermissionCellOptions = ({ permissionName, description }) => {
{t('details')}
</Text>
</MenuItem>
<MenuItem onClick={handleRevokePermission}>
<Text
variant={TextVariant.bodySm}
color={TextColor.errorDefault}
style={{
whiteSpace: 'nowrap',
}}
>
{t('revokePermission')}
</Text>
</MenuItem>
{isRevokable && (
<MenuItem onClick={handleRevokePermission}>
<Text
variant={TextVariant.bodySm}
color={TextColor.errorDefault}
style={{
whiteSpace: 'nowrap',
}}
>
{t('revokePermission')}
</Text>
</MenuItem>
)}
</Menu>
)}
{showDetails && (
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/settings/snaps/view-snap/view-snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function ViewSnap() {
<SnapPermissionsList
permissions={permissions ?? {}}
targetSubjectMetadata={targetSubjectMetadata}
showOptions={true}
showOptions
/>
</Box>
<Box className="view-snap__connected-sites" marginTop={12}>
Expand Down
11 changes: 11 additions & 0 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,17 @@ export function markNotificationsAsRead(
};
}

export function revokeDynamicSnapPermissions(
permissions: string[],
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
return async (dispatch: MetaMaskReduxDispatch) => {
await submitRequestToBackground('revokeDynamicSnapPermissions', [
permissions,
]);
await forceUpdateMetamaskState(dispatch);
};
}

///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)

Expand Down

0 comments on commit 88a96a2

Please sign in to comment.