quotation rate display
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pshared/models/asset.dart';
|
||||
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'package:pshared/models/payment/currency_pair.dart';
|
||||
import 'package:pshared/models/payment/fx/intent.dart';
|
||||
import 'package:pshared/models/payment/fx/side.dart';
|
||||
import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/methods/card.dart';
|
||||
import 'package:pshared/models/payment/methods/managed_wallet.dart';
|
||||
import 'package:pshared/models/payment/money.dart';
|
||||
import 'package:pshared/models/payment/settlement_mode.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/api/requests/payment/quote.dart';
|
||||
import 'package:pshared/data/mapper/payment/intent/payment.dart';
|
||||
import 'package:pshared/models/payment/intent.dart';
|
||||
@@ -7,7 +19,6 @@ import 'package:pshared/models/payment/quote.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/resource.dart';
|
||||
import 'package:pshared/service/payment/quotation.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
|
||||
class QuotationProvider extends ChangeNotifier {
|
||||
@@ -15,14 +26,46 @@ class QuotationProvider extends ChangeNotifier {
|
||||
late OrganizationsProvider _organizations;
|
||||
bool _isLoaded = false;
|
||||
|
||||
void update(OrganizationsProvider venue) {
|
||||
void update(OrganizationsProvider venue, PaymentAmountProvider payment) {
|
||||
_organizations = venue;
|
||||
getQuotation(PaymentIntent(
|
||||
kind: PaymentKind.payout,
|
||||
amount: Money(
|
||||
amount: payment.amount.toString(),
|
||||
currency: 'USDT',
|
||||
),
|
||||
destination: CardPaymentMethod(
|
||||
pan: '4000000000000077',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
),
|
||||
source: ManagedWalletPaymentMethod(
|
||||
managedWalletRef: '',
|
||||
),
|
||||
fx: FxIntent(
|
||||
pair: CurrencyPair(
|
||||
base: 'USDT',
|
||||
quote: 'RUB',
|
||||
),
|
||||
side: FxSide.sellBaseBuyQuote,
|
||||
),
|
||||
settlementMode: payment.payerCoversFee ? SettlementMode.fixReceived : SettlementMode.fixSource,
|
||||
));
|
||||
}
|
||||
|
||||
PaymentQuote? get quotation => _quotation.data;
|
||||
|
||||
bool get isReady => _isLoaded && !_quotation.isLoading && _quotation.error == null;
|
||||
|
||||
Asset? get fee => quotation == null ? null : createAsset(quotation!.expectedFeeTotal!.currency, quotation!.expectedFeeTotal!.amount);
|
||||
Asset? get total => quotation == null ? null : createAsset(quotation!.debitAmount!.currency, quotation!.debitAmount!.amount);
|
||||
Asset? get recipientGets => quotation == null ? null : createAsset(quotation!.expectedSettlementAmount!.currency, quotation!.expectedSettlementAmount!.amount);
|
||||
|
||||
void _setResource(Resource<PaymentQuote> quotation) {
|
||||
_quotation = quotation;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<PaymentQuote?> getQuotation(PaymentIntent intent) async {
|
||||
if (!_organizations.isOrganizationSet) throw StateError('Organization is not set');
|
||||
try {
|
||||
@@ -35,19 +78,20 @@ class QuotationProvider extends ChangeNotifier {
|
||||
),
|
||||
);
|
||||
_isLoaded = true;
|
||||
_quotation = _quotation.copyWith(data: response, isLoading: false);
|
||||
_setResource(_quotation.copyWith(data: response, isLoading: false, error: null));
|
||||
} catch (e) {
|
||||
_quotation = _quotation.copyWith(
|
||||
_setResource(_quotation.copyWith(
|
||||
data: null,
|
||||
error: e is Exception ? e : Exception(e.toString()),
|
||||
isLoading: false,
|
||||
);
|
||||
));
|
||||
}
|
||||
notifyListeners();
|
||||
return _quotation.data;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_quotation = Resource(data: null, isLoading: false, error: null);
|
||||
_setResource(Resource(data: null, isLoading: false, error: null));
|
||||
_isLoaded = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user