2022-08-03 18:02:44 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2022-09-23 12:39:54 +02:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2022-08-03 18:02:44 +02:00
|
|
|
import { PageContainerFooter } from '../../../../components/ui/page-container';
|
|
|
|
import PermissionsConnectFooter from '../../../../components/app/permissions-connect-footer';
|
|
|
|
import PermissionConnectHeader from '../../../../components/app/permissions-connect-header';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import SnapInstallWarning from '../../../../components/app/flask/snap-install-warning';
|
|
|
|
import Box from '../../../../components/ui/box/box';
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
2022-08-03 18:02:44 +02:00
|
|
|
BLOCK_SIZES,
|
2023-02-02 21:15:26 +01:00
|
|
|
BorderStyle,
|
2022-08-03 18:02:44 +02:00
|
|
|
FLEX_DIRECTION,
|
2023-02-02 21:15:26 +01:00
|
|
|
JustifyContent,
|
|
|
|
TypographyVariant,
|
2022-08-03 18:02:44 +02:00
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import Typography from '../../../../components/ui/typography';
|
|
|
|
import UpdateSnapPermissionList from '../../../../components/app/flask/update-snap-permission-list';
|
2022-09-23 12:39:54 +02:00
|
|
|
import { getSnapInstallWarnings } from '../util';
|
2022-08-03 18:02:44 +02:00
|
|
|
|
|
|
|
export default function SnapUpdate({
|
|
|
|
request,
|
|
|
|
approveSnapUpdate,
|
|
|
|
rejectSnapUpdate,
|
|
|
|
targetSubjectMetadata,
|
|
|
|
}) {
|
|
|
|
const t = useI18nContext();
|
|
|
|
|
|
|
|
const [isShowingWarning, setIsShowingWarning] = useState(false);
|
|
|
|
|
|
|
|
const onCancel = useCallback(
|
|
|
|
() => rejectSnapUpdate(request.metadata.id),
|
|
|
|
[request, rejectSnapUpdate],
|
|
|
|
);
|
|
|
|
|
|
|
|
const onSubmit = useCallback(
|
2022-09-20 14:46:25 +02:00
|
|
|
() => approveSnapUpdate(request.metadata.id),
|
2022-08-03 18:02:44 +02:00
|
|
|
[request, approveSnapUpdate],
|
|
|
|
);
|
|
|
|
|
2022-09-20 14:46:25 +02:00
|
|
|
const approvedPermissions = request.approvedPermissions ?? {};
|
|
|
|
const revokedPermissions = request.unusedPermissions ?? {};
|
|
|
|
const newPermissions = request.newPermissions ?? {};
|
|
|
|
const hasPermissions =
|
|
|
|
Object.keys(approvedPermissions).length +
|
|
|
|
Object.keys(revokedPermissions).length +
|
|
|
|
Object.keys(newPermissions).length >
|
|
|
|
0;
|
|
|
|
|
2022-09-23 12:39:54 +02:00
|
|
|
const warnings = getSnapInstallWarnings(
|
|
|
|
newPermissions,
|
|
|
|
targetSubjectMetadata,
|
|
|
|
t,
|
|
|
|
);
|
|
|
|
|
|
|
|
const shouldShowWarning = warnings.length > 0;
|
|
|
|
|
2022-08-03 18:02:44 +02:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className="page-container snap-update"
|
2023-02-02 21:15:26 +01:00
|
|
|
justifyContent={JustifyContent.spaceBetween}
|
2022-08-03 18:02:44 +02:00
|
|
|
height={BLOCK_SIZES.FULL}
|
2023-02-02 21:15:26 +01:00
|
|
|
borderStyle={BorderStyle.none}
|
2022-08-03 18:02:44 +02:00
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
className="headers"
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2022-08-03 18:02:44 +02:00
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
>
|
|
|
|
<PermissionConnectHeader
|
|
|
|
icon={targetSubjectMetadata.iconUrl}
|
|
|
|
iconName={targetSubjectMetadata.name}
|
|
|
|
headerTitle={t('snapUpdate')}
|
|
|
|
headerText={null} // TODO(ritave): Add header text when snaps support description
|
|
|
|
siteOrigin={request.snapId}
|
|
|
|
isSnapInstallOrUpdate
|
|
|
|
snapVersion={request.newVersion}
|
2023-02-02 21:15:26 +01:00
|
|
|
boxProps={{ alignItems: AlignItems.center }}
|
2022-08-03 18:02:44 +02:00
|
|
|
/>
|
|
|
|
<Typography
|
|
|
|
boxProps={{
|
|
|
|
padding: [4, 4, 0, 4],
|
|
|
|
}}
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H7}
|
2022-08-10 21:42:42 +02:00
|
|
|
as="span"
|
2022-08-03 18:02:44 +02:00
|
|
|
>
|
|
|
|
{t('snapUpdateExplanation', [`${request.metadata.dappOrigin}`])}
|
|
|
|
</Typography>
|
2022-09-20 14:46:25 +02:00
|
|
|
{hasPermissions && (
|
|
|
|
<>
|
|
|
|
<Typography
|
|
|
|
boxProps={{
|
|
|
|
padding: [2, 4, 0, 4],
|
|
|
|
}}
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H7}
|
2022-09-20 14:46:25 +02:00
|
|
|
as="span"
|
|
|
|
>
|
|
|
|
{t('snapRequestsPermission')}
|
|
|
|
</Typography>
|
|
|
|
<UpdateSnapPermissionList
|
|
|
|
approvedPermissions={approvedPermissions}
|
|
|
|
revokedPermissions={revokedPermissions}
|
|
|
|
newPermissions={newPermissions}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
2022-08-03 18:02:44 +02:00
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
className="footers"
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={AlignItems.center}
|
2022-08-03 18:02:44 +02:00
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
>
|
|
|
|
<Box className="snap-update__footer--no-source-code" paddingTop={4}>
|
|
|
|
<PermissionsConnectFooter />
|
|
|
|
</Box>
|
|
|
|
<PageContainerFooter
|
|
|
|
cancelButtonType="default"
|
|
|
|
onCancel={onCancel}
|
|
|
|
cancelText={t('cancel')}
|
|
|
|
onSubmit={
|
|
|
|
shouldShowWarning ? () => setIsShowingWarning(true) : onSubmit
|
|
|
|
}
|
|
|
|
submitText={t('approveAndUpdate')}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
{isShowingWarning && (
|
|
|
|
<SnapInstallWarning
|
|
|
|
onCancel={() => setIsShowingWarning(false)}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
snapName={targetSubjectMetadata.name}
|
2022-09-23 12:39:54 +02:00
|
|
|
warnings={warnings}
|
2022-08-03 18:02:44 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
SnapUpdate.propTypes = {
|
|
|
|
request: PropTypes.object.isRequired,
|
|
|
|
approveSnapUpdate: PropTypes.func.isRequired,
|
|
|
|
rejectSnapUpdate: PropTypes.func.isRequired,
|
|
|
|
targetSubjectMetadata: PropTypes.shape({
|
|
|
|
iconUrl: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
origin: PropTypes.string.isRequired,
|
|
|
|
sourceCode: PropTypes.string,
|
|
|
|
version: PropTypes.string,
|
|
|
|
}).isRequired,
|
|
|
|
};
|