mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
fix: monero silently ignoring wallet opens (#3621)
This commit is contained in:
@@ -101,7 +101,6 @@ void createWallet(
|
||||
currentWallet!.setCacheAttribute(key: "cakewallet.passphrase", value: passphrase);
|
||||
currentWallet!.store(path: path);
|
||||
openedWalletsByPath[path] = currentWallet!;
|
||||
_lastOpenedWallet = path;
|
||||
}
|
||||
|
||||
bool isWalletExist({required String path}) {
|
||||
@@ -147,7 +146,6 @@ void restoreWalletFromSeedSync(
|
||||
openedWalletsByPath[path] = currentWallet!;
|
||||
|
||||
currentWallet!.store(path: path);
|
||||
_lastOpenedWallet = path;
|
||||
}
|
||||
|
||||
void storePassphrase({required String path, required String passphrase}) {
|
||||
@@ -220,7 +218,6 @@ void restoreWalletFromKeys(
|
||||
currentWallet = newW;
|
||||
|
||||
openedWalletsByPath[path] = currentWallet!;
|
||||
_lastOpenedWallet = path;
|
||||
}
|
||||
|
||||
// English only, because normalization.
|
||||
@@ -310,11 +307,8 @@ void restoreWalletFromSpendKeySync(
|
||||
setupBackgroundSync(password, currentWallet!);
|
||||
|
||||
openedWalletsByPath[path] = currentWallet!;
|
||||
_lastOpenedWallet = path;
|
||||
}
|
||||
|
||||
String _lastOpenedWallet = "";
|
||||
|
||||
Future<void> restoreWalletFromHardwareWallet(
|
||||
{required String path,
|
||||
required String password,
|
||||
@@ -339,7 +333,6 @@ Future<void> restoreWalletFromHardwareWallet(
|
||||
|
||||
currentWallet = newW;
|
||||
currentWallet!.store(path: path);
|
||||
_lastOpenedWallet = path;
|
||||
openedWalletsByPath[path] = currentWallet!;
|
||||
}
|
||||
|
||||
@@ -351,72 +344,70 @@ Future<void> loadWallet({required String path, required String password, int net
|
||||
currentWallet = openedWalletsByPath[path]!;
|
||||
return;
|
||||
}
|
||||
if (currentWallet == null || path != _lastOpenedWallet) {
|
||||
if (currentWallet != null) {
|
||||
final addr = currentWallet!.ffiAddress();
|
||||
Isolate.run(() {
|
||||
monero.Wallet_store(Pointer.fromAddress(addr));
|
||||
});
|
||||
}
|
||||
txhistory = null;
|
||||
|
||||
/// Get the device type
|
||||
/// 0: Software Wallet
|
||||
/// 1: Ledger
|
||||
/// 2: Trezor
|
||||
var deviceType = 0;
|
||||
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
deviceType = wmPtr.queryWalletDevice(
|
||||
keysFileName: "$path.keys",
|
||||
password: password,
|
||||
kdfRounds: 1,
|
||||
);
|
||||
final status = wmPtr.errorString();
|
||||
if (status != "") {
|
||||
printV("loadWallet:" + status);
|
||||
// This is most likely closeWallet call leaking error. This is fine.
|
||||
if (status.contains("failed to save file")) {
|
||||
printV("loadWallet: error leaked: $status");
|
||||
deviceType = 0;
|
||||
} else {
|
||||
throw WalletOpeningException(message: status);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deviceType = 0;
|
||||
}
|
||||
|
||||
if (deviceType == 1) {
|
||||
if (gLedger == null) {
|
||||
throw Exception("Tried to open a ledger wallet with no ledger connected");
|
||||
}
|
||||
enableLedgerExchange(gLedger!);
|
||||
}
|
||||
|
||||
final addr = wmPtr.ffiAddress();
|
||||
final newWptrAddr = await Isolate.run(() {
|
||||
return monero.WalletManager_openWallet(Pointer.fromAddress(addr),
|
||||
path: path, password: password)
|
||||
.address;
|
||||
if (currentWallet != null) {
|
||||
final addr = currentWallet!.ffiAddress();
|
||||
Isolate.run(() {
|
||||
monero.Wallet_store(Pointer.fromAddress(addr));
|
||||
});
|
||||
|
||||
final newW = MoneroWallet(Pointer.fromAddress(newWptrAddr));
|
||||
|
||||
int status = newW.status();
|
||||
if (status != 0) {
|
||||
final err = newW.errorString();
|
||||
printV("loadWallet:" + err);
|
||||
throw WalletOpeningException(message: err);
|
||||
}
|
||||
if (deviceType == 0) {
|
||||
setupBackgroundSync(password, newW);
|
||||
}
|
||||
|
||||
currentWallet = newW;
|
||||
_lastOpenedWallet = path;
|
||||
openedWalletsByPath[path] = currentWallet!;
|
||||
}
|
||||
txhistory = null;
|
||||
|
||||
/// Get the device type
|
||||
/// 0: Software Wallet
|
||||
/// 1: Ledger
|
||||
/// 2: Trezor
|
||||
var deviceType = 0;
|
||||
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
deviceType = wmPtr.queryWalletDevice(
|
||||
keysFileName: "$path.keys",
|
||||
password: password,
|
||||
kdfRounds: 1,
|
||||
);
|
||||
final status = wmPtr.errorString();
|
||||
if (status != "") {
|
||||
printV("loadWallet:" + status);
|
||||
// This is most likely closeWallet call leaking error. This is fine.
|
||||
if (status.contains("failed to save file")) {
|
||||
printV("loadWallet: error leaked: $status");
|
||||
deviceType = 0;
|
||||
} else {
|
||||
throw WalletOpeningException(message: status);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
deviceType = 0;
|
||||
}
|
||||
|
||||
if (deviceType == 1) {
|
||||
if (gLedger == null) {
|
||||
throw Exception("Tried to open a ledger wallet with no ledger connected");
|
||||
}
|
||||
enableLedgerExchange(gLedger!);
|
||||
}
|
||||
|
||||
final addr = wmPtr.ffiAddress();
|
||||
final newWptrAddr = await Isolate.run(() {
|
||||
return monero.WalletManager_openWallet(Pointer.fromAddress(addr),
|
||||
path: path, password: password)
|
||||
.address;
|
||||
});
|
||||
|
||||
final newW = MoneroWallet(Pointer.fromAddress(newWptrAddr));
|
||||
|
||||
int status = newW.status();
|
||||
if (status != 0) {
|
||||
final err = newW.errorString();
|
||||
printV("loadWallet:" + err);
|
||||
throw WalletOpeningException(message: err);
|
||||
}
|
||||
if (deviceType == 0) {
|
||||
setupBackgroundSync(password, newW);
|
||||
}
|
||||
|
||||
currentWallet = newW;
|
||||
openedWalletsByPath[path] = currentWallet!;
|
||||
}
|
||||
|
||||
void setupBackgroundSync(String password, Wallet2Wallet wallet) {
|
||||
|
||||
Reference in New Issue
Block a user