Fixes.

M committed Nov 10, 2020 at 01:14 UTC 03f47e393cf15c9616749f427e004e3e4fb67aaa
8 files changed +119 -81
cw_monero/ios/Classes/monero_api.cpp
+1 -16
@@ -437,7 +437,7 @@ extern "C"
437 {
438 store_mutex.lock();
439 get_current_wallet()->store(std::string(path));
440 - store_mutex.unlock();
440 + store_mutex.unlock();
441 }
442
443 bool transaction_create(char *address, char *payment_id, char *amount,
@@ -494,8 +494,6 @@ extern "C"
494 return committed;
495 }
496
497 - // START
498 -
497 uint64_t get_node_height_or_update(uint64_t base_eight)
498 {
499 if (m_cached_syncing_blockchain_height < base_eight) {
@@ -512,11 +510,6 @@ extern "C"
510 }
511
512 uint64_t height = m_listener->height();
515 -// uint64_t node_height = get_node_height_or_update(height);
516 -//
517 -// if (height <= 1 || node_height <= 0) {
518 -// return 0;
519 -// }
513
514 if (height <= 1) {
515 return 0;
@@ -537,12 +530,6 @@ extern "C"
530 }
531
532 bool should_refresh = m_listener->isNeedToRefresh();
540 -// uint64_t node_height = get_node_height_or_update(m_last_known_wallet_height);
541 -//
542 -// if (should_refresh || (node_height - m_last_known_wallet_height < MONERO_BLOCK_SIZE))
543 -// {
544 -// m_listener->resetNeedToRefresh();
545 -// }
533
534 if (should_refresh) {
535 m_listener->resetNeedToRefresh();
@@ -580,8 +567,6 @@ extern "C"
567 get_current_wallet()->setListener(m_listener);
568 }
569
583 - // END
584 -
570 int64_t *subaddrress_get_all()
571 {
572 std::vector<Monero::SubaddressRow *> _subaddresses = m_subaddress->getAll();
cw_monero/lib/wallet.dart
+6 -1
@@ -240,12 +240,17 @@ class SyncListener {
240 _initialSyncHeight = 0;
241 _updateSyncInfoTimer ??=
242 Timer.periodic(Duration(milliseconds: 1200), (_) async {
243 - if (isNewTransactionExist() ?? false) {
243 + if (isNewTransactionExist() ?? isNeededToRefresh() ?? false) {
244 onNewTransaction?.call();
245 }
246
247 + final _isNeededToRefresh = isNeededToRefresh();
248 + print('isNeededToRefresh $_isNeededToRefresh');
249 +
250 var syncHeight = getSyncingHeight();
251
252 + print('syncHeight $syncHeight');
253 +
254 if (syncHeight <= 0) {
255 syncHeight = getCurrentHeight();
256 }
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 = 1;
357 + CURRENT_PROJECT_VERSION = 3;
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 = 1;
497 + CURRENT_PROJECT_VERSION = 3;
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 = 1;
531 + CURRENT_PROJECT_VERSION = 3;
532 DEVELOPMENT_TEAM = 32J6BB6VUS;
533 ENABLE_BITCODE = NO;
534 FRAMEWORK_SEARCH_PATHS = (
lib/entities/fs_migration.dart
+26 -22
@@ -391,32 +391,36 @@ Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) async {
391 }
392
393 Future<void> ios_migrate_address_book(Box<Contact> contactSource) async {
394 - final prefs = await SharedPreferences.getInstance();
394 + try {
395 + final prefs = await SharedPreferences.getInstance();
396
396 - if (prefs.getBool('ios_migration_address_book_completed') ?? false) {
397 - return;
398 - }
397 + if (prefs.getBool('ios_migration_address_book_completed') ?? false) {
398 + return;
399 + }
400
400 - final appDocDir = await getApplicationDocumentsDirectory();
401 - final addressBookJSON = File('${appDocDir.path}/address_book.json');
401 + final appDocDir = await getApplicationDocumentsDirectory();
402 + final addressBookJSON = File('${appDocDir.path}/address_book.json');
403
403 - if (!addressBookJSON.existsSync()) {
404 - await prefs.setBool('ios_migration_address_book_completed', true);
405 - return;
406 - }
404 + if (!addressBookJSON.existsSync()) {
405 + await prefs.setBool('ios_migration_address_book_completed', true);
406 + return;
407 + }
408
408 - final List<dynamic> addresses =
409 - json.decode(addressBookJSON.readAsStringSync()) as List<dynamic>;
410 - final contacts = addresses.map((dynamic item) {
411 - final _item = item as Map<String, dynamic>;
412 - final type = _item["type"] as String;
413 - final address = _item["address"] as String;
414 - final name = _item["name"] as String;
409 + final List<dynamic> addresses =
410 + json.decode(addressBookJSON.readAsStringSync()) as List<dynamic>;
411 + final contacts = addresses.map((dynamic item) {
412 + final _item = item as Map<String, dynamic>;
413 + final type = _item["type"] as String;
414 + final address = _item["address"] as String;
415 + final name = _item["name"] as String;
416
416 - return Contact(
417 - address: address, name: name, type: CryptoCurrency.fromString(type));
418 - });
417 + return Contact(
418 + address: address, name: name, type: CryptoCurrency.fromString(type));
419 + });
420
420 - await contactSource.addAll(contacts);
421 - await prefs.setBool('ios_migration_address_book_completed', true);
421 + await contactSource.addAll(contacts);
422 + await prefs.setBool('ios_migration_address_book_completed', true);
423 + } catch(e) {
424 + print(e.toString());
425 + }
426 }
lib/monero/monero_wallet.dart
+51 -10
@@ -44,10 +44,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
44 subaddress = subaddressList.subaddresses.first;
45 address = subaddress.address;
46 _lastAutosaveTimestamp = 0;
47 + _isSavingAfterSync = false;
48 + _isSavingAfterNewTransaction = false;
49 });
50 }
51
50 - static const int _autoAfterSyncSaceInterval = 60000;
52 + static const int _autoAfterSyncSaveInterval = 60000;
53
54 @override
55 final MoneroTransactionHistory transactionHistory;
@@ -88,6 +90,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
90 SyncListener _listener;
91 ReactionDisposer _onAccountChangeReaction;
92 int _lastAutosaveTimestamp;
93 + bool _isSavingAfterSync;
94 + bool _isSavingAfterNewTransaction;
95
96 Future<void> init() async {
97 await accountList.update();
@@ -174,11 +178,14 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
178 @override
179 Future<PendingTransaction> createTransaction(Object credentials) async {
180 final _credentials = credentials as MoneroTransactionCreationCredentials;
177 - final amount = moneroParseAmount(amount: _credentials.amount);
181 + final amount = _credentials.amount != null
182 + ? moneroParseAmount(amount: _credentials.amount)
183 + : null;
184 final unlockedBalance =
185 monero_wallet.getUnlockedBalance(accountIndex: account.id);
186
181 - if (unlockedBalance < amount) {
187 + if ((amount != null && unlockedBalance < amount) ||
188 + (amount == null && unlockedBalance <= 0)) {
189 throw MoneroTransactionCreationException(
190 'Incorrect unlocked balance. Unlocked: $unlockedBalance. Transaction amount: ${_credentials.amount}.');
191 }
@@ -292,8 +299,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
299 }
300
301 void _askForUpdateBalance() {
295 - final fullBalance = _getFullBalance();
302 final unlockedBalance = _getUnlockedBalance();
303 + final fullBalance = _getFullBalance();
304
305 if (balance.fullBalance != fullBalance ||
306 balance.unlockedBalance != unlockedBalance) {
@@ -313,18 +320,47 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
320 monero_wallet.getUnlockedBalance(accountIndex: account.id);
321
322 Future<void> _afterSyncSave() async {
316 - final nowTimestamp = DateTime.now().millisecondsSinceEpoch;
317 - final sum = _lastAutosaveTimestamp + _autoAfterSyncSaceInterval;
323 + if (_isSavingAfterSync) {
324 + return;
325 + }
326 +
327 + _isSavingAfterSync = true;
328 +
329 + try {
330 + final nowTimestamp = DateTime.now().millisecondsSinceEpoch;
331 + final sum = _lastAutosaveTimestamp + _autoAfterSyncSaveInterval;
332 +
333 + if (_lastAutosaveTimestamp > 0 && sum < nowTimestamp) {
334 + return;
335 + }
336 +
337 + await save();
338 + _lastAutosaveTimestamp = nowTimestamp + _autoAfterSyncSaveInterval;
339 + } catch (e) {
340 + print(e.toString());
341 + }
342 +
343 + _isSavingAfterSync = false;
344 + }
345
319 - if (_lastAutosaveTimestamp != 0 && sum < nowTimestamp) {
346 + Future<void> _afterNewTransactionSave() async {
347 + if (_isSavingAfterNewTransaction) {
348 return;
349 }
350
323 - _lastAutosaveTimestamp = nowTimestamp + _autoAfterSyncSaceInterval;
324 - await save();
351 + _isSavingAfterNewTransaction = true;
352 +
353 + try {
354 + await save();
355 + } catch (e) {
356 + print(e.toString());
357 + }
358 +
359 + _isSavingAfterNewTransaction = false;
360 }
361
362 void _onNewBlock(int height, int blocksLeft, double ptc) async {
363 + print('_onNewBlock called');
364 if (walletInfo.isRecovery) {
365 _askForUpdateTransactionHistory();
366 }
@@ -334,14 +370,19 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
370 if (blocksLeft < 100) {
371 syncStatus = SyncedSyncStatus();
372 await _afterSyncSave();
373 +
374 + if (walletInfo.isRecovery) {
375 + setAsRecovered();
376 + }
377 } else {
378 syncStatus = SyncingSyncStatus(blocksLeft, ptc);
379 }
380 }
381
382 void _onNewTransaction() {
383 + print('_onNewTransaction called');
384 _askForUpdateTransactionHistory();
385 _askForUpdateBalance();
345 - _afterSyncSave();
386 + Timer(Duration(seconds: 1), () => _afterNewTransactionSave());
387 }
388 }
lib/src/widgets/address_text_field.dart
+2 -2
@@ -220,9 +220,9 @@ class AddressTextField extends StatelessWidget {
220 Future<void> _pasteAddress(BuildContext context) async {
221 String address;
222
223 - await Clipboard.getData('text/plain').then((value) => address = value.text);
223 + await Clipboard.getData('text/plain').then((value) => address = value?.text);
224
225 - if (address.isNotEmpty) {
225 + if (address?.isNotEmpty ?? false) {
226 controller.text = address;
227 }
228 }
lib/store/settings_store.dart
+6 -3
@@ -160,9 +160,12 @@ abstract class SettingsStoreBase with Store {
160 actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
161 sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
162 defaultActionsMode));
163 - final pinLength =
164 - sharedPreferences.getInt(PreferencesKey.currentPinLength) ??
165 - defaultPinLength;
163 + var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
164 + // If no value
165 + if (pinLength == null || pinLength == 0) {
166 + pinLength = defaultPinLength;
167 + }
168 +
169 final savedLanguageCode =
170 sharedPreferences.getString(PreferencesKey.currentLanguageCode) ??
171 await LanguageService.localeDetection();
pubspec.lock
+24 -24
@@ -14,7 +14,7 @@ packages:
14 name: analyzer
15 url: "https://pub.dartlang.org"
16 source: hosted
17 - version: "0.40.5"
17 + version: "0.40.6"
18 archive:
19 dependency: transitive
20 description:
@@ -77,7 +77,7 @@ packages:
77 name: bip32
78 url: "https://pub.dartlang.org"
79 source: hosted
80 - version: "1.0.5"
80 + version: "1.0.7"
81 bip39:
82 dependency: transitive
83 description:
@@ -133,7 +133,7 @@ packages:
133 name: build_resolvers
134 url: "https://pub.dartlang.org"
135 source: hosted
136 - version: "1.4.2"
136 + version: "1.4.3"
137 build_runner:
138 dependency: "direct dev"
139 description:
@@ -224,14 +224,14 @@ packages:
224 name: connectivity_for_web
225 url: "https://pub.dartlang.org"
226 source: hosted
227 - version: "0.3.1+2"
227 + version: "0.3.1+4"
228 connectivity_macos:
229 dependency: transitive
230 description:
231 name: connectivity_macos
232 url: "https://pub.dartlang.org"
233 source: hosted
234 - version: "0.1.0+5"
234 + version: "0.1.0+7"
235 connectivity_platform_interface:
236 dependency: transitive
237 description:
@@ -273,7 +273,7 @@ packages:
273 name: dart_style
274 url: "https://pub.dartlang.org"
275 source: hosted
276 - version: "1.3.8+1"
276 + version: "1.3.9"
277 dartx:
278 dependency: transitive
279 description:
@@ -470,7 +470,7 @@ packages:
470 name: hive_generator
471 url: "https://pub.dartlang.org"
472 source: hosted
473 - version: "0.8.1"
473 + version: "0.8.2"
474 http:
475 dependency: "direct main"
476 description:
@@ -540,7 +540,7 @@ packages:
540 name: local_auth
541 url: "https://pub.dartlang.org"
542 source: hosted
543 - version: "0.6.3+3"
543 + version: "0.6.3+4"
544 logging:
545 dependency: transitive
546 description:
@@ -582,7 +582,7 @@ packages:
582 name: mobx_codegen
583 url: "https://pub.dartlang.org"
584 source: hosted
585 - version: "1.1.1+3"
585 + version: "1.1.2"
586 node_interop:
587 dependency: transitive
588 description:
@@ -610,7 +610,7 @@ packages:
610 name: package_info
611 url: "https://pub.dartlang.org"
612 source: hosted
613 - version: "0.4.3"
613 + version: "0.4.3+2"
614 password:
615 dependency: "direct main"
616 description:
@@ -645,7 +645,7 @@ packages:
645 name: path_provider
646 url: "https://pub.dartlang.org"
647 source: hosted
648 - version: "1.6.22"
648 + version: "1.6.24"
649 path_provider_linux:
650 dependency: transitive
651 description:
@@ -659,21 +659,21 @@ packages:
659 name: path_provider_macos
660 url: "https://pub.dartlang.org"
661 source: hosted
662 - version: "0.0.4+4"
662 + version: "0.0.4+6"
663 path_provider_platform_interface:
664 dependency: transitive
665 description:
666 name: path_provider_platform_interface
667 url: "https://pub.dartlang.org"
668 source: hosted
669 - version: "1.0.3"
669 + version: "1.0.4"
670 path_provider_windows:
671 dependency: transitive
672 description:
673 name: path_provider_windows
674 url: "https://pub.dartlang.org"
675 source: hosted
676 - version: "0.0.4+1"
676 + version: "0.0.4+3"
677 pedantic:
678 dependency: "direct dev"
679 description:
@@ -764,7 +764,7 @@ packages:
764 name: quiver
765 url: "https://pub.dartlang.org"
766 source: hosted
767 - version: "2.1.4+1"
767 + version: "2.1.5"
768 rxdart:
769 dependency: "direct main"
770 description:
@@ -785,21 +785,21 @@ packages:
785 name: shared_preferences
786 url: "https://pub.dartlang.org"
787 source: hosted
788 - version: "0.5.12+2"
788 + version: "0.5.12+4"
789 shared_preferences_linux:
790 dependency: transitive
791 description:
792 name: shared_preferences_linux
793 url: "https://pub.dartlang.org"
794 source: hosted
795 - version: "0.0.2+2"
795 + version: "0.0.2+4"
796 shared_preferences_macos:
797 dependency: transitive
798 description:
799 name: shared_preferences_macos
800 url: "https://pub.dartlang.org"
801 source: hosted
802 - version: "0.0.1+10"
802 + version: "0.0.1+11"
803 shared_preferences_platform_interface:
804 dependency: transitive
805 description:
@@ -820,7 +820,7 @@ packages:
820 name: shared_preferences_windows
821 url: "https://pub.dartlang.org"
822 source: hosted
823 - version: "0.0.1+1"
823 + version: "0.0.1+3"
824 shelf:
825 dependency: transitive
826 description:
@@ -930,21 +930,21 @@ packages:
930 name: url_launcher
931 url: "https://pub.dartlang.org"
932 source: hosted
933 - version: "5.7.8"
933 + version: "5.7.10"
934 url_launcher_linux:
935 dependency: transitive
936 description:
937 name: url_launcher_linux
938 url: "https://pub.dartlang.org"
939 source: hosted
940 - version: "0.0.1+3"
940 + version: "0.0.1+4"
941 url_launcher_macos:
942 dependency: transitive
943 description:
944 name: url_launcher_macos
945 url: "https://pub.dartlang.org"
946 source: hosted
947 - version: "0.0.1+8"
947 + version: "0.0.1+9"
948 url_launcher_platform_interface:
949 dependency: transitive
950 description:
@@ -958,14 +958,14 @@ packages:
958 name: url_launcher_web
959 url: "https://pub.dartlang.org"
960 source: hosted
961 - version: "0.1.5"
961 + version: "0.1.5+1"
962 url_launcher_windows:
963 dependency: transitive
964 description:
965 name: url_launcher_windows
966 url: "https://pub.dartlang.org"
967 source: hosted
968 - version: "0.0.1+1"
968 + version: "0.0.1+3"
969 uuid:
970 dependency: "direct main"
971 description: