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 {
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 { 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 (
<div className={styles.result}>
<div className={styles.resultLine}>
<span className={styles.logo} data-symbol={tokenSymbol}>
<Image
src={`https://tokens.1inch.io/${tokenAddress}.png`}
width={24}
height={24}
alt={tokenSymbol}
/>
</span>
<TokenLogo token={token} />
<span className={isValidating ? 'isValidating' : ''}>
{formatNumber(amount || 0, tokenSymbol)}
{formatNumber(amount || 0, token?.symbol || '')}
</span>
{amountOriginalFiat ? (

View File

@ -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:
</h3>
<Result
tokenSymbol="OCEAN"
tokenAddress="0x967da4048cd07ab37855c090aaf366e4ce1b9f48"
token={getTokenBySymbol('OCEAN')}
amount={prices.ocean ? debouncedAmount / prices.ocean : 0}
amountAsi={
prices.ocean ? (debouncedAmount / prices.ocean) * ratioOceanToAsi : 0
@ -35,8 +35,7 @@ export function Buy() {
isValidating={isValidating}
/>
<Result
tokenSymbol="AGIX"
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
token={getTokenBySymbol('AGIX')}
amount={prices.agix ? debouncedAmount / prices.agix : 0}
amountAsi={
prices.agix ? (debouncedAmount / prices.agix) * ratioAgixToAsi : 0
@ -49,8 +48,7 @@ export function Buy() {
isValidating={isValidating}
/>
<Result
tokenSymbol="FET"
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
token={getTokenBySymbol('FET')}
amount={prices.fet ? debouncedAmount / prices.fet : 0}
amountAsi={
prices.fet ? (debouncedAmount / prices.fet) * ratioFetToAsi : 0

View File

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

View File

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