From 0dcd03b9fc058faae71d97f7c0baef2ee2c273ae Mon Sep 17 00:00:00 2001 From: Dominik Guzei Date: Tue, 5 Mar 2024 12:39:40 +0100 Subject: [PATCH] feat(core): show positive dapp tx token quantity in green LW-9887 --- .../ActivityDetail/TransactionFee.tsx | 5 ++++- .../DappAddressSections.module.scss | 6 +++++- .../DappAddressSections.tsx | 10 +++++----- .../DappTransaction.module.scss | 4 ++++ .../DappTransaction/DappTransaction.tsx | 6 ++++-- .../dapp-transaction-assets.component.tsx | 18 +++++++++++++----- .../dapp-transaction-summary.component.tsx | 18 +++++++++++------- .../dapp-transaction-summary.css.ts | 9 ++++++++- .../dapp-transaction-summary.stories.tsx | 2 +- .../transaction-summary-amount.component.tsx | 19 +++++++++++++------ .../transaction-summary.css.ts | 13 ++++++++++++- .../transaction-summary.stories.tsx | 11 ++++++++--- packages/ui/src/design-tokens/colors.data.ts | 3 +++ .../src/design-tokens/theme/dark-theme.css.ts | 5 +++++ .../design-tokens/theme/light-theme.css.ts | 5 +++++ 15 files changed, 101 insertions(+), 33 deletions(-) diff --git a/packages/core/src/ui/components/ActivityDetail/TransactionFee.tsx b/packages/core/src/ui/components/ActivityDetail/TransactionFee.tsx index adbaad515..13eb8b50f 100644 --- a/packages/core/src/ui/components/ActivityDetail/TransactionFee.tsx +++ b/packages/core/src/ui/components/ActivityDetail/TransactionFee.tsx @@ -11,6 +11,7 @@ export interface TransactionFeeProps { testId?: string; tooltipInfo?: string; displayFiat?: boolean; + highlightPositiveAmount?: boolean; } export const TransactionFee = ({ fee, @@ -20,7 +21,8 @@ export const TransactionFee = ({ className, testId, tooltipInfo, - displayFiat + displayFiat, + highlightPositiveAmount }: TransactionFeeProps): React.ReactElement => { const { t } = useTranslate(); @@ -33,6 +35,7 @@ export const TransactionFee = ({ data-testid={testId ?? 'fee'} className={className} displayFiat={displayFiat} + highlightPositiveAmount={highlightPositiveAmount} /> ); }; diff --git a/packages/core/src/ui/components/DappAddressSections/DappAddressSections.module.scss b/packages/core/src/ui/components/DappAddressSections/DappAddressSections.module.scss index df9dca452..f9c67c78b 100644 --- a/packages/core/src/ui/components/DappAddressSections/DappAddressSections.module.scss +++ b/packages/core/src/ui/components/DappAddressSections/DappAddressSections.module.scss @@ -22,4 +22,8 @@ display: flex; justify-content: space-between; align-items: end; -} \ No newline at end of file +} + +.positiveAmount { + color: var(--data-green, #2CB67D) !important; +} diff --git a/packages/core/src/ui/components/DappAddressSections/DappAddressSections.tsx b/packages/core/src/ui/components/DappAddressSections/DappAddressSections.tsx index 0fff9d44b..1d291f6f9 100644 --- a/packages/core/src/ui/components/DappAddressSections/DappAddressSections.tsx +++ b/packages/core/src/ui/components/DappAddressSections/DappAddressSections.tsx @@ -177,15 +177,15 @@ export const DappAddressSections = ({ {t('package.core.dappTransaction.tokens')} - - +{getTokenQuantity(addressData.tokens, addressData.coins)} {itemsCountCopy} + <Title level={5} className={styles.positiveAmount}> + {getTokenQuantity(addressData.tokens, addressData.coins)} {itemsCountCopy} {addressData.coins.map((coin) => ( ))} {displayGroupedTokens(addressData.tokens)} @@ -198,8 +198,8 @@ export const DappAddressSections = ({ {t('package.core.dappTransaction.nfts')} - - +{addressData.nfts.length} {itemsCountCopy} + <Title level={5} className={styles.positiveAmount}> + {addressData.nfts.length} {itemsCountCopy} {displayGroupedNFTs(addressData.nfts)} diff --git a/packages/core/src/ui/components/DappTransaction/DappTransaction.module.scss b/packages/core/src/ui/components/DappTransaction/DappTransaction.module.scss index 4533ba6c5..d303636c9 100644 --- a/packages/core/src/ui/components/DappTransaction/DappTransaction.module.scss +++ b/packages/core/src/ui/components/DappTransaction/DappTransaction.module.scss @@ -22,3 +22,7 @@ .transactionAssetsContainer { margin-bottom: size_unit(2.5); } + +.positiveAmount { + color: var(--data-green); +} diff --git a/packages/core/src/ui/components/DappTransaction/DappTransaction.tsx b/packages/core/src/ui/components/DappTransaction/DappTransaction.tsx index 7db06d50d..2724d7b37 100644 --- a/packages/core/src/ui/components/DappTransaction/DappTransaction.tsx +++ b/packages/core/src/ui/components/DappTransaction/DappTransaction.tsx @@ -13,6 +13,7 @@ import { TransactionFee, Collateral } from '@ui/components/ActivityDetail'; import { TransactionType, DappTransactionSummary, TransactionAssets } from '@lace/ui'; import { DappAddressSections } from '../DappAddressSections/DappAddressSections'; +import cn from 'classnames'; const amountTransformer = (fiat: { price: number; code: string }) => (ada: string) => `${Wallet.util.convertAdaToFiat({ ada, fiat: fiat.price })} ${fiat.code}`; @@ -165,15 +166,16 @@ export const DappTransaction = ({ {returnedDeposit !== BigInt(0) && ( `${Wallet.util.lovelacesToAdaString(returnedDeposit.toString())} ${fiatCurrencyCode}` } + highlightPositiveAmount /> )} diff --git a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-assets.component.tsx b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-assets.component.tsx index 0b39190e9..aa2f7e464 100644 --- a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-assets.component.tsx +++ b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-assets.component.tsx @@ -1,5 +1,7 @@ import React from 'react'; +import classNames from 'classnames'; + import DarkFallBack from '../../assets/images/dark-mode-fallback.png'; import LightFallBack from '../../assets/images/light-mode-fallback.png'; import { ThemeColorScheme } from '../../design-tokens'; @@ -9,13 +11,13 @@ import { Grid, Cell } from '../grid'; import { UserProfile } from '../profile-picture'; import * as Typography from '../typography'; -import * as cx from './dapp-transaction-summary.css'; +import * as styles from './dapp-transaction-summary.css'; import type { OmitClassName } from '../../types'; type Props = OmitClassName<'div'> & { imageSrc: string | undefined; - balance?: string; + balance: string; tokenName?: string; coins?: string; testId?: string; @@ -41,6 +43,7 @@ export const TransactionAssets = ({ ...props }: Readonly): JSX.Element => { const { theme } = useThemeVariant(); + const isNegativeBalance = balance.includes('-'); const setThemeFallbackImagine = theme === ThemeColorScheme.Dark ? DarkFallBack : LightFallBack; @@ -58,7 +61,7 @@ export const TransactionAssets = ({ }; return ( -
+
- + {balance} {tokenName} diff --git a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.component.tsx b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.component.tsx index 8a002d030..9685fdafa 100644 --- a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.component.tsx +++ b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.component.tsx @@ -2,12 +2,13 @@ import React from 'react'; import { ReactComponent as AdaComponent } from '@lace/icons/dist/AdaComponent'; +import classNames from 'classnames'; import { Flex } from '../flex'; import { Grid, Cell } from '../grid'; import * as Typography from '../typography'; -import * as cx from './dapp-transaction-summary.css'; +import * as styles from './dapp-transaction-summary.css'; import type { OmitClassName } from '../../types'; @@ -23,24 +24,27 @@ export const TransactionSummary = ({ cardanoSymbol, ...props }: Readonly): JSX.Element => ( -
+
{title !== undefined && ( - + {title} )} -
+
- + {transactionAmount} {cardanoSymbol} diff --git a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.css.ts b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.css.ts index c1d52afd2..70e09012c 100644 --- a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.css.ts +++ b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.css.ts @@ -5,10 +5,17 @@ export const transactionTypeContainer = style({ }); export const label = sx({ - color: '$dapp_transaction_summary_label', fontWeight: '$semibold', }); +export const positiveBalance = sx({ + color: '$dapp_transaction_summary_positive_balance_label_color', +}); + +export const negativeBalance = sx({ + color: '$dapp_transaction_summary_label', +}); + export const txSummaryTitle = style([ sx({ color: '$transaction_summary_label_color', diff --git a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.stories.tsx b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.stories.tsx index a2ff67205..d5a01c37a 100644 --- a/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.stories.tsx +++ b/packages/ui/src/design-system/dapp-transaction-summary/dapp-transaction-summary.stories.tsx @@ -48,7 +48,7 @@ const items = [ }, { imageSrc: token2, - balance: '-1000.00', + balance: '1000.00', tokenName: 'Lapisluzzz', recipient: '', }, diff --git a/packages/ui/src/design-system/transaction-summary/transaction-summary-amount.component.tsx b/packages/ui/src/design-system/transaction-summary/transaction-summary-amount.component.tsx index 1d763a42d..0671b0dac 100644 --- a/packages/ui/src/design-system/transaction-summary/transaction-summary-amount.component.tsx +++ b/packages/ui/src/design-system/transaction-summary/transaction-summary-amount.component.tsx @@ -7,6 +7,7 @@ import { Flex } from '../flex'; import { Grid, Cell } from '../grid'; import { Tooltip } from '../tooltip'; import * as Typography from '../typography'; +import classNames from 'classnames'; import * as cx from './transaction-summary.css'; @@ -20,6 +21,7 @@ type Props = OmitClassName<'div'> & { 'data-testid'?: string; className?: string; displayFiat?: boolean; + highlightPositiveAmount?: boolean; }; const makeTestId = (namespace = '', path = ''): string | undefined => { @@ -33,10 +35,12 @@ export const Amount = ({ tooltip, className, displayFiat = true, + highlightPositiveAmount, ...props }: Readonly): JSX.Element => { const testId = props['data-testid']; - + const shouldHighlightPositiveAmount = + highlightPositiveAmount === true && !amount.includes('-'); return (
@@ -64,19 +68,22 @@ export const Amount = ({ - {amount} - + {displayFiat && ( - {fiatPrice} - + )} diff --git a/packages/ui/src/design-system/transaction-summary/transaction-summary.css.ts b/packages/ui/src/design-system/transaction-summary/transaction-summary.css.ts index 995421544..8c68a6f0f 100644 --- a/packages/ui/src/design-system/transaction-summary/transaction-summary.css.ts +++ b/packages/ui/src/design-system/transaction-summary/transaction-summary.css.ts @@ -7,7 +7,6 @@ export const label = sx({ export const text = style([ sx({ - color: '$transaction_summary_label_color', fontWeight: '$medium', }), { @@ -39,3 +38,15 @@ export const tooltipText = style([ display: 'flex', }), ]); + +export const normalAmount = style([ + sx({ + color: '$transaction_summary_amount_color', + }), +]); + +export const highlightedAmount = style([ + sx({ + color: '$transaction_summary_highlighted_amount_color', + }), +]); diff --git a/packages/ui/src/design-system/transaction-summary/transaction-summary.stories.tsx b/packages/ui/src/design-system/transaction-summary/transaction-summary.stories.tsx index 46b4c49d8..33f5e137b 100644 --- a/packages/ui/src/design-system/transaction-summary/transaction-summary.stories.tsx +++ b/packages/ui/src/design-system/transaction-summary/transaction-summary.stories.tsx @@ -55,9 +55,6 @@ const Example = (): JSX.Element => ( - - - ( data-testid="sample" /> + + + diff --git a/packages/ui/src/design-tokens/colors.data.ts b/packages/ui/src/design-tokens/colors.data.ts index 019be2de3..74121ec64 100644 --- a/packages/ui/src/design-tokens/colors.data.ts +++ b/packages/ui/src/design-tokens/colors.data.ts @@ -161,7 +161,10 @@ export const colors = { $summary_expander_trigger_label_color_pressed: '', $transaction_summary_label_color: '', + $transaction_summary_amount_color: '', + $transaction_summary_highlighted_amount_color: '', $transaction_summary_secondary_label_color: '', + $dapp_transaction_summary_positive_balance_label_color: '', $dapp_transaction_summary_type_label_color: '', $dapp_transaction_summary_label: '', diff --git a/packages/ui/src/design-tokens/theme/dark-theme.css.ts b/packages/ui/src/design-tokens/theme/dark-theme.css.ts index 02c674e61..b371d5fee 100644 --- a/packages/ui/src/design-tokens/theme/dark-theme.css.ts +++ b/packages/ui/src/design-tokens/theme/dark-theme.css.ts @@ -232,8 +232,13 @@ const colors: Colors = { darkColorScheme.$primary_mid_grey, $transaction_summary_label_color: darkColorScheme.$primary_white, + $transaction_summary_amount_color: darkColorScheme.$primary_white, + $transaction_summary_highlighted_amount_color: + darkColorScheme.$secondary_data_green, $transaction_summary_secondary_label_color: darkColorScheme.$primary_light_grey, + $dapp_transaction_summary_positive_balance_label_color: + darkColorScheme.$secondary_data_green, $dapp_transaction_summary_type_label_color: darkColorScheme.$primary_accent_purple, diff --git a/packages/ui/src/design-tokens/theme/light-theme.css.ts b/packages/ui/src/design-tokens/theme/light-theme.css.ts index f03d1ef6b..9c3786b97 100644 --- a/packages/ui/src/design-tokens/theme/light-theme.css.ts +++ b/packages/ui/src/design-tokens/theme/light-theme.css.ts @@ -252,8 +252,13 @@ const colors: Colors = { lightColorScheme.$primary_light_grey_plus, $transaction_summary_label_color: lightColorScheme.$primary_black, + $transaction_summary_amount_color: lightColorScheme.$primary_black, + $transaction_summary_highlighted_amount_color: + lightColorScheme.$secondary_data_green, $transaction_summary_secondary_label_color: lightColorScheme.$primary_dark_grey, + $dapp_transaction_summary_positive_balance_label_color: + lightColorScheme.$secondary_data_green, $dapp_transaction_summary_type_label_color: lightColorScheme.$primary_accent_purple,