diff --git a/cw_monero/lib/wallet.dart b/cw_monero/lib/wallet.dart index 4348c8809..e3a0eb304 100644 --- a/cw_monero/lib/wallet.dart +++ b/cw_monero/lib/wallet.dart @@ -212,13 +212,18 @@ String getPublicSpendKey() => convertUTF8ToString(pointer: getPublicSpendKeyNative()); class SyncListener { - SyncListener({this.onNewBlock}); + SyncListener({this.onNewBlock}) { + _cachedBlockchainHeight = 0; + _lastKnownBlockHeight = 0; + _initialSyncHeight = 0; + } void Function(int, int, double) onNewBlock; Timer _updateSyncInfoTimer; - int _cachedBlockchainHeight = 0; - int _lastKnownBlockHeight = 0; + int _cachedBlockchainHeight; + int _lastKnownBlockHeight; + int _initialSyncHeight; Future getNodeHeightOrUpdate(int baseHeight) async { if (_cachedBlockchainHeight < baseHeight || _cachedBlockchainHeight == 0) { @@ -231,6 +236,7 @@ class SyncListener { void start() { _cachedBlockchainHeight = 0; _lastKnownBlockHeight = 0; + _initialSyncHeight = 0; _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async { var syncHeight = getSyncingHeight(); @@ -239,6 +245,10 @@ class SyncListener { syncHeight = getCurrentHeight(); } + if (_initialSyncHeight <= 0) { + _initialSyncHeight = syncHeight; + } + final bchHeight = await getNodeHeightOrUpdate(syncHeight); if (_lastKnownBlockHeight == syncHeight || syncHeight == null) { @@ -246,10 +256,15 @@ class SyncListener { } _lastKnownBlockHeight = syncHeight; - final track = bchHeight - syncHeight; + final track = bchHeight - _initialSyncHeight; final diff = track - (bchHeight - syncHeight); final ptc = diff <= 0 ? 0.0 : diff / track; final left = bchHeight - syncHeight; + + if (syncHeight < 0 || left < 0) { + return; + } + // 1. Actual new height; 2. Blocks left to finish; 3. Progress in percents; onNewBlock?.call(syncHeight, left, ptc); }); diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 80e5a8a00..41ccba7a1 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -354,7 +354,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = 32J6BB6VUS; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -494,7 +494,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = 32J6BB6VUS; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -528,7 +528,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 12; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = 32J6BB6VUS; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index 8ce53f8d1..84d8b0e43 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -39,10 +39,12 @@ abstract class MoneroWalletBase extends WalletBase with Store { subaddressList.update(accountIndex: account.id); subaddress = subaddressList.subaddresses.first; address = subaddress.address; + _lastAutosaveTimestamp = 0; }); - _cachedRefreshHeight = 0; } + static const int _autoAfterSyncSaceInterval = 60000; + @override final MoneroTransactionHistory transactionHistory; @@ -81,7 +83,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { String _filename; SyncListener _listener; ReactionDisposer _onAccountChangeReaction; - int _cachedRefreshHeight; + int _lastAutosaveTimestamp; Future init() async { await accountList.update(); @@ -95,7 +97,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { address = subaddress.address; _setListeners(); await transactionHistory.update(); - print('walletInfo.isRecovery ${walletInfo.isRecovery}'); + if (walletInfo.isRecovery) { monero_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery); @@ -156,6 +158,8 @@ abstract class MoneroWalletBase extends WalletBase with Store { try { syncStatus = StartingSyncStatus(); monero_wallet.startRefresh(); + _setListeners(); + _listener?.start(); } catch (e) { syncStatus = FailedSyncStatus(); print(e); @@ -234,7 +238,6 @@ abstract class MoneroWalletBase extends WalletBase with Store { void _setListeners() { _listener?.stop(); _listener = monero_wallet.setListeners(_onNewBlock); - _listener.start(); } void _setInitialHeight() { @@ -292,18 +295,15 @@ abstract class MoneroWalletBase extends WalletBase with Store { int _getUnlockedBalance() => monero_wallet.getUnlockedBalance(accountIndex: account.id); - int _lastAutosaveTimestamp = 0; - final int _autosaveInterval = 60000; - - Future _autoSave() async { + Future _afterSyncSave() async { final nowTimestamp = DateTime.now().millisecondsSinceEpoch; - final sum = _lastAutosaveTimestamp + _autosaveInterval; + final sum = _lastAutosaveTimestamp + _autoAfterSyncSaceInterval; if (_lastAutosaveTimestamp != 0 && sum < nowTimestamp) { return; } - _lastAutosaveTimestamp = nowTimestamp + _autosaveInterval; + _lastAutosaveTimestamp = nowTimestamp + _autoAfterSyncSaceInterval; await save(); } @@ -313,7 +313,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { if (blocksLeft < moneroBlockSize) { syncStatus = SyncedSyncStatus(); - await _autoSave(); + await _afterSyncSave(); } else { syncStatus = SyncingSyncStatus(blocksLeft, ptc); } diff --git a/lib/src/widgets/validable_annotated_editable_text.dart b/lib/src/widgets/validable_annotated_editable_text.dart index b407a7950..e603c0327 100644 --- a/lib/src/widgets/validable_annotated_editable_text.dart +++ b/lib/src/widgets/validable_annotated_editable_text.dart @@ -73,12 +73,14 @@ class ValidableAnnotatedEditableText extends EditableText { final TextStyle invalidStyle; @override - ValidableAnnotatedEditableTextState createState() => ValidableAnnotatedEditableTextState(); + ValidableAnnotatedEditableTextState createState() => + ValidableAnnotatedEditableTextState(); } class ValidableAnnotatedEditableTextState extends EditableTextState { @override - ValidableAnnotatedEditableText get widget => super.widget as ValidableAnnotatedEditableText; + ValidableAnnotatedEditableText get widget => + super.widget as ValidableAnnotatedEditableText; List getRanges() { final result = List(); @@ -154,17 +156,13 @@ class ValidableAnnotatedEditableTextState extends EditableTextState { final text = textEditingValue.text; final ranges = getRanges().toSet(); - print('text $text'); - if (ranges.isNotEmpty) { return TextSpan( style: widget.style, - children: ranges.map((item) { - final _text = item.range.textInside(text); - print( - '_text $_text; range ${item.range.start} : ${item.range.end}'); - return TextSpan(style: item.style, text: _text); - }).toList()); + children: ranges + .map((item) => TextSpan( + style: item.style, text: item.range.textInside(text))) + .toList()); } return TextSpan(style: widget.style, text: text); diff --git a/pubspec.lock b/pubspec.lock index a04e9e780..182703e52 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -589,7 +589,7 @@ packages: name: node_interop url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.2.0" node_io: dependency: transitive description: