From 10164565ab265da85c7f99ac211d64bd4d6cea8c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 13 Nov 2025 02:24:25 +0000 Subject: [PATCH] fix: Resolve all dart analyze errors and warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed the following issues reported by dart analyze: 🔴 Errors Fixed: - babel_binance_base.dart: Removed dispose() calls for TestnetSpot and TestnetFuturesUsd classes (they don't have dispose methods) ⚠️ Warnings Fixed: - binance_base.dart: Removed unused import 'dart:io' - rate_limiter.dart: Removed unused field '_orderCountResetTime' - token_bucket.dart: Removed unused extension 'clamp' on double - websocket_stream.dart: Added getter for '_lastPongReceived' to expose connection health monitoring Changes: - Removed 2 dispose() calls that were causing errors - Cleaned up unused imports and declarations - Added useful getter lastPongTime for WebSocket health monitoring - All code now passes dart analyze without errors No functionality changes - only code quality improvements. --- lib/src/babel_binance_base.dart | 4 ++-- lib/src/binance_base.dart | 1 - lib/src/rate_limiting/rate_limiter.dart | 2 -- lib/src/rate_limiting/token_bucket.dart | 8 -------- lib/src/websocket/websocket_stream.dart | 3 +++ 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/src/babel_binance_base.dart b/lib/src/babel_binance_base.dart index d3f80fd..5babc5f 100644 --- a/lib/src/babel_binance_base.dart +++ b/lib/src/babel_binance_base.dart @@ -55,8 +55,8 @@ class Binance { spot.market.dispose(); futuresUsd.dispose(); margin.dispose(); - testnetSpot.dispose(); - testnetFutures.dispose(); + // Note: TestnetSpot and TestnetFuturesUsd don't have dispose methods + // as they are composed of sub-classes that handle their own cleanup } } diff --git a/lib/src/binance_base.dart b/lib/src/binance_base.dart index d01c412..bc3807c 100644 --- a/lib/src/binance_base.dart +++ b/lib/src/binance_base.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:io'; import 'dart:async'; import 'package:http/http.dart' as http; import 'package:crypto/crypto.dart'; diff --git a/lib/src/rate_limiting/rate_limiter.dart b/lib/src/rate_limiting/rate_limiter.dart index 576aee2..2260aa7 100644 --- a/lib/src/rate_limiting/rate_limiter.dart +++ b/lib/src/rate_limiting/rate_limiter.dart @@ -19,7 +19,6 @@ class RateLimiter { // Order count tracking int _orderCountToday = 0; - DateTime _orderCountResetTime = DateTime.now(); RateLimiter({ RateLimitConfig? config, @@ -126,7 +125,6 @@ class RateLimiter { /// Reset daily order count void _resetDailyOrderCount() { _orderCountToday = 0; - _orderCountResetTime = DateTime.now(); } /// Get current rate limit status diff --git a/lib/src/rate_limiting/token_bucket.dart b/lib/src/rate_limiting/token_bucket.dart index 832cd97..f861a26 100644 --- a/lib/src/rate_limiting/token_bucket.dart +++ b/lib/src/rate_limiting/token_bucket.dart @@ -81,11 +81,3 @@ class TokenBucket { _lastRefill = DateTime.now(); } } - -extension on double { - double clamp(num min, num max) { - if (this < min) return min.toDouble(); - if (this > max) return max.toDouble(); - return this; - } -} diff --git a/lib/src/websocket/websocket_stream.dart b/lib/src/websocket/websocket_stream.dart index 9333146..4571aaf 100644 --- a/lib/src/websocket/websocket_stream.dart +++ b/lib/src/websocket/websocket_stream.dart @@ -59,6 +59,9 @@ class BinanceWebSocketStream { return DateTime.now().difference(_connectedAt!); } + /// Last time a pong was received (for connection health monitoring) + DateTime? get lastPongTime => _lastPongReceived; + /// Connect to WebSocket Future connect() async { if (_isDisposed) throw StateError('Stream is disposed');