mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-20 06:08:34 +02:00
@@ -1,8 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
||||
import 'package:cake_wallet/entities/update_haven_rate.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
|
||||
Timer _timer;
|
||||
|
||||
@@ -18,7 +20,16 @@ Future<void> startFiatRateUpdate(AppStore appStore, SettingsStore settingsStore,
|
||||
|
||||
_timer = Timer.periodic(
|
||||
Duration(seconds: 30),
|
||||
(_) async => fiatConversionStore.prices[appStore.wallet.currency] =
|
||||
await FiatConversionService.fetchPrice(
|
||||
appStore.wallet.currency, settingsStore.fiatCurrency));
|
||||
(_) async {
|
||||
try {
|
||||
if (appStore.wallet.type == WalletType.haven) {
|
||||
await updateHavenRate(fiatConversionStore);
|
||||
} else {
|
||||
fiatConversionStore.prices[appStore.wallet.currency] = await FiatConversionService.fetchPrice(
|
||||
appStore.wallet.currency, settingsStore.fiatCurrency);
|
||||
}
|
||||
} catch(e) {
|
||||
print(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/update_haven_rate.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
import 'package:cw_core/balance.dart';
|
||||
import 'package:cw_core/transaction_info.dart';
|
||||
@@ -51,7 +53,7 @@ void startCurrentWalletChangeReaction(AppStore appStore,
|
||||
wallet) async {
|
||||
try {
|
||||
final node = settingsStore.getCurrentNode(wallet.type);
|
||||
startWalletSyncStatusChangeReaction(wallet);
|
||||
startWalletSyncStatusChangeReaction(wallet, fiatConversionStore);
|
||||
startCheckConnectionReaction(wallet, settingsStore);
|
||||
await getIt
|
||||
.get<SharedPreferences>()
|
||||
@@ -60,6 +62,11 @@ void startCurrentWalletChangeReaction(AppStore appStore,
|
||||
PreferencesKey.currentWalletType, serializeToInt(wallet.type));
|
||||
await wallet.connectToNode(node: node);
|
||||
|
||||
if (wallet.type == WalletType.haven) {
|
||||
settingsStore.fiatCurrency = FiatCurrency.usd;
|
||||
await updateHavenRate(fiatConversionStore);
|
||||
}
|
||||
|
||||
if (wallet.walletInfo.address?.isEmpty ?? true) {
|
||||
wallet.walletInfo.address = wallet.walletAddresses.address;
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:cake_wallet/entities/update_haven_rate.dart';
|
||||
import 'package:cake_wallet/entities/wake_lock.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
@@ -12,14 +15,18 @@ ReactionDisposer _onWalletSyncStatusChangeReaction;
|
||||
|
||||
void startWalletSyncStatusChangeReaction(
|
||||
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
||||
TransactionInfo>
|
||||
wallet) {
|
||||
TransactionInfo> wallet,
|
||||
FiatConversionStore fiatConversionStore) {
|
||||
final _wakeLock = getIt.get<WakeLock>();
|
||||
_onWalletSyncStatusChangeReaction?.reaction?.dispose();
|
||||
_onWalletSyncStatusChangeReaction =
|
||||
reaction((_) => wallet.syncStatus, (SyncStatus status) async {
|
||||
if (status is ConnectedSyncStatus) {
|
||||
await wallet.startSync();
|
||||
|
||||
if (wallet.type == WalletType.haven) {
|
||||
await updateHavenRate(fiatConversionStore);
|
||||
}
|
||||
}
|
||||
if (status is SyncingSyncStatus) {
|
||||
await _wakeLock.enableWake();
|
||||
|
||||
Reference in New Issue
Block a user