2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2021-07-23 01:13:40 +02:00
|
|
|
import { useDispatch } from 'react-redux';
|
2021-02-04 19:15:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2020-06-10 22:38:34 +02:00
|
|
|
import {
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionGroupCategory,
|
|
|
|
TransactionGroupStatus,
|
|
|
|
TransactionStatus,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../../shared/constants/transaction';
|
2021-07-23 01:13:40 +02:00
|
|
|
import { captureSingleException } from '../../../store/actions';
|
2023-07-17 19:48:15 +02:00
|
|
|
import { AvatarIcon, IconName } from '../../component-library';
|
|
|
|
import {
|
|
|
|
BackgroundColor,
|
|
|
|
IconColor,
|
|
|
|
Size,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2020-06-10 22:38:34 +02:00
|
|
|
|
|
|
|
const ICON_MAP = {
|
2023-07-17 19:48:15 +02:00
|
|
|
[TransactionGroupCategory.approval]: IconName.Check,
|
|
|
|
[TransactionGroupCategory.interaction]: IconName.ProgrammingArrows,
|
|
|
|
[TransactionGroupCategory.receive]: IconName.Received,
|
|
|
|
[TransactionGroupCategory.send]: IconName.Arrow2UpRight,
|
|
|
|
[TransactionGroupCategory.signatureRequest]: IconName.SecurityTick,
|
|
|
|
[TransactionGroupCategory.swap]: IconName.SwapHorizontal,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-06-10 22:38:34 +02:00
|
|
|
|
|
|
|
const COLOR_MAP = {
|
2023-07-17 19:48:15 +02:00
|
|
|
[TransactionGroupStatus.pending]: IconColor.primaryDefault,
|
|
|
|
[TransactionGroupStatus.cancelled]: IconColor.errorDefault,
|
|
|
|
[TransactionStatus.approved]: IconColor.primaryDefault,
|
|
|
|
[TransactionStatus.dropped]: IconColor.errorDefault,
|
|
|
|
[TransactionStatus.failed]: IconColor.errorDefault,
|
|
|
|
[TransactionStatus.rejected]: IconColor.errorDefault,
|
|
|
|
[TransactionStatus.submitted]: IconColor.primaryDefault,
|
|
|
|
[TransactionStatus.unapproved]: IconColor.primaryDefault,
|
|
|
|
};
|
|
|
|
|
|
|
|
const BACKGROUND_COLOR_MAP = {
|
|
|
|
[TransactionGroupStatus.pending]: BackgroundColor.primaryMuted,
|
|
|
|
[TransactionGroupStatus.cancelled]: BackgroundColor.errorMuted,
|
|
|
|
[TransactionStatus.approved]: BackgroundColor.primaryMuted,
|
|
|
|
[TransactionStatus.dropped]: BackgroundColor.errorMuted,
|
|
|
|
[TransactionStatus.failed]: BackgroundColor.errorMuted,
|
|
|
|
[TransactionStatus.rejected]: BackgroundColor.errorMuted,
|
|
|
|
[TransactionStatus.submitted]: BackgroundColor.primaryMuted,
|
|
|
|
[TransactionStatus.unapproved]: BackgroundColor.primaryMuted,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-06-10 22:38:34 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function TransactionIcon({ status, category }) {
|
2021-07-23 01:13:40 +02:00
|
|
|
const dispatch = useDispatch();
|
2020-06-10 22:38:34 +02:00
|
|
|
|
2023-07-17 19:48:15 +02:00
|
|
|
const color = COLOR_MAP[status] || IconColor.primaryDefault;
|
|
|
|
const backgroundColor =
|
|
|
|
BACKGROUND_COLOR_MAP[status] || BackgroundColor.primaryMuted;
|
2021-02-04 19:15:23 +01:00
|
|
|
const Icon = ICON_MAP[category];
|
2020-06-10 22:38:34 +02:00
|
|
|
|
2021-05-17 16:31:00 +02:00
|
|
|
if (!Icon) {
|
2021-07-23 01:13:40 +02:00
|
|
|
dispatch(
|
|
|
|
captureSingleException(
|
2021-05-17 16:31:00 +02:00
|
|
|
`The category prop passed to TransactionIcon is not supported. The prop is: ${category}`,
|
|
|
|
),
|
|
|
|
);
|
2023-07-17 19:48:15 +02:00
|
|
|
return (
|
|
|
|
<AvatarIcon
|
|
|
|
backgroundColor={BackgroundColor.backgroundAlternative}
|
|
|
|
size={Size.MD}
|
|
|
|
/>
|
|
|
|
);
|
2021-05-17 16:31:00 +02:00
|
|
|
}
|
|
|
|
|
2023-07-17 19:48:15 +02:00
|
|
|
return (
|
|
|
|
<AvatarIcon
|
|
|
|
backgroundColor={backgroundColor}
|
|
|
|
iconName={Icon}
|
|
|
|
size={Size.MD}
|
|
|
|
color={color}
|
|
|
|
/>
|
|
|
|
);
|
2020-06-10 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TransactionIcon.propTypes = {
|
2021-05-17 16:31:00 +02:00
|
|
|
status: PropTypes.oneOf([
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionGroupStatus.cancelled,
|
|
|
|
TransactionGroupStatus.pending,
|
|
|
|
TransactionStatus.approved,
|
|
|
|
TransactionStatus.confirmed,
|
|
|
|
TransactionStatus.dropped,
|
|
|
|
TransactionStatus.failed,
|
|
|
|
TransactionStatus.rejected,
|
|
|
|
TransactionStatus.submitted,
|
|
|
|
TransactionStatus.unapproved,
|
2021-05-17 16:31:00 +02:00
|
|
|
]).isRequired,
|
2021-06-01 02:19:23 +02:00
|
|
|
category: PropTypes.oneOf([
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionGroupCategory.approval,
|
|
|
|
TransactionGroupCategory.interaction,
|
|
|
|
TransactionGroupCategory.receive,
|
|
|
|
TransactionGroupCategory.send,
|
|
|
|
TransactionGroupCategory.signatureRequest,
|
|
|
|
TransactionGroupCategory.swap,
|
2021-06-01 02:19:23 +02:00
|
|
|
]).isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|