quote requests are paused while the payout amount is being edited

This commit is contained in:
Arseni
2025-12-30 19:08:53 +03:00
parent c3ec50c8e4
commit d9a605ce21
3 changed files with 36 additions and 4 deletions

View File

@@ -4,9 +4,11 @@ import 'package:flutter/material.dart';
class PaymentAmountProvider with ChangeNotifier { class PaymentAmountProvider with ChangeNotifier {
double _amount = 10.0; double _amount = 10.0;
bool _payerCoversFee = true; bool _payerCoversFee = true;
bool _isEditing = false;
double get amount => _amount; double get amount => _amount;
bool get payerCoversFee => _payerCoversFee; bool get payerCoversFee => _payerCoversFee;
bool get isEditing => _isEditing;
void setAmount(double value) { void setAmount(double value) {
_amount = value; _amount = value;
@@ -17,4 +19,10 @@ class PaymentAmountProvider with ChangeNotifier {
_payerCoversFee = value; _payerCoversFee = value;
notifyListeners(); notifyListeners();
} }
void setEditing(bool value) {
if (_isEditing == value) return;
_isEditing = value;
notifyListeners();
}
} }

View File

@@ -44,6 +44,7 @@ class QuotationProvider extends ChangeNotifier {
Timer? _debounceTimer; Timer? _debounceTimer;
Timer? _expirationTimer; Timer? _expirationTimer;
bool _autoRefreshEnabled = true; bool _autoRefreshEnabled = true;
bool _amountEditing = false;
static const _inputDebounce = Duration(milliseconds: 500); static const _inputDebounce = Duration(milliseconds: 500);
static const _expiryGracePeriod = Duration(seconds: 1); static const _expiryGracePeriod = Duration(seconds: 1);
@@ -58,6 +59,9 @@ class QuotationProvider extends ChangeNotifier {
) { ) {
_organizations = venue; _organizations = venue;
_organizationAttached = true; _organizationAttached = true;
final wasEditing = _amountEditing;
_amountEditing = payment.isEditing;
final editingJustEnded = wasEditing && !_amountEditing;
_pendingIntent = _buildIntent( _pendingIntent = _buildIntent(
payment: payment, payment: payment,
wallets: wallets, wallets: wallets,
@@ -65,6 +69,22 @@ class QuotationProvider extends ChangeNotifier {
recipients: recipients, recipients: recipients,
methods: methods, methods: methods,
); );
if (_pendingIntent == null) {
_reset();
return;
}
if (_amountEditing) {
_debounceTimer?.cancel();
return;
}
if (editingJustEnded) {
refreshNow(force: false);
return;
}
_scheduleQuotationRefresh(); _scheduleQuotationRefresh();
} }

View File

@@ -33,6 +33,7 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
void dispose() { void dispose() {
_focusNode.removeListener(_handleFocusChange); _focusNode.removeListener(_handleFocusChange);
_focusNode.dispose(); _focusNode.dispose();
context.read<PaymentAmountProvider>().setEditing(false);
_controller.dispose(); _controller.dispose();
super.dispose(); super.dispose();
} }
@@ -62,11 +63,13 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
} }
void _handleFocusChange() { void _handleFocusChange() {
if (_focusNode.hasFocus) return; final amountProvider = context.read<PaymentAmountProvider>();
final quotationProvider = context.read<QuotationProvider>(); if (_focusNode.hasFocus) {
if (quotationProvider.canRequestQuote) { amountProvider.setEditing(true);
quotationProvider.refreshNow(force: false); return;
} }
amountProvider.setEditing(false);
} }
@override @override
@@ -83,6 +86,7 @@ class _PaymentAmountWidgetState extends State<PaymentAmountWidget> {
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
), ),
onChanged: _onChanged, onChanged: _onChanged,
onEditingComplete: () => _focusNode.unfocus(),
); );
} }
} }