fix for quote and operations addition
This commit is contained in:
@@ -12,6 +12,7 @@ import 'package:pshared/api/requests/payment/quote.dart';
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/data/mapper/payment/intent/payment.dart';
|
||||
import 'package:pshared/models/payment/intent.dart';
|
||||
import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/quote/quote.dart';
|
||||
import 'package:pshared/models/auto_refresh_mode.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
@@ -52,13 +53,17 @@ class QuotationProvider extends ChangeNotifier {
|
||||
) {
|
||||
_organizations = venue;
|
||||
_sourceCurrencyCode = source.selectedCurrencyCode;
|
||||
final intent = _intentBuilder.build(
|
||||
final builtIntent = _intentBuilder.build(
|
||||
payment: payment,
|
||||
source: source,
|
||||
flow: flow,
|
||||
recipients: recipients,
|
||||
);
|
||||
if (intent == null) return;
|
||||
if (!_isQuotable(builtIntent)) {
|
||||
_clearQuotation();
|
||||
return;
|
||||
}
|
||||
final intent = builtIntent!;
|
||||
final intentKey = _buildIntentKey(intent);
|
||||
final lastIntent = _lastIntent;
|
||||
if (lastIntent != null && intentKey == _buildIntentKey(lastIntent)) return;
|
||||
@@ -100,12 +105,19 @@ class QuotationProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<PaymentQuote?> refreshQuotation() async {
|
||||
final intent = _lastIntent;
|
||||
if (intent == null) return null;
|
||||
return getQuotation(intent);
|
||||
final lastIntent = _lastIntent;
|
||||
if (!_isQuotable(lastIntent)) {
|
||||
_clearQuotation();
|
||||
return null;
|
||||
}
|
||||
return getQuotation(lastIntent!);
|
||||
}
|
||||
|
||||
Future<PaymentQuote?> getQuotation(PaymentIntent intent) async {
|
||||
if (!_isQuotable(intent)) {
|
||||
_clearQuotation();
|
||||
return null;
|
||||
}
|
||||
if (!_organizations.isOrganizationSet) {
|
||||
throw StateError('Organization is not set');
|
||||
}
|
||||
@@ -138,8 +150,20 @@ class QuotationProvider extends ChangeNotifier {
|
||||
|
||||
void reset() {
|
||||
_isLoaded = false;
|
||||
_lastIntent = null;
|
||||
_sourceCurrencyCode = null;
|
||||
_clearQuotation();
|
||||
}
|
||||
|
||||
bool _isQuotable(PaymentIntent? intent) {
|
||||
if (intent == null) return false;
|
||||
if (intent.kind == PaymentKind.unspecified) return false;
|
||||
if (intent.source == null) return false;
|
||||
if (intent.destination == null) return false;
|
||||
return intent.amount != null;
|
||||
}
|
||||
|
||||
void _clearQuotation() {
|
||||
_lastIntent = null;
|
||||
_setResource(Resource(data: null, isLoading: false, error: null));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user