diff --git a/basicswap/static/js/offers.js b/basicswap/static/js/offers.js index d922d06..ffedd66 100644 --- a/basicswap/static/js/offers.js +++ b/basicswap/static/js/offers.js @@ -578,7 +578,7 @@ function filterAndSortData() { if (offer.is_own_offer || isSentOffers) { percentDiff = ((toValueUSD / fromValueUSD) - 1) * 100; } else { - percentDiff = ((fromValueUSD / toValueUSD) - 1) * 100; + percentDiff = (-((toValueUSD / fromValueUSD) - 1)) * 100; } } } @@ -706,7 +706,7 @@ async function calculateProfitLoss(fromCoin, toCoin, fromAmount, toAmount, isOwn if (isOwnOffer) { percentDiff = ((toValueUSD / fromValueUSD) - 1) * 100; } else { - percentDiff = ((fromValueUSD / toValueUSD) - 1) * 100; + percentDiff = (-((toValueUSD / fromValueUSD) - 1)) * 100; } if (isNaN(percentDiff)) { @@ -975,12 +975,11 @@ function updateProfitLoss(row, fromCoin, toCoin, fromAmount, toAmount, isOwnOffe return; } - const formattedPercentDiff = percentDiff.toFixed(2); - const percentDiffDisplay = formattedPercentDiff === "0.00" ? "0.00" : - (percentDiff > 0 ? `+${formattedPercentDiff}` : formattedPercentDiff); + const percentDiffDisplay = percentDiff === "0.00" ? "0.00" : + (percentDiff > 0 ? percentDiff : -percentDiff); const colorClass = getProfitColorClass(percentDiff); - profitLossElement.textContent = `${percentDiffDisplay}%`; + profitLossElement.textContent = `${percentDiffDisplay.toFixed(2)}%`; profitLossElement.className = `profit-loss text-lg font-bold ${colorClass}`; const tooltipId = `percentage-tooltip-${row.getAttribute('data-offer-id')}`; @@ -1808,38 +1807,37 @@ function createTooltipContent(isSentOffers, coinFrom, coinTo, fromAmount, toAmou if (isSentOffers || isOwnOffer) { percentDiff = ((toValueUSD / fromValueUSD) - 1) * 100; } else { - percentDiff = ((fromValueUSD / toValueUSD) - 1) * 100; + percentDiff = (-((toValueUSD / fromValueUSD) - 1)) * 100; } - const formattedPercentDiff = percentDiff.toFixed(2); - const percentDiffDisplay = formattedPercentDiff === "0.00" ? "0.00" : - (percentDiff > 0 ? `+${formattedPercentDiff}` : formattedPercentDiff); + const percentDiffDisplay = percentDiff === "0.00" ? "0.00" : + (percentDiff > 0 ? percentDiff : -percentDiff); - const profitLabel = (isSentOffers || isOwnOffer) ? "Max Profit" : "Max Loss"; + const profitLabel = percentDiff > 0 ? "Max Profit" : "Max Loss"; const actionLabel = (isSentOffers || isOwnOffer) ? "selling" : "buying"; const directionLabel = (isSentOffers || isOwnOffer) ? "receiving" : "paying"; return `

Profit/Loss Calculation:

You are ${actionLabel} ${fromAmount.toFixed(8)} ${coinFrom} ($${fromValueUSD.toFixed(2)} USD)
and ${directionLabel} ${toAmount.toFixed(8)} ${coinTo} ($${toValueUSD.toFixed(2)} USD).

-

Percentage difference: ${percentDiffDisplay}%

-

${profitLabel}: ${profitUSD > 0 ? '' : '-'}$${Math.abs(profitUSD).toFixed(2)} USD

+

Percentage difference: ${percentDiffDisplay.toFixed(2)}%

+

${profitLabel}: ${Math.abs(profitUSD).toFixed(2)} USD

Calculation:

Percentage = ${(isSentOffers || isOwnOffer) ? "((To Amount in USD / From Amount in USD) - 1) * 100" : - "((From Amount in USD / To Amount in USD) - 1) * 100"}

+ "(-((To Amount in USD / From Amount in USD) - 1)) * 100"}

USD ${profitLabel} = To Amount in USD - From Amount in USD

Interpretation:

${(isSentOffers || isOwnOffer) ? ` -

Positive percentage: You're selling above market rate (profitable)

-

Negative percentage: You're selling below market rate (loss)

+

Green: You're selling above market rate (profitable)

+

Red: You're selling below market rate (loss)

` : ` -

Positive percentage: You're buying below market rate (savings)

-

Negative percentage: You're buying above market rate (premium)

+

Green: You're buying below market rate (savings)

+

Red: You're buying above market rate (premium)

`}

Note: ${(isSentOffers || isOwnOffer) ? - "As a seller, a positive percentage means
you're selling for more than the current market value." : - "As a buyer, a positive percentage indicates
potential savings compared to current market rates."}

+ "As a seller, a green percentage means
you're selling for more than the current market rate." : + "As a buyer, a green percentage indicates
potential savings compared to current market rate."}

Market Rate: 1 ${coinFrom} = ${marketRate.toFixed(8)} ${coinTo}

Offer Rate: 1 ${coinFrom} = ${offerRate.toFixed(8)} ${coinTo}

`; @@ -1921,15 +1919,14 @@ function createCombinedRateTooltip(offer, coinFrom, coinTo, treatAsSentOffer) { const rateInUSD = rate * toPriceUSD; const marketRate = fromPriceUSD / toPriceUSD; const percentDiff = marketRate ? ((rate - marketRate) / marketRate) * 100 : 0; - const formattedPercentDiff = percentDiff.toFixed(2); - const percentDiffDisplay = formattedPercentDiff === "0.00" ? "0.00" : - (percentDiff > 0 ? `+${formattedPercentDiff}` : formattedPercentDiff); + const percentDiffDisplay = percentDiff === "0.00" ? "0.00" : + (percentDiff > 0 ? percentDiff : -percentDiff); const aboveOrBelow = percentDiff > 0 ? "above" : percentDiff < 0 ? "below" : "at"; const action = treatAsSentOffer ? "selling" : "buying"; return `

Exchange Rate Explanation:

-

This offer is ${action} ${coinFrom} for ${coinTo}
at a rate that is ${percentDiffDisplay}% ${aboveOrBelow} market price.

+

This offer is ${action} ${coinFrom} for ${coinTo}
at a rate that is ${percentDiffDisplay.toFixed(2)}% ${aboveOrBelow} market price.

Exchange Rates:

1 ${coinFrom} = ${rate.toFixed(8)} ${coinTo}

1 ${coinTo} = ${inverseRate.toFixed(8)} ${coinFrom}