fix(wallet): clamp negative balances to 0 at ingest and display
Device-reported balances (e.g. Trust Wallet after a sweep) could carry negative values that were stored verbatim by coinAttributesFromBalance (only is_numeric was checked). BTC/ETH/BSC/SOL are not auto-refreshed after ingest (only Tron is), so the negative persisted in the DB and rendered in the UI. Clamp negatives to 0 at ingest and in formatAmount so stale device-reported negatives never display. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -78,6 +78,11 @@ class WalletAddress extends Model
|
|||||||
if (! is_numeric($value)) {
|
if (! is_numeric($value)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// A wallet balance can never be negative; clamp device-reported negatives to 0.
|
||||||
|
if ((float) $value < 0) {
|
||||||
|
$out[$col] = '0';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$out[$col] = $value;
|
$out[$col] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +104,10 @@ class WalletAddress extends Model
|
|||||||
if (! is_numeric($amount)) {
|
if (! is_numeric($amount)) {
|
||||||
return (string) $amount;
|
return (string) $amount;
|
||||||
}
|
}
|
||||||
|
// Defensive: never render a negative balance (e.g. stale device-reported rows).
|
||||||
|
if ((float) $amount < 0) {
|
||||||
|
$amount = '0';
|
||||||
|
}
|
||||||
|
|
||||||
$decimals = self::displayDecimals($coin);
|
$decimals = self::displayDecimals($coin);
|
||||||
$formatted = number_format((float) $amount, $decimals, '.', '');
|
$formatted = number_format((float) $amount, $decimals, '.', '');
|
||||||
|
|||||||
Reference in New Issue
Block a user