Skip to content

Commit

Permalink
hide diff percentage when usd 0
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki committed Apr 16, 2024
1 parent d224f29 commit 4ee73f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/components/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ function AssetInput({
}}
/>
<div className="flex h-8 items-center space-x-2 tabular-nums">
<p className="text-sm tabular-nums text-neutral-400">{amountUSD ? formatUSD(amountUSD) : null}</p>
{amountUSD !== undefined && diffPercentage !== 0 && context === "destination" ? (
<p className="text-sm tabular-nums text-neutral-400">
{amountUSD && Number(amountUSD) > 0 ? formatUSD(amountUSD) : null}
</p>
{amountUSD !== undefined && Number(amountUSD) > 0 && diffPercentage !== 0 && context === "destination" ? (
<p className={cn("text-sm tabular-nums", diffPercentage >= 0 ? "text-green-500" : "text-red-500")}>
({formatPercent(diffPercentage)})
</p>
Expand Down
6 changes: 1 addition & 5 deletions src/components/SwapWidget/SwapWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,9 @@ export function SwapWidget() {
sourceFeeAmount,
sourceFeeAsset,
swapPriceImpactPercent,
usdDiffPercent,
} = useSwapWidget();

let usdDiffPercent = 0.0;
if (route?.usdAmountIn && route?.usdAmountOut) {
usdDiffPercent = (parseFloat(route.usdAmountOut) - parseFloat(route.usdAmountIn)) / parseFloat(route.usdAmountIn);
}

const srcAccount = useAccount("source");
const destAccount = useAccount("destination");

Expand Down
9 changes: 7 additions & 2 deletions src/components/SwapWidget/useSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ export function useSwapWidget() {
if (!route) {
return undefined;
}

if (!route.usdAmountIn || !route.usdAmountOut) {
if (
!route.usdAmountIn ||
!route.usdAmountOut ||
Number(route.usdAmountIn) === 0 ||
Number(route.usdAmountOut) === 0
) {
return undefined;
}

Expand Down Expand Up @@ -831,6 +835,7 @@ export function useSwapWidget() {
sourceFeeAmount: gasRequired,
sourceFeeAsset: srcFeeAsset,
swapPriceImpactPercent,
usdDiffPercent,
};
}

Expand Down

0 comments on commit 4ee73f8

Please sign in to comment.