import PropTypes from 'prop-types'; import React, { useCallback, useMemo, useState } from 'react'; import { PageContainerFooter } from '../../../../components/ui/page-container'; import PermissionsConnectPermissionList from '../../../../components/app/permissions-connect-permission-list'; 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 { ALIGN_ITEMS, BLOCK_SIZES, BORDER_STYLE, FLEX_DIRECTION, JUSTIFY_CONTENT, TYPOGRAPHY, } from '../../../../helpers/constants/design-system'; import Typography from '../../../../components/ui/typography'; export default function SnapInstall({ request, approveSnapInstall, rejectSnapInstall, targetSubjectMetadata, }) { const t = useI18nContext(); const [isShowingWarning, setIsShowingWarning] = useState(false); const onCancel = useCallback(() => rejectSnapInstall(request.metadata.id), [ request, rejectSnapInstall, ]); const onSubmit = useCallback(() => approveSnapInstall(request), [ request, approveSnapInstall, ]); const npmId = useMemo(() => { if (!targetSubjectMetadata.origin.startsWith('npm:')) { return undefined; } return targetSubjectMetadata.origin.substring(4); }, [targetSubjectMetadata]); const shouldShowWarning = useMemo( () => Boolean( request.permissions && Object.keys(request.permissions).find((v) => v.startsWith('snap_getBip44Entropy_'), ), ), [request.permissions], ); return ( {t('snapRequestsPermission')} {targetSubjectMetadata.sourceCode ? ( <>
{t('areYouDeveloper')}
global.platform.openTab({ url: targetSubjectMetadata.sourceCode, }) } > {t('openSourceCode')}
) : ( )} setIsShowingWarning(true) : onSubmit } submitText={t('approveAndInstall')} />
{isShowingWarning && ( setIsShowingWarning(false)} onSubmit={onSubmit} snapName={targetSubjectMetadata.name} /> )}
); } SnapInstall.propTypes = { request: PropTypes.object.isRequired, approveSnapInstall: PropTypes.func.isRequired, rejectSnapInstall: PropTypes.func.isRequired, targetSubjectMetadata: PropTypes.shape({ iconUrl: PropTypes.string, name: PropTypes.string, origin: PropTypes.string.isRequired, sourceCode: PropTypes.string, }).isRequired, };