Fixes.

M committed Nov 4, 2020 at 17:54 UTC fdb0f49f88d458fe4d87b12a27b62328c44608c7
5 files changed +42 -29
cw_monero/lib/wallet.dart
+19 -4
@@ -212,13 +212,18 @@ String getPublicSpendKey() =>
212 convertUTF8ToString(pointer: getPublicSpendKeyNative());
213
214 class SyncListener {
215 - SyncListener({this.onNewBlock});
215 + SyncListener({this.onNewBlock}) {
216 + _cachedBlockchainHeight = 0;
217 + _lastKnownBlockHeight = 0;
218 + _initialSyncHeight = 0;
219 + }
220
221 void Function(int, int, double) onNewBlock;
222
223 Timer _updateSyncInfoTimer;
220 - int _cachedBlockchainHeight = 0;
221 - int _lastKnownBlockHeight = 0;
224 + int _cachedBlockchainHeight;
225 + int _lastKnownBlockHeight;
226 + int _initialSyncHeight;
227
228 Future<int> getNodeHeightOrUpdate(int baseHeight) async {
229 if (_cachedBlockchainHeight < baseHeight || _cachedBlockchainHeight == 0) {
@@ -231,6 +236,7 @@ class SyncListener {
236 void start() {
237 _cachedBlockchainHeight = 0;
238 _lastKnownBlockHeight = 0;
239 + _initialSyncHeight = 0;
240 _updateSyncInfoTimer ??=
241 Timer.periodic(Duration(milliseconds: 1200), (_) async {
242 var syncHeight = getSyncingHeight();
@@ -239,6 +245,10 @@ class SyncListener {
245 syncHeight = getCurrentHeight();
246 }
247
248 + if (_initialSyncHeight <= 0) {
249 + _initialSyncHeight = syncHeight;
250 + }
251 +
252 final bchHeight = await getNodeHeightOrUpdate(syncHeight);
253
254 if (_lastKnownBlockHeight == syncHeight || syncHeight == null) {
@@ -246,10 +256,15 @@ class SyncListener {
256 }
257
258 _lastKnownBlockHeight = syncHeight;
249 - final track = bchHeight - syncHeight;
259 + final track = bchHeight - _initialSyncHeight;
260 final diff = track - (bchHeight - syncHeight);
261 final ptc = diff <= 0 ? 0.0 : diff / track;
262 final left = bchHeight - syncHeight;
263 +
264 + if (syncHeight < 0 || left < 0) {
265 + return;
266 + }
267 +
268 // 1. Actual new height; 2. Blocks left to finish; 3. Progress in percents;
269 onNewBlock?.call(syncHeight, left, ptc);
270 });
ios/Runner.xcodeproj/project.pbxproj
+3 -3
@@ -354,7 +354,7 @@
354 buildSettings = {
355 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
356 CLANG_ENABLE_MODULES = YES;
357 - CURRENT_PROJECT_VERSION = 12;
357 + CURRENT_PROJECT_VERSION = 17;
358 DEVELOPMENT_TEAM = 32J6BB6VUS;
359 ENABLE_BITCODE = NO;
360 FRAMEWORK_SEARCH_PATHS = (
@@ -494,7 +494,7 @@
494 buildSettings = {
495 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
496 CLANG_ENABLE_MODULES = YES;
497 - CURRENT_PROJECT_VERSION = 12;
497 + CURRENT_PROJECT_VERSION = 17;
498 DEVELOPMENT_TEAM = 32J6BB6VUS;
499 ENABLE_BITCODE = NO;
500 FRAMEWORK_SEARCH_PATHS = (
@@ -528,7 +528,7 @@
528 buildSettings = {
529 ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
530 CLANG_ENABLE_MODULES = YES;
531 - CURRENT_PROJECT_VERSION = 12;
531 + CURRENT_PROJECT_VERSION = 17;
532 DEVELOPMENT_TEAM = 32J6BB6VUS;
533 ENABLE_BITCODE = NO;
534 FRAMEWORK_SEARCH_PATHS = (
lib/monero/monero_wallet.dart
+11 -11
@@ -39,10 +39,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
39 subaddressList.update(accountIndex: account.id);
40 subaddress = subaddressList.subaddresses.first;
41 address = subaddress.address;
42 + _lastAutosaveTimestamp = 0;
43 });
43 - _cachedRefreshHeight = 0;
44 }
45
46 + static const int _autoAfterSyncSaceInterval = 60000;
47 +
48 @override
49 final MoneroTransactionHistory transactionHistory;
50
@@ -81,7 +83,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
83 String _filename;
84 SyncListener _listener;
85 ReactionDisposer _onAccountChangeReaction;
84 - int _cachedRefreshHeight;
86 + int _lastAutosaveTimestamp;
87
88 Future<void> init() async {
89 await accountList.update();
@@ -95,7 +97,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
97 address = subaddress.address;
98 _setListeners();
99 await transactionHistory.update();
98 - print('walletInfo.isRecovery ${walletInfo.isRecovery}');
100 +
101 if (walletInfo.isRecovery) {
102 monero_wallet.setRecoveringFromSeed(isRecovery: walletInfo.isRecovery);
103
@@ -156,6 +158,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
158 try {
159 syncStatus = StartingSyncStatus();
160 monero_wallet.startRefresh();
161 + _setListeners();
162 + _listener?.start();
163 } catch (e) {
164 syncStatus = FailedSyncStatus();
165 print(e);
@@ -234,7 +238,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
238 void _setListeners() {
239 _listener?.stop();
240 _listener = monero_wallet.setListeners(_onNewBlock);
237 - _listener.start();
241 }
242
243 void _setInitialHeight() {
@@ -292,18 +295,15 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
295 int _getUnlockedBalance() =>
296 monero_wallet.getUnlockedBalance(accountIndex: account.id);
297
295 - int _lastAutosaveTimestamp = 0;
296 - final int _autosaveInterval = 60000;
297 -
298 - Future<void> _autoSave() async {
298 + Future<void> _afterSyncSave() async {
299 final nowTimestamp = DateTime.now().millisecondsSinceEpoch;
300 - final sum = _lastAutosaveTimestamp + _autosaveInterval;
300 + final sum = _lastAutosaveTimestamp + _autoAfterSyncSaceInterval;
301
302 if (_lastAutosaveTimestamp != 0 && sum < nowTimestamp) {
303 return;
304 }
305
306 - _lastAutosaveTimestamp = nowTimestamp + _autosaveInterval;
306 + _lastAutosaveTimestamp = nowTimestamp + _autoAfterSyncSaceInterval;
307 await save();
308 }
309
@@ -313,7 +313,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
313
314 if (blocksLeft < moneroBlockSize) {
315 syncStatus = SyncedSyncStatus();
316 - await _autoSave();
316 + await _afterSyncSave();
317 } else {
318 syncStatus = SyncingSyncStatus(blocksLeft, ptc);
319 }
lib/src/widgets/validable_annotated_editable_text.dart
+8 -10
@@ -73,12 +73,14 @@ class ValidableAnnotatedEditableText extends EditableText {
73 final TextStyle invalidStyle;
74
75 @override
76 - ValidableAnnotatedEditableTextState createState() => ValidableAnnotatedEditableTextState();
76 + ValidableAnnotatedEditableTextState createState() =>
77 + ValidableAnnotatedEditableTextState();
78 }
79
80 class ValidableAnnotatedEditableTextState extends EditableTextState {
81 @override
81 - ValidableAnnotatedEditableText get widget => super.widget as ValidableAnnotatedEditableText;
82 + ValidableAnnotatedEditableText get widget =>
83 + super.widget as ValidableAnnotatedEditableText;
84
85 List<Annotation> getRanges() {
86 final result = List<Annotation>();
@@ -154,17 +156,13 @@ class ValidableAnnotatedEditableTextState extends EditableTextState {
156 final text = textEditingValue.text;
157 final ranges = getRanges().toSet();
158
157 - print('text $text');
158 -
159 if (ranges.isNotEmpty) {
160 return TextSpan(
161 style: widget.style,
162 - children: ranges.map((item) {
163 - final _text = item.range.textInside(text);
164 - print(
165 - '_text $_text; range ${item.range.start} : ${item.range.end}');
166 - return TextSpan(style: item.style, text: _text);
167 - }).toList());
162 + children: ranges
163 + .map((item) => TextSpan(
164 + style: item.style, text: item.range.textInside(text)))
165 + .toList());
166 }
167
168 return TextSpan(style: widget.style, text: text);
pubspec.lock
+1 -1
@@ -589,7 +589,7 @@ packages:
589 name: node_interop
590 url: "https://pub.dartlang.org"
591 source: hosted
592 - version: "1.1.1"
592 + version: "1.2.0"
593 node_io:
594 dependency: transitive
595 description: