asi-calculator/features/strategies/components/Result/Result.tsx

74 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-04-01 15:23:01 +02:00
import { TokenLogo } from '@/components'
import { useLocale } from '@/features/prices'
import { formatCrypto, formatFiat } from '@/lib'
import type { Token } from '@/types'
import { ArrowRightIcon } from '@radix-ui/react-icons'
import styles from './Result.module.css'
2024-03-29 21:37:30 +01:00
2024-03-29 19:54:14 +01:00
type Props = {
2024-03-31 16:58:26 +02:00
token: Token | undefined
2024-03-29 19:54:14 +01:00
amount: number
amountAsi: number
amountFiat: number
2024-03-31 05:03:37 +02:00
amountOriginalFiat?: number
2024-03-31 05:32:11 +02:00
isValidating: boolean
2024-04-01 02:15:51 +02:00
isLoading: boolean
2024-03-29 19:54:14 +01:00
}
2024-03-30 02:03:43 +01:00
export function Result({
2024-03-31 16:58:26 +02:00
token,
2024-03-30 02:03:43 +01:00
amount,
amountAsi,
2024-03-31 05:03:37 +02:00
amountFiat,
2024-03-31 05:32:11 +02:00
amountOriginalFiat,
2024-04-01 02:15:51 +02:00
isValidating,
isLoading
2024-03-30 02:03:43 +01:00
}: Props) {
const locale = useLocale()
2024-04-01 02:15:51 +02:00
const feedbackClasses = isLoading
? 'isLoading'
: isValidating
? 'isValidating'
: ''
2024-04-01 02:15:51 +02:00
2024-03-29 19:54:14 +01:00
return (
2024-03-29 21:37:30 +01:00
<div className={styles.result}>
2024-03-31 15:24:07 +02:00
<div className={styles.resultLine}>
2024-03-31 16:58:26 +02:00
<TokenLogo token={token} />
2024-03-30 02:03:43 +01:00
2024-04-01 02:15:51 +02:00
<p>
<span
className={feedbackClasses}
title={`${amount} ${token?.symbol}`}
>
{formatCrypto(amount || 0, token?.symbol || '', locale)}
2024-04-01 02:15:51 +02:00
</span>
</p>
2024-03-31 05:03:37 +02:00
{amountOriginalFiat ? (
2024-04-01 02:15:51 +02:00
<p>
<span className={`${styles.fiat} ${feedbackClasses}`}>
{formatFiat(amountOriginalFiat || 0, 'USD', locale)}
2024-04-01 02:15:51 +02:00
</span>
</p>
2024-03-31 05:03:37 +02:00
) : null}
</div>
2024-04-01 02:15:51 +02:00
2024-03-31 15:24:07 +02:00
<div className={styles.resultLine}>
<TokenLogo token={{ symbol: 'ASI', address: '0x' }} />
2024-04-01 02:15:51 +02:00
<p>
<strong title={`${amountAsi} ASI`} className={feedbackClasses}>
{formatCrypto(amountAsi || 0, 'ASI', locale)}
2024-04-01 02:15:51 +02:00
</strong>
</p>
<p>
<strong className={`${styles.fiat} ${feedbackClasses}`}>
{formatFiat(amountFiat || 0, 'USD', locale)}
2024-04-01 02:15:51 +02:00
</strong>
</p>
2024-03-31 05:03:37 +02:00
</div>
2024-03-29 21:37:30 +01:00
</div>
2024-03-29 19:54:14 +01:00
)
}