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 (
{successScreenTitle}
{t('snapResultSuccessDescription', [
{snapNameToRender}
,
])}
);
}
function getFailedScreen(requestType, snapNameToRender) {
let failedScreenTitle;
let failedScreenDescription;
switch (requestType) {
case 'wallet_installSnap':
failedScreenTitle = t('snapInstallationErrorTitle');
failedScreenDescription = t('snapInstallationErrorDescription', [
{snapNameToRender}
,
]);
break;
case 'wallet_updateSnap':
failedScreenTitle = t('snapUpdateErrorTitle');
failedScreenDescription = t('snapUpdateErrorDescription', [
{snapNameToRender}
,
]);
break;
default:
failedScreenTitle = t('snapResultError');
}
return (
);
}
return (
{isLoading && (
)}
{!isLoading &&
!hasError &&
getSuccessScreen(requestState.type, snapName)}
{hasError && getFailedScreen(requestState.type, snapName)}
);
}
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,
};