From 24ddace1eb247e459d10eed709f2bfd83ef6d64e Mon Sep 17 00:00:00 2001 From: Charles Bachmeier Date: Tue, 10 Oct 2023 12:24:57 -0700 Subject: [PATCH] feat: [info] update color extract default and have PDP fallback (#7432) * feat: [info] update color extract default and have a fallback * uncomment section removed for testing * update snapshot --- src/hooks/useColor.ts | 8 +++++--- src/pages/PoolDetails/PoolDetailsStats.tsx | 9 +++++++-- .../__snapshots__/PoolDetailsStats.test.tsx.snap | 4 ++-- src/pages/PoolDetails/__snapshots__/index.test.tsx.snap | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/hooks/useColor.ts b/src/hooks/useColor.ts index 777d471cc2..14ecaa9d73 100644 --- a/src/hooks/useColor.ts +++ b/src/hooks/useColor.ts @@ -4,6 +4,7 @@ import useTokenLogoSource from 'hooks/useAssetLogoSource' import { rgb } from 'polished' import { useEffect, useState } from 'react' import { WrappedTokenInfo } from 'state/lists/wrappedTokenInfo' +import { useTheme } from 'styled-components' import { getColor } from 'utils/getColor' function URIForEthToken(address: string) { @@ -54,7 +55,8 @@ function convertColorArrayToString([red, green, blue]: number[]): string { } export function useColor(token?: Token) { - const [color, setColor] = useState('#2172E5') + const theme = useTheme() + const [color, setColor] = useState(theme.accent1) const [src] = useTokenLogoSource(token?.address, token?.chainId, token?.isNative) useEffect(() => { @@ -70,9 +72,9 @@ export function useColor(token?: Token) { return () => { stale = true - setColor('#2172E5') + setColor(theme.accent1) } - }, [src, token]) + }, [src, theme.accent1, token]) return color } diff --git a/src/pages/PoolDetails/PoolDetailsStats.tsx b/src/pages/PoolDetails/PoolDetailsStats.tsx index 3fdcdff916..9d98d4cf0f 100644 --- a/src/pages/PoolDetails/PoolDetailsStats.tsx +++ b/src/pages/PoolDetails/PoolDetailsStats.tsx @@ -9,8 +9,9 @@ import { useColor } from 'hooks/useColor' import { useScreenSize } from 'hooks/useScreenSize' import { ReactNode, useMemo } from 'react' import { Text } from 'rebass' -import styled, { css } from 'styled-components' +import styled, { css, useTheme } from 'styled-components' import { BREAKPOINTS } from 'theme' +import { colors } from 'theme/colors' import { ThemedText } from 'theme/components' import { NumberType, useFormatter } from 'utils/formatNumbers' @@ -99,12 +100,16 @@ export function PoolDetailsStats({ poolData, isReversed, chainId }: PoolDetailsS const isScreenSize = useScreenSize() const screenIsNotLarge = isScreenSize['lg'] const { formatNumber } = useFormatter() + const theme = useTheme() const currency0 = useCurrency(poolData?.token0?.id, chainId) ?? undefined const currency1 = useCurrency(poolData?.token1?.id, chainId) ?? undefined const color0 = useColor(currency0?.wrapped) - const color1 = useColor(currency1?.wrapped) + let color1 = useColor(currency1?.wrapped) + if (color0 === color1 && color0 === theme.accent1) { + color1 = colors.blue400 + } const [token0, token1] = useMemo(() => { const fullWidth = poolData?.tvlToken0 / poolData?.token0Price + poolData?.tvlToken1 diff --git a/src/pages/PoolDetails/__snapshots__/PoolDetailsStats.test.tsx.snap b/src/pages/PoolDetails/__snapshots__/PoolDetailsStats.test.tsx.snap index 2bea8407e2..08cbabaab8 100644 --- a/src/pages/PoolDetails/__snapshots__/PoolDetailsStats.test.tsx.snap +++ b/src/pages/PoolDetails/__snapshots__/PoolDetailsStats.test.tsx.snap @@ -506,7 +506,7 @@ exports[`PoolDetailsStats renders stats text correctly 1`] = ` .c9 { height: 8px; width: 40.698463777008904%; - background: #2172E5; + background: #FC72FF; border-top-left-radius: 5px; border-bottom-left-radius: 5px; border-right: 1px solid #F9F9F9; @@ -515,7 +515,7 @@ exports[`PoolDetailsStats renders stats text correctly 1`] = ` .c10 { height: 8px; width: 59.3015362229911%; - background: #2172E5; + background: #4C82FB; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-left: 1px solid #F9F9F9; diff --git a/src/pages/PoolDetails/__snapshots__/index.test.tsx.snap b/src/pages/PoolDetails/__snapshots__/index.test.tsx.snap index fde90bd8fb..42eb6bc4df 100644 --- a/src/pages/PoolDetails/__snapshots__/index.test.tsx.snap +++ b/src/pages/PoolDetails/__snapshots__/index.test.tsx.snap @@ -324,7 +324,7 @@ exports[`PoolDetailsPage pool header is displayed when data is received from the .c27 { height: 8px; width: 40.698463777008904%; - background: #2172E5; + background: #FC72FF; border-top-left-radius: 5px; border-bottom-left-radius: 5px; border-right: 1px solid #F9F9F9; @@ -333,7 +333,7 @@ exports[`PoolDetailsPage pool header is displayed when data is received from the .c28 { height: 8px; width: 59.3015362229911%; - background: #2172E5; + background: #4C82FB; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-left: 1px solid #F9F9F9;