2024-05-03 13:39:27 +00:00
|
|
|
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
|
|
|
import 'package:cake_wallet/entities/transaction_description.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cake_wallet/entities/update_haven_rate.dart';
|
|
|
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
2024-05-03 13:39:27 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
2022-03-30 15:57:04 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2024-05-03 13:39:27 +00:00
|
|
|
import 'package:hive/hive.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/transaction_history.dart';
|
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
import 'package:cw_core/transaction_info.dart';
|
|
|
|
import 'package:cw_core/sync_status.dart';
|
2023-11-17 22:15:15 +00:00
|
|
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2024-05-03 13:39:27 +00:00
|
|
|
import 'fiat_historical_rate_update.dart';
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
ReactionDisposer? _onWalletSyncStatusChangeReaction;
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
void startWalletSyncStatusChangeReaction(
|
2024-05-03 13:39:27 +00:00
|
|
|
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet,
|
|
|
|
FiatConversionStore fiatConversionStore,
|
|
|
|
SettingsStore settingsStore,
|
|
|
|
Box<TransactionDescription> transactionDescription) {
|
2022-10-12 17:09:57 +00:00
|
|
|
_onWalletSyncStatusChangeReaction?.reaction.dispose();
|
2024-05-03 13:39:27 +00:00
|
|
|
_onWalletSyncStatusChangeReaction = reaction((_) => wallet.syncStatus, (SyncStatus status) async {
|
2022-10-17 20:55:41 +00:00
|
|
|
try {
|
|
|
|
if (status is ConnectedSyncStatus) {
|
|
|
|
await wallet.startSync();
|
2022-03-30 15:57:04 +00:00
|
|
|
|
2022-10-17 20:55:41 +00:00
|
|
|
if (wallet.type == WalletType.haven) {
|
|
|
|
await updateHavenRate(fiatConversionStore);
|
|
|
|
}
|
2022-03-30 15:57:04 +00:00
|
|
|
}
|
2022-10-17 20:55:41 +00:00
|
|
|
if (status is SyncingSyncStatus) {
|
2023-11-17 22:15:15 +00:00
|
|
|
await WakelockPlus.enable();
|
2022-10-17 20:55:41 +00:00
|
|
|
}
|
|
|
|
if (status is SyncedSyncStatus || status is FailedSyncStatus) {
|
2023-11-17 22:15:15 +00:00
|
|
|
await WakelockPlus.disable();
|
2024-05-03 13:39:27 +00:00
|
|
|
|
|
|
|
if (settingsStore.fiatApiMode != FiatApiMode.disabled) {
|
|
|
|
if (settingsStore.showHistoricalFiatAmount) {
|
|
|
|
await historicalRateUpdate(
|
|
|
|
wallet, settingsStore, fiatConversionStore, transactionDescription);
|
|
|
|
}
|
|
|
|
}
|
2022-10-17 20:55:41 +00:00
|
|
|
}
|
2024-05-03 13:39:27 +00:00
|
|
|
} catch (e) {
|
2022-10-17 20:55:41 +00:00
|
|
|
print(e.toString());
|
2022-01-21 13:02:00 +00:00
|
|
|
}
|
2021-05-07 07:36:38 +00:00
|
|
|
});
|
|
|
|
}
|