-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathcoins_state.dart
58 lines (50 loc) · 1.69 KB
/
coins_state.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
part of 'coins_bloc.dart';
class CoinsState extends Equatable {
const CoinsState({
required this.coins,
required this.walletCoins,
required this.loginActivationFinished,
required this.pubkeys,
});
factory CoinsState.initial() => const CoinsState(
coins: {},
walletCoins: {},
loginActivationFinished: false,
pubkeys: {},
);
final Map<String, Coin> coins;
final Map<String, Coin> walletCoins;
final bool loginActivationFinished;
final Map<String, AssetPubkeys> pubkeys;
@override
List<Object> get props =>
[coins, walletCoins, loginActivationFinished, pubkeys];
CoinsState copyWith({
Map<String, Coin>? coins,
Map<String, Coin>? walletCoins,
bool? loginActivationFinished,
Map<String, AssetPubkeys>? pubkeys,
}) {
final walletCoinsWithoutExcludedCoins = walletCoins ?? this.walletCoins
..removeWhere((coinId, _) => excludedAssetList.contains(coinId));
final coinsWithoutExcludedCoins = coins ?? this.coins
..removeWhere((coinId, _) => excludedAssetList.contains(coinId));
return CoinsState(
coins: coinsWithoutExcludedCoins,
walletCoins: walletCoinsWithoutExcludedCoins,
loginActivationFinished:
loginActivationFinished ?? this.loginActivationFinished,
pubkeys: pubkeys ?? this.pubkeys,
);
}
// TODO! Migrate to SDK
double? getUsdPriceByAmount(String amount, String coinAbbr) {
final Coin? coin = coins[coinAbbr];
final double? parsedAmount = double.tryParse(amount);
final double? usdPrice = coin?.usdPrice?.price;
if (coin == null || usdPrice == null || parsedAmount == null) {
return null;
}
return parsedAmount * usdPrice;
}
}