mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-25 21:19:37 +00:00
work on getting monero wallets synced
This commit is contained in:
parent
14b672cc84
commit
1577096b89
1 changed files with 62 additions and 1 deletions
|
@ -2,18 +2,23 @@ import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
||||||
|
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||||
import 'package:cake_wallet/store/app_store.dart';
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/utils/device_info.dart';
|
import 'package:cake_wallet/utils/device_info.dart';
|
||||||
import 'package:cake_wallet/utils/feature_flag.dart';
|
import 'package:cake_wallet/utils/feature_flag.dart';
|
||||||
import 'package:cake_wallet/view_model/settings/sync_mode.dart';
|
import 'package:cake_wallet/view_model/settings/sync_mode.dart';
|
||||||
|
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
|
||||||
import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
|
import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart';
|
||||||
|
import 'package:cw_core/wallet_base.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_background_service/flutter_background_service.dart';
|
import 'package:flutter_background_service/flutter_background_service.dart';
|
||||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||||
import 'package:cake_wallet/main.dart';
|
import 'package:cake_wallet/main.dart';
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
const moneroSyncTaskKey = "com.fotolockr.cakewallet.monero_sync_task";
|
const moneroSyncTaskKey = "com.fotolockr.cakewallet.monero_sync_task";
|
||||||
const mwebSyncTaskKey = "com.fotolockr.cakewallet.mweb_sync_task";
|
const mwebSyncTaskKey = "com.fotolockr.cakewallet.mweb_sync_task";
|
||||||
|
@ -88,6 +93,62 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
|
|
||||||
print("initialized app configs");
|
print("initialized app configs");
|
||||||
|
|
||||||
|
final currentWallet = getIt.get<AppStore>().wallet;
|
||||||
|
// don't start syncing immediately:
|
||||||
|
await currentWallet?.stopSync();
|
||||||
|
|
||||||
|
final walletLoadingService = getIt.get<WalletLoadingService>();
|
||||||
|
final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType);
|
||||||
|
|
||||||
|
bool syncAll = true;
|
||||||
|
List<WalletBase?> syncingWallets = [];
|
||||||
|
|
||||||
|
if (syncAll) {
|
||||||
|
/// get all Monero wallets of the user and sync them
|
||||||
|
final List<WalletListItem> moneroWallets = getIt
|
||||||
|
.get<WalletListViewModel>()
|
||||||
|
.wallets
|
||||||
|
.where((element) => [WalletType.monero, WalletType.wownero].contains(element.type))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
for (int i = 0; i < moneroWallets.length; i++) {
|
||||||
|
final wallet =
|
||||||
|
await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name);
|
||||||
|
final node = getIt.get<SettingsStore>().getCurrentNode(moneroWallets[i].type);
|
||||||
|
await wallet.connectToNode(node: node);
|
||||||
|
await wallet.startSync();
|
||||||
|
syncingWallets.add(wallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get all litecoin wallets and sync them:
|
||||||
|
final List<WalletListItem> litecoinWallets = getIt
|
||||||
|
.get<WalletListViewModel>()
|
||||||
|
.wallets
|
||||||
|
.where((element) => element.type == WalletType.litecoin)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// we only need to sync the first litecoin wallet since they share the same collection of blocks
|
||||||
|
if (litecoinWallets.isNotEmpty) {
|
||||||
|
var firstWallet = litecoinWallets.first;
|
||||||
|
final wallet = await walletLoadingService.load(firstWallet.type, firstWallet.name);
|
||||||
|
final node = getIt.get<SettingsStore>().getCurrentNode(firstWallet.type);
|
||||||
|
await wallet.connectToNode(node: node);
|
||||||
|
await wallet.startSync();
|
||||||
|
syncingWallets.add(wallet);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// /// if the user chose to sync only active wallet
|
||||||
|
// /// if the current wallet is monero; sync it only
|
||||||
|
// if (typeRaw == WalletType.monero.index || typeRaw == WalletType.wownero.index) {
|
||||||
|
// final name = getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName);
|
||||||
|
// wallet = await walletLoadingService.load(WalletType.values[typeRaw!], name!);
|
||||||
|
// final node = getIt.get<SettingsStore>().getCurrentNode(WalletType.values[typeRaw]);
|
||||||
|
// await wallet.connectToNode(node: node);
|
||||||
|
// await wallet.startSync();
|
||||||
|
// syncingWallets.add(wallet);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) {
|
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) {
|
||||||
final wallet = getIt.get<AppStore>().wallet;
|
final wallet = getIt.get<AppStore>().wallet;
|
||||||
|
@ -96,7 +157,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
flutterLocalNotificationsPlugin.show(
|
flutterLocalNotificationsPlugin.show(
|
||||||
notificationId,
|
notificationId,
|
||||||
"${syncProgress}% Synced",
|
"${syncProgress}% Synced",
|
||||||
'Mweb background sync - ${DateTime.now()}',
|
'Background sync - ${DateTime.now()}',
|
||||||
const NotificationDetails(
|
const NotificationDetails(
|
||||||
android: AndroidNotificationDetails(
|
android: AndroidNotificationDetails(
|
||||||
notificationChannelId,
|
notificationChannelId,
|
||||||
|
|
Loading…
Reference in a new issue