From 900304d40532e9226439a38387853519299f670a Mon Sep 17 00:00:00 2001 From: cyan Date: Fri, 27 Jun 2025 14:06:56 +0200 Subject: [PATCH] fix(cw_monero): keys nullcheck handling (#2338) add default values to monero wallet keys functions in order to prevent null check crashes --- cw_monero/lib/api/wallet.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index e98ba71ca..148b271ff 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -116,12 +116,17 @@ String getSeedLegacy(String? language) { } String getPassphrase() { - return currentWallet!.getCacheAttribute(key: "cakewallet.passphrase"); + return currentWallet?.getCacheAttribute(key: "cakewallet.passphrase") ?? ""; } Map>> addressCache = {}; String getAddress({int accountIndex = 0, int addressIndex = 0}) { + // this is a workaround for when we switch the wallet pointer, + // it should never reach UI but should be good enough to prevent gray screen + // or other errors because of forced null check. + if (currentWallet == null) return ""; + // printV("getaddress: ${accountIndex}/${addressIndex}: ${monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex)}: ${monero.Wallet_address(wptr!, accountIndex: accountIndex, addressIndex: addressIndex)}"); // this could be a while loop, but I'm in favor of making it if to not cause freezes if (currentWallet!.numSubaddresses(accountIndex: accountIndex)-1 < addressIndex) { @@ -272,13 +277,13 @@ void closeCurrentWallet() { currentWallet!.stop(); } -String getSecretViewKey() => currentWallet!.secretViewKey(); +String getSecretViewKey() => currentWallet?.secretViewKey() ?? ""; -String getPublicViewKey() => currentWallet!.publicViewKey(); +String getPublicViewKey() => currentWallet?.publicViewKey() ?? ""; -String getSecretSpendKey() => currentWallet!.secretSpendKey(); +String getSecretSpendKey() => currentWallet?.secretSpendKey() ?? ""; -String getPublicSpendKey() => currentWallet!.publicSpendKey(); +String getPublicSpendKey() => currentWallet?.publicSpendKey() ?? ""; class SyncListener { SyncListener(this.onNewBlock, this.onNewTransaction)