mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
handle label event and update entries
This commit is contained in:
parent
766afae9c1
commit
67d624f049
11 changed files with 114 additions and 9 deletions
|
@ -61,7 +61,7 @@ public class AddressCell extends TreeTableCell<Entry, Entry> {
|
||||||
return utxoEntry.getNode().getDerivationPath() + (utxoEntry.isDuplicateAddress() ? " (Duplicate address)" : "");
|
return utxoEntry.getNode().getDerivationPath() + (utxoEntry.isDuplicateAddress() ? " (Duplicate address)" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Glyph getDuplicateGlyph() {
|
public static Glyph getDuplicateGlyph() {
|
||||||
Glyph duplicateGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.EXCLAMATION_CIRCLE);
|
Glyph duplicateGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.EXCLAMATION_CIRCLE);
|
||||||
duplicateGlyph.getStyleClass().add("duplicate-warning");
|
duplicateGlyph.getStyleClass().add("duplicate-warning");
|
||||||
duplicateGlyph.setFontSize(12);
|
duplicateGlyph.setFontSize(12);
|
||||||
|
|
|
@ -109,4 +109,9 @@ public class AddressTreeTable extends TreeTableView<Entry> {
|
||||||
|
|
||||||
sort();
|
sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateLabel(Entry entry) {
|
||||||
|
Entry rootEntry = getRoot().getValue();
|
||||||
|
rootEntry.updateLabel(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,4 +75,9 @@ public class TransactionsTreeTable extends TreeTableView<Entry> {
|
||||||
rootEntry.updateTransactions();
|
rootEntry.updateTransactions();
|
||||||
sort();
|
sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateLabel(Entry entry) {
|
||||||
|
Entry rootEntry = getRoot().getValue();
|
||||||
|
rootEntry.updateLabel(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,4 +92,9 @@ public class UtxosTreeTable extends TreeTableView<Entry> {
|
||||||
rootEntry.updateUtxos();
|
rootEntry.updateUtxos();
|
||||||
sort();
|
sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateLabel(Entry entry) {
|
||||||
|
Entry rootEntry = getRoot().getValue();
|
||||||
|
rootEntry.updateLabel(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.sparrowwallet.drongo.KeyPurpose;
|
||||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
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.WalletEntryLabelChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
|
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
@ -54,4 +55,12 @@ public class AddressesController extends WalletFormController implements Initial
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void walletEntryLabelChanged(WalletEntryLabelChangedEvent event) {
|
||||||
|
if(event.getWallet().equals(walletForm.getWallet())) {
|
||||||
|
receiveTable.updateLabel(event.getEntry());
|
||||||
|
changeTable.updateLabel(event.getEntry());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,14 @@ public abstract class Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Long getValue();
|
public abstract Long getValue();
|
||||||
|
|
||||||
|
public void updateLabel(Entry entry) {
|
||||||
|
if(this.equals(entry)) {
|
||||||
|
labelProperty.set(entry.getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Entry child : getChildren()) {
|
||||||
|
child.updateLabel(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class HashIndexEntry extends Entry implements Comparable<HashIndexEntry>
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (!(o instanceof HashIndexEntry)) return false;
|
||||||
HashIndexEntry that = (HashIndexEntry) o;
|
HashIndexEntry that = (HashIndexEntry) o;
|
||||||
return wallet.equals(that.wallet) &&
|
return wallet.equals(that.wallet) &&
|
||||||
hashIndex.equals(that.hashIndex) &&
|
hashIndex.equals(that.hashIndex) &&
|
||||||
|
|
|
@ -7,13 +7,19 @@ import com.google.zxing.client.j2se.MatrixToImageWriter;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
import com.sparrowwallet.drongo.KeyPurpose;
|
import com.sparrowwallet.drongo.KeyPurpose;
|
||||||
|
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex;
|
||||||
|
import com.sparrowwallet.sparrow.AppController;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
|
import com.sparrowwallet.sparrow.control.AddressCell;
|
||||||
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
import com.sparrowwallet.sparrow.control.CopyableLabel;
|
||||||
import com.sparrowwallet.sparrow.control.CopyableTextField;
|
import com.sparrowwallet.sparrow.control.CopyableTextField;
|
||||||
import com.sparrowwallet.sparrow.event.ReceiveToEvent;
|
import com.sparrowwallet.sparrow.event.ReceiveToEvent;
|
||||||
|
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
||||||
|
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
@ -22,9 +28,14 @@ import org.fxmisc.richtext.CodeArea;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ReceiveController extends WalletFormController implements Initializable {
|
public class ReceiveController extends WalletFormController implements Initializable {
|
||||||
|
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private CopyableTextField address;
|
private CopyableTextField address;
|
||||||
|
|
||||||
|
@ -35,7 +46,7 @@ public class ReceiveController extends WalletFormController implements Initializ
|
||||||
private CopyableLabel derivationPath;
|
private CopyableLabel derivationPath;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private CopyableLabel lastUsed;
|
private Label lastUsed;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ImageView qrCode;
|
private ImageView qrCode;
|
||||||
|
@ -64,15 +75,11 @@ public class ReceiveController extends WalletFormController implements Initializ
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentEntry = nodeEntry;
|
this.currentEntry = nodeEntry;
|
||||||
|
|
||||||
address.setText(nodeEntry.getAddress().toString());
|
address.setText(nodeEntry.getAddress().toString());
|
||||||
|
|
||||||
label.textProperty().bindBidirectional(nodeEntry.labelProperty());
|
label.textProperty().bindBidirectional(nodeEntry.labelProperty());
|
||||||
|
|
||||||
derivationPath.setText(nodeEntry.getNode().getDerivationPath());
|
derivationPath.setText(nodeEntry.getNode().getDerivationPath());
|
||||||
|
|
||||||
//TODO: Find last used block height if available (red flag?)
|
updateLastUsed();
|
||||||
lastUsed.setText("Unknown");
|
|
||||||
|
|
||||||
Image qrImage = getQrCode(nodeEntry.getAddress().toString());
|
Image qrImage = getQrCode(nodeEntry.getAddress().toString());
|
||||||
if(qrImage != null) {
|
if(qrImage != null) {
|
||||||
|
@ -86,6 +93,22 @@ public class ReceiveController extends WalletFormController implements Initializ
|
||||||
outputDescriptor.appendText(nodeEntry.getOutputDescriptor());
|
outputDescriptor.appendText(nodeEntry.getOutputDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateLastUsed() {
|
||||||
|
Set<BlockTransactionHashIndex> currentOutputs = currentEntry.getNode().getTransactionOutputs();
|
||||||
|
if(AppController.isOnline() && currentOutputs.isEmpty()) {
|
||||||
|
lastUsed.setText("Never");
|
||||||
|
lastUsed.setGraphic(null);
|
||||||
|
} else if(!currentOutputs.isEmpty()) {
|
||||||
|
long count = currentOutputs.size();
|
||||||
|
BlockTransactionHashIndex lastUsedReference = currentOutputs.stream().skip(count - 1).findFirst().get();
|
||||||
|
lastUsed.setText(DATE_FORMAT.format(lastUsedReference.getDate()));
|
||||||
|
lastUsed.setGraphic(AddressCell.getDuplicateGlyph());
|
||||||
|
} else {
|
||||||
|
lastUsed.setText("Unknown");
|
||||||
|
lastUsed.setGraphic(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Image getQrCode(String address) {
|
private Image getQrCode(String address) {
|
||||||
try {
|
try {
|
||||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||||
|
@ -108,10 +131,42 @@ public class ReceiveController extends WalletFormController implements Initializ
|
||||||
setNodeEntry(freshEntry);
|
setNodeEntry(freshEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
if(currentEntry != null) {
|
||||||
|
label.textProperty().unbindBidirectional(currentEntry.labelProperty());
|
||||||
|
}
|
||||||
|
|
||||||
|
address.setText("");
|
||||||
|
label.setText("");
|
||||||
|
derivationPath.setText("");
|
||||||
|
lastUsed.setText("");
|
||||||
|
lastUsed.setGraphic(null);
|
||||||
|
qrCode.setImage(null);
|
||||||
|
scriptPubKeyArea.clear();
|
||||||
|
outputDescriptor.clear();
|
||||||
|
this.currentEntry = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void receiveTo(ReceiveToEvent event) {
|
public void receiveTo(ReceiveToEvent event) {
|
||||||
if(event.getReceiveEntry().getWallet().equals(getWalletForm().getWallet())) {
|
if(event.getReceiveEntry().getWallet().equals(getWalletForm().getWallet())) {
|
||||||
setNodeEntry(event.getReceiveEntry());
|
setNodeEntry(event.getReceiveEntry());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void walletNodesChanged(WalletNodesChangedEvent event) {
|
||||||
|
if(event.getWallet().equals(walletForm.getWallet())) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void walletHistoryChanged(WalletHistoryChangedEvent event) {
|
||||||
|
if(event.getWallet().equals(walletForm.getWallet())) {
|
||||||
|
if(event.getHistoryChangedNodes().contains(currentEntry.getNode())) {
|
||||||
|
updateLastUsed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.common.eventbus.Subscribe;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.control.TransactionsTreeTable;
|
import com.sparrowwallet.sparrow.control.TransactionsTreeTable;
|
||||||
import com.sparrowwallet.sparrow.event.WalletBlockHeightChangedEvent;
|
import com.sparrowwallet.sparrow.event.WalletBlockHeightChangedEvent;
|
||||||
|
import com.sparrowwallet.sparrow.event.WalletEntryLabelChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
|
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
@ -42,6 +43,13 @@ public class TransactionsController extends WalletFormController implements Init
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void walletEntryLabelChanged(WalletEntryLabelChangedEvent event) {
|
||||||
|
if(event.getWallet().equals(walletForm.getWallet())) {
|
||||||
|
transactionsTable.updateLabel(event.getEntry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Remove
|
//TODO: Remove
|
||||||
public void advanceBlock(MouseEvent event) {
|
public void advanceBlock(MouseEvent event) {
|
||||||
Integer currentBlock = getWalletForm().getWallet().getStoredBlockHeight();
|
Integer currentBlock = getWalletForm().getWallet().getStoredBlockHeight();
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.sparrowwallet.sparrow.wallet;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.control.UtxosTreeTable;
|
import com.sparrowwallet.sparrow.control.UtxosTreeTable;
|
||||||
|
import com.sparrowwallet.sparrow.event.WalletEntryLabelChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
import com.sparrowwallet.sparrow.event.WalletHistoryChangedEvent;
|
||||||
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
|
import com.sparrowwallet.sparrow.event.WalletNodesChangedEvent;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
|
@ -97,6 +98,13 @@ public class UtxosController extends WalletFormController implements Initializab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void walletEntryLabelChanged(WalletEntryLabelChangedEvent event) {
|
||||||
|
if(event.getWallet().equals(walletForm.getWallet())) {
|
||||||
|
utxosTable.updateLabel(event.getEntry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class UtxoData {
|
private static class UtxoData {
|
||||||
public final Entry entry;
|
public final Entry entry;
|
||||||
public final String name;
|
public final String name;
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<CopyableLabel fx:id="derivationPath" />
|
<CopyableLabel fx:id="derivationPath" />
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Last Used:">
|
<Field text="Last Used:">
|
||||||
<CopyableLabel fx:id="lastUsed" />
|
<Label fx:id="lastUsed" />
|
||||||
</Field>
|
</Field>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
Loading…
Reference in a new issue