multiple payout page and small fixes

This commit is contained in:
Arseni
2026-02-11 02:48:30 +03:00
parent 66989ea36c
commit edb43f9909
77 changed files with 2120 additions and 1289 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:uuid/uuid.dart';
@@ -17,11 +19,13 @@ class MultiQuotationProvider extends ChangeNotifier {
String? _loadedOrganizationRef;
Resource<PaymentQuotes> _quotation = Resource(data: null);
bool _isLoaded = false;
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;
@@ -29,7 +33,7 @@ class MultiQuotationProvider extends ChangeNotifier {
Exception? get error => _quotation.error;
bool get canRefresh => _lastIntents != null && _lastIntents!.isNotEmpty;
bool get isReady =>
_isLoaded && !_quotation.isLoading && _quotation.error == null;
quotation != null && !_quotation.isLoading && _quotation.error == null;
DateTime? get quoteExpiresAt {
final quotes = quotation?.quotes;
@@ -82,6 +86,7 @@ class MultiQuotationProvider extends ChangeNotifier {
? null
: Map<String, String>.from(metadata);
_cancelAutoRefresh();
_setResource(_quotation.copyWith(isLoading: true, error: null));
try {
final response = await MultiplePaymentsService.getQuotation(
@@ -94,10 +99,10 @@ class MultiQuotationProvider extends ChangeNotifier {
),
);
_isLoaded = true;
_setResource(
_quotation.copyWith(data: response, isLoading: false, error: null),
);
_scheduleAutoRefresh();
} catch (e) {
_setResource(
_quotation.copyWith(
@@ -123,10 +128,10 @@ class MultiQuotationProvider extends ChangeNotifier {
}
void reset() {
_isLoaded = false;
_lastIntents = null;
_lastPreviewOnly = false;
_lastMetadata = null;
_cancelAutoRefresh();
_quotation = Resource(data: null);
notifyListeners();
}
@@ -135,4 +140,37 @@ class MultiQuotationProvider extends ChangeNotifier {
_quotation = quotation;
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();
}
}