address history updating

This commit is contained in:
Craig Raw 2020-06-19 17:57:07 +02:00
parent b1e8e25837
commit efba293564
4 changed files with 44 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.control;
import com.sparrowwallet.drongo.Utils; import com.sparrowwallet.drongo.Utils;
import com.sparrowwallet.drongo.address.Address; import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.drongo.wallet.WalletNode;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.event.ReceiveActionEvent; import com.sparrowwallet.sparrow.event.ReceiveActionEvent;
import com.sparrowwallet.sparrow.event.ReceiveToEvent; import com.sparrowwallet.sparrow.event.ReceiveToEvent;
@ -27,7 +28,9 @@ import org.controlsfx.glyphfont.FontAwesome;
import org.controlsfx.glyphfont.Glyph; import org.controlsfx.glyphfont.Glyph;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
public class AddressTreeTable extends TreeTableView<Entry> { public class AddressTreeTable extends TreeTableView<Entry> {
public void initialize(NodeEntry rootEntry) { public void initialize(NodeEntry rootEntry) {
@ -93,6 +96,19 @@ public class AddressTreeTable extends TreeTableView<Entry> {
}); });
} }
public void updateHistory(List<WalletNode> updatedNodes) {
NodeEntry rootEntry = (NodeEntry)getRoot().getValue();
for(WalletNode updatedNode : updatedNodes) {
Optional<Entry> optEntry = rootEntry.getChildren().stream().filter(childEntry -> ((NodeEntry)childEntry).getNode().equals(updatedNode)).findFirst();
if(optEntry.isPresent()) {
int index = rootEntry.getChildren().indexOf(optEntry.get());
NodeEntry nodeEntry = new NodeEntry(rootEntry.getWallet(), updatedNode);
rootEntry.getChildren().set(index, nodeEntry);
}
}
}
private static void applyRowStyles(TreeTableCell<?, ?> cell, Entry entry) { private static void applyRowStyles(TreeTableCell<?, ?> cell, Entry entry) {
cell.getStyleClass().remove("node-row"); cell.getStyleClass().remove("node-row");
cell.getStyleClass().remove("hashindex-row"); cell.getStyleClass().remove("hashindex-row");

View file

@ -50,8 +50,7 @@ public class RecursiveTreeItem<T> extends TreeItem<T> {
while(change.next()){ while(change.next()){
if(change.wasAdded()){ if(change.wasAdded()){
change.getAddedSubList().forEach(t-> RecursiveTreeItem.this.getChildren().add( change.getAddedSubList().forEach(t-> RecursiveTreeItem.this.getChildren().add(change.getFrom(), new RecursiveTreeItem<>(t, this.graphicsFactory, childrenFactory)));
new RecursiveTreeItem<>(t, this.graphicsFactory, childrenFactory)));
} }
if(change.wasRemoved()){ if(change.wasRemoved()){

View file

@ -1,9 +1,11 @@
package com.sparrowwallet.sparrow.event; package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.drongo.KeyPurpose;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletNode; import com.sparrowwallet.drongo.wallet.WalletNode;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class WalletHistoryChangedEvent extends WalletChangedEvent { public class WalletHistoryChangedEvent extends WalletChangedEvent {
private final List<WalletNode> historyChangedNodes; private final List<WalletNode> historyChangedNodes;
@ -16,4 +18,12 @@ public class WalletHistoryChangedEvent extends WalletChangedEvent {
public List<WalletNode> getHistoryChangedNodes() { public List<WalletNode> getHistoryChangedNodes() {
return historyChangedNodes; return historyChangedNodes;
} }
public List<WalletNode> getReceiveNodes() {
return getWallet().getNode(KeyPurpose.RECEIVE).getChildren().stream().filter(historyChangedNodes::contains).collect(Collectors.toList());
}
public List<WalletNode> getChangeNodes() {
return getWallet().getNode(KeyPurpose.CHANGE).getChildren().stream().filter(historyChangedNodes::contains).collect(Collectors.toList());
}
} }

View file

@ -1,13 +1,17 @@
package com.sparrowwallet.sparrow.wallet; package com.sparrowwallet.sparrow.wallet;
import com.google.common.eventbus.Subscribe;
import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.KeyPurpose;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.drongo.wallet.WalletNode;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.control.AddressTreeTable; import com.sparrowwallet.sparrow.control.AddressTreeTable;
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import java.net.URL; import java.net.URL;
import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
public class AddressesController extends WalletFormController implements Initializable { public class AddressesController extends WalletFormController implements Initializable {
@ -29,4 +33,17 @@ public class AddressesController extends WalletFormController implements Initial
receiveTable.initialize(getWalletForm().getNodeEntry(KeyPurpose.RECEIVE)); receiveTable.initialize(getWalletForm().getNodeEntry(KeyPurpose.RECEIVE));
changeTable.initialize(getWalletForm().getNodeEntry(KeyPurpose.CHANGE)); changeTable.initialize(getWalletForm().getNodeEntry(KeyPurpose.CHANGE));
} }
@Subscribe
public void walletHistoryChanged(WalletHistoryChangedEvent event) {
List<WalletNode> receiveNodes = event.getReceiveNodes();
if(!receiveNodes.isEmpty()) {
receiveTable.updateHistory(receiveNodes);
}
List<WalletNode> changeNodes = event.getChangeNodes();
if(!changeNodes.isEmpty()) {
changeTable.updateHistory(changeNodes);
}
}
} }