small fixes

This commit is contained in:
Arseni
2026-02-11 15:26:11 +03:00
parent edb43f9909
commit 0a1e04d0d6
7 changed files with 138 additions and 53 deletions

View File

@@ -1,5 +1,3 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:uuid/uuid.dart';
@@ -23,9 +21,6 @@ class MultiQuotationProvider extends ChangeNotifier {
List<PaymentIntent>? _lastIntents;
bool _lastPreviewOnly = false;
Map<String, String>? _lastMetadata;
Timer? _autoRefreshTimer;
static const Duration _autoRefreshLead = Duration(seconds: 5);
Resource<PaymentQuotes> get resource => _quotation;
PaymentQuotes? get quotation => _quotation.data;
@@ -86,7 +81,6 @@ class MultiQuotationProvider extends ChangeNotifier {
? null
: Map<String, String>.from(metadata);
_cancelAutoRefresh();
_setResource(_quotation.copyWith(isLoading: true, error: null));
try {
final response = await MultiplePaymentsService.getQuotation(
@@ -102,7 +96,6 @@ class MultiQuotationProvider extends ChangeNotifier {
_setResource(
_quotation.copyWith(data: response, isLoading: false, error: null),
);
_scheduleAutoRefresh();
} catch (e) {
_setResource(
_quotation.copyWith(
@@ -131,7 +124,6 @@ class MultiQuotationProvider extends ChangeNotifier {
_lastIntents = null;
_lastPreviewOnly = false;
_lastMetadata = null;
_cancelAutoRefresh();
_quotation = Resource(data: null);
notifyListeners();
}
@@ -141,36 +133,8 @@ class MultiQuotationProvider extends ChangeNotifier {
notifyListeners();
}
void _scheduleAutoRefresh() {
_autoRefreshTimer?.cancel();
final expiresAt = quoteExpiresAt;
if (expiresAt == null) return;
final now = DateTime.now().toUtc();
var delay = expiresAt.difference(now) - _autoRefreshLead;
if (delay.isNegative) delay = Duration.zero;
_autoRefreshTimer = Timer(delay, _triggerAutoRefresh);
}
Future<void> _triggerAutoRefresh() async {
if (_quotation.isLoading) return;
final intents = _lastIntents;
if (intents == null || intents.isEmpty) return;
await quotePayments(
intents,
previewOnly: _lastPreviewOnly,
metadata: _lastMetadata,
);
}
void _cancelAutoRefresh() {
_autoRefreshTimer?.cancel();
_autoRefreshTimer = null;
}
@override
void dispose() {
_cancelAutoRefresh();
super.dispose();
}
}