more token refactor

This commit is contained in:
Matthias Kretschmann 2024-03-31 15:58:26 +01:00
parent 6123e5d182
commit 20bef02de1
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 72 additions and 63 deletions

View File

@ -24,37 +24,3 @@
.iconArrow { .iconArrow {
margin-left: 0.25rem; 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);
}
}

View File

@ -1,11 +1,11 @@
import styles from './ResultRow.module.css' import styles from './ResultRow.module.css'
import { formatNumber } from '@/utils' import { formatNumber } from '@/utils'
import { ArrowRightIcon } from '@radix-ui/react-icons' import { ArrowRightIcon } from '@radix-ui/react-icons'
import Image from 'next/image' import { TokenLogo } from '../TokenLogo/TokenLogo'
import { Token } from '@/types'
type Props = { type Props = {
tokenSymbol: string token: Token | undefined
tokenAddress: string
amount: number amount: number
amountAsi: number amountAsi: number
amountFiat: number amountFiat: number
@ -14,8 +14,7 @@ type Props = {
} }
export function Result({ export function Result({
tokenSymbol, token,
tokenAddress,
amount, amount,
amountAsi, amountAsi,
amountFiat, amountFiat,
@ -25,17 +24,10 @@ export function Result({
return ( return (
<div className={styles.result}> <div className={styles.result}>
<div className={styles.resultLine}> <div className={styles.resultLine}>
<span className={styles.logo} data-symbol={tokenSymbol}> <TokenLogo token={token} />
<Image
src={`https://tokens.1inch.io/${tokenAddress}.png`}
width={24}
height={24}
alt={tokenSymbol}
/>
</span>
<span className={isValidating ? 'isValidating' : ''}> <span className={isValidating ? 'isValidating' : ''}>
{formatNumber(amount || 0, tokenSymbol)} {formatNumber(amount || 0, token?.symbol || '')}
</span> </span>
{amountOriginalFiat ? ( {amountOriginalFiat ? (

View File

@ -7,9 +7,10 @@ import { useDebounce } from 'use-debounce'
import stylesShared from './styles.module.css' import stylesShared from './styles.module.css'
import { usePrices } from '@/hooks' import { usePrices } from '@/hooks'
import { FormAmount } from '@/components/FormAmount' import { FormAmount } from '@/components/FormAmount'
import { getTokenBySymbol } from '@/utils'
export function Buy() { export function Buy() {
const { prices, isValidating, isLoading } = usePrices() const { prices, isValidating } = usePrices()
const [amount, setAmount] = useState(100) const [amount, setAmount] = useState(100)
const [debouncedAmount] = useDebounce(amount, 500) const [debouncedAmount] = useDebounce(amount, 500)
@ -21,8 +22,7 @@ export function Buy() {
right now gets you: right now gets you:
</h3> </h3>
<Result <Result
tokenSymbol="OCEAN" token={getTokenBySymbol('OCEAN')}
tokenAddress="0x967da4048cd07ab37855c090aaf366e4ce1b9f48"
amount={prices.ocean ? debouncedAmount / prices.ocean : 0} amount={prices.ocean ? debouncedAmount / prices.ocean : 0}
amountAsi={ amountAsi={
prices.ocean ? (debouncedAmount / prices.ocean) * ratioOceanToAsi : 0 prices.ocean ? (debouncedAmount / prices.ocean) * ratioOceanToAsi : 0
@ -35,8 +35,7 @@ export function Buy() {
isValidating={isValidating} isValidating={isValidating}
/> />
<Result <Result
tokenSymbol="AGIX" token={getTokenBySymbol('AGIX')}
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
amount={prices.agix ? debouncedAmount / prices.agix : 0} amount={prices.agix ? debouncedAmount / prices.agix : 0}
amountAsi={ amountAsi={
prices.agix ? (debouncedAmount / prices.agix) * ratioAgixToAsi : 0 prices.agix ? (debouncedAmount / prices.agix) * ratioAgixToAsi : 0
@ -49,8 +48,7 @@ export function Buy() {
isValidating={isValidating} isValidating={isValidating}
/> />
<Result <Result
tokenSymbol="FET" token={getTokenBySymbol('FET')}
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
amount={prices.fet ? debouncedAmount / prices.fet : 0} amount={prices.fet ? debouncedAmount / prices.fet : 0}
amountAsi={ amountAsi={
prices.fet ? (debouncedAmount / prices.fet) * ratioFetToAsi : 0 prices.fet ? (debouncedAmount / prices.fet) * ratioFetToAsi : 0

View File

@ -6,7 +6,7 @@ import {
tokens tokens
} from '@/constants' } from '@/constants'
import { usePrices } from '@/hooks' import { usePrices } from '@/hooks'
import { fetcher } from '@/utils' import { fetcher, getTokenBySymbol } from '@/utils'
import useSWR from 'swr' import useSWR from 'swr'
import { TokenSymbol } from '@/types' import { TokenSymbol } from '@/types'
@ -33,8 +33,7 @@ export function SwapResults({
return ( return (
<> <>
<Result <Result
tokenSymbol="OCEAN" token={getTokenBySymbol('OCEAN')}
tokenAddress="0x967da4048cd07ab37855c090aaf366e4ce1b9f48"
amount={amount} amount={amount}
amountAsi={amount * ratioOceanToAsi} amountAsi={amount * ratioOceanToAsi}
amountFiat={amount * ratioOceanToAsi * prices.asi} amountFiat={amount * ratioOceanToAsi * prices.asi}
@ -52,8 +51,7 @@ export function SwapResults({
/> />
<Result <Result
tokenSymbol="AGIX" token={getTokenBySymbol('AGIX')}
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
amount={ amount={
dataSwapOceanToAgix?.amountOut / dataSwapOceanToAgix?.amountOut /
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0 Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0
@ -76,8 +74,7 @@ export function SwapResults({
/> />
<Result <Result
tokenSymbol="FET" token={getTokenBySymbol('FET')}
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
amount={ amount={
dataSwapOceanToFet?.amountOut / dataSwapOceanToFet?.amountOut /
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0 Number(`1e${dataSwapOceanToFet?.decimals}`) || 0

View File

@ -20,7 +20,7 @@ export function Swap() {
amount={amount} amount={amount}
token={token} token={token}
setAmount={setAmount} setAmount={setAmount}
// setToken={setToken} setToken={setToken}
/>{' '} />{' '}
right now gets you: right now gets you:
</h3> </h3>

View File

@ -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);
}
}

View File

@ -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 ? (
<span className={styles.logo} data-symbol={token.symbol}>
<Image
src={`https://tokens.1inch.io/${token.address}.png`}
width={size}
height={size}
alt={token.symbol}
/>
</span>
) : null
}

View File

@ -0,0 +1 @@
export * from './TokenLogo'