fixes
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:pshared/data/dto/payment/operation.dart';
|
||||
import 'package:pshared/data/dto/payment/intent/payment.dart';
|
||||
import 'package:pshared/data/dto/payment/payment_quote.dart';
|
||||
import 'package:pshared/data/dto/payment/response_endpoint.dart';
|
||||
|
||||
part 'payment.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class PaymentDTO {
|
||||
final String? paymentRef;
|
||||
@@ -15,7 +15,6 @@ class PaymentDTO {
|
||||
final PaymentResponseEndpointDTO? destination;
|
||||
final String? failureCode;
|
||||
final String? failureReason;
|
||||
final PaymentIntentDTO? intent;
|
||||
final List<PaymentOperationDTO> operations;
|
||||
final PaymentQuoteDTO? lastQuote;
|
||||
final Map<String, String>? metadata;
|
||||
@@ -28,7 +27,6 @@ class PaymentDTO {
|
||||
this.destination,
|
||||
this.failureCode,
|
||||
this.failureReason,
|
||||
this.intent,
|
||||
this.operations = const <PaymentOperationDTO>[],
|
||||
this.lastQuote,
|
||||
this.metadata,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'package:pshared/data/dto/payment/payment.dart';
|
||||
import 'package:pshared/data/mapper/payment/intent/payment.dart';
|
||||
import 'package:pshared/data/mapper/payment/operation.dart';
|
||||
import 'package:pshared/data/mapper/payment/quote.dart';
|
||||
import 'package:pshared/data/mapper/payment/response_endpoint.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/state.dart';
|
||||
|
||||
|
||||
extension PaymentDTOMapper on PaymentDTO {
|
||||
Payment toDomain() => Payment(
|
||||
paymentRef: paymentRef,
|
||||
@@ -15,7 +15,6 @@ extension PaymentDTOMapper on PaymentDTO {
|
||||
orchestrationState: paymentOrchestrationStateFromValue(state),
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
intent: intent?.toDomain(),
|
||||
operations: operations.map((item) => item.toDomain()).toList(),
|
||||
lastQuote: lastQuote?.toDomain(),
|
||||
metadata: metadata,
|
||||
@@ -31,7 +30,6 @@ extension PaymentMapper on Payment {
|
||||
destination: destination?.toDTO(),
|
||||
failureCode: failureCode,
|
||||
failureReason: failureReason,
|
||||
intent: intent?.toDTO(),
|
||||
operations: operations.map((item) => item.toDTO()).toList(),
|
||||
lastQuote: lastQuote?.toDTO(),
|
||||
metadata: metadata,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:pshared/models/payment/endpoint.dart';
|
||||
import 'package:pshared/models/payment/execution_operation.dart';
|
||||
import 'package:pshared/models/payment/intent.dart';
|
||||
import 'package:pshared/models/payment/quote/quote.dart';
|
||||
import 'package:pshared/models/payment/state.dart';
|
||||
|
||||
|
||||
class Payment {
|
||||
final String? paymentRef;
|
||||
final String? state;
|
||||
@@ -12,7 +12,6 @@ class Payment {
|
||||
final PaymentOrchestrationState orchestrationState;
|
||||
final String? failureCode;
|
||||
final String? failureReason;
|
||||
final PaymentIntent? intent;
|
||||
final List<PaymentExecutionOperation> operations;
|
||||
final PaymentQuote? lastQuote;
|
||||
final Map<String, String>? metadata;
|
||||
@@ -26,7 +25,6 @@ class Payment {
|
||||
required this.orchestrationState,
|
||||
required this.failureCode,
|
||||
required this.failureReason,
|
||||
this.intent,
|
||||
required this.operations,
|
||||
required this.lastQuote,
|
||||
required this.metadata,
|
||||
|
||||
@@ -4,6 +4,16 @@ import 'package:pshared/models/asset.dart';
|
||||
import 'package:pshared/models/currency.dart';
|
||||
|
||||
|
||||
const nonBreakingSpace = '\u00A0';
|
||||
|
||||
String withTrailingNonBreakingSpace(String value) {
|
||||
return '$value$nonBreakingSpace';
|
||||
}
|
||||
|
||||
String joinWithNonBreakingSpace(String left, String right) {
|
||||
return '$left$nonBreakingSpace$right';
|
||||
}
|
||||
|
||||
String currencyCodeToSymbol(Currency currencyCode) {
|
||||
switch (currencyCode) {
|
||||
case Currency.usd:
|
||||
@@ -24,7 +34,10 @@ String amountToString(double amount) {
|
||||
}
|
||||
|
||||
String currencyToString(Currency currencyCode, double amount) {
|
||||
return '${currencyCodeToSymbol(currencyCode)}\u00A0${amountToString(amount)}';
|
||||
return joinWithNonBreakingSpace(
|
||||
currencyCodeToSymbol(currencyCode),
|
||||
amountToString(amount),
|
||||
);
|
||||
}
|
||||
|
||||
String assetToString(Asset asset) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
double parseMoneyAmount(String? raw, {double fallback = 0}) {
|
||||
@@ -7,6 +8,34 @@ double parseMoneyAmount(String? raw, {double fallback = 0}) {
|
||||
return double.tryParse(trimmed) ?? fallback;
|
||||
}
|
||||
|
||||
String formatMoneyDisplay(
|
||||
Money? money, {
|
||||
String fallback = '--',
|
||||
String separator = ' ',
|
||||
String invalidAmountFallback = '',
|
||||
}) {
|
||||
if (money == null) return fallback;
|
||||
|
||||
final rawAmount = money.amount.trim();
|
||||
final rawCurrency = money.currency.trim();
|
||||
final parsedAmount = parseMoneyAmount(rawAmount, fallback: double.nan);
|
||||
final amountToken = parsedAmount.isNaN
|
||||
? (rawAmount.isEmpty ? invalidAmountFallback : rawAmount)
|
||||
: amountToString(parsedAmount);
|
||||
|
||||
final symbol = currencySymbolFromCode(rawCurrency);
|
||||
final normalizedSymbol = symbol?.trim() ?? '';
|
||||
final hasSymbol = normalizedSymbol.isNotEmpty;
|
||||
final currencyToken = hasSymbol ? normalizedSymbol : rawCurrency;
|
||||
final first = amountToken;
|
||||
final second = currencyToken;
|
||||
|
||||
if (first.isEmpty && second.isEmpty) return fallback;
|
||||
if (first.isEmpty) return second;
|
||||
if (second.isEmpty) return first;
|
||||
return '$first$separator$second';
|
||||
}
|
||||
|
||||
extension MoneyAmountX on Money {
|
||||
double get amountValue => parseMoneyAmount(amount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user