mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-30 08:09:15 +01:00
354788510e
* Update UI (for audit) Revert yarn.lock change Update e2e tests with new copy for a button Make UI changes to custom Snap UI Update UI on snap installation success page Fix icon on installation success Fix snap name font weight in installation page Add UI changes for Snap installation failed page Add new copy for snap installation screen Update e2e tests OK button name Update OK button names in e2e tests Return previous functionality of update flow Add error message handling for update screens * Fix after rebase * Fix messages.json update message * Revert SCSS changes * Refactor failed and success screen rendering
194 lines
5.5 KiB
JavaScript
194 lines
5.5 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import React, { useCallback } from 'react';
|
|
import { PageContainerFooter } from '../../../../components/ui/page-container';
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import Box from '../../../../components/ui/box/box';
|
|
import {
|
|
AlignItems,
|
|
BLOCK_SIZES,
|
|
BorderStyle,
|
|
FLEX_DIRECTION,
|
|
FONT_WEIGHT,
|
|
JustifyContent,
|
|
TextVariant,
|
|
BackgroundColor,
|
|
IconColor,
|
|
TextAlign,
|
|
FontWeight,
|
|
} from '../../../../helpers/constants/design-system';
|
|
import {
|
|
AvatarIcon,
|
|
IconName,
|
|
IconSize,
|
|
Text,
|
|
ValidTag,
|
|
} from '../../../../components/component-library';
|
|
import PulseLoader from '../../../../components/ui/pulse-loader/pulse-loader';
|
|
import InstallError from '../../../../components/app/snaps/install-error/install-error';
|
|
import SnapAuthorship from '../../../../components/app/snaps/snap-authorship';
|
|
import { getSnapName } from '../../../../helpers/utils/util';
|
|
|
|
export default function SnapResult({
|
|
request,
|
|
requestState,
|
|
approveSnapResult,
|
|
targetSubjectMetadata,
|
|
}) {
|
|
const t = useI18nContext();
|
|
|
|
const onSubmit = useCallback(
|
|
() => approveSnapResult(request.metadata.id),
|
|
[request, approveSnapResult],
|
|
);
|
|
|
|
const hasError = !requestState.loading && requestState.error;
|
|
const isLoading = requestState.loading;
|
|
const snapName = getSnapName(targetSubjectMetadata.origin);
|
|
|
|
function getSuccessScreen(requestType, snapNameToRender) {
|
|
let successScreenTitle;
|
|
switch (requestType) {
|
|
case 'wallet_installSnap':
|
|
successScreenTitle = t('snapInstallSuccess');
|
|
break;
|
|
case 'wallet_updateSnap':
|
|
successScreenTitle = t('snapUpdateSuccess');
|
|
break;
|
|
default:
|
|
successScreenTitle = t('snapResultSuccess');
|
|
}
|
|
|
|
return (
|
|
<Box
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
alignItems={AlignItems.center}
|
|
justifyContent={JustifyContent.center}
|
|
height={BLOCK_SIZES.FULL}
|
|
paddingTop={2}
|
|
paddingBottom={2}
|
|
>
|
|
<AvatarIcon
|
|
className="snap-result__header__icon"
|
|
iconName={IconName.Confirmation}
|
|
size={IconSize.Xl}
|
|
iconProps={{
|
|
size: IconSize.Xl,
|
|
}}
|
|
color={IconColor.successDefault}
|
|
backgroundColor={BackgroundColor.successMuted}
|
|
/>
|
|
<Text
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
variant={TextVariant.headingLg}
|
|
paddingBottom={2}
|
|
marginTop={4}
|
|
>
|
|
{successScreenTitle}
|
|
</Text>
|
|
<Text textAlign={TextAlign.Center}>
|
|
{t('snapResultSuccessDescription', [
|
|
<Text as={ValidTag.Span} key="1" fontWeight={FontWeight.Medium}>
|
|
{snapNameToRender}
|
|
</Text>,
|
|
])}
|
|
</Text>
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
function getFailedScreen(requestType, snapNameToRender) {
|
|
let failedScreenTitle;
|
|
let failedScreenDescription;
|
|
|
|
switch (requestType) {
|
|
case 'wallet_installSnap':
|
|
failedScreenTitle = t('snapInstallationErrorTitle');
|
|
failedScreenDescription = t('snapInstallationErrorDescription', [
|
|
<Text as={ValidTag.Span} key="1" fontWeight={FontWeight.Medium}>
|
|
{snapNameToRender}
|
|
</Text>,
|
|
]);
|
|
break;
|
|
case 'wallet_updateSnap':
|
|
failedScreenTitle = t('snapUpdateErrorTitle');
|
|
failedScreenDescription = t('snapUpdateErrorDescription', [
|
|
<Text as={ValidTag.Span} key="1" fontWeight={FontWeight.Medium}>
|
|
{snapNameToRender}
|
|
</Text>,
|
|
]);
|
|
break;
|
|
default:
|
|
failedScreenTitle = t('snapResultError');
|
|
}
|
|
|
|
return (
|
|
<InstallError
|
|
error={requestState.error}
|
|
title={failedScreenTitle}
|
|
description={failedScreenDescription}
|
|
iconName={IconName.Warning}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Box
|
|
className="page-container snap-result"
|
|
justifyContent={JustifyContent.spaceBetween}
|
|
height={BLOCK_SIZES.FULL}
|
|
borderStyle={BorderStyle.none}
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
>
|
|
<Box
|
|
className="snap-result__header"
|
|
paddingLeft={4}
|
|
paddingRight={4}
|
|
alignItems={AlignItems.center}
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
>
|
|
<SnapAuthorship snapId={targetSubjectMetadata.origin} />
|
|
{isLoading && (
|
|
<Box
|
|
className="snap-result__header__loader-container"
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
alignItems={AlignItems.center}
|
|
justifyContent={JustifyContent.center}
|
|
>
|
|
<PulseLoader />
|
|
</Box>
|
|
)}
|
|
{!isLoading &&
|
|
!hasError &&
|
|
getSuccessScreen(requestState.type, snapName)}
|
|
{hasError && getFailedScreen(requestState.type, snapName)}
|
|
</Box>
|
|
<Box
|
|
className="snap-result__footer"
|
|
alignItems={AlignItems.center}
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
>
|
|
<PageContainerFooter
|
|
hideCancel
|
|
disabled={isLoading}
|
|
onSubmit={onSubmit}
|
|
submitText={t('ok').toUpperCase()}
|
|
/>
|
|
</Box>
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
SnapResult.propTypes = {
|
|
request: PropTypes.object.isRequired,
|
|
requestState: PropTypes.object.isRequired,
|
|
approveSnapResult: PropTypes.func.isRequired,
|
|
targetSubjectMetadata: PropTypes.shape({
|
|
iconUrl: PropTypes.string,
|
|
name: PropTypes.string,
|
|
origin: PropTypes.string.isRequired,
|
|
sourceCode: PropTypes.string,
|
|
version: PropTypes.string,
|
|
}).isRequired,
|
|
};
|