mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-21 02:04:43 +00:00
updates to bg sync
This commit is contained in:
parent
b089d928e1
commit
53dd533580
5 changed files with 24 additions and 6 deletions
|
@ -103,5 +103,6 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
|
||||||
|
|
||||||
bool isTestnet = false;
|
bool isTestnet = false;
|
||||||
|
|
||||||
Future<void> closeWallet() async {}
|
// TODO: use proxy layer
|
||||||
|
Future<void> reopenWallet() async {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,6 +233,10 @@ void closeCurrentWallet() {
|
||||||
monero.Wallet_stop(wptr!);
|
monero.Wallet_stop(wptr!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopWallet() {
|
||||||
|
monero.Wallet_stop(wptr!);
|
||||||
|
}
|
||||||
|
|
||||||
String getSecretViewKey() => monero.Wallet_secretViewKey(wptr!);
|
String getSecretViewKey() => monero.Wallet_secretViewKey(wptr!);
|
||||||
|
|
||||||
String getPublicViewKey() => monero.Wallet_publicViewKey(wptr!);
|
String getPublicViewKey() => monero.Wallet_publicViewKey(wptr!);
|
||||||
|
|
|
@ -39,6 +39,7 @@ import 'package:hive/hive.dart';
|
||||||
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
|
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:monero/monero.dart' as monero;
|
import 'package:monero/monero.dart' as monero;
|
||||||
|
import 'package:cw_monero/api/transaction_history.dart' as transaction_history;
|
||||||
|
|
||||||
part 'monero_wallet.g.dart';
|
part 'monero_wallet.g.dart';
|
||||||
|
|
||||||
|
@ -175,6 +176,7 @@ abstract class MoneroWalletBase
|
||||||
_onAccountChangeReaction?.reaction.dispose();
|
_onAccountChangeReaction?.reaction.dispose();
|
||||||
_onTxHistoryChangeReaction?.reaction.dispose();
|
_onTxHistoryChangeReaction?.reaction.dispose();
|
||||||
_autoSaveTimer?.cancel();
|
_autoSaveTimer?.cancel();
|
||||||
|
monero_wallet.stopWallet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -268,6 +270,7 @@ abstract class MoneroWalletBase
|
||||||
_listener?.stop();
|
_listener?.stop();
|
||||||
if (isBackgroundSync) {
|
if (isBackgroundSync) {
|
||||||
isBackgroundSyncing = false;
|
isBackgroundSyncing = false;
|
||||||
|
monero_wallet.stopWallet();
|
||||||
monero_wallet.stopBackgroundSync(password);
|
monero_wallet.stopBackgroundSync(password);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +280,7 @@ abstract class MoneroWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> closeWallet() async {
|
Future<void> reopenWallet() async {
|
||||||
printV("closing wallet");
|
printV("closing wallet");
|
||||||
final currentWalletDirPath = await pathForWalletDir(name: name, type: type);
|
final currentWalletDirPath = await pathForWalletDir(name: name, type: type);
|
||||||
final wmaddr = wmPtr.address;
|
final wmaddr = wmPtr.address;
|
||||||
|
@ -286,7 +289,10 @@ abstract class MoneroWalletBase
|
||||||
monero.WalletManager_closeWallet(
|
monero.WalletManager_closeWallet(
|
||||||
Pointer.fromAddress(wmaddr), Pointer.fromAddress(waddr), true);
|
Pointer.fromAddress(wmaddr), Pointer.fromAddress(waddr), true);
|
||||||
});
|
});
|
||||||
await init();
|
wptr = monero.WalletManager_openWallet(wmPtr, path: currentWalletDirPath, password: password);
|
||||||
|
openedWalletsByPath["$currentWalletDirPath/$name"] = wptr!;
|
||||||
|
transaction_history.txhistory = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -164,17 +164,16 @@ Future<void> onStart(ServiceInstance service) async {
|
||||||
for (int i = 0; i < syncingWallets.length; i++) {
|
for (int i = 0; i < syncingWallets.length; i++) {
|
||||||
final wallet = syncingWallets[i];
|
final wallet = syncingWallets[i];
|
||||||
await wallet.stopSync(isBackgroundSync: true);
|
await wallet.stopSync(isBackgroundSync: true);
|
||||||
await wallet.close();
|
|
||||||
}
|
}
|
||||||
// stop all standby wallets (just in case):
|
// stop all standby wallets (just in case):
|
||||||
for (int i = 0; i < standbyWallets.length; i++) {
|
for (int i = 0; i < standbyWallets.length; i++) {
|
||||||
final wallet = standbyWallets[i];
|
final wallet = standbyWallets[i];
|
||||||
await wallet.stopSync(isBackgroundSync: true);
|
await wallet.stopSync(isBackgroundSync: true);
|
||||||
await wallet.close();
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
printV("error stopping sync: $e");
|
printV("error stopping sync: $e");
|
||||||
}
|
}
|
||||||
|
printV("done stopping sync");
|
||||||
}
|
}
|
||||||
|
|
||||||
service.on("stopService").listen((event) async {
|
service.on("stopService").listen((event) async {
|
||||||
|
|
|
@ -180,10 +180,18 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await wallet?.stopSync(isBackgroundSync: true);
|
|
||||||
// await wallet?.closeWallet();
|
// await wallet?.closeWallet();
|
||||||
// restart the background service if it was running before:
|
// restart the background service if it was running before:
|
||||||
await getIt.get<BackgroundTasks>().serviceForeground();
|
await getIt.get<BackgroundTasks>().serviceForeground();
|
||||||
|
|
||||||
|
await Future.delayed(const Duration(seconds: 10));
|
||||||
|
|
||||||
|
await wallet?.stopSync(isBackgroundSync: true);
|
||||||
|
|
||||||
|
await Future.delayed(const Duration(seconds: 10));
|
||||||
|
|
||||||
|
await wallet?.reopenWallet();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.hidden:
|
case AppLifecycleState.hidden:
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
|
|
Loading…
Reference in a new issue