add view option to hide used empty addresses

This commit is contained in:
Craig Raw 2020-12-09 16:06:30 +02:00
parent 2b47740539
commit ccead92388
10 changed files with 81 additions and 4 deletions

View file

@ -92,6 +92,9 @@ public class AppController implements Initializable {
@FXML @FXML
private CheckMenuItem openWalletsInNewWindows; private CheckMenuItem openWalletsInNewWindows;
@FXML
private CheckMenuItem hideEmptyUsedAddresses;
@FXML @FXML
private CheckMenuItem showTxHex; private CheckMenuItem showTxHex;
@ -214,6 +217,7 @@ public class AppController implements Initializable {
setTheme(null); setTheme(null);
openWalletsInNewWindows.setSelected(Config.get().isOpenWalletsInNewWindows()); openWalletsInNewWindows.setSelected(Config.get().isOpenWalletsInNewWindows());
hideEmptyUsedAddresses.setSelected(Config.get().isHideEmptyUsedAddresses());
showTxHex.setSelected(Config.get().isShowTransactionHex()); showTxHex.setSelected(Config.get().isShowTransactionHex());
exportWallet.setDisable(true); exportWallet.setDisable(true);
@ -491,6 +495,12 @@ public class AppController implements Initializable {
EventManager.get().post(new OpenWalletsNewWindowsStatusEvent(item.isSelected())); EventManager.get().post(new OpenWalletsNewWindowsStatusEvent(item.isSelected()));
} }
public void hideEmptyUsedAddresses(ActionEvent event) {
CheckMenuItem item = (CheckMenuItem)event.getSource();
Config.get().setHideEmptyUsedAddresses(item.isSelected());
EventManager.get().post(new HideEmptyUsedAddressesStatusEvent(item.isSelected()));
}
public void showTxHex(ActionEvent event) { public void showTxHex(ActionEvent event) {
CheckMenuItem item = (CheckMenuItem)event.getSource(); CheckMenuItem item = (CheckMenuItem)event.getSource();
Config.get().setShowTransactionHex(item.isSelected()); Config.get().setShowTransactionHex(item.isSelected());
@ -1260,6 +1270,11 @@ public class AppController implements Initializable {
openWalletsInNewWindows.setSelected(event.isOpenWalletsInNewWindows()); openWalletsInNewWindows.setSelected(event.isOpenWalletsInNewWindows());
} }
@Subscribe
public void hideEmptyUsedAddressesStatusChanged(HideEmptyUsedAddressesStatusEvent event) {
hideEmptyUsedAddresses.setSelected(event.isHideEmptyUsedAddresses());
}
@Subscribe @Subscribe
public void requestOpenWallets(RequestOpenWalletsEvent event) { public void requestOpenWallets(RequestOpenWalletsEvent event) {
EventManager.get().post(new OpenWalletsEvent(tabs.getScene().getWindow(), getOpenWallets())); EventManager.get().post(new OpenWalletsEvent(tabs.getScene().getWindow(), getOpenWallets()));

View file

@ -14,6 +14,7 @@ import javafx.scene.input.MouseButton;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalInt;
public class AddressTreeTable extends CoinTreeTable { public class AddressTreeTable extends CoinTreeTable {
public void initialize(NodeEntry rootEntry) { public void initialize(NodeEntry rootEntry) {
@ -60,7 +61,10 @@ public class AddressTreeTable extends CoinTreeTable {
Integer highestUsedIndex = rootEntry.getNode().getHighestUsedIndex(); Integer highestUsedIndex = rootEntry.getNode().getHighestUsedIndex();
if(highestUsedIndex != null) { if(highestUsedIndex != null) {
scrollTo(highestUsedIndex); OptionalInt tableIndex = rootEntry.getChildren().stream().filter(childEntry -> ((NodeEntry)childEntry).getNode().getIndex() == highestUsedIndex + 1).mapToInt(childEntry -> rootEntry.getChildren().indexOf(childEntry)).findFirst();
if(tableIndex.isPresent() && tableIndex.getAsInt() > 5) {
scrollTo(tableIndex.getAsInt());
}
} }
setOnMouseClicked(mouseEvent -> { setOnMouseClicked(mouseEvent -> {

View file

@ -0,0 +1,13 @@
package com.sparrowwallet.sparrow.event;
public class HideEmptyUsedAddressesStatusEvent {
private final boolean hideEmptyUsedAddresses;
public HideEmptyUsedAddressesStatusEvent(boolean hideEmptyUsedAddresses) {
this.hideEmptyUsedAddresses = hideEmptyUsedAddresses;
}
public boolean isHideEmptyUsedAddresses() {
return hideEmptyUsedAddresses;
}
}

View file

@ -0,0 +1,18 @@
package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.drongo.wallet.Wallet;
/**
* Used to indicate that the display configuration of wallet addresses has been updated
*/
public class WalletAddressesStatusEvent {
private final Wallet wallet;
public WalletAddressesStatusEvent(Wallet wallet) {
this.wallet = wallet;
}
public Wallet getWallet() {
return wallet;
}
}

View file

@ -32,6 +32,7 @@ public class Config {
private boolean checkNewVersions = true; private boolean checkNewVersions = true;
private Theme theme; private Theme theme;
private boolean openWalletsInNewWindows = false; private boolean openWalletsInNewWindows = false;
private boolean hideEmptyUsedAddresses = false;
private boolean showTransactionHex = true; private boolean showTransactionHex = true;
private List<File> recentWalletFiles; private List<File> recentWalletFiles;
private Integer keyDerivationPeriod; private Integer keyDerivationPeriod;
@ -195,6 +196,15 @@ public class Config {
flush(); flush();
} }
public boolean isHideEmptyUsedAddresses() {
return hideEmptyUsedAddresses;
}
public void setHideEmptyUsedAddresses(boolean hideEmptyUsedAddresses) {
this.hideEmptyUsedAddresses = hideEmptyUsedAddresses;
flush();
}
public boolean isShowTransactionHex() { public boolean isShowTransactionHex() {
return showTransactionHex; return showTransactionHex;
} }

View file

@ -248,8 +248,8 @@ public class Storage {
} }
public static boolean walletExists(String walletName) { public static boolean walletExists(String walletName) {
File encrypted = new File(getWalletsDir(), walletName); File encrypted = new File(getWalletsDir(), walletName.trim());
File unencrypted = new File(getWalletsDir(), walletName + ".json"); File unencrypted = new File(getWalletsDir(), walletName.trim() + ".json");
return (encrypted.exists() || unencrypted.exists()); return (encrypted.exists() || unencrypted.exists());
} }

View file

@ -75,4 +75,12 @@ public class AddressesController extends WalletFormController implements Initial
changeTable.refresh(); changeTable.refresh();
} }
} }
@Subscribe
public void walletAddressesStatusChanged(WalletAddressesStatusEvent event) {
if(event.getWallet().equals(walletForm.getWallet())) {
receiveTable.updateAll(getWalletForm().getNodeEntry(KeyPurpose.RECEIVE));
changeTable.updateAll(getWalletForm().getNodeEntry(KeyPurpose.CHANGE));
}
}
} }

View file

@ -6,6 +6,7 @@ import com.sparrowwallet.drongo.wallet.Wallet;
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.event.WalletEntryLabelChangedEvent; import com.sparrowwallet.sparrow.event.WalletEntryLabelChangedEvent;
import com.sparrowwallet.sparrow.io.Config;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -15,7 +16,7 @@ public class NodeEntry extends Entry implements Comparable<NodeEntry> {
public NodeEntry(Wallet wallet, WalletNode node) { public NodeEntry(Wallet wallet, WalletNode node) {
super(wallet, node.getLabel(), super(wallet, node.getLabel(),
!node.getChildren().isEmpty() ? !node.getChildren().isEmpty() ?
node.getChildren().stream().map(childNode -> new NodeEntry(wallet, childNode)).collect(Collectors.toList()) : node.getChildren().stream().filter(childNode -> !Config.get().isHideEmptyUsedAddresses() || childNode.getTransactionOutputs().isEmpty() || !childNode.getUnspentTransactionOutputs().isEmpty()).map(childNode -> new NodeEntry(wallet, childNode)).collect(Collectors.toList()) :
node.getTransactionOutputs().stream().map(txo -> new HashIndexEntry(wallet, txo, HashIndexEntry.Type.OUTPUT, node.getKeyPurpose())).collect(Collectors.toList())); node.getTransactionOutputs().stream().map(txo -> new HashIndexEntry(wallet, txo, HashIndexEntry.Type.OUTPUT, node.getKeyPurpose())).collect(Collectors.toList()));
this.node = node; this.node = node;

View file

@ -262,4 +262,10 @@ public class WalletForm {
} }
} }
} }
@Subscribe
public void hideEmptyUsedAddressesStatusChanged(HideEmptyUsedAddressesStatusEvent event) {
accountEntries.clear();
EventManager.get().post(new WalletAddressesStatusEvent(wallet));
}
} }

View file

@ -78,7 +78,9 @@
</RadioMenuItem> </RadioMenuItem>
</items> </items>
</Menu> </Menu>
<SeparatorMenuItem />
<CheckMenuItem fx:id="openWalletsInNewWindows" mnemonicParsing="false" text="Open Wallets in New Windows" onAction="#openWalletsInNewWindows"/> <CheckMenuItem fx:id="openWalletsInNewWindows" mnemonicParsing="false" text="Open Wallets in New Windows" onAction="#openWalletsInNewWindows"/>
<CheckMenuItem fx:id="hideEmptyUsedAddresses" mnemonicParsing="false" text="Hide Empty Used Addresses" onAction="#hideEmptyUsedAddresses"/>
<CheckMenuItem fx:id="showTxHex" mnemonicParsing="false" text="Show Transaction Hex" onAction="#showTxHex"/> <CheckMenuItem fx:id="showTxHex" mnemonicParsing="false" text="Show Transaction Hex" onAction="#showTxHex"/>
</items> </items>
</Menu> </Menu>