Fiat api fix (#1070)

* Cw 474 linux swapping wallets btc then xmr still shows btc receive qr code (#1068)

* feat: improve address page txt field

* fix: switching wallets from the desktop dropdown updates dashboard pages

* Revert "feat: improve address page txt field"

This reverts commit 0a30e6d9e1d13795219b66a6fdf2c1d218479089.

* refactor: rename to WalletChangeListener

* fix: _init also behaves on wallet change

* Fix Fiat conversion API parsing
Cherry pick fix for Desktop switching wallets not updating dashboard screens

* Minor indentations fix [skip ci]

---------

Co-authored-by: Rafael Saes <76502841+saltrafael@users.noreply.github.com>
This commit is contained in:
Omar Hatem
2023-09-01 18:06:18 +03:00
committed by GitHub
co-authored by Rafael Saes
parent 710fe82d7a
commit 68a821cc0e
7 changed files with 209 additions and 201 deletions
+4 -4
View File
@@ -21,7 +21,7 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
'key': secrets.fiatApiKey,
};
double price = 0.0;
num price = 0.0;
try {
late final Uri uri;
@@ -41,12 +41,12 @@ Future<double> _fetchPrice(Map<String, dynamic> args) async {
final results = responseJSON['results'] as Map<String, dynamic>;
if (results.isNotEmpty) {
price = results.values.first as double;
price = results.values.first as num;
}
return price;
return price.toDouble();
} catch (e) {
return price;
return price.toDouble();
}
}
@@ -0,0 +1,30 @@
import 'package:cw_core/balance.dart';
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/store/app_store.dart';
part 'wallet_change_listener_view_model.g.dart';
class WalletChangeListenerViewModel = WalletChangeListenerViewModelBase
with _$WalletChangeListenerViewModel;
abstract class WalletChangeListenerViewModelBase with Store {
WalletChangeListenerViewModelBase({
required AppStore appStore,
}) : _wallet = appStore.wallet! {
reaction((_) => appStore.wallet, (WalletBase? wallet) {
_wallet = wallet!;
onWalletChange(wallet);
});
}
void onWalletChange(WalletBase wallet) {}
@observable
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> _wallet;
@computed
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> get wallet =>
_wallet;
}