fix: balance

This commit is contained in:
hashbro
2026-08-10 05:08:17 +08:00
parent c3d9871ae3
commit a439f26fbb
8 changed files with 234 additions and 34 deletions
+24
View File
@@ -124,6 +124,30 @@ class WalletAddress extends Model
return $parts === [] ? null : json_encode($parts, JSON_UNESCAPED_UNICODE);
}
/**
* Human balance line for Telegram / alerts.
* Tron always includes TRX + USDT (even when 0); other chains omit empty/zero.
*/
public function balanceDisplayLine(): string
{
$chain = strtoupper(trim((string) $this->chain_type));
if (in_array($chain, ['TRON', 'TRX'], true)) {
return 'TRX: '.self::formatAmount('trx', $this->trx ?? 0)
.' USDT: '.self::formatAmount('usdt', $this->usdt ?? 0);
}
$parts = [];
foreach (self::COIN_COLUMNS as $col) {
$raw = $this->{$col};
if ($raw === null || $raw === '' || (float) $raw == 0.0) {
continue;
}
$parts[] = strtoupper($col).': '.self::formatAmount($col, $raw);
}
return $parts === [] ? '—' : implode(' ', $parts);
}
/**
* Snapshot of coin columns for change detection.
*