diff --git a/frontend/pshared/lib/provider/payment/amount.dart b/frontend/pshared/lib/provider/payment/amount.dart index f2cde54..2ddcfc1 100644 --- a/frontend/pshared/lib/provider/payment/amount.dart +++ b/frontend/pshared/lib/provider/payment/amount.dart @@ -4,9 +4,11 @@ import 'package:flutter/material.dart'; class PaymentAmountProvider with ChangeNotifier { double _amount = 10.0; bool _payerCoversFee = true; + bool _isEditing = false; double get amount => _amount; bool get payerCoversFee => _payerCoversFee; + bool get isEditing => _isEditing; void setAmount(double value) { _amount = value; @@ -17,4 +19,10 @@ class PaymentAmountProvider with ChangeNotifier { _payerCoversFee = value; notifyListeners(); } + + void setEditing(bool value) { + if (_isEditing == value) return; + _isEditing = value; + notifyListeners(); + } } diff --git a/frontend/pshared/lib/provider/payment/quotation.dart b/frontend/pshared/lib/provider/payment/quotation.dart index 21aeec4..9bad7e6 100644 --- a/frontend/pshared/lib/provider/payment/quotation.dart +++ b/frontend/pshared/lib/provider/payment/quotation.dart @@ -44,6 +44,7 @@ class QuotationProvider extends ChangeNotifier { Timer? _debounceTimer; Timer? _expirationTimer; bool _autoRefreshEnabled = true; + bool _amountEditing = false; static const _inputDebounce = Duration(milliseconds: 500); static const _expiryGracePeriod = Duration(seconds: 1); @@ -58,6 +59,9 @@ class QuotationProvider extends ChangeNotifier { ) { _organizations = venue; _organizationAttached = true; + final wasEditing = _amountEditing; + _amountEditing = payment.isEditing; + final editingJustEnded = wasEditing && !_amountEditing; _pendingIntent = _buildIntent( payment: payment, wallets: wallets, @@ -65,6 +69,22 @@ class QuotationProvider extends ChangeNotifier { recipients: recipients, methods: methods, ); + + if (_pendingIntent == null) { + _reset(); + return; + } + + if (_amountEditing) { + _debounceTimer?.cancel(); + return; + } + + if (editingJustEnded) { + refreshNow(force: false); + return; + } + _scheduleQuotationRefresh(); } diff --git a/frontend/pweb/lib/pages/dashboard/payouts/amount.dart b/frontend/pweb/lib/pages/dashboard/payouts/amount.dart index a75ebaa..f05b933 100644 --- a/frontend/pweb/lib/pages/dashboard/payouts/amount.dart +++ b/frontend/pweb/lib/pages/dashboard/payouts/amount.dart @@ -33,6 +33,7 @@ class _PaymentAmountWidgetState extends State { void dispose() { _focusNode.removeListener(_handleFocusChange); _focusNode.dispose(); + context.read().setEditing(false); _controller.dispose(); super.dispose(); } @@ -62,11 +63,13 @@ class _PaymentAmountWidgetState extends State { } void _handleFocusChange() { - if (_focusNode.hasFocus) return; - final quotationProvider = context.read(); - if (quotationProvider.canRequestQuote) { - quotationProvider.refreshNow(force: false); + final amountProvider = context.read(); + if (_focusNode.hasFocus) { + amountProvider.setEditing(true); + return; } + + amountProvider.setEditing(false); } @override @@ -83,6 +86,7 @@ class _PaymentAmountWidgetState extends State { border: const OutlineInputBorder(), ), onChanged: _onChanged, + onEditingComplete: () => _focusNode.unfocus(), ); } }