Skip to content

Commit

Permalink
allow negative price impact to be shown in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyJousting committed Jan 30, 2025
1 parent 324e821 commit 1db1a44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/main/src/lend/components/DetailInfoPriceImpact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DetailInfoPriceImpact = ({
}) => {
const formattedPriceImpact = useMemo(() => {
if (priceImpact === 'N/A') return 'N/A'
if (+priceImpact > 0) return `≈${formatNumber(priceImpact, { style: 'percent', maximumSignificantDigits: 4 })}`
if (!isNaN(+priceImpact)) return `≈${formatNumber(priceImpact, { style: 'percent', maximumSignificantDigits: 4 })}`
return ''
}, [priceImpact])

Expand Down
8 changes: 6 additions & 2 deletions apps/main/src/lend/lib/apiLending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2100,8 +2100,12 @@ function _getPriceImpactResp(priceImpactResp: PromiseSettledResult<string | unde

if (resp.priceImpact === 'N/A') return resp

if (+resp.priceImpact > 0 && +slippage > 0) {
resp.isHighPriceImpact = +resp.priceImpact > +slippage
// Convert both values to numbers and get absolute value of price impact
const priceImpactNum = Math.abs(+resp.priceImpact)
const slippageNum = +slippage

if (slippageNum > 0) {
resp.isHighPriceImpact = priceImpactNum > slippageNum
}
return resp
}
Expand Down

0 comments on commit 1db1a44

Please sign in to comment.