32 lines
1.0 KiB
Dart
32 lines
1.0 KiB
Dart
import 'package:pshared/models/wallet/wallet.dart' as domain;
|
|
|
|
import 'package:pshared/models/currency.dart';
|
|
|
|
import 'package:pweb/models/wallet.dart';
|
|
|
|
|
|
extension WalletUiMapper on domain.WalletModel {
|
|
Wallet toUi() {
|
|
final amountStr = availableMoney?.amount ?? balance?.available?.amount ?? '0';
|
|
final currencyStr = availableMoney?.currency ?? balance?.available?.currency ?? Currency.usd.toString().toUpperCase();
|
|
final parsedAmount = double.tryParse(amountStr) ?? 0;
|
|
final currency = Currency.values.firstWhere(
|
|
(c) => c.name.toUpperCase() == currencyStr.toUpperCase(),
|
|
orElse: () => Currency.usd,
|
|
);
|
|
return Wallet(
|
|
id: walletRef,
|
|
walletUserID: walletRef,
|
|
name: metadata?['name'] ?? walletRef,
|
|
balance: parsedAmount,
|
|
currency: currency,
|
|
isHidden: true,
|
|
calculatedAt: balance?.calculatedAt ?? DateTime.now(),
|
|
depositAddress: depositAddress,
|
|
network: asset.chain,
|
|
tokenSymbol: asset.tokenSymbol,
|
|
contractAddress: asset.contractAddress,
|
|
);
|
|
}
|
|
}
|