import 'package:flutter/foundation.dart'; import 'package:pweb/models/wallet/wallet_transaction.dart'; import 'package:pweb/services/wallet_transactions.dart'; class WalletTransactionsProvider extends ChangeNotifier { final WalletTransactionsService _service; WalletTransactionsProvider(this._service); List _transactions = const []; bool _isLoading = false; String? _error; String? _walletId; int _loadSeq = 0; List get transactions => List.unmodifiable(_transactions); bool get isLoading => _isLoading; String? get error => _error; String? get walletId => _walletId; Future load({String? walletId}) async { final targetWalletId = walletId ?? _walletId; final requestSeq = ++_loadSeq; _walletId = targetWalletId; _isLoading = true; _error = null; notifyListeners(); try { final fetched = await _service.fetchHistory(walletId: targetWalletId); if (requestSeq != _loadSeq) return; _transactions = targetWalletId == null ? fetched : fetched.where((tx) => tx.walletId == targetWalletId).toList(); } catch (e) { if (requestSeq != _loadSeq) return; _error = e.toString(); } finally { if (requestSeq == _loadSeq) { _isLoading = false; notifyListeners(); } } } }