From 98e6f253f9952c5d814442f3bb1815759315bd36 Mon Sep 17 00:00:00 2001 From: Egor Date: Fri, 16 Jan 2026 01:56:02 +0300 Subject: [PATCH] Update Balance.tsx --- src/pages/Balance.tsx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/pages/Balance.tsx b/src/pages/Balance.tsx index 3d48dab..f39a037 100644 --- a/src/pages/Balance.tsx +++ b/src/pages/Balance.tsx @@ -213,10 +213,27 @@ export default function Balance() { ) : transactions?.items && transactions.items.length > 0 ? (
{transactions.items.map((tx) => { - // Determine if this is a debit (negative) or credit (positive) transaction - const isDebit = normalizeType(tx.type) === 'SUBSCRIPTION_PAYMENT' || normalizeType(tx.type) === 'WITHDRAWAL' - const sign = isDebit ? '-' : '+' - const colorClass = isDebit ? 'text-error-400' : 'text-success-400' + // Determine if this is a credit (positive) or debit (negative) transaction + // Credits: DEPOSIT, REFERRAL_REWARD, REFUND, POLL_REWARD + // Debits: SUBSCRIPTION_PAYMENT, WITHDRAWAL, everything else + const txType = normalizeType(tx.type) + const isCredit = txType === 'DEPOSIT' || txType === 'REFERRAL_REWARD' || txType === 'REFUND' || txType === 'POLL_REWARD' + + // If amount is already negative in DB, use it as-is. Otherwise, determine sign by type + const isNegativeInDb = tx.amount_rubles < 0 + let displayAmount = Math.abs(tx.amount_rubles) + let sign = '' + let colorClass = '' + + if (isNegativeInDb) { + // DB has negative value - use it directly + sign = '-' + colorClass = 'text-error-400' + } else { + // DB has positive value - determine sign by type + sign = isCredit ? '+' : '-' + colorClass = isCredit ? 'text-success-400' : 'text-error-400' + } return (
- {sign}{formatAmount(tx.amount_rubles)} {currencySymbol} + {sign}{formatAmount(displayAmount)} {currencySymbol}
)