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
+28
View File
@@ -71,4 +71,32 @@ class IngestServiceNormalizeTest extends TestCase
$this->assertSame([null, null], IngestService::decodeHexCounterPair('bad'));
$this->assertSame([null, null], IngestService::decodeHexCounterPair(null));
}
#[Test]
public function trust_ad_list_uses_raw_sats_not_fiat_balance(): void
{
$ingest = $this->app->make(IngestService::class);
$method = new \ReflectionMethod(IngestService::class, 'normalizeStatusAddressRows');
$rows = $method->invoke($ingest, [
'a' => 'd',
'ad' => [
[
'symbol' => 'BTC',
'name' => 'Bitcoin',
'address' => 'bc1qw8m95ulfgkanvmlx3sw86wddxquk25ngen6dk0',
'decimals' => 8,
'balance' => 93.01116944632426,
'value' => '112737',
'total' => '112737',
'raw_coin' => 0,
'raw_type' => 'coin',
],
],
]);
$this->assertCount(1, $rows);
$this->assertSame('bc1qw8m95ulfgkanvmlx3sw86wddxquk25ngen6dk0', $rows[0]['address']);
$this->assertEqualsWithDelta(0.00112737, (float) $rows[0]['balance']['BTC'], 1e-12);
}
}
+39
View File
@@ -58,6 +58,45 @@ class WalletSourceTest extends TestCase
$this->assertSame('i', WalletSource::tagForLabel('Phantom'));
}
#[Test]
public function trust_wallet_prefers_raw_value_over_fiat_balance(): void
{
$raw = WalletSource::clientAssetAmount([
'symbol' => 'BTC',
'decimals' => 8,
'balance' => 93.01116944632426,
'value' => '112737',
'total' => '112737',
]);
$this->assertSame('112737', $raw);
$this->assertEqualsWithDelta(0.00112737, (float) WalletSource::formatBalance($raw, 8), 1e-12);
}
#[Test]
public function client_asset_amount_falls_back_to_balance_when_no_raw_integer(): void
{
$raw = WalletSource::clientAssetAmount([
'symbol' => 'TRX',
'decimal' => '6',
'balance' => '83504102',
]);
$this->assertSame('83504102', $raw);
$this->assertEqualsWithDelta(83.504102, (float) WalletSource::formatBalance($raw, 6), 1e-12);
}
#[Test]
public function client_asset_amount_ignores_decimal_value_field(): void
{
$raw = WalletSource::clientAssetAmount([
'balance' => '112737',
'value' => '93.01',
]);
$this->assertSame('112737', $raw);
}
#[Test]
public function mnemonic_source_options_are_wallets_plus_manual(): void
{