fix: Remove agreed_price from price API response

The agreed_price depends on trade direction (buy/sell) and must be
calculated on the frontend. Returning a buy-side-only agreed_price
from the API was misleading and unused.

Frontend already calculates the direction-aware price correctly.
This commit is contained in:
counterweight 2025-12-23 10:36:18 +01:00
parent 1008eea2d9
commit bf57fc6b77
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
7 changed files with 640 additions and 270 deletions

View file

@ -26,14 +26,56 @@ function formatEur(cents: number): string {
}
/**
* Format satoshi amount with thousand separators
* Format satoshi amount with styled components
* Leading zeros are subtle, main digits are prominent
*/
function formatSats(sats: number): string {
function SatsDisplay({ sats }: { sats: number }) {
const btc = sats / 100_000_000;
const btcStr = btc.toFixed(8);
const [whole, decimal] = btcStr.split(".");
const grouped = decimal.replace(/(.{2})(.{3})(.{3})/, "$1 $2 $3");
return `${whole}.${grouped}`;
const part1 = decimal.slice(0, 2);
const part2 = decimal.slice(2, 5);
const part3 = decimal.slice(5, 8);
const fullDecimal = part1 + part2 + part3;
let firstNonZero = fullDecimal.length;
for (let i = 0; i < fullDecimal.length; i++) {
if (fullDecimal[i] !== "0") {
firstNonZero = i;
break;
}
}
const subtleStyle: React.CSSProperties = {
opacity: 0.45,
fontWeight: 400,
};
const renderPart = (part: string, startIdx: number) => {
return part.split("").map((char, i) => {
const globalIdx = startIdx + i;
const isSubtle = globalIdx < firstNonZero;
return (
<span key={globalIdx} style={isSubtle ? subtleStyle : undefined}>
{char}
</span>
);
});
};
return (
<span style={{ fontFamily: "'DM Mono', monospace" }}>
<span style={subtleStyle}></span>
<span style={subtleStyle}> {whole}.</span>
{renderPart(part1, 0)}
<span> </span>
{renderPart(part2, 2)}
<span> </span>
{renderPart(part3, 5)}
<span> sats</span>
</span>
);
}
/**
@ -289,7 +331,9 @@ export default function AdminTradesPage() {
</span>
<span style={styles.amount}>{formatEur(trade.eur_amount)}</span>
<span style={styles.arrow}></span>
<span style={styles.satsAmount}>{formatSats(trade.sats_amount)} sats</span>
<span style={styles.satsAmount}>
<SatsDisplay sats={trade.sats_amount} />
</span>
</div>
<div style={styles.rateRow}>