tolerate errors resuming from standby

This commit is contained in:
woodser 2023-07-28 13:52:04 -04:00
parent 7de40e2c33
commit b3c607152d
3 changed files with 35 additions and 9 deletions

View file

@ -853,7 +853,12 @@ public class XmrWalletService {
UserThread.execute(new Runnable() { // TODO (woodser): don't execute on UserThread
@Override
public void run() {
try {
balanceListener.onBalanceChanged(balance);
} catch (Exception e) {
log.warn("Failed to notify balance listener of change");
e.printStackTrace();
}
}
});
}
@ -1116,20 +1121,21 @@ public class XmrWalletService {
public BigInteger getAvailableBalanceForSubaddress(int subaddressIndex) {
synchronized (walletLock) {
if (wallet == null) throw new IllegalStateException("Cannot get available balance for subaddress because main wallet is null");
return wallet.getUnlockedBalance(0, subaddressIndex);
}
}
public BigInteger getBalance() {
if (wallet == null) return BigInteger.valueOf(0);
synchronized (walletLock) {
if (wallet == null) throw new IllegalStateException("Cannot get balance because main wallet is null");
return wallet.getBalance(0);
}
}
public BigInteger getAvailableBalance() {
if (wallet == null) return BigInteger.valueOf(0);
synchronized (walletLock) {
if (wallet == null) throw new IllegalStateException("Cannot get available balance because main wallet is null");
return wallet.getUnlockedBalance(0);
}
}

View file

@ -133,11 +133,18 @@ public class DepositView extends ActivatableView<VBox, Void> {
confirmationsColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.confirmations")));
usageColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.usage")));
// try to initialize with wallet txs
try {
// prefetch all incoming txs to avoid query per subaddress
txsWithIncomingOutputs = xmrWalletService.getTxsWithIncomingOutputs();
// trigger creation of at least 1 address
xmrWalletService.getFreshAddressEntry(txsWithIncomingOutputs);
} catch (Exception e) {
log.warn("Failed to get wallet txs to initialize DepositView");
e.printStackTrace();
}
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setPlaceholder(new AutoTooltipLabel(Res.get("funds.deposit.noAddresses")));
@ -237,7 +244,13 @@ public class DepositView extends ActivatableView<VBox, Void> {
tableView.getSelectionModel().selectedItemProperty().addListener(tableViewSelectionListener);
sortedList.comparatorProperty().bind(tableView.comparatorProperty());
// try to update deposits list
try {
updateList();
} catch (Exception e) {
log.warn("Could not update deposits list");
e.printStackTrace();
}
xmrWalletService.addBalanceListener(balanceListener);
xmrWalletService.addWalletListener(walletListener);

View file

@ -185,7 +185,14 @@ public class TransactionsView extends ActivatableView<VBox, Void> {
protected void activate() {
sortedDisplayedTransactions.comparatorProperty().bind(tableView.comparatorProperty());
tableView.setItems(sortedDisplayedTransactions);
// try to update displayed transactions
try {
displayedTransactions.update();
} catch (Exception e) {
log.warn("Failed to update displayed transactions");
e.printStackTrace();
}
xmrWalletService.addWalletListener(transactionsUpdater);