From 03f47e393cf15c9616749f427e004e3e4fb67aaa Mon Sep 17 00:00:00 2001 From: M Date: Tue, 10 Nov 2020 01:14:47 +0200 Subject: [PATCH] Fixes. --- cw_monero/ios/Classes/monero_api.cpp | 17 +------ cw_monero/lib/wallet.dart | 7 ++- ios/Runner.xcodeproj/project.pbxproj | 6 +-- lib/entities/fs_migration.dart | 50 +++++++++++--------- lib/monero/monero_wallet.dart | 63 ++++++++++++++++++++----- lib/src/widgets/address_text_field.dart | 4 +- lib/store/settings_store.dart | 9 ++-- pubspec.lock | 48 +++++++++---------- 8 files changed, 121 insertions(+), 83 deletions(-) diff --git a/cw_monero/ios/Classes/monero_api.cpp b/cw_monero/ios/Classes/monero_api.cpp index 019f38ed2..2dfd8a0ae 100644 --- a/cw_monero/ios/Classes/monero_api.cpp +++ b/cw_monero/ios/Classes/monero_api.cpp @@ -437,7 +437,7 @@ extern "C" { store_mutex.lock(); get_current_wallet()->store(std::string(path)); - store_mutex.unlock(); + store_mutex.unlock(); } bool transaction_create(char *address, char *payment_id, char *amount, @@ -494,8 +494,6 @@ extern "C" return committed; } - // START - uint64_t get_node_height_or_update(uint64_t base_eight) { if (m_cached_syncing_blockchain_height < base_eight) { @@ -512,11 +510,6 @@ extern "C" } uint64_t height = m_listener->height(); -// uint64_t node_height = get_node_height_or_update(height); -// -// if (height <= 1 || node_height <= 0) { -// return 0; -// } if (height <= 1) { return 0; @@ -537,12 +530,6 @@ extern "C" } bool should_refresh = m_listener->isNeedToRefresh(); -// uint64_t node_height = get_node_height_or_update(m_last_known_wallet_height); -// -// if (should_refresh || (node_height - m_last_known_wallet_height < MONERO_BLOCK_SIZE)) -// { -// m_listener->resetNeedToRefresh(); -// } if (should_refresh) { m_listener->resetNeedToRefresh(); @@ -580,8 +567,6 @@ extern "C" get_current_wallet()->setListener(m_listener); } - // END - int64_t *subaddrress_get_all() { std::vector _subaddresses = m_subaddress->getAll(); diff --git a/cw_monero/lib/wallet.dart b/cw_monero/lib/wallet.dart index f10c35620..f1139c0d0 100644 --- a/cw_monero/lib/wallet.dart +++ b/cw_monero/lib/wallet.dart @@ -240,12 +240,17 @@ class SyncListener { _initialSyncHeight = 0; _updateSyncInfoTimer ??= Timer.periodic(Duration(milliseconds: 1200), (_) async { - if (isNewTransactionExist() ?? false) { + if (isNewTransactionExist() ?? isNeededToRefresh() ?? false) { onNewTransaction?.call(); } + final _isNeededToRefresh = isNeededToRefresh(); + print('isNeededToRefresh $_isNeededToRefresh'); + var syncHeight = getSyncingHeight(); + print('syncHeight $syncHeight'); + if (syncHeight <= 0) { syncHeight = getCurrentHeight(); } diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index ed2fd238d..b9a43c0aa 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 = 1; + CURRENT_PROJECT_VERSION = 3; 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 = 1; + CURRENT_PROJECT_VERSION = 3; 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 = 1; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_TEAM = 32J6BB6VUS; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( diff --git a/lib/entities/fs_migration.dart b/lib/entities/fs_migration.dart index 54b72c9ce..3e7513117 100644 --- a/lib/entities/fs_migration.dart +++ b/lib/entities/fs_migration.dart @@ -391,32 +391,36 @@ Future ios_migrate_trades_list(Box tradeSource) async { } Future ios_migrate_address_book(Box contactSource) async { - final prefs = await SharedPreferences.getInstance(); + try { + final prefs = await SharedPreferences.getInstance(); - if (prefs.getBool('ios_migration_address_book_completed') ?? false) { - return; - } + if (prefs.getBool('ios_migration_address_book_completed') ?? false) { + return; + } - final appDocDir = await getApplicationDocumentsDirectory(); - final addressBookJSON = File('${appDocDir.path}/address_book.json'); + final appDocDir = await getApplicationDocumentsDirectory(); + final addressBookJSON = File('${appDocDir.path}/address_book.json'); - if (!addressBookJSON.existsSync()) { + if (!addressBookJSON.existsSync()) { + await prefs.setBool('ios_migration_address_book_completed', true); + return; + } + + final List addresses = + json.decode(addressBookJSON.readAsStringSync()) as List; + final contacts = addresses.map((dynamic item) { + final _item = item as Map; + final type = _item["type"] as String; + final address = _item["address"] as String; + final name = _item["name"] as String; + + return Contact( + address: address, name: name, type: CryptoCurrency.fromString(type)); + }); + + await contactSource.addAll(contacts); await prefs.setBool('ios_migration_address_book_completed', true); - return; + } catch(e) { + print(e.toString()); } - - final List addresses = - json.decode(addressBookJSON.readAsStringSync()) as List; - final contacts = addresses.map((dynamic item) { - final _item = item as Map; - final type = _item["type"] as String; - final address = _item["address"] as String; - final name = _item["name"] as String; - - return Contact( - address: address, name: name, type: CryptoCurrency.fromString(type)); - }); - - await contactSource.addAll(contacts); - await prefs.setBool('ios_migration_address_book_completed', true); } diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index d4d4b7de4..f5e0f637f 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -44,10 +44,12 @@ abstract class MoneroWalletBase extends WalletBase with Store { subaddress = subaddressList.subaddresses.first; address = subaddress.address; _lastAutosaveTimestamp = 0; + _isSavingAfterSync = false; + _isSavingAfterNewTransaction = false; }); } - static const int _autoAfterSyncSaceInterval = 60000; + static const int _autoAfterSyncSaveInterval = 60000; @override final MoneroTransactionHistory transactionHistory; @@ -88,6 +90,8 @@ abstract class MoneroWalletBase extends WalletBase with Store { SyncListener _listener; ReactionDisposer _onAccountChangeReaction; int _lastAutosaveTimestamp; + bool _isSavingAfterSync; + bool _isSavingAfterNewTransaction; Future init() async { await accountList.update(); @@ -174,11 +178,14 @@ abstract class MoneroWalletBase extends WalletBase with Store { @override Future createTransaction(Object credentials) async { final _credentials = credentials as MoneroTransactionCreationCredentials; - final amount = moneroParseAmount(amount: _credentials.amount); + final amount = _credentials.amount != null + ? moneroParseAmount(amount: _credentials.amount) + : null; final unlockedBalance = monero_wallet.getUnlockedBalance(accountIndex: account.id); - if (unlockedBalance < amount) { + if ((amount != null && unlockedBalance < amount) || + (amount == null && unlockedBalance <= 0)) { throw MoneroTransactionCreationException( 'Incorrect unlocked balance. Unlocked: $unlockedBalance. Transaction amount: ${_credentials.amount}.'); } @@ -292,8 +299,8 @@ abstract class MoneroWalletBase extends WalletBase with Store { } void _askForUpdateBalance() { - final fullBalance = _getFullBalance(); final unlockedBalance = _getUnlockedBalance(); + final fullBalance = _getFullBalance(); if (balance.fullBalance != fullBalance || balance.unlockedBalance != unlockedBalance) { @@ -313,18 +320,47 @@ abstract class MoneroWalletBase extends WalletBase with Store { monero_wallet.getUnlockedBalance(accountIndex: account.id); Future _afterSyncSave() async { - final nowTimestamp = DateTime.now().millisecondsSinceEpoch; - final sum = _lastAutosaveTimestamp + _autoAfterSyncSaceInterval; - - if (_lastAutosaveTimestamp != 0 && sum < nowTimestamp) { + if (_isSavingAfterSync) { return; } - _lastAutosaveTimestamp = nowTimestamp + _autoAfterSyncSaceInterval; - await save(); + _isSavingAfterSync = true; + + try { + final nowTimestamp = DateTime.now().millisecondsSinceEpoch; + final sum = _lastAutosaveTimestamp + _autoAfterSyncSaveInterval; + + if (_lastAutosaveTimestamp > 0 && sum < nowTimestamp) { + return; + } + + await save(); + _lastAutosaveTimestamp = nowTimestamp + _autoAfterSyncSaveInterval; + } catch (e) { + print(e.toString()); + } + + _isSavingAfterSync = false; + } + + Future _afterNewTransactionSave() async { + if (_isSavingAfterNewTransaction) { + return; + } + + _isSavingAfterNewTransaction = true; + + try { + await save(); + } catch (e) { + print(e.toString()); + } + + _isSavingAfterNewTransaction = false; } void _onNewBlock(int height, int blocksLeft, double ptc) async { + print('_onNewBlock called'); if (walletInfo.isRecovery) { _askForUpdateTransactionHistory(); } @@ -334,14 +370,19 @@ abstract class MoneroWalletBase extends WalletBase with Store { if (blocksLeft < 100) { syncStatus = SyncedSyncStatus(); await _afterSyncSave(); + + if (walletInfo.isRecovery) { + setAsRecovered(); + } } else { syncStatus = SyncingSyncStatus(blocksLeft, ptc); } } void _onNewTransaction() { + print('_onNewTransaction called'); _askForUpdateTransactionHistory(); _askForUpdateBalance(); - _afterSyncSave(); + Timer(Duration(seconds: 1), () => _afterNewTransactionSave()); } } diff --git a/lib/src/widgets/address_text_field.dart b/lib/src/widgets/address_text_field.dart index d72431491..6074319e7 100644 --- a/lib/src/widgets/address_text_field.dart +++ b/lib/src/widgets/address_text_field.dart @@ -220,9 +220,9 @@ class AddressTextField extends StatelessWidget { Future _pasteAddress(BuildContext context) async { String address; - await Clipboard.getData('text/plain').then((value) => address = value.text); + await Clipboard.getData('text/plain').then((value) => address = value?.text); - if (address.isNotEmpty) { + if (address?.isNotEmpty ?? false) { controller.text = address; } } diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index c62c9b2e8..b4b76bb8d 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -160,9 +160,12 @@ abstract class SettingsStoreBase with Store { actionListDisplayMode.addAll(deserializeActionlistDisplayModes( sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? defaultActionsMode)); - final pinLength = - sharedPreferences.getInt(PreferencesKey.currentPinLength) ?? - defaultPinLength; + var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength); + // If no value + if (pinLength == null || pinLength == 0) { + pinLength = defaultPinLength; + } + final savedLanguageCode = sharedPreferences.getString(PreferencesKey.currentLanguageCode) ?? await LanguageService.localeDetection(); diff --git a/pubspec.lock b/pubspec.lock index 182703e52..87132a57e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -14,7 +14,7 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.40.5" + version: "0.40.6" archive: dependency: transitive description: @@ -77,7 +77,7 @@ packages: name: bip32 url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.0.7" bip39: dependency: transitive description: @@ -133,7 +133,7 @@ packages: name: build_resolvers url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "1.4.3" build_runner: dependency: "direct dev" description: @@ -224,14 +224,14 @@ packages: name: connectivity_for_web url: "https://pub.dartlang.org" source: hosted - version: "0.3.1+2" + version: "0.3.1+4" connectivity_macos: dependency: transitive description: name: connectivity_macos url: "https://pub.dartlang.org" source: hosted - version: "0.1.0+5" + version: "0.1.0+7" connectivity_platform_interface: dependency: transitive description: @@ -273,7 +273,7 @@ packages: name: dart_style url: "https://pub.dartlang.org" source: hosted - version: "1.3.8+1" + version: "1.3.9" dartx: dependency: transitive description: @@ -470,7 +470,7 @@ packages: name: hive_generator url: "https://pub.dartlang.org" source: hosted - version: "0.8.1" + version: "0.8.2" http: dependency: "direct main" description: @@ -540,7 +540,7 @@ packages: name: local_auth url: "https://pub.dartlang.org" source: hosted - version: "0.6.3+3" + version: "0.6.3+4" logging: dependency: transitive description: @@ -582,7 +582,7 @@ packages: name: mobx_codegen url: "https://pub.dartlang.org" source: hosted - version: "1.1.1+3" + version: "1.1.2" node_interop: dependency: transitive description: @@ -610,7 +610,7 @@ packages: name: package_info url: "https://pub.dartlang.org" source: hosted - version: "0.4.3" + version: "0.4.3+2" password: dependency: "direct main" description: @@ -645,7 +645,7 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.22" + version: "1.6.24" path_provider_linux: dependency: transitive description: @@ -659,21 +659,21 @@ packages: name: path_provider_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+4" + version: "0.0.4+6" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" path_provider_windows: dependency: transitive description: name: path_provider_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.4+1" + version: "0.0.4+3" pedantic: dependency: "direct dev" description: @@ -764,7 +764,7 @@ packages: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.1.4+1" + version: "2.1.5" rxdart: dependency: "direct main" description: @@ -785,21 +785,21 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.12+2" + version: "0.5.12+4" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.2+2" + version: "0.0.2+4" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+10" + version: "0.0.1+11" shared_preferences_platform_interface: dependency: transitive description: @@ -820,7 +820,7 @@ packages: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+1" + version: "0.0.1+3" shelf: dependency: transitive description: @@ -930,21 +930,21 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "5.7.8" + version: "5.7.10" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+3" + version: "0.0.1+4" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+8" + version: "0.0.1+9" url_launcher_platform_interface: dependency: transitive description: @@ -958,14 +958,14 @@ packages: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.5" + version: "0.1.5+1" url_launcher_windows: dependency: transitive description: name: url_launcher_windows url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+1" + version: "0.0.1+3" uuid: dependency: "direct main" description: