2022-09-20 19:00:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import Preloader from '../../../ui/icon/preloader/preloader-icon.component';
|
|
|
|
import Typography from '../../../ui/typography/typography';
|
|
|
|
import {
|
2023-02-02 21:15:26 +01:00
|
|
|
AlignItems,
|
2022-09-20 19:00:07 +02:00
|
|
|
FLEX_DIRECTION,
|
2023-02-02 21:15:26 +01:00
|
|
|
JustifyContent,
|
2022-09-20 19:00:07 +02:00
|
|
|
TEXT_ALIGN,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
|
|
|
TypographyVariant,
|
2022-09-20 19:00:07 +02:00
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import { useTransactionInsightSnap } from '../../../../hooks/flask/useTransactionInsightSnap';
|
|
|
|
import Box from '../../../ui/box/box';
|
2022-11-09 14:20:57 +01:00
|
|
|
import ActionableMessage from '../../../ui/actionable-message/actionable-message';
|
2022-12-20 11:44:49 +01:00
|
|
|
import { SnapUIRenderer } from '../../flask/snap-ui-renderer';
|
2022-09-20 19:00:07 +02:00
|
|
|
|
2022-12-01 14:38:56 +01:00
|
|
|
export const SnapInsight = ({ transaction, origin, chainId, selectedSnap }) => {
|
2022-09-20 19:00:07 +02:00
|
|
|
const t = useI18nContext();
|
2022-11-09 14:20:57 +01:00
|
|
|
const {
|
|
|
|
data: response,
|
|
|
|
error,
|
|
|
|
loading,
|
|
|
|
} = useTransactionInsightSnap({
|
2022-09-20 19:00:07 +02:00
|
|
|
transaction,
|
|
|
|
chainId,
|
2022-12-01 14:38:56 +01:00
|
|
|
origin,
|
2022-09-20 19:00:07 +02:00
|
|
|
snapId: selectedSnap.id,
|
|
|
|
});
|
|
|
|
|
2022-12-20 11:44:49 +01:00
|
|
|
const data = response?.content;
|
2022-09-20 19:00:07 +02:00
|
|
|
|
2022-11-09 14:20:57 +01:00
|
|
|
const hasNoData =
|
|
|
|
!error && (loading || !data || (data && Object.keys(data).length === 0));
|
2022-09-20 19:00:07 +02:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
height="full"
|
|
|
|
marginTop={hasNoData && 12}
|
|
|
|
marginBottom={hasNoData && 12}
|
2023-02-02 21:15:26 +01:00
|
|
|
alignItems={hasNoData && AlignItems.center}
|
|
|
|
justifyContent={hasNoData && JustifyContent.center}
|
2022-09-20 19:00:07 +02:00
|
|
|
textAlign={hasNoData && TEXT_ALIGN.CENTER}
|
|
|
|
className="snap-insight"
|
|
|
|
>
|
2022-11-09 14:20:57 +01:00
|
|
|
{!loading && !error && (
|
2022-09-20 19:00:07 +02:00
|
|
|
<Box
|
|
|
|
height="full"
|
|
|
|
flexDirection={FLEX_DIRECTION.COLUMN}
|
|
|
|
className="snap-insight__container"
|
|
|
|
>
|
2022-11-09 14:20:57 +01:00
|
|
|
{data && Object.keys(data).length > 0 ? (
|
2022-12-20 11:44:49 +01:00
|
|
|
<SnapUIRenderer snapId={selectedSnap.id} data={data} />
|
2022-09-20 19:00:07 +02:00
|
|
|
) : (
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography
|
|
|
|
color={TextColor.textAlternative}
|
|
|
|
variant={TypographyVariant.H6}
|
|
|
|
>
|
2022-09-20 19:00:07 +02:00
|
|
|
{t('snapsNoInsight')}
|
|
|
|
</Typography>
|
|
|
|
)}
|
|
|
|
</Box>
|
2022-11-09 14:20:57 +01:00
|
|
|
)}
|
|
|
|
|
|
|
|
{!loading && error && (
|
|
|
|
<Box
|
|
|
|
paddingTop={0}
|
|
|
|
paddingRight={6}
|
|
|
|
paddingBottom={3}
|
|
|
|
paddingLeft={6}
|
|
|
|
className="snap-insight__container__error"
|
|
|
|
>
|
|
|
|
<ActionableMessage
|
|
|
|
message={t('snapsInsightError', [
|
|
|
|
selectedSnap.manifest.proposedName,
|
|
|
|
error.message,
|
|
|
|
])}
|
|
|
|
type="danger"
|
|
|
|
useIcon
|
|
|
|
iconFillColor="var(--color-error-default)"
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{loading && (
|
2022-09-20 19:00:07 +02:00
|
|
|
<>
|
|
|
|
<Preloader size={40} />
|
|
|
|
<Typography
|
|
|
|
marginTop={3}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
|
|
|
variant={TypographyVariant.H6}
|
2022-09-20 19:00:07 +02:00
|
|
|
>
|
|
|
|
{t('snapsInsightLoading')}
|
|
|
|
</Typography>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
SnapInsight.propTypes = {
|
|
|
|
/*
|
|
|
|
* The transaction data object
|
|
|
|
*/
|
|
|
|
transaction: PropTypes.object,
|
|
|
|
/*
|
|
|
|
* CAIP2 Chain ID
|
|
|
|
*/
|
|
|
|
chainId: PropTypes.string,
|
2022-12-01 14:38:56 +01:00
|
|
|
/*
|
|
|
|
* The origin of the transaction
|
|
|
|
*/
|
|
|
|
origin: PropTypes.string,
|
2022-09-20 19:00:07 +02:00
|
|
|
/*
|
|
|
|
* The insight snap selected
|
|
|
|
*/
|
|
|
|
selectedSnap: PropTypes.object,
|
|
|
|
};
|