always display fresh unused address on startup and when address has been used

This commit is contained in:
Craig Raw 2021-04-21 10:23:48 +02:00
parent 18075e0686
commit 58bee33383
3 changed files with 27 additions and 7 deletions

2
drongo

@ -1 +1 @@
Subproject commit efaa6a066d2b7d7f982086060aa8f014ca89a190 Subproject commit b0d37fe8fe6a4bec756e8c24bee562d1a377cf10

View file

@ -7,11 +7,9 @@ import com.google.zxing.client.j2se.MatrixToImageConfig;
import com.google.zxing.client.j2se.MatrixToImageWriter; 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.KeyDerivation;
import com.sparrowwallet.drongo.KeyPurpose; import com.sparrowwallet.drongo.KeyPurpose;
import com.sparrowwallet.drongo.OutputDescriptor; import com.sparrowwallet.drongo.OutputDescriptor;
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex; import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex;
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.KeystoreSource; import com.sparrowwallet.drongo.wallet.KeystoreSource;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.AppServices;
@ -23,6 +21,7 @@ import com.sparrowwallet.sparrow.io.Device;
import com.sparrowwallet.sparrow.io.Hwi; import com.sparrowwallet.sparrow.io.Hwi;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Button; import javafx.scene.control.Button;
@ -30,6 +29,7 @@ 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;
import javafx.scene.input.MouseEvent;
import org.controlsfx.glyphfont.Glyph; import org.controlsfx.glyphfont.Glyph;
import org.fxmisc.richtext.CodeArea; import org.fxmisc.richtext.CodeArea;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -88,6 +88,15 @@ public class ReceiveController extends WalletFormController implements Initializ
displayAddress.managedProperty().bind(displayAddress.visibleProperty()); displayAddress.managedProperty().bind(displayAddress.visibleProperty());
displayAddress.setVisible(false); displayAddress.setVisible(false);
qrCode.setOnMouseClicked(event -> {
if(currentEntry != null) {
QRDisplayDialog qrDisplayDialog = new QRDisplayDialog(currentEntry.getAddress().toString());
qrDisplayDialog.showAndWait();
}
});
Platform.runLater(this::refreshAddress);
} }
public void setNodeEntry(NodeEntry nodeEntry) { public void setNodeEntry(NodeEntry nodeEntry) {
@ -138,7 +147,7 @@ public class ReceiveController extends WalletFormController implements Initializ
} }
} else { } else {
lastUsed.setText("Unknown"); lastUsed.setText("Unknown");
lastUsed.setGraphic(null); lastUsed.setGraphic(getUnknownGlyph());
address.getStyleClass().remove("error"); address.getStyleClass().remove("error");
address.setDisable(false); address.setDisable(false);
} }
@ -189,6 +198,10 @@ public class ReceiveController extends WalletFormController implements Initializ
} }
public void getNewAddress(ActionEvent event) { public void getNewAddress(ActionEvent event) {
refreshAddress();
}
public void refreshAddress() {
NodeEntry freshEntry = getWalletForm().getFreshNodeEntry(KeyPurpose.RECEIVE, currentEntry); NodeEntry freshEntry = getWalletForm().getFreshNodeEntry(KeyPurpose.RECEIVE, currentEntry);
setNodeEntry(freshEntry); setNodeEntry(freshEntry);
} }
@ -252,6 +265,12 @@ public class ReceiveController extends WalletFormController implements Initializ
return duplicateGlyph; return duplicateGlyph;
} }
public static Glyph getUnknownGlyph() {
Glyph duplicateGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.QUESTION_CIRCLE);
duplicateGlyph.setFontSize(12);
return duplicateGlyph;
}
@Subscribe @Subscribe
public void walletAddressesChanged(WalletAddressesChangedEvent event) { public void walletAddressesChanged(WalletAddressesChangedEvent event) {
displayAddress.setUserData(null); displayAddress.setUserData(null);
@ -267,7 +286,8 @@ public class ReceiveController extends WalletFormController implements Initializ
@Subscribe @Subscribe
public void walletNodesChanged(WalletNodesChangedEvent event) { public void walletNodesChanged(WalletNodesChangedEvent event) {
if(event.getWallet().equals(walletForm.getWallet())) { if(event.getWallet().equals(walletForm.getWallet())) {
clear(); currentEntry = null;
refreshAddress();
} }
} }
@ -275,7 +295,7 @@ public class ReceiveController extends WalletFormController implements Initializ
public void walletHistoryChanged(WalletHistoryChangedEvent event) { public void walletHistoryChanged(WalletHistoryChangedEvent event) {
if(event.getWallet().equals(walletForm.getWallet())) { if(event.getWallet().equals(walletForm.getWallet())) {
if(currentEntry != null && event.getHistoryChangedNodes().contains(currentEntry.getNode())) { if(currentEntry != null && event.getHistoryChangedNodes().contains(currentEntry.getNode())) {
updateLastUsed(); refreshAddress();
} }
} }
} }

View file

@ -44,7 +44,7 @@
<CopyableLabel fx:id="derivationPath" /> <CopyableLabel fx:id="derivationPath" />
</Field> </Field>
<Field fx:id="lastUsedField" text="Last Used:"> <Field fx:id="lastUsedField" text="Last Used:">
<Label fx:id="lastUsed" contentDisplay="RIGHT" /> <Label fx:id="lastUsed" />
</Field> </Field>
</Fieldset> </Fieldset>
</Form> </Form>