cake_wallet/cw_haven/lib/haven_balance.dart
2022-02-21 21:11:18 +02:00

34 lines
No EOL
1.2 KiB
Dart

import 'package:cw_core/crypto_currency.dart';
import 'package:cw_monero/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;
}