mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
Fixes.
This commit is contained in:
parent
c2e7a854bb
commit
03f47e393c
8 changed files with 121 additions and 83 deletions
|
@ -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<Monero::SubaddressRow *> _subaddresses = m_subaddress->getAll();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 = (
|
||||
|
|
|
@ -391,32 +391,36 @@ Future<void> ios_migrate_trades_list(Box<Trade> tradeSource) 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) {
|
||||
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<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);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -44,10 +44,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> 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<MoneroBalance> with Store {
|
|||
SyncListener _listener;
|
||||
ReactionDisposer _onAccountChangeReaction;
|
||||
int _lastAutosaveTimestamp;
|
||||
bool _isSavingAfterSync;
|
||||
bool _isSavingAfterNewTransaction;
|
||||
|
||||
Future<void> init() async {
|
||||
await accountList.update();
|
||||
|
@ -174,11 +178,14 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
|||
@override
|
||||
Future<PendingTransaction> 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<MoneroBalance> 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<MoneroBalance> with Store {
|
|||
monero_wallet.getUnlockedBalance(accountIndex: account.id);
|
||||
|
||||
Future<void> _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<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 {
|
||||
print('_onNewBlock called');
|
||||
if (walletInfo.isRecovery) {
|
||||
_askForUpdateTransactionHistory();
|
||||
}
|
||||
|
@ -334,14 +370,19 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,9 +220,9 @@ class AddressTextField extends StatelessWidget {
|
|||
Future<void> _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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
48
pubspec.lock
48
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:
|
||||
|
|
Loading…
Reference in a new issue