mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-28 06:28:41 +01:00
CW-1186-Show-the-fiat-amount-for-UTXOs-in-coin-control (#2595)
* Add fiat amount display to unspent coins list * refactor fiat amount handling for unspent coins * Update lib/view_model/unspent_coins/unspent_coins_list_view_model.dart [skip ci] --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/monero/monero.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/utils/exception_handler.dart';
|
||||
import 'package:cake_wallet/decred/decred.dart';
|
||||
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
|
||||
@@ -27,13 +32,19 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||
required this.wallet,
|
||||
required Box<UnspentCoinsInfo> unspentCoinsInfo,
|
||||
this.coinTypeToSpendFrom = UnspentCoinType.any,
|
||||
required FiatConversionStore fiatConversationStore,
|
||||
required SettingsStore settingsStore,
|
||||
}) : _unspentCoinsInfo = unspentCoinsInfo,
|
||||
_fiatConversationStore = fiatConversationStore,
|
||||
_settingsStore = settingsStore,
|
||||
items = ObservableList<UnspentCoinsItem>(),
|
||||
_originalState = {};
|
||||
|
||||
@observable
|
||||
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet;
|
||||
final Box<UnspentCoinsInfo> _unspentCoinsInfo;
|
||||
final FiatConversionStore _fiatConversationStore;
|
||||
final SettingsStore _settingsStore;
|
||||
final UnspentCoinType coinTypeToSpendFrom;
|
||||
|
||||
@observable
|
||||
@@ -47,6 +58,30 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||
@computed
|
||||
bool get isAllSelected => items.every((element) => element.isFrozen || element.isSending);
|
||||
|
||||
@computed
|
||||
FiatCurrency get fiatCurrency => _settingsStore.fiatCurrency;
|
||||
|
||||
@computed
|
||||
bool get isFiatDisabled => _settingsStore.fiatApiMode == FiatApiMode.disabled;
|
||||
|
||||
@computed
|
||||
Map<String, String> get fiatAmounts {
|
||||
|
||||
final currency = wallet.currency;
|
||||
final price = _fiatConversationStore.prices[currency];
|
||||
if (price == null || price == 0.0 || isFiatDisabled) return {};
|
||||
|
||||
final result = <String, String>{};
|
||||
for (final item in items) {
|
||||
final formatted = formatAmountToString(item.value);
|
||||
final cryptoAmount = double.tryParse(formatted.replaceAll(',', '')) ?? 0.0;
|
||||
final fiatValue = price * cryptoAmount;
|
||||
result[item.hash] = fiatCurrency.title + ' ' + fiatValue.toStringAsFixed(2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> initialSetup() async {
|
||||
await _updateUnspents();
|
||||
_storeOriginalState();
|
||||
@@ -176,7 +211,7 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||
.map((elem) {
|
||||
try {
|
||||
final existingItem = _unspentCoinsInfo.values
|
||||
.firstWhereOrNull((item) => item.walletId == wallet.id && item == elem);
|
||||
.firstWhereOrNull((item) => item.walletId == wallet.id && item == elem);;
|
||||
|
||||
if (existingItem == null) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user