fix: catch error in newly added fetchTransactions call (#2265)
fix: null handling in cw_monero
cyan committed
May 15, 2025 at 01:07 UTC
40084ec53202cb77ad0337865703fd95b0a5ce3c
2 files changed
+12
-6
cw_monero/lib/api/wallet.dart
+5
-5
@@ -139,16 +139,16 @@ String getAddress({int accountIndex = 0, int addressIndex = 0}) {
139
}
140
141
int getFullBalance({int accountIndex = 0}) =>
142
- currentWallet!.balance(accountIndex: accountIndex);
142
+ currentWallet?.balance(accountIndex: accountIndex) ?? 0;
143
144
int getUnlockedBalance({int accountIndex = 0}) =>
145
- currentWallet!.unlockedBalance(accountIndex: accountIndex);
145
+ currentWallet?.unlockedBalance(accountIndex: accountIndex) ?? 0;
146
147
-int getCurrentHeight() => currentWallet!.blockChainHeight();
147
+int getCurrentHeight() => currentWallet?.blockChainHeight() ?? 0;
148
149
-int getNodeHeightSync() => currentWallet!.daemonBlockChainHeight();
149
+int getNodeHeightSync() => currentWallet?.daemonBlockChainHeight() ?? 0;
150
151
-bool isConnectedSync() => currentWallet!.connected() != 0;
151
+bool isConnectedSync() => currentWallet?.connected() != 0;
152
153
Future<bool> setupNodeSync(
154
{required String address,
lib/view_model/send/send_view_model.dart
+7
-1
@@ -593,7 +593,13 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
593
}
594
final sharedPreferences = await SharedPreferences.getInstance();
595
await sharedPreferences.setString(PreferencesKey.backgroundSyncLastTrigger(wallet.name), DateTime.now().add(Duration(minutes: 1)).toIso8601String());
596
- unawaited(wallet.fetchTransactions());
596
+ unawaited(() {
597
+ try {
598
+ wallet.fetchTransactions();
599
+ } catch (e) {
600
+ printV(e);
601
+ }
602
+ }());
603
state = TransactionCommitted();
604
} catch (e) {
605
state = FailureState(translateErrorMessage(e, wallet.type, wallet.currency));