chore(mining-app): remove WebSocket debug logs

移除前端 WebSocket 相关的调试日志

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-18 21:34:07 -08:00
parent c05bcc9a76
commit 94153058d8
2 changed files with 7 additions and 38 deletions

View File

@ -1,5 +1,4 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO; import 'package:socket_io_client/socket_io_client.dart' as IO;
/// ///
@ -75,8 +74,6 @@ class PriceWebSocketService {
/// ///
/// [baseUrl] API https://api.example.com /// [baseUrl] API https://api.example.com
void connect(String baseUrl) { void connect(String baseUrl) {
debugPrint('[PriceWS] 🔌 connect() called with baseUrl: $baseUrl');
// WebSocket URL // WebSocket URL
// https://api.example.com -> wss://api.example.com/ws/price // https://api.example.com -> wss://api.example.com/ws/price
_wsUrl = baseUrl _wsUrl = baseUrl
@ -84,8 +81,6 @@ class PriceWebSocketService {
.replaceFirst('http://', 'ws://'); .replaceFirst('http://', 'ws://');
_wsUrl = '$_wsUrl/ws/price'; _wsUrl = '$_wsUrl/ws/price';
debugPrint('[PriceWS] 🔌 Constructed WebSocket URL: $_wsUrl');
_doConnect(); _doConnect();
} }
@ -96,7 +91,6 @@ class PriceWebSocketService {
} }
_updateStatus(WebSocketStatus.connecting); _updateStatus(WebSocketStatus.connecting);
debugPrint('[PriceWS] Connecting to $_wsUrl');
_socket = IO.io( _socket = IO.io(
_wsUrl, _wsUrl,
@ -111,14 +105,12 @@ class PriceWebSocketService {
); );
_socket!.onConnect((_) { _socket!.onConnect((_) {
debugPrint('[PriceWS] ✅ Connected successfully to $_wsUrl');
_updateStatus(WebSocketStatus.connected); _updateStatus(WebSocketStatus.connected);
_reconnectAttempts = 0; _reconnectAttempts = 0;
_cancelReconnectTimer(); _cancelReconnectTimer();
}); });
_socket!.onDisconnect((reason) { _socket!.onDisconnect((_) {
debugPrint('[PriceWS] ❌ Disconnected, reason: $reason');
_updateStatus(WebSocketStatus.disconnected); _updateStatus(WebSocketStatus.disconnected);
// //
if (_status != WebSocketStatus.disconnected) { if (_status != WebSocketStatus.disconnected) {
@ -126,31 +118,26 @@ class PriceWebSocketService {
} }
}); });
_socket!.onConnectError((error) { _socket!.onConnectError((_) {
debugPrint('[PriceWS] ❌ Connect error: $error');
debugPrint('[PriceWS] URL was: $_wsUrl');
_updateStatus(WebSocketStatus.disconnected); _updateStatus(WebSocketStatus.disconnected);
_scheduleReconnect(); _scheduleReconnect();
}); });
_socket!.onError((error) { _socket!.onError((_) {
debugPrint('[PriceWS] ⚠️ Socket error: $error'); //
}); });
//
_socket!.onConnectTimeout((_) { _socket!.onConnectTimeout((_) {
debugPrint('[PriceWS] ⏰ Connection timeout'); //
}); });
// //
_socket!.on('priceUpdate', (data) { _socket!.on('priceUpdate', (data) {
try { try {
debugPrint('[PriceWS] 📊 Received price update: $data');
final update = PriceUpdate.fromJson(data as Map<String, dynamic>); final update = PriceUpdate.fromJson(data as Map<String, dynamic>);
debugPrint('[PriceWS] 📊 Parsed: price=${update.price}, burnMultiplier=${update.burnMultiplier}');
_priceUpdateController.add(update); _priceUpdateController.add(update);
} catch (e) { } catch (_) {
debugPrint('[PriceWS] ❌ Parse error: $e, data: $data'); //
} }
}); });
@ -161,20 +148,16 @@ class PriceWebSocketService {
/// ///
/// ///
void disconnect() { void disconnect() {
debugPrint('[PriceWS] 🔌 disconnect() called, current status: $_status');
_cancelReconnectTimer(); _cancelReconnectTimer();
_reconnectAttempts = 0; _reconnectAttempts = 0;
if (_socket != null) { if (_socket != null) {
debugPrint('[PriceWS] 🔌 Disposing socket...');
_socket!.disconnect(); _socket!.disconnect();
_socket!.dispose(); _socket!.dispose();
_socket = null; _socket = null;
debugPrint('[PriceWS] 🔌 Socket disposed');
} }
_updateStatus(WebSocketStatus.disconnected); _updateStatus(WebSocketStatus.disconnected);
debugPrint('[PriceWS] 🔌 Disconnect complete');
} }
/// ///
@ -183,7 +166,6 @@ class PriceWebSocketService {
/// ///
void _scheduleReconnect() { void _scheduleReconnect() {
if (_reconnectAttempts >= _maxReconnectAttempts) { if (_reconnectAttempts >= _maxReconnectAttempts) {
debugPrint('[PriceWS] Max reconnect attempts reached');
return; return;
} }
@ -200,7 +182,6 @@ class PriceWebSocketService {
); );
_reconnectAttempts++; _reconnectAttempts++;
debugPrint('[PriceWS] Reconnect attempt $_reconnectAttempts in ${delay.inSeconds}s');
_reconnectTimer = Timer(delay, () { _reconnectTimer = Timer(delay, () {
if (_status != WebSocketStatus.connected) { if (_status != WebSocketStatus.connected) {

View File

@ -48,15 +48,11 @@ class _AssetPageState extends ConsumerState<AssetPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
debugPrint('[AssetPage] 📱 initState - connecting WebSocket');
// WebSocket
_connectWebSocket(); _connectWebSocket();
} }
@override @override
void dispose() { void dispose() {
debugPrint('[AssetPage] 📱 dispose - disconnecting WebSocket');
// WebSocket
_disconnectWebSocket(); _disconnectWebSocket();
_refreshTimer?.cancel(); _refreshTimer?.cancel();
super.dispose(); super.dispose();
@ -64,33 +60,25 @@ class _AssetPageState extends ConsumerState<AssetPage> {
/// WebSocket /// WebSocket
void _connectWebSocket() { void _connectWebSocket() {
debugPrint('[AssetPage] 🔌 _connectWebSocket called');
final wsService = PriceWebSocketService.instance; final wsService = PriceWebSocketService.instance;
// 使 AppConstants baseUrl
debugPrint('[AssetPage] 🔌 Using baseUrl: ${AppConstants.baseUrl}');
wsService.connect(AppConstants.baseUrl); wsService.connect(AppConstants.baseUrl);
// //
_priceSubscription = wsService.priceUpdates.listen((update) { _priceSubscription = wsService.priceUpdates.listen((update) {
debugPrint('[AssetPage] 📊 Received price update: price=${update.price}, multiplier=${update.burnMultiplier}');
if (mounted) { if (mounted) {
setState(() { setState(() {
_currentPrice = update.price; _currentPrice = update.price;
_currentBurnMultiplier = update.burnMultiplier; _currentBurnMultiplier = update.burnMultiplier;
}); });
debugPrint('[AssetPage] 📊 State updated: _currentPrice=$_currentPrice, _currentBurnMultiplier=$_currentBurnMultiplier');
} }
}); });
debugPrint('[AssetPage] 🔌 WebSocket listener attached');
} }
/// WebSocket /// WebSocket
void _disconnectWebSocket() { void _disconnectWebSocket() {
debugPrint('[AssetPage] 🔌 _disconnectWebSocket called');
_priceSubscription?.cancel(); _priceSubscription?.cancel();
_priceSubscription = null; _priceSubscription = null;
PriceWebSocketService.instance.disconnect(); PriceWebSocketService.instance.disconnect();
debugPrint('[AssetPage] 🔌 WebSocket disconnected');
} }
/// 使 /// 使