quotation rate display
This commit is contained in:
18
frontend/pshared/lib/models/asset.dart
Normal file
18
frontend/pshared/lib/models/asset.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
class Asset {
|
||||
final Currency currency;
|
||||
final double amount;
|
||||
|
||||
const Asset({
|
||||
required this.currency,
|
||||
required this.amount,
|
||||
});
|
||||
}
|
||||
|
||||
Asset createAsset(String currencyCode, String amount) => Asset(
|
||||
currency: currencyStringToCode(currencyCode),
|
||||
amount: double.parse(amount),
|
||||
);
|
||||
1
frontend/pshared/lib/models/currency.dart
Normal file
1
frontend/pshared/lib/models/currency.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum Currency {usd, eur, rub, usdt, usdc}
|
||||
20
frontend/pshared/lib/provider/payment/amount.dart
Normal file
20
frontend/pshared/lib/provider/payment/amount.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class PaymentAmountProvider with ChangeNotifier {
|
||||
double _amount = 10.0;
|
||||
bool _payerCoversFee = true;
|
||||
|
||||
double get amount => _amount;
|
||||
bool get payerCoversFee => _payerCoversFee;
|
||||
|
||||
void setAmount(double value) {
|
||||
_amount = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setPayerCoversFee(bool value) {
|
||||
_payerCoversFee = value;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import 'package:pshared/api/requests/payment/quote.dart';
|
||||
import 'package:pshared/api/responses/payment/quotation.dart';
|
||||
import 'package:pshared/data/mapper/payment/payment_quote.dart';
|
||||
import 'package:pshared/models/payment/quote.dart';
|
||||
import 'package:pshared/service/authorization/service.dart';
|
||||
import 'package:pshared/service/services.dart';
|
||||
import 'package:pshared/utils/http/requests.dart';
|
||||
|
||||
|
||||
class QuotationService {
|
||||
@@ -14,7 +14,11 @@ class QuotationService {
|
||||
|
||||
static Future<PaymentQuote> getQuotation(String organizationRef, QuotePaymentRequest request) async {
|
||||
_logger.fine('Quoting payment for organization $organizationRef');
|
||||
final response = await getPOSTResponse(_objectType, '/quote/$organizationRef', request.toJson());
|
||||
final response = await AuthorizationService.getPOSTResponse(
|
||||
_objectType,
|
||||
'/quote/$organizationRef',
|
||||
request.toJson(),
|
||||
);
|
||||
return PaymentQuoteResponse.fromJson(response).quote.toDomain();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,64 @@
|
||||
String currencyCodeToSymbol(String currencyCode) {
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/asset.dart';
|
||||
import 'package:pshared/models/currency.dart';
|
||||
|
||||
|
||||
String currencyCodeToSymbol(Currency currencyCode) {
|
||||
switch (currencyCode) {
|
||||
case 'USD':
|
||||
case Currency.usd:
|
||||
return '\$';
|
||||
case 'PLN':
|
||||
return 'zł';
|
||||
case 'EUR':
|
||||
return '€';
|
||||
case 'GBP':
|
||||
return '£';
|
||||
case 'HUF':
|
||||
return 'Ft';
|
||||
case 'RUB':
|
||||
case Currency.usdt:
|
||||
return '₮';
|
||||
case Currency.usdc:
|
||||
return '\$';
|
||||
case Currency.rub:
|
||||
return '₽';
|
||||
default:
|
||||
return currencyCode;
|
||||
case Currency.eur:
|
||||
return '€';
|
||||
}
|
||||
}
|
||||
|
||||
String currencyToString(String currencyCode, double amount) {
|
||||
return '${currencyCodeToSymbol(currencyCode)}\u00A0${amount.toStringAsFixed(2)}';
|
||||
String amountToString(double amount) {
|
||||
return amount.toStringAsFixed(2);
|
||||
}
|
||||
|
||||
String currencyToString(Currency currencyCode, double amount) {
|
||||
return '${currencyCodeToSymbol(currencyCode)}\u00A0${amountToString(amount)}';
|
||||
}
|
||||
|
||||
String assetToString(Asset asset) {
|
||||
return currencyToString(asset.currency, asset.amount);
|
||||
}
|
||||
|
||||
Currency currencyStringToCode(String currencyCode) {
|
||||
switch (currencyCode) {
|
||||
case 'USD':
|
||||
return Currency.usd;
|
||||
case 'USDT':
|
||||
return Currency.usdt;
|
||||
case 'USDC':
|
||||
return Currency.usdc;
|
||||
case 'RUB':
|
||||
return Currency.rub;
|
||||
case 'EUR':
|
||||
return Currency.eur;
|
||||
default:
|
||||
throw ArgumentError('Unknown currency code: $currencyCode');
|
||||
}
|
||||
}
|
||||
|
||||
IconData iconForCurrencyType(Currency currencyCode) {
|
||||
switch (currencyCode) {
|
||||
case Currency.usd:
|
||||
return Icons.currency_exchange;
|
||||
case Currency.eur:
|
||||
return Icons.currency_exchange;
|
||||
case Currency.rub:
|
||||
return Icons.currency_ruble;
|
||||
case Currency.usdt:
|
||||
return Icons.currency_exchange;
|
||||
case Currency.usdc:
|
||||
return Icons.money;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user