From 20bef02de169063d83060322b650f862f88a6912 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sun, 31 Mar 2024 15:58:26 +0100 Subject: [PATCH] more token refactor --- components/ResultRow/ResultRow.module.css | 34 ----------------------- components/ResultRow/ResultRow.tsx | 20 ++++--------- components/Strategies/Buy.tsx | 12 ++++---- components/Strategies/Swap/Results.tsx | 11 +++----- components/Strategies/Swap/Swap.tsx | 2 +- components/TokenLogo/TokenLogo.module.css | 33 ++++++++++++++++++++++ components/TokenLogo/TokenLogo.tsx | 22 +++++++++++++++ components/TokenLogo/index.tsx | 1 + 8 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 components/TokenLogo/TokenLogo.module.css create mode 100644 components/TokenLogo/TokenLogo.tsx create mode 100644 components/TokenLogo/index.tsx diff --git a/components/ResultRow/ResultRow.module.css b/components/ResultRow/ResultRow.module.css index f288283..36d3450 100644 --- a/components/ResultRow/ResultRow.module.css +++ b/components/ResultRow/ResultRow.module.css @@ -24,37 +24,3 @@ .iconArrow { margin-left: 0.25rem; } - -.logo { - margin-top: -0.15rem; - vertical-align: middle; - display: inline-flex; - align-items: center; - justify-content: center; - width: 24px; - height: 24px; - border-radius: 50%; - background-color: rgba(var(--foreground-rgb), 0.5); -} - -.logo img { - width: 23px; - height: 23px; - border-radius: 50%; - filter: grayscale(1); -} - -.logo[data-symbol='AGIX'] img { - filter: invert(1) grayscale(1) contrast(1.5); -} - -@media (prefers-color-scheme: dark) { - .logo[data-symbol='OCEAN'] img, - .logo[data-symbol='FET'] img { - filter: invert(1) grayscale(1); - } - - .logo[data-symbol='AGIX'] img { - filter: grayscale(1); - } -} diff --git a/components/ResultRow/ResultRow.tsx b/components/ResultRow/ResultRow.tsx index 29fa508..c30b75d 100644 --- a/components/ResultRow/ResultRow.tsx +++ b/components/ResultRow/ResultRow.tsx @@ -1,11 +1,11 @@ import styles from './ResultRow.module.css' import { formatNumber } from '@/utils' import { ArrowRightIcon } from '@radix-ui/react-icons' -import Image from 'next/image' +import { TokenLogo } from '../TokenLogo/TokenLogo' +import { Token } from '@/types' type Props = { - tokenSymbol: string - tokenAddress: string + token: Token | undefined amount: number amountAsi: number amountFiat: number @@ -14,8 +14,7 @@ type Props = { } export function Result({ - tokenSymbol, - tokenAddress, + token, amount, amountAsi, amountFiat, @@ -25,17 +24,10 @@ export function Result({ return (
- - {tokenSymbol} - + - {formatNumber(amount || 0, tokenSymbol)} + {formatNumber(amount || 0, token?.symbol || '')} {amountOriginalFiat ? ( diff --git a/components/Strategies/Buy.tsx b/components/Strategies/Buy.tsx index 53d0bdb..6af278f 100644 --- a/components/Strategies/Buy.tsx +++ b/components/Strategies/Buy.tsx @@ -7,9 +7,10 @@ import { useDebounce } from 'use-debounce' import stylesShared from './styles.module.css' import { usePrices } from '@/hooks' import { FormAmount } from '@/components/FormAmount' +import { getTokenBySymbol } from '@/utils' export function Buy() { - const { prices, isValidating, isLoading } = usePrices() + const { prices, isValidating } = usePrices() const [amount, setAmount] = useState(100) const [debouncedAmount] = useDebounce(amount, 500) @@ -21,8 +22,7 @@ export function Buy() { right now gets you: {' '} right now gets you: diff --git a/components/TokenLogo/TokenLogo.module.css b/components/TokenLogo/TokenLogo.module.css new file mode 100644 index 0000000..9233ab7 --- /dev/null +++ b/components/TokenLogo/TokenLogo.module.css @@ -0,0 +1,33 @@ +.logo { + margin-top: -0.15rem; + vertical-align: middle; + display: inline-flex; + align-items: center; + justify-content: center; + width: 24px; + height: 24px; + border-radius: 50%; + background-color: rgba(var(--foreground-rgb), 0.5); +} + +.logo img { + width: 23px; + height: 23px; + border-radius: 50%; + filter: grayscale(1); +} + +.logo[data-symbol='AGIX'] img { + filter: invert(1) grayscale(1) contrast(1.5); +} + +@media (prefers-color-scheme: dark) { + .logo[data-symbol='OCEAN'] img, + .logo[data-symbol='FET'] img { + filter: invert(1) grayscale(1); + } + + .logo[data-symbol='AGIX'] img { + filter: grayscale(1); + } +} diff --git a/components/TokenLogo/TokenLogo.tsx b/components/TokenLogo/TokenLogo.tsx new file mode 100644 index 0000000..e09c6c0 --- /dev/null +++ b/components/TokenLogo/TokenLogo.tsx @@ -0,0 +1,22 @@ +import { Token } from '@/types' +import Image from 'next/image' +import styles from './TokenLogo.module.css' + +export function TokenLogo({ + token, + size = 24 +}: { + token: Token | undefined + size?: number +}) { + return token ? ( + + {token.symbol} + + ) : null +} diff --git a/components/TokenLogo/index.tsx b/components/TokenLogo/index.tsx new file mode 100644 index 0000000..a5e2397 --- /dev/null +++ b/components/TokenLogo/index.tsx @@ -0,0 +1 @@ +export * from './TokenLogo'