Files
sendico/frontend/pshared/lib/data/mapper/wallet/wallet.dart

34 lines
1.2 KiB
Dart

import 'package:pshared/data/dto/wallet/balance.dart';
import 'package:pshared/data/dto/wallet/wallet.dart';
import 'package:pshared/data/mapper/wallet/balance.dart';
import 'package:pshared/data/mapper/wallet/money.dart';
import 'package:pshared/models/describable.dart';
import 'package:pshared/models/wallet/wallet.dart';
extension WalletDTOMapper on WalletDTO {
WalletModel toDomain({WalletBalanceDTO? balance}) => WalletModel(
walletRef: walletRef,
organizationRef: organizationRef,
ownerRef: ownerRef,
asset: WalletAsset(
chain: asset.chain,
tokenSymbol: asset.tokenSymbol,
contractAddress: asset.contractAddress,
),
depositAddress: depositAddress,
status: status,
metadata: metadata,
createdAt: (createdAt == null || createdAt!.isEmpty) ? null : DateTime.tryParse(createdAt!),
updatedAt: (updatedAt == null || updatedAt!.isEmpty) ? null : DateTime.tryParse(updatedAt!),
balance: balance?.toDomain(),
availableMoney: balance?.available?.toDomain(),
describable: newDescribable(
name: name.isNotEmpty ? name : (metadata?['name'] ?? 'Crypto Wallet'),
description: (description != null && description!.isNotEmpty)
? description
: metadata?['description'],
),
);
}