cake_wallet/cw_haven/lib/haven_balance.dart

34 lines
1.2 KiB
Dart
Raw Normal View History

2022-03-30 15:57:04 +00:00
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/monero_balance.dart';
import 'package:cw_haven/api/balance_list.dart';
import 'package:cw_haven/api/structs/haven_balance_row.dart';
const inactiveBalances = [
CryptoCurrency.xcad,
CryptoCurrency.xjpy,
CryptoCurrency.xnok,
CryptoCurrency.xnzd];
Map<CryptoCurrency, MoneroBalance> getHavenBalance({int accountIndex}) {
final fullBalances = getHavenFullBalance(accountIndex: accountIndex);
final unlockedBalances = getHavenUnlockedBalance(accountIndex: accountIndex);
final havenBalances = <CryptoCurrency, MoneroBalance>{};
final balancesLength = fullBalances.length;
for (int i = 0; i < balancesLength; i++) {
final assetType = fullBalances[i].getAssetType();
final fullBalance = fullBalances[i].getAmount();
final unlockedBalance = unlockedBalances[i].getAmount();
final moneroBalance = MoneroBalance(
fullBalance: fullBalance, unlockedBalance: unlockedBalance);
final currency = CryptoCurrency.fromString(assetType);
if (inactiveBalances.indexOf(currency) >= 0) {
continue;
}
havenBalances[currency] = moneroBalance;
}
return havenBalances;
}