diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java index e9c877d5..e51d137a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionsTreeTable.java @@ -5,6 +5,7 @@ import com.sparrowwallet.sparrow.wallet.Entry; import com.sparrowwallet.sparrow.wallet.TransactionEntry; import com.sparrowwallet.sparrow.wallet.WalletTransactionsEntry; import javafx.beans.property.ReadOnlyObjectWrapper; +import javafx.scene.control.Label; import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableView; @@ -49,6 +50,7 @@ public class TransactionsTreeTable extends TreeTableView { balanceCol.setSortable(true); getColumns().add(balanceCol); + setPlaceholder(new Label("No transactions")); setEditable(true); setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); dateCol.setSortType(TreeTableColumn.SortType.DESCENDING); @@ -59,6 +61,12 @@ public class TransactionsTreeTable extends TreeTableView { RecursiveTreeItem rootItem = new RecursiveTreeItem<>(rootEntry, Entry::getChildren); setRoot(rootItem); rootItem.setExpanded(true); + + if(getColumns().size() > 0) { + TreeTableColumn dateCol = getColumns().get(0); + getSortOrder().add(dateCol); + dateCol.setSortType(TreeTableColumn.SortType.DESCENDING); + } } public void updateHistory(List updatedNodes) { diff --git a/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java index f1e10f5e..867d2a41 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/ElectrumServer.java @@ -274,12 +274,15 @@ public class ElectrumServer { references.addAll(nodeReferences); } - Map blockHeaderMap = getBlockHeaders(references); - Map transactionMap = getTransactions(references, blockHeaderMap); + Map transactionMap = new HashMap<>(); + if(!references.isEmpty()) { + Map blockHeaderMap = getBlockHeaders(references); + transactionMap = getTransactions(references, blockHeaderMap); + } if(!transactionMap.equals(wallet.getTransactions())) { for(BlockTransaction blockTx : transactionMap.values()) { - Optional optionalLabel = wallet.getTransactions().values().stream().filter(oldBlTx -> oldBlTx.getHash().equals(blockTx.getHash())).map(BlockTransaction::getLabel).findFirst(); + Optional optionalLabel = wallet.getTransactions().values().stream().filter(oldBlTx -> oldBlTx.getHash().equals(blockTx.getHash())).map(BlockTransaction::getLabel).filter(Objects::nonNull).findFirst(); optionalLabel.ifPresent(blockTx::setLabel); } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java index b97d29ea..59d898c2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java @@ -32,6 +32,5 @@ public class SettingsWalletForm extends WalletForm { wallet = walletCopy.copy(); save(); EventManager.get().post(new WalletSettingsChangedEvent(wallet, getWalletFile())); - refreshHistory(wallet.getStoredBlockHeight()); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index 0558f1e8..c100d565 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -25,7 +25,7 @@ public class WalletForm { public WalletForm(Storage storage, Wallet currentWallet) { this.storage = storage; this.wallet = currentWallet; - refreshHistory(wallet.getStoredBlockHeight()); + refreshHistory(AppController.getCurrentBlockHeight()); } public Wallet getWallet() { @@ -51,7 +51,7 @@ public class WalletForm { public void saveAndRefresh() throws IOException { wallet.clearHistory(); save(); - refreshHistory(wallet.getStoredBlockHeight()); + refreshHistory(AppController.getCurrentBlockHeight()); } public void refreshHistory(Integer blockHeight) { @@ -136,31 +136,36 @@ public class WalletForm { @Subscribe public void walletLabelChanged(WalletEntryLabelChangedEvent event) { - backgroundSaveWallet(event); + if(event.getWallet().equals(wallet)) { + backgroundSaveWallet(event); + } } @Subscribe public void walletBlockHeightChanged(WalletBlockHeightChangedEvent event) { - backgroundSaveWallet(event); + if(event.getWallet().equals(wallet)) { + backgroundSaveWallet(event); + } } private void backgroundSaveWallet(WalletChangedEvent event) { - if(event.getWallet().equals(wallet)) { - try { - save(); - } catch (IOException e) { - //Background save failed - e.printStackTrace(); - } + try { + save(); + } catch (IOException e) { + //Background save failed + e.printStackTrace(); } } @Subscribe public void walletSettingsChanged(WalletSettingsChangedEvent event) { - walletTransactionsEntry = null; - accountEntries.clear(); - - EventManager.get().post(new WalletNodesChangedEvent(wallet)); + if(event.getWalletFile().equals(storage.getWalletFile())) { + wallet = event.getWallet(); + walletTransactionsEntry = null; + accountEntries.clear(); + EventManager.get().post(new WalletNodesChangedEvent(wallet)); + refreshHistory(AppController.getCurrentBlockHeight()); + } } @Subscribe diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletTransactionsEntry.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletTransactionsEntry.java index 616bae5f..c7031660 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletTransactionsEntry.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletTransactionsEntry.java @@ -37,7 +37,7 @@ public class WalletTransactionsEntry extends Entry { } public void updateTransactions() { - List current = getWalletTransactions(wallet).stream().map(WalletTransaction::getTransactionEntry).collect(Collectors.toList()); + List current = getWalletTransactions(wallet).stream().map(WalletTransaction::getTransactionEntry).peek(entry -> entry.setParent(this)).collect(Collectors.toList()); List previous = new ArrayList<>(getChildren()); for(Entry currentEntry : current) { int index = previous.indexOf(currentEntry); @@ -57,7 +57,9 @@ public class WalletTransactionsEntry extends Entry { getWalletTransactions(wallet, walletTransactionMap, wallet.getNode(KeyPurpose.RECEIVE)); getWalletTransactions(wallet, walletTransactionMap, wallet.getNode(KeyPurpose.CHANGE)); - return walletTransactionMap.values(); + List walletTxList = new ArrayList<>(walletTransactionMap.values()); + Collections.reverse(walletTxList); + return walletTxList; } private static void getWalletTransactions(Wallet wallet, Map walletTransactionMap, WalletNode purposeNode) {