mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-23 10:45:27 +01:00
Fixes issue with loading old android wallets. Changed seed text field type to visual password.
This commit is contained in:
@@ -20,7 +20,7 @@ abstract class MoneroAccountListBase with Store {
|
||||
bool _isRefreshing;
|
||||
bool _isUpdating;
|
||||
|
||||
Future update() async {
|
||||
void update() async {
|
||||
if (_isUpdating) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
||||
_onAccountChangeReaction?.reaction?.dispose();
|
||||
}
|
||||
|
||||
Future<bool> validate() async {
|
||||
await accountList.update();
|
||||
bool validate() {
|
||||
accountList.update();
|
||||
final accountListLength = accountList.accounts?.length ?? 0;
|
||||
|
||||
if (accountListLength <= 0) {
|
||||
|
||||
@@ -27,7 +27,7 @@ class MoneroRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||
|
||||
class MoneroWalletLoadingException implements Exception {
|
||||
@override
|
||||
String toString() => 'The wallet is damaged.';
|
||||
String toString() => 'Failure to load the wallet.';
|
||||
}
|
||||
|
||||
class MoneroRestoreWalletFromKeysCredentials extends WalletCredentials {
|
||||
@@ -93,6 +93,11 @@ class MoneroWalletService extends WalletService<
|
||||
Future<MoneroWallet> openWallet(String name, String password) async {
|
||||
try {
|
||||
final path = await pathForWallet(name: name, type: WalletType.monero);
|
||||
|
||||
if (!File(path).existsSync()) {
|
||||
await repairOldAndroidWallet(name);
|
||||
}
|
||||
|
||||
await monero_wallet_manager
|
||||
.openWalletAsync({'path': path, 'password': password});
|
||||
final walletInfo = walletInfoSource.values.firstWhere(
|
||||
@@ -100,17 +105,17 @@ class MoneroWalletService extends WalletService<
|
||||
orElse: () => null);
|
||||
final wallet = MoneroWallet(
|
||||
filename: monero_wallet.getFilename(), walletInfo: walletInfo);
|
||||
final isValid = await wallet.validate();
|
||||
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);
|
||||
// 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();
|
||||
@@ -187,4 +192,38 @@ class MoneroWalletService extends WalletService<
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> repairOldAndroidWallet(String name) async {
|
||||
try {
|
||||
if (!Platform.isAndroid) {
|
||||
return;
|
||||
}
|
||||
|
||||
final oldAndroidWalletDirPath =
|
||||
await outdatedAndroidPathForWalletDir(name: name);
|
||||
final dir = Directory(oldAndroidWalletDirPath);
|
||||
|
||||
if (!dir.existsSync()) {
|
||||
throw MoneroWalletLoadingException();
|
||||
}
|
||||
|
||||
final newWalletDirPath =
|
||||
await pathForWalletDir(name: name, type: WalletType.monero);
|
||||
|
||||
dir.listSync().forEach((f) {
|
||||
final file = File(f.path);
|
||||
final name = f.path.split('/').last;
|
||||
final newPath = newWalletDirPath + '/$name';
|
||||
final newFile = File(newPath);
|
||||
print(file.path);
|
||||
if (!newFile.existsSync()) {
|
||||
newFile.createSync();
|
||||
}
|
||||
newFile.writeAsBytesSync(file.readAsBytesSync());
|
||||
});
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
throw MoneroWalletLoadingException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user