1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/components/app/transaction-icon/transaction-icon.js
vthomas13 4dcde1e216
Multichain Activity Screen (#19557)
* layout wip

* Icon changes, add badgewrapped icons to smart tx

* grouping by date wip

* typo fix

* group txs by date, button styling

* removing queue/history division, adding datestamp for pending tx, minor styling changes

* adding tests, updating snap

* font size fix

* e2e fixes

* Remove unnecessary tabIndex and keypress handler

* Fix typo for fontWeight

* Fix nesting warning by removing unnecessary Text

* Fix tests

* Fix import and exports

* Remove unused verbiage

* Update E2E selectors

* More E2E

* More E2Es

* More test fixes

* awaiting find instead of click

* adding regularDelayMs to flaky test

* removing delay

* increasing delay outside of wait

* adding back first-child to selector

* test fixes

* using datatestid for primary currency

* sorting date txgroups

* wip alignment for big numbers

* alignment issues fix

* lintfix

* adding tabindex, cursor pointer, updating snap

* unit test fix

* storybook additions

* snaphot update

* update snap

---------

Co-authored-by: David Walsh <davidwalsh83@gmail.com>
2023-07-17 13:48:15 -04:00

101 lines
3.2 KiB
JavaScript

import React from 'react';
import { useDispatch } from 'react-redux';
import PropTypes from 'prop-types';
import {
TransactionGroupCategory,
TransactionGroupStatus,
TransactionStatus,
} from '../../../../shared/constants/transaction';
import { captureSingleException } from '../../../store/actions';
import { AvatarIcon, IconName } from '../../component-library';
import {
BackgroundColor,
IconColor,
Size,
} from '../../../helpers/constants/design-system';
const ICON_MAP = {
[TransactionGroupCategory.approval]: IconName.Check,
[TransactionGroupCategory.interaction]: IconName.ProgrammingArrows,
[TransactionGroupCategory.receive]: IconName.Received,
[TransactionGroupCategory.send]: IconName.Arrow2UpRight,
[TransactionGroupCategory.signatureRequest]: IconName.SecurityTick,
[TransactionGroupCategory.swap]: IconName.SwapHorizontal,
};
const COLOR_MAP = {
[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,
};
export default function TransactionIcon({ status, category }) {
const dispatch = useDispatch();
const color = COLOR_MAP[status] || IconColor.primaryDefault;
const backgroundColor =
BACKGROUND_COLOR_MAP[status] || BackgroundColor.primaryMuted;
const Icon = ICON_MAP[category];
if (!Icon) {
dispatch(
captureSingleException(
`The category prop passed to TransactionIcon is not supported. The prop is: ${category}`,
),
);
return (
<AvatarIcon
backgroundColor={BackgroundColor.backgroundAlternative}
size={Size.MD}
/>
);
}
return (
<AvatarIcon
backgroundColor={backgroundColor}
iconName={Icon}
size={Size.MD}
color={color}
/>
);
}
TransactionIcon.propTypes = {
status: PropTypes.oneOf([
TransactionGroupStatus.cancelled,
TransactionGroupStatus.pending,
TransactionStatus.approved,
TransactionStatus.confirmed,
TransactionStatus.dropped,
TransactionStatus.failed,
TransactionStatus.rejected,
TransactionStatus.submitted,
TransactionStatus.unapproved,
]).isRequired,
category: PropTypes.oneOf([
TransactionGroupCategory.approval,
TransactionGroupCategory.interaction,
TransactionGroupCategory.receive,
TransactionGroupCategory.send,
TransactionGroupCategory.signatureRequest,
TransactionGroupCategory.swap,
]).isRequired,
};