Skip to content

Commit

Permalink
fix: improve generate colors for tokens label and price impact color
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasackermn authored and RanGojo committed Jul 7, 2024
1 parent 4953b96 commit 5f2893c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
8 changes: 4 additions & 4 deletions widget/embedded/src/components/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ export function TokenList(props: PropTypes) {
) as BlockchainMeta;
const colors = createTintsAndShades(blockchain.color, 'main');
const customCssForTag = {
$$color: colors.main250,
$$color: colors.main150,
[`.${darkTheme} &`]: {
$$color: colors.main850,
$$color: colors.main750,
},
backgroundColor: '$$color',
};

const customCssForTagTitle = {
$$color: colors.main600,
$$color: colors.main750,
[`.${darkTheme} &`]: {
$$color: colors.main200,
$$color: colors.main150,
},
color: '$$color',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export function FullExpandedQuote(props: PropTypes) {
</div>
<StyledPriceImpact
size="small"
outputColor="$neutral700"
warningLevel={warningLevel}
outputUsdValue={props.outputPrice.usdValue}
realOutputUsdValue={props.outputPrice.realUsdValue}
Expand Down
31 changes: 27 additions & 4 deletions widget/ui/src/components/PriceImpact/PriceImpact.styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { styled } from '../../theme';
import { Typography } from '../Typography';
import { darkTheme, styled } from '../../theme';

export const Container = styled('div', {
width: '100%',
Expand All @@ -8,8 +7,32 @@ export const Container = styled('div', {
alignItems: 'center',
});

export const OutputUsdValue = styled(Typography, {
overflow: 'hidden',
export const ValueTypography = styled('div', {
display: 'flex',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
'& ._typography': {
$$color: '$colors$neutral600',
[`.${darkTheme} &`]: {
$$color: '$colors$neutral700',
},
color: '$$color',
},
variants: {
hasWarning: {
true: {
'& ._typography': {
color: '$warning500',
},
},
},
hasError: {
true: {
'& ._typography': {
color: '$error500',
},
},
},
},
});
28 changes: 11 additions & 17 deletions widget/ui/src/components/PriceImpact/PriceImpact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';

import { Divider, Tooltip, Typography } from '..';

import { Container, OutputUsdValue } from './PriceImpact.styles';
import { Container, ValueTypography } from './PriceImpact.styles';

export function PriceImpact(props: PriceImpactPropTypes) {
const {
Expand All @@ -19,12 +19,8 @@ export function PriceImpact(props: PriceImpactPropTypes) {
...rest
} = props;

let percentageChangeColor = '$neutral600';
if (!outputUsdValue || warningLevel === 'low') {
percentageChangeColor = '$warning500';
} else if (warningLevel === 'high') {
percentageChangeColor = '$error500';
}
const hasWarning = !outputUsdValue || warningLevel === 'low';
const hasError = warningLevel === 'high';

return (
<Container {...rest}>
Expand All @@ -38,19 +34,17 @@ export function PriceImpact(props: PriceImpactPropTypes) {
: undefined
}
side={tooltipProps?.side}>
<OutputUsdValue
size={size}
variant="body"
color={outputColor || '$neutral600'}>
{outputUsdValue === '0' ? '0.00' : `~$${outputUsdValue}`}
</OutputUsdValue>
<ValueTypography>
<Typography size={size} variant="body" color={outputColor}>
{outputUsdValue === '0' ? '0.00' : `~$${outputUsdValue}`}
</Typography>
</ValueTypography>
</Tooltip>
)}
{((outputUsdValue && percentageChange) || !outputUsdValue) && (
<>
<ValueTypography hasError={hasError} hasWarning={hasWarning}>
<Divider direction="horizontal" size={4} />

<Typography size={size} variant="body" color={percentageChangeColor}>
<Typography size={size} variant="body">
{outputUsdValue &&
percentageChange &&
`(${
Expand All @@ -61,7 +55,7 @@ export function PriceImpact(props: PriceImpactPropTypes) {

{!outputUsdValue && error}
</Typography>
</>
</ValueTypography>
)}
</Container>
);
Expand Down
7 changes: 4 additions & 3 deletions widget/ui/src/components/TokenAmount/TokenAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react';
import { ChainToken } from '../ChainToken';
import { Divider } from '../Divider';
import { PriceImpact } from '../PriceImpact';
import { ValueTypography } from '../PriceImpact/PriceImpact.styles';
import { Tooltip } from '../Tooltip';
import { Typography } from '../Typography';

Expand Down Expand Up @@ -59,12 +60,12 @@ export function TokenAmount(props: PropTypes) {
content={props.price.realUsdValue}
container={props.tooltipContainer}>
{props.type === 'input' && (
<>
<Typography size="small" variant="body" color="$neutral700">
<ValueTypography>
<Typography size="small" variant="body">
{`~$${props.price.usdValue}`}
</Typography>
<Divider direction="horizontal" size={4} />
</>
</ValueTypography>
)}
</Tooltip>
{props.type === 'output' && (
Expand Down

0 comments on commit 5f2893c

Please sign in to comment.