better fiat representation

This commit is contained in:
Matthias Kretschmann 2024-03-31 04:03:37 +01:00
parent 5ed62c9668
commit 1aa4ee1afc
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 50 additions and 20 deletions

View File

@ -1,5 +1,5 @@
:root { :root {
--max-width: 42rem; --max-width: 40rem;
--border-radius: 0.3rem; --border-radius: 0.3rem;
--foreground-rgb: 20, 20, 20; --foreground-rgb: 20, 20, 20;

View File

@ -1,6 +1,6 @@
.calculationBase { .calculationBase {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
justify-content: center; justify-content: center;
border-top: 1px solid rgba(var(--foreground-rgb), 0.2); border-top: 1px solid rgba(var(--foreground-rgb), 0.2);
border-left: 1px solid rgba(var(--foreground-rgb), 0.2); border-left: 1px solid rgba(var(--foreground-rgb), 0.2);

View File

@ -6,13 +6,25 @@
margin-bottom: 0; margin-bottom: 0;
} }
.conversion { .resultLine {
padding-left: calc(24px + 0.5rem); display: inline-grid;
grid-template-columns: 24px 1fr 2fr;
gap: 0.5rem;
align-items: center;
width: 100%;
margin-bottom: 0.25rem;
}
.fiat {
color: rgba(var(--foreground-rgb), 0.6);
}
.iconArrow {
margin-left: 0.25rem;
} }
.logo { .logo {
margin-right: 0.5rem; margin-top: -0.15rem;
margin-top: -0.2rem;
vertical-align: middle; vertical-align: middle;
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;

View File

@ -1,5 +1,6 @@
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 Image from 'next/image' import Image from 'next/image'
type Props = { type Props = {
@ -8,6 +9,7 @@ type Props = {
amount: number amount: number
amountAsi: number amountAsi: number
amountFiat: number amountFiat: number
amountOriginalFiat?: number
} }
export function Result({ export function Result({
@ -15,11 +17,12 @@ export function Result({
tokenAddress, tokenAddress,
amount, amount,
amountAsi, amountAsi,
amountFiat amountFiat,
amountOriginalFiat
}: Props) { }: Props) {
return ( return (
<div className={styles.result}> <div className={styles.result}>
<p> <div className={styles.resultLine}>
<span className={styles.logo} data-symbol={tokenSymbol}> <span className={styles.logo} data-symbol={tokenSymbol}>
<Image <Image
src={`https://tokens.1inch.io/${tokenAddress}.png`} src={`https://tokens.1inch.io/${tokenAddress}.png`}
@ -29,15 +32,23 @@ export function Result({
/> />
</span> </span>
{formatNumber(amount || 0, tokenSymbol)} <span>{formatNumber(amount || 0, tokenSymbol)}</span>
</p>
<p className={styles.conversion}> {amountOriginalFiat ? (
{' '} <span className={styles.fiat}>
{formatNumber(amountOriginalFiat || 0, 'USD')}
</span>
) : null}
</div>
<div className={styles.resultLine}>
<ArrowRightIcon className={styles.iconArrow} />
<strong title={`${amountAsi}`}> <strong title={`${amountAsi}`}>
{formatNumber(amountAsi || 0, 'ASI')} {formatNumber(amountAsi || 0, 'ASI')}
</strong>{' '} </strong>
= <strong>{formatNumber(amountFiat || 0, 'USD')}</strong> <strong className={styles.fiat}>
</p> {formatNumber(amountFiat || 0, 'USD')}
</strong>
</div>
</div> </div>
) )
} }

View File

@ -6,7 +6,7 @@ import {
ratioFetToAsi, ratioFetToAsi,
tokens tokens
} from '@/constants' } from '@/constants'
import { fetcher, formatNumber } from '@/utils' import { fetcher } from '@/utils'
import { Result } from '@/components/ResultRow' import { Result } from '@/components/ResultRow'
import stylesShared from './styles.module.css' import stylesShared from './styles.module.css'
import { useState } from 'react' import { useState } from 'react'
@ -41,8 +41,7 @@ export function Swap() {
setAmount={setAmount} setAmount={setAmount}
// setToken={setToken} // setToken={setToken}
/>{' '} />{' '}
({formatNumber(amount * prices[token || 'ocean'], 'USD')}) right now right now gets you:
gets you:
</h3> </h3>
<Result <Result
@ -51,6 +50,7 @@ export function Swap() {
amount={debouncedAmount} amount={debouncedAmount}
amountAsi={debouncedAmount * ratioOceanToAsi} amountAsi={debouncedAmount * ratioOceanToAsi}
amountFiat={debouncedAmount * ratioOceanToAsi * prices.asi} amountFiat={debouncedAmount * ratioOceanToAsi * prices.asi}
amountOriginalFiat={token ? debouncedAmount * prices[token] : undefined}
/> />
<Result <Result
@ -70,6 +70,10 @@ export function Swap() {
ratioAgixToAsi * ratioAgixToAsi *
prices.asi prices.asi
} }
amountOriginalFiat={
(dataSwapOceanToAgix?.amountOut /
Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0) * prices.agix
}
/> />
<Result <Result
@ -87,6 +91,10 @@ export function Swap() {
(dataSwapOceanToFet?.amountOut / (dataSwapOceanToFet?.amountOut /
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) * prices.asi Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) * prices.asi
} }
amountOriginalFiat={
(dataSwapOceanToFet?.amountOut /
Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) * prices.asi
}
/> />
</div> </div>
) )

View File

@ -18,7 +18,6 @@
.title { .title {
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
font-size: 1.1rem; font-size: 1.2rem;
min-height: 52px;
color: rgb(var(--foreground-rgb-highlight)); color: rgb(var(--foreground-rgb-highlight));
} }