Fixes for 4.0.94. Changed version for 4.0.94.

This commit is contained in:
M
2020-12-29 18:55:58 +02:00
parent 647577497d
commit 84ad97c0b0
5 changed files with 26 additions and 29 deletions
+15 -18
View File
@@ -3,7 +3,7 @@ import 'package:cake_wallet/core/wallet_base.dart';
import 'package:hive/hive.dart';
import 'package:cw_monero/wallet_manager.dart' as monero_wallet_manager;
import 'package:cw_monero/wallet.dart' as monero_wallet;
import 'package:cw_monero/exceptions/wallet_loading_exception.dart';
import 'package:cw_monero/exceptions/wallet_opening_exception.dart';
import 'package:cake_wallet/monero/monero_wallet.dart';
import 'package:cake_wallet/core/wallet_credentials.dart';
import 'package:cake_wallet/core/wallet_service.dart';
@@ -56,7 +56,7 @@ class MoneroWalletService extends WalletService<
final Box<WalletInfo> walletInfoSource;
static void _removeCache(String name) async {
static Future<void> _removeCache(String name) async {
final path = await pathForWallet(name: name, type: WalletType.monero);
final cacheFile = File(path);
@@ -65,6 +65,9 @@ class MoneroWalletService extends WalletService<
}
}
static bool walletFilesExist(String path) =>
!File(path).existsSync() && !File('$path.keys').existsSync();
@override
Future<MoneroWallet> create(MoneroNewWalletCredentials credentials) async {
try {
@@ -104,7 +107,7 @@ class MoneroWalletService extends WalletService<
try {
final path = await pathForWallet(name: name, type: WalletType.monero);
if (!File(path).existsSync()) {
if (walletFilesExist(path)) {
await repairOldAndroidWallet(name);
}
@@ -118,17 +121,9 @@ class MoneroWalletService extends WalletService<
final isValid = wallet.validate();
if (!isValid) {
// if (wallet.seed?.isNotEmpty ?? false) {
// let restore from seed in this case;
// final seed = wallet.seed;
// final credentials = MoneroRestoreWalletFromSeedCredentials(
// name: name, password: password, mnemonic: seed, height: 2000000)
// ..walletInfo = walletInfo;
// await remove(name);
// return restoreFromSeed(credentials);
// }
throw MoneroWalletLoadingException();
await _removeCache(name);
wallet.close();
return openWallet(name, password);
}
await wallet.init();
@@ -137,8 +132,11 @@ class MoneroWalletService extends WalletService<
} catch (e) {
// TODO: Implement Exception for wallet list service.
if (e.message == 'std::bad_alloc') {
_removeCache(name);
if (e.toString().contains('bad_alloc') ||
(e is WalletOpeningException &&
(e.message == 'std::bad_alloc' ||
e.message.contains('bad_alloc')))) {
await _removeCache(name);
return openWallet(name, password);
}
@@ -219,7 +217,7 @@ class MoneroWalletService extends WalletService<
final dir = Directory(oldAndroidWalletDirPath);
if (!dir.existsSync()) {
throw MoneroWalletLoadingException();
return;
}
final newWalletDirPath =
@@ -238,7 +236,6 @@ class MoneroWalletService extends WalletService<
});
} catch (e) {
print(e.toString());
throw MoneroWalletLoadingException();
}
}
}