Skip to content

Commit c8b830a

Browse files
committed
Update remaining text components
1 parent aa99c44 commit c8b830a

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

src/components/swap/components/quote-result/available.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Image from 'next/image'
44

55
import { StyledSkeleton } from '@/components/skeleton'
66
import { colors } from '@/lib/styles/colors'
7+
import { cn } from '@/lib/utils/tailwind'
78

89
import { QuoteDisplay } from './types'
910

@@ -23,12 +24,22 @@ function getBackgroundColor(isSelected: boolean, isBestQuote: boolean) {
2324
}
2425

2526
function useHighlightColor(isSelected: boolean, isBestQuote: boolean) {
26-
if (isBestQuote && isSelected) return colors.ic.blue[600]
27-
if (isBestQuote && !isSelected) return '#CFF5F6'
27+
if (isBestQuote && isSelected) {
28+
return { border: colors.ic.blue[600], text: 'text-ic-blue-600' }
29+
}
30+
if (isBestQuote && !isSelected) {
31+
return { border: '#CFF5F6', text: 'text-[#CFF5F6]' }
32+
}
2833
if (!isBestQuote && isSelected) {
29-
return '#F178B6'
34+
return {
35+
border: '#F178B6',
36+
text: 'text-[#F178B6]',
37+
}
38+
}
39+
return {
40+
border: colors.ic.gray[400],
41+
text: 'text-ic-gray-400',
3042
}
31-
return colors.ic.gray[400]
3243
}
3344

3445
export const QuoteAvailable = (props: QuoteAvailableProps) => {
@@ -39,7 +50,7 @@ export const QuoteAvailable = (props: QuoteAvailableProps) => {
3950
return (
4051
<Flex
4152
bg={background}
42-
borderColor={highlight}
53+
borderColor={highlight.border}
4354
borderRadius='12'
4455
borderWidth={borderWidth}
4556
cursor='pointer'
@@ -66,7 +77,7 @@ export const QuoteAvailable = (props: QuoteAvailableProps) => {
6677
/>
6778
</Flex>
6879
)}
69-
<p className='text-sm font-semibold' textColor={highlight}>
80+
<p className={cn('text-sm font-semibold', highlight.text)}>
7081
{type.toUpperCase()}
7182
</p>
7283
</Flex>

src/components/swap/components/trade-input-selector.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Flex, Input, Text } from '@chakra-ui/react'
1+
import { Flex, Input } from '@chakra-ui/react'
22

33
import { colors } from '@/lib/styles/colors'
4+
import { cn } from '@/lib/utils/tailwind'
45

56
import { Caption } from './caption'
67
import { SelectorButton } from './selector-button'
@@ -56,20 +57,16 @@ export const TradeInputSelector = (props: TradeInputSelectorProps) => {
5657
<Caption caption={props.caption} />
5758
<Flex align='center' direction='row' justify='space-between' mt='6px'>
5859
{config.isReadOnly ? (
59-
<Text
60-
color={
60+
<p
61+
className={cn(
62+
'text-ellipsis whitespace-nowrap pr-1 text-[25px] font-medium',
6163
props.selectedTokenAmount === '0'
62-
? colors.ic.gray[400]
63-
: colors.ic.black
64-
}
65-
fontSize='25px'
66-
fontWeight={500}
67-
pr='4px'
68-
textOverflow='ellipsis'
69-
whiteSpace='nowrap'
64+
? 'text-ic-gray-400'
65+
: 'text-ic-black',
66+
)}
7067
>
7168
{props.selectedTokenAmount}
72-
</Text>
69+
</p>
7370
) : (
7471
<Input
7572
className='text-ic-black dark:text-ic-white bg-transparent pr-1 text-3xl'
@@ -153,7 +150,7 @@ const PriceUsd = (props: PriceUsdProps) => (
153150
<Flex>
154151
<p className='text-ic-gray-400 text-xs font-medium'>{props.fiat}</p>
155152
{props.priceImpact && (
156-
<p className='text-xs' textColor={props.priceImpact.colorCoding}>
153+
<p className={cn('text-xs', props.priceImpact.colorCoding)}>
157154
&nbsp;{props.priceImpact.value}
158155
</p>
159156
)}

src/components/swap/hooks/use-swap/formatters/price-impact.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getPriceImpact } from '@/lib/hooks/use-best-quote/utils/price-impact'
2-
import { colors } from '@/lib/styles/colors'
32

4-
import { getPriceImpactColorCoding } from './price-impact'
3+
import { getPriceImpactTextColor } from './price-impact'
54

65
describe('getPriceImpact()', () => {
76
test('should return null if input/output token amount smaller or equal 0', async () => {
@@ -42,19 +41,18 @@ describe('getPriceImpact()', () => {
4241

4342
describe('getPriceImpaceColorCoding()', () => {
4443
test('should return correct color for > 5% price impact', async () => {
45-
const colorCoding = getPriceImpactColorCoding(-5.1, true)
46-
expect(colorCoding).toEqual(colors.ic.red)
44+
const colorCoding = getPriceImpactTextColor(-5.1)
45+
expect(colorCoding).toEqual('text-ic-red')
4746
})
4847

4948
test('should return correct color for price impact > 3% < 5%', async () => {
50-
const colorCoding = getPriceImpactColorCoding(-3.1, true)
51-
expect(colorCoding).toEqual(colors.ic.blue[500])
49+
const colorCoding = getPriceImpactTextColor(-3.1)
50+
expect(colorCoding).toEqual('text-ic-blue-500')
5251
})
5352

5453
test('should return correct color for price impact < 3%', async () => {
55-
const colorCodingDarkMode = getPriceImpactColorCoding(2, true)
56-
expect(colorCodingDarkMode).toEqual(colors.icGrayDarkMode)
57-
const colorCodingLightMode = getPriceImpactColorCoding(2, false)
58-
expect(colorCodingLightMode).toEqual(colors.icGrayLightMode)
54+
const colorCodingFallback = getPriceImpactTextColor(2)
55+
expect(colorCodingFallback).toContain('text-[#aaa]')
56+
expect(colorCodingFallback).toContain('dark:text-[#777]')
5957
})
6058
})
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1-
import { colors } from '@/lib/styles/colors'
2-
3-
export function getPriceImpactColorCoding(
4-
priceImpact: number,
5-
isDarkMode: boolean,
6-
): string {
1+
export function getPriceImpactTextColor(priceImpact: number): string {
72
if (priceImpact < -5) {
8-
return colors.ic.red
3+
return 'text-ic-red'
94
}
105

116
if (priceImpact < -3) {
12-
return colors.ic.blue[500]
7+
return 'text-ic-blue-500'
138
}
149

15-
return isDarkMode ? colors.icGrayDarkMode : colors.icGrayLightMode
10+
return 'text-[#aaa] dark:text-[#777]'
1611
}
1712

1813
/**
1914
* Returns price impact in the format (x.yy%)
2015
*/
2116
export function getFormattedPriceImpact(
2217
priceImpact: number,
23-
isDarkMode: boolean,
2418
): { priceImpact: string; colorCoding: string } | null {
2519
if (!priceImpact) return null
26-
const colorCoding = getPriceImpactColorCoding(priceImpact, isDarkMode)
20+
const colorCoding = getPriceImpactTextColor(priceImpact)
2721
return { priceImpact: `(${priceImpact.toFixed(2)}%)`, colorCoding }
2822
}

0 commit comments

Comments
 (0)