remove block hash from transaction tab fields, add to context menu for block height and timestamp

This commit is contained in:
Craig Raw 2023-10-11 13:08:42 +02:00
parent 4e3e8b7cc4
commit a6a671f687
2 changed files with 34 additions and 28 deletions

View file

@ -176,12 +176,6 @@ public class HeadersController extends TransactionFormController implements Init
@FXML
private CopyableLabel blockTimestamp;
@FXML
private Field blockHashField;
@FXML
private IdLabel blockHash;
@FXML
private Form signingWalletForm;
@ -746,11 +740,11 @@ public class HeadersController extends TransactionFormController implements Init
blockHeightField.managedProperty().bind(blockHeightField.visibleProperty());
blockTimestampField.managedProperty().bind(blockTimestampField.visibleProperty());
blockHashField.managedProperty().bind(blockHashField.visibleProperty());
if(blockTransaction.getHeight() > 0) {
blockHeightField.setVisible(true);
blockHeight.setText(Integer.toString(blockTransaction.getHeight()));
blockHeight.setContextMenu(new BlockHeightContextMenu(blockTransaction));
} else {
blockHeightField.setVisible(false);
}
@ -759,17 +753,10 @@ public class HeadersController extends TransactionFormController implements Init
blockTimestampField.setVisible(true);
SimpleDateFormat dateFormat = new SimpleDateFormat(BLOCK_TIMESTAMP_DATE_FORMAT);
blockTimestamp.setText(dateFormat.format(blockTransaction.getDate()));
blockTimestamp.setContextMenu(new BlockHeightContextMenu(blockTransaction));
} else {
blockTimestampField.setVisible(false);
}
if(blockTransaction.getBlockHash() != null && !blockTransaction.getBlockHash().equals(Sha256Hash.ZERO_HASH)) {
blockHashField.setVisible(true);
blockHash.setText(blockTransaction.getBlockHash().toString());
blockHash.setContextMenu(new BlockHeightContextMenu(blockTransaction.getBlockHash()));
} else {
blockHashField.setVisible(false);
}
}
private void initializeSignButton(Wallet signingWallet) {
@ -809,17 +796,40 @@ public class HeadersController extends TransactionFormController implements Init
}
private static class BlockHeightContextMenu extends ContextMenu {
public BlockHeightContextMenu(Sha256Hash blockHash) {
public BlockHeightContextMenu(BlockTransaction blockTransaction) {
if(blockTransaction.getHeight() > 0) {
MenuItem copyBlockHeight = new MenuItem("Copy Block Height");
copyBlockHeight.setOnAction(AE -> {
hide();
ClipboardContent content = new ClipboardContent();
content.putString(Integer.toString(blockTransaction.getHeight()));
Clipboard.getSystemClipboard().setContent(content);
});
getItems().add(copyBlockHeight);
}
if(blockTransaction.getDate() != null) {
MenuItem copyBlockTimestamp = new MenuItem("Copy Block Timestamp");
copyBlockTimestamp.setOnAction(AE -> {
hide();
ClipboardContent content = new ClipboardContent();
SimpleDateFormat dateFormat = new SimpleDateFormat(BLOCK_TIMESTAMP_DATE_FORMAT);
content.putString(dateFormat.format(blockTransaction.getDate()));
Clipboard.getSystemClipboard().setContent(content);
});
getItems().add(copyBlockTimestamp);
}
if(blockTransaction.getBlockHash() != null && !blockTransaction.getBlockHash().equals(Sha256Hash.ZERO_HASH)) {
MenuItem copyBlockHash = new MenuItem("Copy Block Hash");
copyBlockHash.setOnAction(AE -> {
hide();
ClipboardContent content = new ClipboardContent();
content.putString(blockHash.toString());
content.putString(blockTransaction.getBlockHash().toString());
Clipboard.getSystemClipboard().setContent(content);
});
getItems().add(copyBlockHash);
}
}
}
private void updateTxId() {
id.setText(headersForm.getTransaction().calculateTxId(false).toString());
@ -1342,7 +1352,6 @@ public class HeadersController extends TransactionFormController implements Init
errorGlyph.getStyleClass().add("failure");
blockHeightField.setVisible(false);
blockTimestampField.setVisible(false);
blockHashField.setVisible(false);
}
}

View file

@ -187,9 +187,6 @@
<Field fx:id="blockTimestampField" text="Timestamp:">
<CopyableLabel fx:id="blockTimestamp" />
</Field>
<Field fx:id="blockHashField" text="Block Hash:">
<IdLabel fx:id="blockHash" />
</Field>
</Fieldset>
</DynamicForm>