small fixes
This commit is contained in:
@@ -24,6 +24,7 @@ import 'package:pweb/app/router/payout_routes.dart';
|
||||
import 'package:pweb/controllers/multiple_payouts.dart';
|
||||
import 'package:pweb/controllers/payment_page.dart';
|
||||
import 'package:pweb/providers/multiple_payouts.dart';
|
||||
import 'package:pweb/controllers/multi_quotation.dart';
|
||||
import 'package:pweb/providers/quotation/quotation.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pweb/pages/address_book/form/page.dart';
|
||||
@@ -44,6 +45,7 @@ import 'package:pweb/services/payments/csv_input.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
RouteBase payoutShellRoute() => ShellRoute(
|
||||
builder: (context, state, child) => MultiProvider(
|
||||
providers: [
|
||||
@@ -138,6 +140,13 @@ RouteBase payoutShellRoute() => ShellRoute(
|
||||
update: (context, organization, provider) =>
|
||||
provider!..update(organization),
|
||||
),
|
||||
ChangeNotifierProxyProvider<
|
||||
MultiQuotationProvider,
|
||||
MultiQuotationController
|
||||
>(
|
||||
create: (_) => MultiQuotationController(),
|
||||
update: (_, quotation, controller) => controller!..update(quotation),
|
||||
),
|
||||
ChangeNotifierProxyProvider2<
|
||||
OrganizationsProvider,
|
||||
MultiQuotationProvider,
|
||||
|
||||
70
frontend/pweb/lib/controllers/multi_quotation.dart
Normal file
70
frontend/pweb/lib/controllers/multi_quotation.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pshared/provider/payment/multiple/quotation.dart';
|
||||
|
||||
import 'package:pweb/providers/quotation/auto_refresh.dart';
|
||||
|
||||
|
||||
class MultiQuotationController extends ChangeNotifier {
|
||||
static const Duration _autoRefreshLead = Duration(seconds: 5);
|
||||
|
||||
MultiQuotationProvider? _quotation;
|
||||
final QuotationAutoRefreshController _autoRefreshController =
|
||||
QuotationAutoRefreshController();
|
||||
|
||||
void update(MultiQuotationProvider quotation) {
|
||||
if (identical(_quotation, quotation)) return;
|
||||
_quotation?.removeListener(_handleQuotationChanged);
|
||||
_quotation = quotation;
|
||||
_quotation?.addListener(_handleQuotationChanged);
|
||||
_handleQuotationChanged();
|
||||
}
|
||||
|
||||
bool get isLoading => _quotation?.isLoading ?? false;
|
||||
Exception? get error => _quotation?.error;
|
||||
bool get canRefresh => _quotation?.canRefresh ?? false;
|
||||
bool get isReady => _quotation?.isReady ?? false;
|
||||
|
||||
DateTime? get quoteExpiresAt => _quotation?.quoteExpiresAt;
|
||||
|
||||
void refreshQuotation() {
|
||||
_quotation?.refreshQuotation();
|
||||
}
|
||||
|
||||
void _handleQuotationChanged() {
|
||||
_syncAutoRefresh();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _syncAutoRefresh() {
|
||||
final quotation = _quotation;
|
||||
if (quotation == null) {
|
||||
_autoRefreshController.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
final expiresAt = quoteExpiresAt;
|
||||
final scheduledAt = expiresAt == null
|
||||
? null
|
||||
: expiresAt.subtract(_autoRefreshLead);
|
||||
|
||||
_autoRefreshController.setEnabled(true);
|
||||
_autoRefreshController.sync(
|
||||
isLoading: quotation.isLoading,
|
||||
canRefresh: quotation.canRefresh,
|
||||
expiresAt: scheduledAt,
|
||||
onRefresh: _refreshQuotation,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _refreshQuotation() async {
|
||||
await _quotation?.refreshQuotation();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_quotation?.removeListener(_handleQuotationChanged);
|
||||
_autoRefreshController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user