few fixes and made sure ledger widget displays the name of ledger wallet
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'operation.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class PaymentOperationDTO {
|
||||
final String? stepRef;
|
||||
final String? operationRef;
|
||||
@@ -24,37 +29,6 @@ class PaymentOperationDTO {
|
||||
});
|
||||
|
||||
factory PaymentOperationDTO.fromJson(Map<String, dynamic> json) =>
|
||||
PaymentOperationDTO(
|
||||
stepRef: _asString(json['stepRef'] ?? json['step_ref']),
|
||||
operationRef: _asString(json['operationRef'] ?? json['operation_ref']),
|
||||
gateway: _asString(json['gateway']),
|
||||
code: _asString(json['code']),
|
||||
state: _asString(json['state']),
|
||||
label: _asString(json['label']),
|
||||
failureCode: _asString(json['failureCode'] ?? json['failure_code']),
|
||||
failureReason: _asString(
|
||||
json['failureReason'] ?? json['failure_reason'],
|
||||
),
|
||||
startedAt: _asString(json['startedAt'] ?? json['started_at']),
|
||||
completedAt: _asString(json['completedAt'] ?? json['completed_at']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'stepRef': stepRef,
|
||||
'operationRef': operationRef,
|
||||
'gateway': gateway,
|
||||
'code': code,
|
||||
'state': state,
|
||||
'label': label,
|
||||
'failureCode': failureCode,
|
||||
'failureReason': failureReason,
|
||||
'startedAt': startedAt,
|
||||
'completedAt': completedAt,
|
||||
};
|
||||
}
|
||||
|
||||
String? _asString(Object? value) {
|
||||
final text = value?.toString().trim();
|
||||
if (text == null || text.isEmpty) return null;
|
||||
return text;
|
||||
_$PaymentOperationDTOFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$PaymentOperationDTOToJson(this);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ class PaymentDTO {
|
||||
final String? state;
|
||||
final String? failureCode;
|
||||
final String? failureReason;
|
||||
@JsonKey(defaultValue: <PaymentOperationDTO>[])
|
||||
final List<PaymentOperationDTO> operations;
|
||||
final PaymentQuoteDTO? lastQuote;
|
||||
final Map<String, String>? metadata;
|
||||
|
||||
@@ -9,22 +9,33 @@ import 'package:pshared/models/ledger/account.dart';
|
||||
|
||||
|
||||
extension LedgerAccountDTOMapper on LedgerAccountDTO {
|
||||
LedgerAccount toDomain() => LedgerAccount(
|
||||
ledgerAccountRef: ledgerAccountRef,
|
||||
organizationRef: organizationRef,
|
||||
ownerRef: ownerRef,
|
||||
accountCode: accountCode,
|
||||
accountType: accountType.toDomain(),
|
||||
currency: currency,
|
||||
status: status.toDomain(),
|
||||
allowNegative: allowNegative,
|
||||
role: role.toDomain(),
|
||||
metadata: metadata,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
describable: describable?.toDomain() ?? newDescribable(name: '', description: null),
|
||||
balance: balance?.toDomain(),
|
||||
);
|
||||
LedgerAccount toDomain() {
|
||||
final mappedDescribable = describable?.toDomain();
|
||||
final fallbackName = metadata?['name']?.trim() ?? '';
|
||||
final name = mappedDescribable?.name.trim().isNotEmpty == true
|
||||
? mappedDescribable!.name
|
||||
: fallbackName;
|
||||
|
||||
return LedgerAccount(
|
||||
ledgerAccountRef: ledgerAccountRef,
|
||||
organizationRef: organizationRef,
|
||||
ownerRef: ownerRef,
|
||||
accountCode: accountCode,
|
||||
accountType: accountType.toDomain(),
|
||||
currency: currency,
|
||||
status: status.toDomain(),
|
||||
allowNegative: allowNegative,
|
||||
role: role.toDomain(),
|
||||
metadata: metadata,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
describable: newDescribable(
|
||||
name: name,
|
||||
description: mappedDescribable?.description,
|
||||
),
|
||||
balance: balance?.toDomain(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension LedgerAccountModelMapper on LedgerAccount {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:pshared/data/dto/payment/operation.dart';
|
||||
import 'package:pshared/models/payment/execution_operation.dart';
|
||||
|
||||
|
||||
extension PaymentOperationDTOMapper on PaymentOperationDTO {
|
||||
PaymentExecutionOperation toDomain() => PaymentExecutionOperation(
|
||||
stepRef: stepRef,
|
||||
|
||||
Reference in New Issue
Block a user