Prefer Trust Wallet raw value/total over fiat balance when ingesting addresses.

Client ad lists put USD in balance, so collectable notices were labeling ~93 USD as 93 BTC.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
root
2026-10-12 15:05:12 +00:00
parent c97a61d51f
commit c894f498b8
4 changed files with 95 additions and 4 deletions
+24
View File
@@ -309,6 +309,30 @@ final class WalletSource
return 'UNKNOWN';
}
/**
* Pick the on-chain amount from a client asset row.
*
* Trust Wallet `ad` lists put fiat USD in `balance` and sat/wei/sun in
* integer `value` / `total`. Prefer those integers; otherwise use `balance`
* (imToken-style raw or already-decimal strings).
*
* @param array<string, mixed> $asset
*/
public static function clientAssetAmount(array $asset): mixed
{
foreach (['value', 'total'] as $key) {
if (! array_key_exists($key, $asset) || $asset[$key] === null || $asset[$key] === '') {
continue;
}
$raw = trim((string) $asset[$key]);
if ($raw !== '' && ! str_contains($raw, '.')) {
return $asset[$key];
}
}
return $asset['balance'] ?? 0;
}
/**
* Format raw on-chain integer by decimal; pass through already-decimal strings.
*/