This commit is contained in:
M 2020-11-10 01:14:47 +02:00
parent c2e7a854bb
commit 03f47e393c
8 changed files with 121 additions and 83 deletions

View file

@ -437,7 +437,7 @@ extern "C"
{ {
store_mutex.lock(); store_mutex.lock();
get_current_wallet()->store(std::string(path)); get_current_wallet()->store(std::string(path));
store_mutex.unlock(); store_mutex.unlock();
} }
bool transaction_create(char *address, char *payment_id, char *amount, bool transaction_create(char *address, char *payment_id, char *amount,
@ -494,8 +494,6 @@ extern "C"
return committed; return committed;
} }
// START
uint64_t get_node_height_or_update(uint64_t base_eight) uint64_t get_node_height_or_update(uint64_t base_eight)
{ {
if (m_cached_syncing_blockchain_height < base_eight) { if (m_cached_syncing_blockchain_height < base_eight) {
@ -512,11 +510,6 @@ extern "C"
} }
uint64_t height = m_listener->height(); 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) { if (height <= 1) {
return 0; return 0;
@ -537,12 +530,6 @@ extern "C"
} }
bool should_refresh = m_listener->isNeedToRefresh(); 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) { if (should_refresh) {
m_listener->resetNeedToRefresh(); m_listener->resetNeedToRefresh();
@ -580,8 +567,6 @@ extern "C"
get_current_wallet()->setListener(m_listener); get_current_wallet()->setListener(m_listener);
} }
// END
int64_t *subaddrress_get_all() int64_t *subaddrress_get_all()
{ {
std::vector<Monero::SubaddressRow *> _subaddresses = m_subaddress->getAll(); std::vector<Monero::SubaddressRow *> _subaddresses = m_subaddress->getAll();

View file

@ -240,12 +240,17 @@ class SyncListener {
_initialSyncHeight = 0; _initialSyncHeight = 0;
_updateSyncInfoTimer ??= _updateSyncInfoTimer ??=
Timer.periodic(Duration(milliseconds: 1200), (_) async { Timer.periodic(Duration(milliseconds: 1200), (_) async {
if (isNewTransactionExist() ?? false) { if (isNewTransactionExist() ?? isNeededToRefresh() ?? false) {
onNewTransaction?.call(); onNewTransaction?.call();
} }
final _isNeededToRefresh = isNeededToRefresh();
print('isNeededToRefresh $_isNeededToRefresh');
var syncHeight = getSyncingHeight(); var syncHeight = getSyncingHeight();
print('syncHeight $syncHeight');
if (syncHeight <= 0) { if (syncHeight <= 0) {
syncHeight = getCurrentHeight(); syncHeight = getCurrentHeight();
} }

View file

@ -354,7 +354,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -494,7 +494,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
@ -528,7 +528,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 32J6BB6VUS; DEVELOPMENT_TEAM = 32J6BB6VUS;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (

View file

@ -391,32 +391,36 @@ Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) async {
} }
Future<void> ios_migrate_address_book(Box<Contact> contactSource) async { Future<void> ios_migrate_address_book(Box<Contact> contactSource) async {
final prefs = await SharedPreferences.getInstance(); try {
final prefs = await SharedPreferences.getInstance();
if (prefs.getBool('ios_migration_address_book_completed') ?? false) { if (prefs.getBool('ios_migration_address_book_completed') ?? false) {
return; return;
} }
final appDocDir = await getApplicationDocumentsDirectory(); final appDocDir = await getApplicationDocumentsDirectory();
final addressBookJSON = File('${appDocDir.path}/address_book.json'); 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<dynamic> addresses =
json.decode(addressBookJSON.readAsStringSync()) as List<dynamic>;
final contacts = addresses.map((dynamic item) {
final _item = item as Map<String, dynamic>;
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); await prefs.setBool('ios_migration_address_book_completed', true);
return; } catch(e) {
print(e.toString());
} }
final List<dynamic> addresses =
json.decode(addressBookJSON.readAsStringSync()) as List<dynamic>;
final contacts = addresses.map((dynamic item) {
final _item = item as Map<String, dynamic>;
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);
} }

View file

@ -44,10 +44,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
subaddress = subaddressList.subaddresses.first; subaddress = subaddressList.subaddresses.first;
address = subaddress.address; address = subaddress.address;
_lastAutosaveTimestamp = 0; _lastAutosaveTimestamp = 0;
_isSavingAfterSync = false;
_isSavingAfterNewTransaction = false;
}); });
} }
static const int _autoAfterSyncSaceInterval = 60000; static const int _autoAfterSyncSaveInterval = 60000;
@override @override
final MoneroTransactionHistory transactionHistory; final MoneroTransactionHistory transactionHistory;
@ -88,6 +90,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
SyncListener _listener; SyncListener _listener;
ReactionDisposer _onAccountChangeReaction; ReactionDisposer _onAccountChangeReaction;
int _lastAutosaveTimestamp; int _lastAutosaveTimestamp;
bool _isSavingAfterSync;
bool _isSavingAfterNewTransaction;
Future<void> init() async { Future<void> init() async {
await accountList.update(); await accountList.update();
@ -174,11 +178,14 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
@override @override
Future<PendingTransaction> createTransaction(Object credentials) async { Future<PendingTransaction> createTransaction(Object credentials) async {
final _credentials = credentials as MoneroTransactionCreationCredentials; final _credentials = credentials as MoneroTransactionCreationCredentials;
final amount = moneroParseAmount(amount: _credentials.amount); final amount = _credentials.amount != null
? moneroParseAmount(amount: _credentials.amount)
: null;
final unlockedBalance = final unlockedBalance =
monero_wallet.getUnlockedBalance(accountIndex: account.id); monero_wallet.getUnlockedBalance(accountIndex: account.id);
if (unlockedBalance < amount) { if ((amount != null && unlockedBalance < amount) ||
(amount == null && unlockedBalance <= 0)) {
throw MoneroTransactionCreationException( throw MoneroTransactionCreationException(
'Incorrect unlocked balance. Unlocked: $unlockedBalance. Transaction amount: ${_credentials.amount}.'); 'Incorrect unlocked balance. Unlocked: $unlockedBalance. Transaction amount: ${_credentials.amount}.');
} }
@ -292,8 +299,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
} }
void _askForUpdateBalance() { void _askForUpdateBalance() {
final fullBalance = _getFullBalance();
final unlockedBalance = _getUnlockedBalance(); final unlockedBalance = _getUnlockedBalance();
final fullBalance = _getFullBalance();
if (balance.fullBalance != fullBalance || if (balance.fullBalance != fullBalance ||
balance.unlockedBalance != unlockedBalance) { balance.unlockedBalance != unlockedBalance) {
@ -313,18 +320,47 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
monero_wallet.getUnlockedBalance(accountIndex: account.id); monero_wallet.getUnlockedBalance(accountIndex: account.id);
Future<void> _afterSyncSave() async { Future<void> _afterSyncSave() async {
final nowTimestamp = DateTime.now().millisecondsSinceEpoch; if (_isSavingAfterSync) {
final sum = _lastAutosaveTimestamp + _autoAfterSyncSaceInterval;
if (_lastAutosaveTimestamp != 0 && sum < nowTimestamp) {
return; return;
} }
_lastAutosaveTimestamp = nowTimestamp + _autoAfterSyncSaceInterval; _isSavingAfterSync = true;
await save();
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<void> _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 { void _onNewBlock(int height, int blocksLeft, double ptc) async {
print('_onNewBlock called');
if (walletInfo.isRecovery) { if (walletInfo.isRecovery) {
_askForUpdateTransactionHistory(); _askForUpdateTransactionHistory();
} }
@ -334,14 +370,19 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
if (blocksLeft < 100) { if (blocksLeft < 100) {
syncStatus = SyncedSyncStatus(); syncStatus = SyncedSyncStatus();
await _afterSyncSave(); await _afterSyncSave();
if (walletInfo.isRecovery) {
setAsRecovered();
}
} else { } else {
syncStatus = SyncingSyncStatus(blocksLeft, ptc); syncStatus = SyncingSyncStatus(blocksLeft, ptc);
} }
} }
void _onNewTransaction() { void _onNewTransaction() {
print('_onNewTransaction called');
_askForUpdateTransactionHistory(); _askForUpdateTransactionHistory();
_askForUpdateBalance(); _askForUpdateBalance();
_afterSyncSave(); Timer(Duration(seconds: 1), () => _afterNewTransactionSave());
} }
} }

View file

@ -220,9 +220,9 @@ class AddressTextField extends StatelessWidget {
Future<void> _pasteAddress(BuildContext context) async { Future<void> _pasteAddress(BuildContext context) async {
String address; 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; controller.text = address;
} }
} }

View file

@ -160,9 +160,12 @@ abstract class SettingsStoreBase with Store {
actionListDisplayMode.addAll(deserializeActionlistDisplayModes( actionListDisplayMode.addAll(deserializeActionlistDisplayModes(
sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ?? sharedPreferences.getInt(PreferencesKey.displayActionListModeKey) ??
defaultActionsMode)); defaultActionsMode));
final pinLength = var pinLength = sharedPreferences.getInt(PreferencesKey.currentPinLength);
sharedPreferences.getInt(PreferencesKey.currentPinLength) ?? // If no value
defaultPinLength; if (pinLength == null || pinLength == 0) {
pinLength = defaultPinLength;
}
final savedLanguageCode = final savedLanguageCode =
sharedPreferences.getString(PreferencesKey.currentLanguageCode) ?? sharedPreferences.getString(PreferencesKey.currentLanguageCode) ??
await LanguageService.localeDetection(); await LanguageService.localeDetection();

View file

@ -14,7 +14,7 @@ packages:
name: analyzer name: analyzer
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.40.5" version: "0.40.6"
archive: archive:
dependency: transitive dependency: transitive
description: description:
@ -77,7 +77,7 @@ packages:
name: bip32 name: bip32
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.5" version: "1.0.7"
bip39: bip39:
dependency: transitive dependency: transitive
description: description:
@ -133,7 +133,7 @@ packages:
name: build_resolvers name: build_resolvers
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.4.2" version: "1.4.3"
build_runner: build_runner:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -224,14 +224,14 @@ packages:
name: connectivity_for_web name: connectivity_for_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.1+2" version: "0.3.1+4"
connectivity_macos: connectivity_macos:
dependency: transitive dependency: transitive
description: description:
name: connectivity_macos name: connectivity_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.0+5" version: "0.1.0+7"
connectivity_platform_interface: connectivity_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -273,7 +273,7 @@ packages:
name: dart_style name: dart_style
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.8+1" version: "1.3.9"
dartx: dartx:
dependency: transitive dependency: transitive
description: description:
@ -470,7 +470,7 @@ packages:
name: hive_generator name: hive_generator
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.1" version: "0.8.2"
http: http:
dependency: "direct main" dependency: "direct main"
description: description:
@ -540,7 +540,7 @@ packages:
name: local_auth name: local_auth
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.3+3" version: "0.6.3+4"
logging: logging:
dependency: transitive dependency: transitive
description: description:
@ -582,7 +582,7 @@ packages:
name: mobx_codegen name: mobx_codegen
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.1+3" version: "1.1.2"
node_interop: node_interop:
dependency: transitive dependency: transitive
description: description:
@ -610,7 +610,7 @@ packages:
name: package_info name: package_info
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.3" version: "0.4.3+2"
password: password:
dependency: "direct main" dependency: "direct main"
description: description:
@ -645,7 +645,7 @@ packages:
name: path_provider name: path_provider
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.22" version: "1.6.24"
path_provider_linux: path_provider_linux:
dependency: transitive dependency: transitive
description: description:
@ -659,21 +659,21 @@ packages:
name: path_provider_macos name: path_provider_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.4+4" version: "0.0.4+6"
path_provider_platform_interface: path_provider_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: path_provider_platform_interface name: path_provider_platform_interface
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.3" version: "1.0.4"
path_provider_windows: path_provider_windows:
dependency: transitive dependency: transitive
description: description:
name: path_provider_windows name: path_provider_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.4+1" version: "0.0.4+3"
pedantic: pedantic:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -764,7 +764,7 @@ packages:
name: quiver name: quiver
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.4+1" version: "2.1.5"
rxdart: rxdart:
dependency: "direct main" dependency: "direct main"
description: description:
@ -785,21 +785,21 @@ packages:
name: shared_preferences name: shared_preferences
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.5.12+2" version: "0.5.12+4"
shared_preferences_linux: shared_preferences_linux:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_linux name: shared_preferences_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.2+2" version: "0.0.2+4"
shared_preferences_macos: shared_preferences_macos:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_macos name: shared_preferences_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.1+10" version: "0.0.1+11"
shared_preferences_platform_interface: shared_preferences_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -820,7 +820,7 @@ packages:
name: shared_preferences_windows name: shared_preferences_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.1+1" version: "0.0.1+3"
shelf: shelf:
dependency: transitive dependency: transitive
description: description:
@ -930,21 +930,21 @@ packages:
name: url_launcher name: url_launcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.7.8" version: "5.7.10"
url_launcher_linux: url_launcher_linux:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_linux name: url_launcher_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.1+3" version: "0.0.1+4"
url_launcher_macos: url_launcher_macos:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_macos name: url_launcher_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.1+8" version: "0.0.1+9"
url_launcher_platform_interface: url_launcher_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -958,14 +958,14 @@ packages:
name: url_launcher_web name: url_launcher_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.5" version: "0.1.5+1"
url_launcher_windows: url_launcher_windows:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_windows name: url_launcher_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.1+1" version: "0.0.1+3"
uuid: uuid:
dependency: "direct main" dependency: "direct main"
description: description: