keep a selection in single-choice toggle groups when the selected button is pressed again
What changed, and why it matters
This commit fixes a minor user-interface behavior in several toggle-button groups. In JavaFX, pressing an already-selected toggle button can deselect it, leaving the group with no active choice. The patch ensures that if the user re-presses the currently selected button, the previous selection is restored instead of becoming blank. This prevents confusing UI state but does not appear to protect against malicious attacks or data loss.
No immediate security action required. Treat as a normal UI bug fix. If reviewing for a security release, consider whether any of the affected toggles could lead to unsafe defaults when deselected; the diff suggests the previous selection is simply restored, so downstream logic should remain unchanged.
Security signals we found
UI state consistency fix in single-choice toggle groups
Prevents accidental deselection of required configuration options
No input validation, cryptographic, or network changes observed
Evidence from the diff
The change adds null-checks to selectedToggleProperty listeners across five UI controllers. When newValue is null (meaning the selected toggle was deselected, typically by clicking it again), the listener now re-selects oldValue. Previously, the code either updated state based on the new selection or skipped the update. Affected toggle groups control fee-rate selection, transaction locktime type, input sequence locktime type, message-signing format, and mempool chart period. The patch is defensive UI hardening rather than a fix for an exploitable vulnerability.
Changed components
MempoolSizeFeeRatesChart.javaMessageSignDialog.javaHeadersController.javaInputController.javaSendController.javaInspect captured patch +25 / −8
### src/main/java/com/sparrowwallet/sparrow/control/MempoolSizeFeeRatesChart.java
@@ -90,8 +90,12 @@ public void handle(MouseEvent event) {
periodButtons.setToggleGroup(periodGroup);
periodButtons.getButtons().forEach(button -> button.setAccessibleRole(AccessibleRole.RADIO_BUTTON));
periodGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
- expandedChart.maxPeriodHours = (newValue == period2 ? 2 : 24);
- expandedChart.update(AppServices.getMempoolHistogram());
+ if(newValue == null) {
+ oldValue.setSelected(true);
+ } else {
+ expandedChart.maxPeriodHours = (newValue == period2 ? 2 : 24);
+ expandedChart.update(AppServices.getMempoolHistogram());
+ }
});
Optional<Date> optEarliest = AppServices.getMempoolHistogram().keySet().stream().findFirst();
### src/main/java/com/sparrowwallet/sparrow/control/MessageSignDialog.java
@@ -268,8 +268,10 @@ public MessageSignDialog(Wallet wallet, WalletNode walletNode, String title, Str
}
});
- formatGroup.selectedToggleProperty().addListener((_, _, newVal) -> {
- if(wallet != null) {
+ formatGroup.selectedToggleProperty().addListener((_, oldVal, newVal) -> {
+ if(newVal == null) {
+ oldVal.setSelected(true);
+ } else if(wallet != null) {
boolean canSignSelectedFormat = canSignAllFormats(wallet) || newVal == formatElectrum;
signButton.setDisable(!isValidAddress() || !canSign || !canSignSelectedFormat);
}
### src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java
@@ -313,7 +313,9 @@ private void initializeView() {
updateType();
locktimeToggleGroup.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
- if(locktimeToggleGroup.getSelectedToggle() != null) {
+ if(new_toggle == null) {
+ old_toggle.setSelected(true);
+ } else {
String selection = locktimeToggleGroup.getSelectedToggle().getUserData().toString();
if(selection.equals("none")) {
locktimeFieldset.getChildren().remove(locktimeDateField);
### src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java
@@ -388,7 +388,9 @@ private void setInputSequenceNumber(TransactionInput txInput, long sequence) {
private void initializeLocktimeFields(TransactionInput txInput) {
Transaction transaction = inputForm.getTransaction();
locktimeToggleGroup.selectedToggleProperty().addListener((ov, old_toggle, new_toggle) -> {
- if(locktimeToggleGroup.getSelectedToggle() != null) {
+ if(new_toggle == null) {
+ old_toggle.setSelected(true);
+ } else {
String selection = locktimeToggleGroup.getSelectedToggle().getUserData().toString();
if(selection.equals("none")) {
locktimeFieldset.getChildren().removeAll(locktimeRelativeField, locktimeAbsoluteField);
### src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java
@@ -355,11 +355,13 @@ public Double fromString(String string) {
feeSelectionToggleGroup.selectToggle(feeRatesSelection == FeeRatesSelection.BLOCK_TARGET ? targetBlocksToggle :
(feeRatesSelection == FeeRatesSelection.MEMPOOL_SIZE ? mempoolSizeToggle : recentBlocksToggle));
feeSelectionToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
- if(newValue != null) {
+ if(newValue == null) {
+ oldValue.setSelected(true);
+ } else {
FeeRatesSelection newFeeRatesSelection = (FeeRatesSelection)newValue.getUserData();
Config.get().setFeeRatesSelection(newFeeRatesSelection);
EventManager.get().post(new FeeRatesSelectionChangedEvent(getWalletForm().getWallet(), newFeeRatesSelection));
- };
+ }
});
BitcoinUnit unit = getBitcoinUnit(Config.get().getBitcoinUnit());
@@ -445,6 +447,11 @@ public Double fromString(String string) {
Config.get().setSendOptimizationStrategy(OptimizationStrategy.PRIVACY);
updateTransaction();
});
+ optimizationToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
+ if(newValue == null) {
+ oldValue.setSelected(true);
+ }
+ });
setPreferredOptimizationStrategy();
updatePrivacyAnalysis(null);
optimizationHelp.managedProperty().bind(optimizationHelp.visibleProperty());Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.