Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): LW-9037 add new styling for outgoing txs #899

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,11 @@
line-height: size_unit(3);
}
}

.negativeBalance {
color: var(--data-orange);
}

.positiveBalance {
color: var(--data-green);
}
19 changes: 17 additions & 2 deletions packages/core/src/ui/components/Activity/AssetActivityItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { useMemo, useRef, useEffect, useCallback } from 'react';
import debounce from 'lodash/debounce';
import { Image, Tooltip } from 'antd';
import cn from 'classnames';
import Icon from '@ant-design/icons';
import { getTextWidth } from '@lace/common';
import { ReactComponent as PendingIcon } from '../../assets/icons/pending.component.svg';
Expand Down Expand Up @@ -96,6 +97,8 @@ const translationTypes = {
self: 'package.core.assetActivityItem.entry.name.self'
};

const negativeBalanceStyling: Set<ActivityType> = new Set(['outgoing', 'delegationRegistration', 'self', 'delegation']);

// TODO: Handle pluralization and i18n of assetsNumber when we will have more than Ada.
export const AssetActivityItem = ({
amount,
Expand Down Expand Up @@ -176,6 +179,8 @@ export const AssetActivityItem = ({
assetAmountContent
);

const isNegativeBalance = negativeBalanceStyling.has(type);

return (
<div data-testid="asset-activity-item" onClick={onClick} className={styles.assetActivityItem}>
<div className={styles.leftSide}>
Expand All @@ -196,9 +201,19 @@ export const AssetActivityItem = ({
</div>
</div>
<div data-testid="asset-amount" className={styles.rightSide}>
<h6 data-testid="total-amount" className={styles.title} ref={ref}>
<h6
data-testid="total-amount"
className={cn(styles.title, {
[styles.negativeBalance]: isNegativeBalance,
[styles.positiveBalance]: !isNegativeBalance
})}
ref={ref}
>
<span>
{assetsText.text}
<span data-testid="balance">
{isNegativeBalance ? '-' : ''}
{assetsText.text}
</span>
{assetsText.suffix && (
<Tooltip
overlayClassName={styles.tooltip}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import { render, within, fireEvent, queryByTestId } from '@testing-library/react';
import '@testing-library/jest-dom';
import { AssetActivityItem, AssetActivityItemProps, ActivityStatus } from '../AssetActivityItem';
import { ActivityType } from '../../ActivityDetail';

const assetsAmountTestId = 'asset-amount';

Expand All @@ -21,8 +22,8 @@ describe('Testing AssetActivityItem component', () => {

const assetActivityItemId = 'asset-activity-item';

test('should render an asset activity item', async () => {
const { findByTestId } = render(<AssetActivityItem {...props} />);
test('should render an asset activity item with type incoming', async () => {
const { findByTestId } = render(<AssetActivityItem {...props} type="incoming" />);
const activityItem = await findByTestId(assetActivityItemId);

const activityIcon = await findByTestId('asset-icon');
Expand All @@ -43,6 +44,16 @@ describe('Testing AssetActivityItem component', () => {
expect(activityFiatAmountText).toBeVisible();
});

['outgoing', 'delegationRegistration', 'self', 'delegation'].forEach((type) => {
test(`should apply negative balance for: ${type} activity`, async () => {
const { findByTestId } = render(<AssetActivityItem {...props} type={type as ActivityType} />);

const totalAmount = await findByTestId('balance');

expect(totalAmount).toHaveTextContent(`-${props.amount}`);
});
});

test('should render an asset activity item with proper assets text when there is enough space to show assets info', async () => {
const elWidth = 100;
Object.defineProperties(window.HTMLElement.prototype, {
Expand All @@ -53,7 +64,7 @@ describe('Testing AssetActivityItem component', () => {
const { findByTestId } = render(<AssetActivityItem {...props} />);

const activityAmount = await findByTestId(assetsAmountTestId);
const tickerText = `${props.amount}, ${props.assets[0].val} ${props.assets[0].info.ticker}`;
const tickerText = `-${props.amount}, ${props.assets[0].val} ${props.assets[0].info.ticker}`;
const activityAssetTickerText = await within(activityAmount).findByText(tickerText);

expect(activityAssetTickerText).toBeVisible();
Expand Down
Loading