2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-05-17 16:31:00 +02:00
|
|
|
import { captureException } from '@sentry/browser';
|
2021-02-04 19:15:23 +01:00
|
|
|
import Approve from '../../ui/icon/approve-icon.component';
|
|
|
|
import Interaction from '../../ui/icon/interaction-icon.component';
|
|
|
|
import Receive from '../../ui/icon/receive-icon.component';
|
|
|
|
import Send from '../../ui/icon/send-icon.component';
|
|
|
|
import Sign from '../../ui/icon/sign-icon.component';
|
|
|
|
import Swap from '../../ui/icon/swap-icon-for-list.component';
|
2020-06-10 22:38:34 +02:00
|
|
|
import {
|
2020-11-03 23:57:51 +01:00
|
|
|
TRANSACTION_GROUP_CATEGORIES,
|
|
|
|
TRANSACTION_GROUP_STATUSES,
|
|
|
|
TRANSACTION_STATUSES,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../../shared/constants/transaction';
|
2020-06-10 22:38:34 +02:00
|
|
|
|
|
|
|
const ICON_MAP = {
|
2020-11-03 23:57:51 +01:00
|
|
|
[TRANSACTION_GROUP_CATEGORIES.APPROVAL]: Approve,
|
|
|
|
[TRANSACTION_GROUP_CATEGORIES.INTERACTION]: Interaction,
|
|
|
|
[TRANSACTION_GROUP_CATEGORIES.SEND]: Send,
|
|
|
|
[TRANSACTION_GROUP_CATEGORIES.SIGNATURE_REQUEST]: Sign,
|
|
|
|
[TRANSACTION_GROUP_CATEGORIES.RECEIVE]: Receive,
|
|
|
|
[TRANSACTION_GROUP_CATEGORIES.SWAP]: Swap,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-06-10 22:38:34 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const FAIL_COLOR = '#D73A49';
|
|
|
|
const PENDING_COLOR = '#6A737D';
|
|
|
|
const OK_COLOR = '#2F80ED';
|
2020-06-10 22:38:34 +02:00
|
|
|
|
|
|
|
const COLOR_MAP = {
|
2020-11-03 23:57:51 +01:00
|
|
|
[TRANSACTION_GROUP_STATUSES.PENDING]: PENDING_COLOR,
|
|
|
|
[TRANSACTION_STATUSES.UNAPPROVED]: PENDING_COLOR,
|
|
|
|
[TRANSACTION_STATUSES.APPROVED]: PENDING_COLOR,
|
|
|
|
[TRANSACTION_STATUSES.FAILED]: FAIL_COLOR,
|
|
|
|
[TRANSACTION_STATUSES.REJECTED]: FAIL_COLOR,
|
|
|
|
[TRANSACTION_GROUP_STATUSES.CANCELLED]: FAIL_COLOR,
|
|
|
|
[TRANSACTION_STATUSES.DROPPED]: FAIL_COLOR,
|
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-02-04 19:15:23 +01:00
|
|
|
const color = COLOR_MAP[status] || OK_COLOR;
|
2020-06-10 22:38:34 +02:00
|
|
|
|
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) {
|
|
|
|
captureException(
|
|
|
|
Error(
|
|
|
|
`The category prop passed to TransactionIcon is not supported. The prop is: ${category}`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return <div className="transaction-icon__grey-circle" />;
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return <Icon color={color} size={28} />;
|
2020-06-10 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TransactionIcon.propTypes = {
|
2021-05-17 16:31:00 +02:00
|
|
|
status: PropTypes.oneOf([
|
|
|
|
TRANSACTION_GROUP_CATEGORIES.APPROVAL,
|
|
|
|
TRANSACTION_GROUP_CATEGORIES.INTERACTION,
|
|
|
|
TRANSACTION_GROUP_CATEGORIES.SEND,
|
|
|
|
TRANSACTION_GROUP_CATEGORIES.SIGNATURE_REQUEST,
|
|
|
|
TRANSACTION_GROUP_CATEGORIES.RECEIVE,
|
|
|
|
TRANSACTION_GROUP_CATEGORIES.SWAP,
|
|
|
|
]).isRequired,
|
|
|
|
category: PropTypes.oneOf([
|
|
|
|
TRANSACTION_GROUP_STATUSES.PENDING,
|
|
|
|
TRANSACTION_STATUSES.UNAPPROVED,
|
|
|
|
TRANSACTION_STATUSES.APPROVED,
|
|
|
|
TRANSACTION_STATUSES.FAILED,
|
|
|
|
TRANSACTION_STATUSES.REJECTED,
|
|
|
|
TRANSACTION_GROUP_STATUSES.CANCELLED,
|
|
|
|
TRANSACTION_STATUSES.DROPPED,
|
|
|
|
]).isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|