mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
ui improvements, still figuring out silent payments issues
This commit is contained in:
parent
e6b9a49a28
commit
756fb3d0e2
5 changed files with 162 additions and 130 deletions
|
@ -406,6 +406,8 @@ abstract class ElectrumWalletBase
|
||||||
nodeSupportsSilentPayments = false;
|
nodeSupportsSilentPayments = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("sp sync: ${message.syncStatus.progress() * 100}%");
|
||||||
|
|
||||||
syncStatus = message.syncStatus;
|
syncStatus = message.syncStatus;
|
||||||
await walletInfo.updateRestoreHeight(message.height);
|
await walletInfo.updateRestoreHeight(message.height);
|
||||||
}
|
}
|
||||||
|
@ -476,7 +478,12 @@ abstract class ElectrumWalletBase
|
||||||
@override
|
@override
|
||||||
Future<void> stopSync() async {
|
Future<void> stopSync() async {
|
||||||
syncStatus = StoppedSyncingSyncStatus();
|
syncStatus = StoppedSyncingSyncStatus();
|
||||||
|
try {
|
||||||
|
await _receiveStream?.cancel();
|
||||||
|
await electrumClient.close();
|
||||||
|
} catch (_) {}
|
||||||
_updateFeeRateTimer?.cancel();
|
_updateFeeRateTimer?.cancel();
|
||||||
|
_autoSaveTimer?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|
58
lib/di.dart
58
lib/di.dart
|
@ -290,6 +290,10 @@ Future<void> setup({
|
||||||
getIt.registerFactory(() => BackgroundTasks());
|
getIt.registerFactory(() => BackgroundTasks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getIt.registerSingleton<BackgroundTasks>(BackgroundTasks(
|
||||||
|
// settingsStore: getIt.get<SettingsStore>(),
|
||||||
|
// ));
|
||||||
|
|
||||||
final isBitcoinBuyEnabled = (secrets.wyreSecretKey.isNotEmpty) &&
|
final isBitcoinBuyEnabled = (secrets.wyreSecretKey.isNotEmpty) &&
|
||||||
(secrets.wyreApiKey.isNotEmpty) &&
|
(secrets.wyreApiKey.isNotEmpty) &&
|
||||||
(secrets.wyreAccountId.isNotEmpty);
|
(secrets.wyreAccountId.isNotEmpty);
|
||||||
|
@ -369,60 +373,50 @@ Future<void> setup({
|
||||||
type: type));
|
type: type));
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletUnlockPage, WalletUnlockArguments, bool>((args, closable) {
|
getIt.registerFactoryParam<WalletUnlockPage, WalletUnlockArguments, bool>((args, closable) {
|
||||||
return WalletUnlockPage(
|
return WalletUnlockPage(getIt.get<WalletUnlockLoadableViewModel>(param1: args), args.callback,
|
||||||
getIt.get<WalletUnlockLoadableViewModel>(param1: args),
|
|
||||||
args.callback,
|
|
||||||
args.authPasswordHandler,
|
args.authPasswordHandler,
|
||||||
closable: closable);
|
closable: closable);
|
||||||
}, instanceName: 'wallet_unlock_loadable');
|
}, instanceName: 'wallet_unlock_loadable');
|
||||||
|
|
||||||
getIt.registerFactory<WalletUnlockPage>(
|
getIt.registerFactory<WalletUnlockPage>(
|
||||||
() => getIt.get<WalletUnlockPage>(
|
() => getIt.get<WalletUnlockPage>(
|
||||||
param1: WalletUnlockArguments(
|
param1: WalletUnlockArguments(callback: (bool successful, _) {
|
||||||
callback: (bool successful, _) {
|
|
||||||
if (successful) {
|
if (successful) {
|
||||||
final authStore = getIt.get<AuthenticationStore>();
|
final authStore = getIt.get<AuthenticationStore>();
|
||||||
authStore.allowed();
|
authStore.allowed();
|
||||||
}}),
|
}
|
||||||
|
}),
|
||||||
param2: false,
|
param2: false,
|
||||||
instanceName: 'wallet_unlock_loadable'),
|
instanceName: 'wallet_unlock_loadable'),
|
||||||
instanceName: 'wallet_password_login');
|
instanceName: 'wallet_password_login');
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletUnlockPage, WalletUnlockArguments, bool>((args, closable) {
|
getIt.registerFactoryParam<WalletUnlockPage, WalletUnlockArguments, bool>((args, closable) {
|
||||||
return WalletUnlockPage(
|
return WalletUnlockPage(getIt.get<WalletUnlockVerifiableViewModel>(param1: args), args.callback,
|
||||||
getIt.get<WalletUnlockVerifiableViewModel>(param1: args),
|
|
||||||
args.callback,
|
|
||||||
args.authPasswordHandler,
|
args.authPasswordHandler,
|
||||||
closable: closable);
|
closable: closable);
|
||||||
}, instanceName: 'wallet_unlock_verifiable');
|
}, instanceName: 'wallet_unlock_verifiable');
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletUnlockLoadableViewModel, WalletUnlockArguments, void>((args, _) {
|
getIt.registerFactoryParam<WalletUnlockLoadableViewModel, WalletUnlockArguments, void>((args, _) {
|
||||||
final currentWalletName = getIt
|
final currentWalletName =
|
||||||
.get<SharedPreferences>()
|
getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName) ?? '';
|
||||||
.getString(PreferencesKey.currentWalletName) ?? '';
|
|
||||||
final currentWalletTypeRaw =
|
final currentWalletTypeRaw =
|
||||||
getIt.get<SharedPreferences>()
|
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ?? 0;
|
||||||
.getInt(PreferencesKey.currentWalletType) ?? 0;
|
|
||||||
final currentWalletType = deserializeFromInt(currentWalletTypeRaw);
|
final currentWalletType = deserializeFromInt(currentWalletTypeRaw);
|
||||||
|
|
||||||
return WalletUnlockLoadableViewModel(
|
return WalletUnlockLoadableViewModel(getIt.get<AppStore>(), getIt.get<WalletLoadingService>(),
|
||||||
getIt.get<AppStore>(),
|
|
||||||
getIt.get<WalletLoadingService>(),
|
|
||||||
walletName: args.walletName ?? currentWalletName,
|
walletName: args.walletName ?? currentWalletName,
|
||||||
walletType: args.walletType ?? currentWalletType);
|
walletType: args.walletType ?? currentWalletType);
|
||||||
});
|
});
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletUnlockVerifiableViewModel, WalletUnlockArguments, void>((args, _) {
|
getIt.registerFactoryParam<WalletUnlockVerifiableViewModel, WalletUnlockArguments, void>(
|
||||||
final currentWalletName = getIt
|
(args, _) {
|
||||||
.get<SharedPreferences>()
|
final currentWalletName =
|
||||||
.getString(PreferencesKey.currentWalletName) ?? '';
|
getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName) ?? '';
|
||||||
final currentWalletTypeRaw =
|
final currentWalletTypeRaw =
|
||||||
getIt.get<SharedPreferences>()
|
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ?? 0;
|
||||||
.getInt(PreferencesKey.currentWalletType) ?? 0;
|
|
||||||
final currentWalletType = deserializeFromInt(currentWalletTypeRaw);
|
final currentWalletType = deserializeFromInt(currentWalletTypeRaw);
|
||||||
|
|
||||||
return WalletUnlockVerifiableViewModel(
|
return WalletUnlockVerifiableViewModel(getIt.get<AppStore>(),
|
||||||
getIt.get<AppStore>(),
|
|
||||||
walletName: args.walletName ?? currentWalletName,
|
walletName: args.walletName ?? currentWalletName,
|
||||||
walletType: args.walletType ?? currentWalletType);
|
walletType: args.walletType ?? currentWalletType);
|
||||||
});
|
});
|
||||||
|
@ -842,8 +836,9 @@ Future<void> setup({
|
||||||
getIt.registerFactory(() => TrocadorProvidersViewModel(getIt.get<SettingsStore>()));
|
getIt.registerFactory(() => TrocadorProvidersViewModel(getIt.get<SettingsStore>()));
|
||||||
|
|
||||||
getIt.registerFactory(() {
|
getIt.registerFactory(() {
|
||||||
return OtherSettingsViewModel(getIt.get<SettingsStore>(), getIt.get<AppStore>().wallet!,
|
return OtherSettingsViewModel(
|
||||||
getIt.get<SendViewModel>());});
|
getIt.get<SettingsStore>(), getIt.get<AppStore>().wallet!, getIt.get<SendViewModel>());
|
||||||
|
});
|
||||||
|
|
||||||
getIt.registerFactory(() {
|
getIt.registerFactory(() {
|
||||||
return SecuritySettingsViewModel(getIt.get<SettingsStore>());
|
return SecuritySettingsViewModel(getIt.get<SettingsStore>());
|
||||||
|
@ -851,7 +846,8 @@ Future<void> setup({
|
||||||
|
|
||||||
getIt.registerFactory(() => WalletSeedViewModel(getIt.get<AppStore>().wallet!));
|
getIt.registerFactory(() => WalletSeedViewModel(getIt.get<AppStore>().wallet!));
|
||||||
|
|
||||||
getIt.registerFactory<SeedSettingsViewModel>(() => SeedSettingsViewModel(getIt.get<AppStore>(), getIt.get<SeedSettingsStore>()));
|
getIt.registerFactory<SeedSettingsViewModel>(
|
||||||
|
() => SeedSettingsViewModel(getIt.get<AppStore>(), getIt.get<SeedSettingsStore>()));
|
||||||
|
|
||||||
getIt.registerFactoryParam<WalletSeedPage, bool, void>((bool isWalletCreated, _) =>
|
getIt.registerFactoryParam<WalletSeedPage, bool, void>((bool isWalletCreated, _) =>
|
||||||
WalletSeedPage(getIt.get<WalletSeedViewModel>(), isNewWalletCreated: isWalletCreated));
|
WalletSeedPage(getIt.get<WalletSeedViewModel>(), isNewWalletCreated: isWalletCreated));
|
||||||
|
@ -1011,7 +1007,8 @@ Future<void> setup({
|
||||||
_unspentCoinsInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
_unspentCoinsInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
||||||
case WalletType.nano:
|
case WalletType.nano:
|
||||||
case WalletType.banano:
|
case WalletType.banano:
|
||||||
return nano!.createNanoWalletService(_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
return nano!.createNanoWalletService(
|
||||||
|
_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
||||||
case WalletType.polygon:
|
case WalletType.polygon:
|
||||||
return polygon!.createPolygonWalletService(
|
return polygon!.createPolygonWalletService(
|
||||||
_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
||||||
|
@ -1019,7 +1016,8 @@ Future<void> setup({
|
||||||
return solana!.createSolanaWalletService(
|
return solana!.createSolanaWalletService(
|
||||||
_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
||||||
case WalletType.tron:
|
case WalletType.tron:
|
||||||
return tron!.createTronWalletService(_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
return tron!.createTronWalletService(
|
||||||
|
_walletInfoSource, SettingsStoreBase.walletPasswordDirectInput);
|
||||||
case WalletType.wownero:
|
case WalletType.wownero:
|
||||||
return wownero!.createWowneroWalletService(_walletInfoSource, _unspentCoinsInfoSource);
|
return wownero!.createWowneroWalletService(_walletInfoSource, _unspentCoinsInfoSource);
|
||||||
case WalletType.none:
|
case WalletType.none:
|
||||||
|
|
|
@ -12,6 +12,7 @@ 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_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_bitcoin/electrum_wallet.dart';
|
import 'package:cw_bitcoin/electrum_wallet.dart';
|
||||||
|
import 'package:cw_core/sync_status.dart';
|
||||||
import 'package:cw_core/wallet_base.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';
|
||||||
|
@ -25,7 +26,9 @@ const moneroSyncTaskKey = "com.fotolockr.cakewallet.monero_sync_task";
|
||||||
const mwebSyncTaskKey = "com.fotolockr.cakewallet.mweb_sync_task";
|
const mwebSyncTaskKey = "com.fotolockr.cakewallet.mweb_sync_task";
|
||||||
|
|
||||||
const initialNotificationTitle = 'Cake Background Sync';
|
const initialNotificationTitle = 'Cake Background Sync';
|
||||||
const initialNotificationContent = 'On standby - app is in the foreground';
|
const standbyMessage = 'On standby - app is in the foreground';
|
||||||
|
const readyMessage = 'Ready to sync - waiting until the app has been in the background for a while';
|
||||||
|
|
||||||
const notificationId = 888;
|
const notificationId = 888;
|
||||||
const notificationChannelId = 'cake_service';
|
const notificationChannelId = 'cake_service';
|
||||||
const notificationChannelName = 'CAKE BACKGROUND SERVICE';
|
const notificationChannelName = 'CAKE BACKGROUND SERVICE';
|
||||||
|
@ -37,7 +40,24 @@ void setNotificationStandby(FlutterLocalNotificationsPlugin flutterLocalNotifica
|
||||||
flutterLocalNotificationsPlugin.show(
|
flutterLocalNotificationsPlugin.show(
|
||||||
notificationId,
|
notificationId,
|
||||||
initialNotificationTitle,
|
initialNotificationTitle,
|
||||||
initialNotificationContent,
|
standbyMessage,
|
||||||
|
const NotificationDetails(
|
||||||
|
android: AndroidNotificationDetails(
|
||||||
|
notificationChannelId,
|
||||||
|
notificationChannelName,
|
||||||
|
icon: 'ic_bg_service_small',
|
||||||
|
ongoing: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setNotificationReady(FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin) async {
|
||||||
|
flutterLocalNotificationsPlugin.cancelAll();
|
||||||
|
flutterLocalNotificationsPlugin.show(
|
||||||
|
notificationId,
|
||||||
|
initialNotificationTitle,
|
||||||
|
readyMessage,
|
||||||
const NotificationDetails(
|
const NotificationDetails(
|
||||||
android: AndroidNotificationDetails(
|
android: AndroidNotificationDetails(
|
||||||
notificationChannelId,
|
notificationChannelId,
|
||||||
|
@ -77,6 +97,10 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
setNotificationStandby(flutterLocalNotificationsPlugin);
|
setNotificationStandby(flutterLocalNotificationsPlugin);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
service.on('setReady').listen((event) async {
|
||||||
|
setNotificationReady(flutterLocalNotificationsPlugin);
|
||||||
|
});
|
||||||
|
|
||||||
// we have entered the background, start the sync:
|
// we have entered the background, start the sync:
|
||||||
service.on('setBackground').listen((event) async {
|
service.on('setBackground').listen((event) async {
|
||||||
if (bgSyncStarted) {
|
if (bgSyncStarted) {
|
||||||
|
@ -93,7 +117,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
// these errors still show up in logs which doesn't really make sense to me
|
// these errors still show up in logs which doesn't really make sense to me
|
||||||
}
|
}
|
||||||
|
|
||||||
print("initialized app configs");
|
print("INITIALIZED APP CONFIGS");
|
||||||
|
|
||||||
final currentWallet = getIt.get<AppStore>().wallet;
|
final currentWallet = getIt.get<AppStore>().wallet;
|
||||||
// don't start syncing immediately:
|
// don't start syncing immediately:
|
||||||
|
@ -101,6 +125,7 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
|
|
||||||
final walletLoadingService = getIt.get<WalletLoadingService>();
|
final walletLoadingService = getIt.get<WalletLoadingService>();
|
||||||
final settingsStore = getIt.get<SettingsStore>();
|
final settingsStore = getIt.get<SettingsStore>();
|
||||||
|
final walletListViewModel = getIt.get<WalletListViewModel>();
|
||||||
final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType);
|
final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType);
|
||||||
|
|
||||||
bool syncAll = true;
|
bool syncAll = true;
|
||||||
|
@ -108,101 +133,95 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
|
|
||||||
if (syncAll) {
|
if (syncAll) {
|
||||||
/// get all Monero wallets of the user and sync them
|
/// get all Monero wallets of the user and sync them
|
||||||
final List<WalletListItem> moneroWallets = getIt
|
final List<WalletListItem> moneroWallets = walletListViewModel.wallets
|
||||||
.get<WalletListViewModel>()
|
|
||||||
.wallets
|
|
||||||
.where((element) => [WalletType.monero, WalletType.wownero].contains(element.type))
|
.where((element) => [WalletType.monero, WalletType.wownero].contains(element.type))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
for (int i = 0; i < moneroWallets.length; i++) {
|
for (int i = 0; i < moneroWallets.length; i++) {
|
||||||
final wallet =
|
final wallet =
|
||||||
await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name);
|
await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name);
|
||||||
final node = getIt.get<SettingsStore>().getCurrentNode(moneroWallets[i].type);
|
final node = settingsStore.getCurrentNode(moneroWallets[i].type);
|
||||||
await wallet.connectToNode(node: node);
|
await wallet.connectToNode(node: node);
|
||||||
await wallet.startSync();
|
await wallet.startSync();
|
||||||
syncingWallets.add(wallet);
|
syncingWallets.add(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all litecoin wallets and sync them:
|
// get all litecoin wallets and sync them:
|
||||||
final List<WalletListItem> litecoinWallets = getIt
|
final List<WalletListItem> litecoinWallets = walletListViewModel.wallets
|
||||||
.get<WalletListViewModel>()
|
|
||||||
.wallets
|
|
||||||
.where((element) => element.type == WalletType.litecoin)
|
.where((element) => element.type == WalletType.litecoin)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
// we only need to sync the first litecoin wallet since they share the same collection of blocks
|
// we only need to sync the first litecoin wallet since they share the same collection of blocks
|
||||||
if (litecoinWallets.isNotEmpty) {
|
if (litecoinWallets.isNotEmpty) {
|
||||||
|
try {
|
||||||
final firstWallet = litecoinWallets.first;
|
final firstWallet = litecoinWallets.first;
|
||||||
final wallet = await walletLoadingService.load(firstWallet.type, firstWallet.name);
|
final wallet = await walletLoadingService.load(firstWallet.type, firstWallet.name);
|
||||||
final node = getIt.get<SettingsStore>().getCurrentNode(firstWallet.type);
|
final node = settingsStore.getCurrentNode(firstWallet.type);
|
||||||
await wallet.connectToNode(node: node);
|
await wallet.connectToNode(node: node);
|
||||||
await wallet.startSync();
|
await wallet.startSync();
|
||||||
syncingWallets.add(wallet);
|
syncingWallets.add(wallet);
|
||||||
|
} catch (e) {
|
||||||
|
// couldn't connect to mwebd (most likely)
|
||||||
|
print("error syncing litecoin wallet: $e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<WalletListItem> bitcoinWallets = getIt
|
final List<WalletListItem> bitcoinWallets = walletListViewModel.wallets
|
||||||
.get<WalletListViewModel>()
|
|
||||||
.wallets
|
|
||||||
.where((element) => element.type == WalletType.bitcoin)
|
.where((element) => element.type == WalletType.bitcoin)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
for (int i = 0; i < bitcoinWallets.length; i++) {
|
for (int i = 0; i < bitcoinWallets.length; i++) {
|
||||||
|
try {
|
||||||
final wallet =
|
final wallet =
|
||||||
await walletLoadingService.load(bitcoinWallets[i].type, bitcoinWallets[i].name);
|
await walletLoadingService.load(bitcoinWallets[i].type, bitcoinWallets[i].name);
|
||||||
final node = getIt.get<SettingsStore>().getCurrentNode(bitcoinWallets[i].type);
|
final node = settingsStore.getCurrentNode(bitcoinWallets[i].type);
|
||||||
await wallet.connectToNode(node: node);
|
await wallet.connectToNode(node: node);
|
||||||
await wallet.startSync();
|
await wallet.startSync();
|
||||||
// TODO: use proxy layer:
|
// TODO: use proxy layer:
|
||||||
await (wallet as ElectrumWallet).setSilentPaymentsScanning(true);
|
await (wallet as ElectrumWallet).rescan(height: 1);
|
||||||
syncingWallets.add(wallet);
|
syncingWallets.add(wallet);
|
||||||
|
} catch (e) {
|
||||||
|
print("error syncing bitcoin wallet: $e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// /// if the user chose to sync only active wallet
|
/// if the user chose to sync only active wallet
|
||||||
// /// if the current wallet is monero; sync it only
|
/// if the current wallet is monero; sync it only
|
||||||
// if (typeRaw == WalletType.monero.index || typeRaw == WalletType.wownero.index) {
|
if (typeRaw == WalletType.monero.index || typeRaw == WalletType.wownero.index) {
|
||||||
// final name = getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName);
|
final name = getIt.get<SharedPreferences>().getString(PreferencesKey.currentWalletName);
|
||||||
// wallet = await walletLoadingService.load(WalletType.values[typeRaw!], name!);
|
final wallet = await walletLoadingService.load(WalletType.values[typeRaw!], name!);
|
||||||
// final node = getIt.get<SettingsStore>().getCurrentNode(WalletType.values[typeRaw]);
|
final node = getIt.get<SettingsStore>().getCurrentNode(WalletType.values[typeRaw]);
|
||||||
// await wallet.connectToNode(node: node);
|
await wallet.connectToNode(node: node);
|
||||||
// await wallet.startSync();
|
await wallet.startSync();
|
||||||
// syncingWallets.add(wallet);
|
syncingWallets.add(wallet);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print("STARTING SYNC TIMER");
|
print("STARTING SYNC TIMER");
|
||||||
_syncTimer?.cancel();
|
_syncTimer?.cancel();
|
||||||
_syncTimer = Timer.periodic(const Duration(milliseconds: 2000), (timer) {
|
_syncTimer = Timer.periodic(const Duration(milliseconds: 2000), (timer) {
|
||||||
// final wallet = getIt.get<AppStore>().wallet;
|
|
||||||
if (syncingWallets.isEmpty) {
|
if (syncingWallets.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// final wallet = syncingWallets.first!;
|
|
||||||
// final syncProgress = ((wallet.syncStatus.progress() ?? 0) * 100).toStringAsPrecision(5);
|
|
||||||
// String title = "${wallet!.name} ${syncProgress}% Synced";
|
|
||||||
// flutterLocalNotificationsPlugin.show(
|
|
||||||
// notificationId,
|
|
||||||
// title,
|
|
||||||
// 'Background sync - ${DateTime.now()}',
|
|
||||||
// const NotificationDetails(
|
|
||||||
// android: AndroidNotificationDetails(
|
|
||||||
// notificationChannelId,
|
|
||||||
// notificationChannelName,
|
|
||||||
// icon: 'ic_bg_service_small',
|
|
||||||
// ongoing: true,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
|
|
||||||
for (int i = 0; i < syncingWallets.length; i++) {
|
for (int i = 0; i < syncingWallets.length; i++) {
|
||||||
final wallet = syncingWallets[i];
|
final wallet = syncingWallets[i];
|
||||||
final syncProgress = ((wallet!.syncStatus.progress()) * 100).toStringAsPrecision(5);
|
final syncProgress = ((wallet!.syncStatus.progress()) * 100).toStringAsPrecision(5);
|
||||||
String title = "${wallet.name}-${syncProgress}% Synced";
|
String title = "${wallet.name} - ${wallet.type}";
|
||||||
|
late String content;
|
||||||
|
try {
|
||||||
|
final blocksLeft = (wallet.syncStatus as SyncingSyncStatus).blocksLeft;
|
||||||
|
content = "${blocksLeft} Blocks Left";
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
content = "${wallet.name} ${syncProgress}% Synced";
|
||||||
|
}
|
||||||
|
content += " - ${DateTime.now()}";
|
||||||
|
|
||||||
flutterLocalNotificationsPlugin.show(
|
flutterLocalNotificationsPlugin.show(
|
||||||
notificationId + i,
|
notificationId + i,
|
||||||
title,
|
title,
|
||||||
'Background sync - ${DateTime.now()}',
|
content,
|
||||||
NotificationDetails(
|
NotificationDetails(
|
||||||
android: AndroidNotificationDetails(
|
android: AndroidNotificationDetails(
|
||||||
"${notificationChannelId}_$i",
|
"${notificationChannelId}_$i",
|
||||||
|
@ -274,7 +293,7 @@ Future<void> initializeService(FlutterBackgroundService bgService, bool useNotif
|
||||||
isForegroundMode: true,
|
isForegroundMode: true,
|
||||||
notificationChannelId: notificationChannelId,
|
notificationChannelId: notificationChannelId,
|
||||||
initialNotificationTitle: initialNotificationTitle,
|
initialNotificationTitle: initialNotificationTitle,
|
||||||
initialNotificationContent: initialNotificationContent,
|
initialNotificationContent: standbyMessage,
|
||||||
foregroundServiceNotificationId: notificationId,
|
foregroundServiceNotificationId: notificationId,
|
||||||
foregroundServiceTypes: [AndroidForegroundType.dataSync],
|
foregroundServiceTypes: [AndroidForegroundType.dataSync],
|
||||||
),
|
),
|
||||||
|
@ -291,34 +310,40 @@ class BackgroundTasks {
|
||||||
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||||
FlutterLocalNotificationsPlugin();
|
FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
void updateServiceState(bool foreground, bool useNotifications) async {
|
void serviceBackground() {
|
||||||
if (foreground) {
|
bgService.invoke("setBackground");
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> serviceForeground() async {
|
||||||
|
final settingsStore = getIt.get<SettingsStore>();
|
||||||
|
bool showNotifications = settingsStore.showSyncNotification;
|
||||||
bgService.invoke('stopService');
|
bgService.invoke('stopService');
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
initializeService(bgService, useNotifications);
|
initializeService(bgService, showNotifications);
|
||||||
} else {
|
}
|
||||||
bgService.invoke("setBackground");
|
|
||||||
|
void serviceReady() {
|
||||||
|
final settingsStore = getIt.get<SettingsStore>();
|
||||||
|
bool showNotifications = settingsStore.showSyncNotification;
|
||||||
|
if (showNotifications) {
|
||||||
|
bgService.invoke('setReady');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerBackgroundService() async {
|
void registerBackgroundService() async {
|
||||||
|
print("REGISTER BACKGROUND SERVICE");
|
||||||
try {
|
try {
|
||||||
bool hasMonero = getIt
|
|
||||||
.get<WalletListViewModel>()
|
|
||||||
.wallets
|
|
||||||
.any((element) => element.type == WalletType.monero);
|
|
||||||
|
|
||||||
bool hasLitecoin = getIt
|
|
||||||
.get<WalletListViewModel>()
|
|
||||||
.wallets
|
|
||||||
.any((element) => element.type == WalletType.litecoin);
|
|
||||||
|
|
||||||
bool hasBitcoin = getIt
|
|
||||||
.get<WalletListViewModel>()
|
|
||||||
.wallets
|
|
||||||
.any((element) => element.type == WalletType.bitcoin);
|
|
||||||
|
|
||||||
final settingsStore = getIt.get<SettingsStore>();
|
final settingsStore = getIt.get<SettingsStore>();
|
||||||
|
final walletListViewModel = getIt.get<WalletListViewModel>();
|
||||||
|
bool hasMonero =
|
||||||
|
walletListViewModel.wallets.any((element) => element.type == WalletType.monero);
|
||||||
|
|
||||||
|
bool hasLitecoin =
|
||||||
|
walletListViewModel.wallets.any((element) => element.type == WalletType.litecoin);
|
||||||
|
|
||||||
|
bool hasBitcoin =
|
||||||
|
walletListViewModel.wallets.any((element) => element.type == WalletType.bitcoin);
|
||||||
|
|
||||||
if (!settingsStore.silentPaymentsAlwaysScan) {
|
if (!settingsStore.silentPaymentsAlwaysScan) {
|
||||||
hasBitcoin = false;
|
hasBitcoin = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,6 @@ Future<void> loadCurrentWallet({String? password}) async {
|
||||||
final walletLoadingService = getIt.get<WalletLoadingService>();
|
final walletLoadingService = getIt.get<WalletLoadingService>();
|
||||||
final wallet = await walletLoadingService.load(type, name, password: password);
|
final wallet = await walletLoadingService.load(type, name, password: password);
|
||||||
await appStore.changeCurrentWallet(wallet);
|
await appStore.changeCurrentWallet(wallet);
|
||||||
getIt.get<BackgroundTasks>().registerBackgroundService();
|
// TODO: re-enable (need to figure out how to prevent current wallet from being loaded in the background service!)
|
||||||
|
// getIt.get<BackgroundTasks>().registerBackgroundService();
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,11 +163,10 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
// background service handling:
|
// background service handling:
|
||||||
bool showNotifications = getIt.get<SettingsStore>().showSyncNotification;
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AppLifecycleState.resumed:
|
case AppLifecycleState.resumed:
|
||||||
// restart the background service if it was running before:
|
// restart the background service if it was running before:
|
||||||
getIt.get<BackgroundTasks>().updateServiceState(true, showNotifications);
|
getIt.get<BackgroundTasks>().serviceForeground();
|
||||||
_stateTimer?.cancel();
|
_stateTimer?.cancel();
|
||||||
if (!wasInBackground) {
|
if (!wasInBackground) {
|
||||||
return;
|
return;
|
||||||
|
@ -182,17 +181,19 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.paused:
|
case AppLifecycleState.paused:
|
||||||
// TODO: experimental: maybe should uncomment this:
|
// TODO: experimental: maybe should uncomment this:
|
||||||
// getIt.get<BackgroundTasks>().updateServiceState(false, showNotifications);
|
// getIt.get<BackgroundTasks>().serviceBackground(false, showNotifications);
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
case AppLifecycleState.detached:
|
case AppLifecycleState.detached:
|
||||||
default:
|
default:
|
||||||
|
// anything other than resumed update the notification to say we're in the "ready" state:
|
||||||
|
getIt.get<BackgroundTasks>().serviceReady();
|
||||||
// if we enter any state other than resumed start a timer for 30 seconds
|
// if we enter any state other than resumed start a timer for 30 seconds
|
||||||
// after which we'll consider the app to be in the background
|
// after which we'll consider the app to be in the background
|
||||||
_stateTimer?.cancel();
|
_stateTimer?.cancel();
|
||||||
// TODO: bump this to > 30 seconds when testing is done:
|
// TODO: bump this to > 30 seconds when testing is done:
|
||||||
_stateTimer = Timer(const Duration(seconds: 10), () async {
|
_stateTimer = Timer(const Duration(seconds: 10), () async {
|
||||||
wasInBackground = true;
|
wasInBackground = true;
|
||||||
getIt.get<BackgroundTasks>().updateServiceState(false, showNotifications);
|
getIt.get<BackgroundTasks>().serviceBackground();
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue