mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-23 20:36:44 +00:00
address history updating
This commit is contained in:
parent
b1e8e25837
commit
efba293564
4 changed files with 44 additions and 2 deletions
|
@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.control;
|
|||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.address.Address;
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.ReceiveActionEvent;
|
||||
import com.sparrowwallet.sparrow.event.ReceiveToEvent;
|
||||
|
@ -27,7 +28,9 @@ import org.controlsfx.glyphfont.FontAwesome;
|
|||
import org.controlsfx.glyphfont.Glyph;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
public class AddressTreeTable extends TreeTableView<Entry> {
|
||||
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) {
|
||||
cell.getStyleClass().remove("node-row");
|
||||
cell.getStyleClass().remove("hashindex-row");
|
||||
|
|
|
@ -50,8 +50,7 @@ public class RecursiveTreeItem<T> extends TreeItem<T> {
|
|||
while(change.next()){
|
||||
|
||||
if(change.wasAdded()){
|
||||
change.getAddedSubList().forEach(t-> RecursiveTreeItem.this.getChildren().add(
|
||||
new RecursiveTreeItem<>(t, this.graphicsFactory, childrenFactory)));
|
||||
change.getAddedSubList().forEach(t-> RecursiveTreeItem.this.getChildren().add(change.getFrom(), new RecursiveTreeItem<>(t, this.graphicsFactory, childrenFactory)));
|
||||
}
|
||||
|
||||
if(change.wasRemoved()){
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WalletHistoryChangedEvent extends WalletChangedEvent {
|
||||
private final List<WalletNode> historyChangedNodes;
|
||||
|
@ -16,4 +18,12 @@ public class WalletHistoryChangedEvent extends WalletChangedEvent {
|
|||
public List<WalletNode> getHistoryChangedNodes() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.AddressTreeTable;
|
||||
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class AddressesController extends WalletFormController implements Initializable {
|
||||
|
@ -29,4 +33,17 @@ public class AddressesController extends WalletFormController implements Initial
|
|||
receiveTable.initialize(getWalletForm().getNodeEntry(KeyPurpose.RECEIVE));
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue