Fixes for 4.0.94. Changed version for 4.0.94.

M committed Dec 29, 2020 at 18:55 UTC 84ad97c0b01b1da850d43f0f87edc11ee9ac2448
5 files changed +26 -29
cw_monero/lib/exceptions/wallet_loading_exception.dart deleted
-8
@@ -1,8 +0,0 @@
1 -class WalletLoadingException implements Exception {
2 - WalletLoadingException({this.message});
3 -
4 - final String message;
5 -
6 - @override
7 - String toString() => message;
8 -}
\ No newline at end of file
cw_monero/lib/exceptions/wallet_opening_exception.dart new
+8
@@ -0,0 +1,8 @@
1 +class WalletOpeningException implements Exception {
2 + WalletOpeningException({this.message});
3 +
4 + final String message;
5 +
6 + @override
7 + String toString() => message;
8 +}
\ No newline at end of file
cw_monero/lib/wallet_manager.dart
+2 -2
@@ -1,4 +1,5 @@
1 import 'dart:ffi';
2 +import 'package:cw_monero/exceptions/wallet_opening_exception.dart';
3 import 'package:cw_monero/wallet.dart';
4 import 'package:ffi/ffi.dart';
5 import 'package:flutter/foundation.dart';
@@ -7,7 +8,6 @@ import 'package:cw_monero/signatures.dart';
8 import 'package:cw_monero/types.dart';
9 import 'package:cw_monero/monero_api.dart';
10 import 'package:cw_monero/exceptions/wallet_creation_exception.dart';
10 -import 'package:cw_monero/exceptions/wallet_loading_exception.dart';
11 import 'package:cw_monero/exceptions/wallet_restore_from_keys_exception.dart';
12 import 'package:cw_monero/exceptions/wallet_restore_from_seed_exception.dart';
13
@@ -146,7 +146,7 @@ void loadWallet({String path, String password, int nettype = 0}) {
146 free(passwordPointer);
147
148 if (!loaded) {
149 - throw WalletLoadingException(
149 + throw WalletOpeningException(
150 message: convertUTF8ToString(pointer: errorStringNative()));
151 }
152 }
lib/monero/monero_wallet_service.dart
+15 -18
@@ -3,7 +3,7 @@ import 'package:cake_wallet/core/wallet_base.dart';
3 import 'package:hive/hive.dart';
4 import 'package:cw_monero/wallet_manager.dart' as monero_wallet_manager;
5 import 'package:cw_monero/wallet.dart' as monero_wallet;
6 -import 'package:cw_monero/exceptions/wallet_loading_exception.dart';
6 +import 'package:cw_monero/exceptions/wallet_opening_exception.dart';
7 import 'package:cake_wallet/monero/monero_wallet.dart';
8 import 'package:cake_wallet/core/wallet_credentials.dart';
9 import 'package:cake_wallet/core/wallet_service.dart';
@@ -56,7 +56,7 @@ class MoneroWalletService extends WalletService<
56
57 final Box<WalletInfo> walletInfoSource;
58
59 - static void _removeCache(String name) async {
59 + static Future<void> _removeCache(String name) async {
60 final path = await pathForWallet(name: name, type: WalletType.monero);
61 final cacheFile = File(path);
62
@@ -65,6 +65,9 @@ class MoneroWalletService extends WalletService<
65 }
66 }
67
68 + static bool walletFilesExist(String path) =>
69 + !File(path).existsSync() && !File('$path.keys').existsSync();
70 +
71 @override
72 Future<MoneroWallet> create(MoneroNewWalletCredentials credentials) async {
73 try {
@@ -104,7 +107,7 @@ class MoneroWalletService extends WalletService<
107 try {
108 final path = await pathForWallet(name: name, type: WalletType.monero);
109
107 - if (!File(path).existsSync()) {
110 + if (walletFilesExist(path)) {
111 await repairOldAndroidWallet(name);
112 }
113
@@ -118,17 +121,9 @@ class MoneroWalletService extends WalletService<
121 final isValid = wallet.validate();
122
123 if (!isValid) {
121 - // if (wallet.seed?.isNotEmpty ?? false) {
122 - // let restore from seed in this case;
123 - // final seed = wallet.seed;
124 - // final credentials = MoneroRestoreWalletFromSeedCredentials(
125 - // name: name, password: password, mnemonic: seed, height: 2000000)
126 - // ..walletInfo = walletInfo;
127 - // await remove(name);
128 - // return restoreFromSeed(credentials);
129 - // }
130 -
131 - throw MoneroWalletLoadingException();
124 + await _removeCache(name);
125 + wallet.close();
126 + return openWallet(name, password);
127 }
128
129 await wallet.init();
@@ -137,8 +132,11 @@ class MoneroWalletService extends WalletService<
132 } catch (e) {
133 // TODO: Implement Exception for wallet list service.
134
140 - if (e.message == 'std::bad_alloc') {
141 - _removeCache(name);
135 + if (e.toString().contains('bad_alloc') ||
136 + (e is WalletOpeningException &&
137 + (e.message == 'std::bad_alloc' ||
138 + e.message.contains('bad_alloc')))) {
139 + await _removeCache(name);
140 return openWallet(name, password);
141 }
142
@@ -219,7 +217,7 @@ class MoneroWalletService extends WalletService<
217 final dir = Directory(oldAndroidWalletDirPath);
218
219 if (!dir.existsSync()) {
222 - throw MoneroWalletLoadingException();
220 + return;
221 }
222
223 final newWalletDirPath =
@@ -238,7 +236,6 @@ class MoneroWalletService extends WalletService<
236 });
237 } catch (e) {
238 print(e.toString());
241 - throw MoneroWalletLoadingException();
239 }
240 }
241 }
pubspec.yaml
+1 -1
@@ -11,7 +11,7 @@ description: Cake Wallet.
11 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
12 # Read more about iOS versioning at
13 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
14 -version: 4.0.92+23
14 +version: 4.0.94+25
15
16 environment:
17 sdk: ">=2.7.0 <3.0.0"