Skip to content

Commit a7ccfea

Browse files
committed
fix(trades): edge cases for floor price calculation
1 parent 04176f0 commit a7ccfea

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

components/trade/overviewModal/Details.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<script setup lang="ts">
4646
import { useIsTradeOverview } from './utils'
4747
import { formatToNow } from '@/utils/format/time'
48+
import { blank } from '@/components/collection/activity/events/eventRow/common'
4849
import { type TradeNftItem } from '@/components/trade/types'
4950
import type { NFT } from '@/types'
5051
@@ -57,14 +58,22 @@ const { decimals, chainSymbol } = useChain()
5758
const { isMyTrade, isIncomingTrade } = useIsTradeOverview(computed(() => props.trade))
5859
5960
const getFormattedDifference = (a: number, b: number) => {
61+
if (b === 0 && a === 0) {
62+
return blank
63+
}
64+
65+
if (b === 0 && a > 0) {
66+
return '+100%'
67+
}
68+
6069
const diff = ((b - a) / b) * 100
6170
6271
return diff > 0
6372
? `-${diff.toFixed()}%`
6473
: `+${Math.abs(diff).toFixed()}%`
6574
}
6675
67-
const floorPrice = computed(() => Number(props.desired?.collection.floorPrice[0].price) || 0)
76+
const floorPrice = computed(() => Number(props.desired?.collection.floorPrice[0]?.price) || 0)
6877
const diff = computed(() => getFormattedDifference(Number(props.trade.price || 0), floorPrice.value))
6978
7079
const { formatted: formmatedOffer, usd: offerUsd } = useAmount(

0 commit comments

Comments
 (0)