small fixes
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import 'package:pshared/models/wallet/wallet.dart' as domain;
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
|
||||
extension WalletUiMapper on domain.WalletModel {
|
||||
Wallet toUi() => Wallet(
|
||||
id: walletRef,
|
||||
walletUserID: walletRef,
|
||||
balance: double.tryParse(availableMoney?.amount ?? balance?.available?.amount ?? '0') ?? 0,
|
||||
balance: parseMoneyAmount(
|
||||
availableMoney?.amount ?? balance?.available?.amount,
|
||||
),
|
||||
currency: currencyStringToCode(asset.tokenSymbol),
|
||||
calculatedAt: balance?.calculatedAt ?? DateTime.now(),
|
||||
depositAddress: depositAddress,
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:pshared/models/describable.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/models/wallet/chain_asset.dart';
|
||||
import 'package:pshared/service/wallet.dart' as shared_wallet_service;
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
|
||||
abstract class WalletsService {
|
||||
@@ -29,8 +30,7 @@ class ApiWalletsService implements WalletsService {
|
||||
organizationRef: organizationRef,
|
||||
walletRef: walletRef,
|
||||
);
|
||||
final amount = balance.available?.amount;
|
||||
return amount == null ? 0 : double.tryParse(amount) ?? 0;
|
||||
return parseMoneyAmount(balance.available?.amount);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
12
frontend/pshared/lib/utils/money.dart
Normal file
12
frontend/pshared/lib/utils/money.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'package:pshared/models/money.dart';
|
||||
|
||||
|
||||
double parseMoneyAmount(String? raw, {double fallback = 0}) {
|
||||
final trimmed = raw?.trim();
|
||||
if (trimmed == null || trimmed.isEmpty) return fallback;
|
||||
return double.tryParse(trimmed) ?? fallback;
|
||||
}
|
||||
|
||||
extension MoneyAmountX on Money {
|
||||
double get amountValue => parseMoneyAmount(amount);
|
||||
}
|
||||
Reference in New Issue
Block a user