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:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user