improve voiceover reading of the send form
What changed, and why it matters
This commit improves how screen readers (voiceover software) describe parts of the Bitcoin wallet's send form. It adds labels to input fields, makes read-only labels announce themselves properly, and makes a fee-rate slider and recent-blocks graph easier to understand by voice. There is no security bug being fixed here.
No security action required. Treat as a normal accessibility improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is an accessibility/usability patch. It introduces a custom FieldSkin (LabelledFieldSkin) that links tornadofx Field labels to their actual input controls so assistive technologies announce the label with the input. It overrides accessible attributes in CopyableLabel and RecentBlocksView to provide better screen-reader text, and updates FeeRangeSlider to put the computed fee rate into accessible text. The build.gradle change merely exports an additional tornadofx package so the new skin can extend FieldSkin. No cryptographic, network, or input-validation logic is modified.
Changed components
UI accessibility layer (JavaFX accessible attributes)CopyableLabel controlFeeRangeSlider controlRecentBlocksView controlField/form skinning in general.csspayment.fxml and send.fxml layoutsInspect captured patch +184 / −32
### build.gradle
@@ -524,6 +524,7 @@ tasks.register('extractNativeLibraries') {
extraJavaModuleInfo {
module('no.tornado:tornadofx-controls', 'tornadofx.controls') {
exports('tornadofx.control')
+ exports('tornadofx.control.skin')
requires('javafx.controls')
}
module('com.github.arteam:simple-json-rpc-core', 'simple.json.rpc.core') {
### src/main/java/com/sparrowwallet/sparrow/control/CopyableLabel.java
@@ -1,5 +1,8 @@
package com.sparrowwallet.sparrow.control;
+import javafx.collections.FXCollections;
+import javafx.scene.AccessibleAttribute;
+import javafx.scene.AccessibleRole;
import javafx.scene.control.TextField;
public class CopyableLabel extends TextField {
@@ -21,4 +24,17 @@ public CopyableLabel(String text) {
});
}
+ @Override
+ public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
+ //An empty value has nothing to read
+ if(getText() == null || getText().isEmpty()) {
+ if(attribute == AccessibleAttribute.ROLE) {
+ return AccessibleRole.NODE;
+ } else if(attribute == AccessibleAttribute.CHILDREN) {
+ return FXCollections.emptyObservableList();
+ }
+ }
+
+ return super.queryAccessibleAttribute(attribute, parameters);
+ }
}
### src/main/java/com/sparrowwallet/sparrow/control/FeeRangeSlider.java
@@ -2,10 +2,10 @@
import com.sparrowwallet.drongo.protocol.Transaction;
import com.sparrowwallet.sparrow.AppServices;
+import com.sparrowwallet.sparrow.UnitFormat;
+import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.net.FeeRatesSource;
import javafx.application.Platform;
-import javafx.scene.AccessibleAction;
-import javafx.scene.AccessibleAttribute;
import javafx.scene.Node;
import javafx.scene.control.Slider;
import javafx.util.StringConverter;
@@ -29,7 +29,7 @@ public FeeRangeSlider() {
setShowTickLabels(true);
setShowTickMarks(true);
setBlockIncrement(Math.log(1.02) / Math.log(2));
- setAccessibleText("Fee Rate (sats/vB)");
+ updateAccessibleText();
setLabelFormatter(new StringConverter<>() {
@Override
@@ -53,6 +53,7 @@ public Double fromString(String string) {
if(newValue != null) {
updateMaxFeeRange(newValue.doubleValue());
}
+ updateAccessibleText();
});
setOnScroll(event -> {
@@ -73,22 +74,18 @@ public double getFeeRate() {
}
public double getFeeRate(Double minRelayFeeRate) {
- return getFeeRate(getValue(), minRelayFeeRate);
- }
-
- private double getFeeRate(double value, Double minRelayFeeRate) {
if(minRelayFeeRate >= Transaction.DEFAULT_MIN_RELAY_FEE) {
- return Math.pow(2.0, value);
+ return Math.pow(2.0, getValue());
}
- if(value < 1.0d) {
+ if(getValue() < 1.0d) {
if(minRelayFeeRate == 0.0d) {
- return value;
+ return getValue();
}
- return Math.pow(minRelayFeeRate, 1.0d - value);
+ return Math.pow(minRelayFeeRate, 1.0d - getValue());
}
- return Math.pow(2.0, value - 1.0d);
+ return Math.pow(2.0, getValue() - 1.0d);
}
public void setFeeRate(double feeRate) {
@@ -144,24 +141,10 @@ private void updateMaxFeeRange(double value) {
}
}
- @Override
- public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
- //Report fee rates rather than the logarithmic slider position
- return switch(attribute) {
- case VALUE -> Math.round(getFeeRate() * 1000) / 1000.0;
- case MIN_VALUE -> getFeeRate(getMin(), AppServices.getMinimumRelayFeeRate());
- case MAX_VALUE -> getFeeRate(getMax(), AppServices.getMinimumRelayFeeRate());
- default -> super.queryAccessibleAttribute(attribute, parameters);
- };
- }
-
- @Override
- public void executeAccessibleAction(AccessibleAction action, Object... parameters) {
- if(action == AccessibleAction.SET_VALUE && parameters.length > 0 && parameters[0] instanceof Double feeRate) {
- setFeeRate(Math.clamp(feeRate, AppServices.getLongFeeRatesRange().getFirst(), AppServices.getLongFeeRatesRange().getLast()));
- } else {
- super.executeAccessibleAction(action, parameters);
- }
+ private void updateAccessibleText() {
+ //Screen readers announce a slider's value as a percentage of its range, so the fee rate is given in the name
+ UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
+ setAccessibleText("Fee rate " + format.getCurrencyFormat().format(getFeeRate()) + " sats/vB");
}
public boolean isLongFeeRange() {
### src/main/java/com/sparrowwallet/sparrow/control/LabelledFieldSkin.java
@@ -0,0 +1,95 @@
+package com.sparrowwallet.sparrow.control;
+
+import javafx.beans.InvalidationListener;
+import javafx.scene.Node;
+import javafx.scene.Parent;
+import javafx.scene.control.*;
+import org.controlsfx.control.RangeSlider;
+import org.controlsfx.control.ToggleSwitch;
+import tornadofx.control.Field;
+import tornadofx.control.skin.FieldSkin;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Field skin that links the field's label to its input, so screen readers announce the label with the input.
+ * Applied to every field with -fx-skin in general.css.
+ */
+public class LabelledFieldSkin extends FieldSkin {
+ private final Label label;
+ private final InvalidationListener labelForListener = _ -> updateLabelFor();
+ private final List<Node> visibilityWatched = new ArrayList<>();
+
+ public LabelledFieldSkin(Field field) {
+ super(field);
+ label = (Label)field.getLabelContainer().getChildren().getFirst();
+ field.getInputs().addListener(labelForListener);
+ field.textProperty().addListener(labelForListener);
+ updateLabelFor();
+ }
+
+ @Override
+ public void dispose() {
+ getSkinnable().getInputs().removeListener(labelForListener);
+ getSkinnable().textProperty().removeListener(labelForListener);
+ unwatchVisibility();
+ label.setLabelFor(null);
+ super.dispose();
+ }
+
+ private void updateLabelFor() {
+ unwatchVisibility();
+ String text = getSkinnable().getText();
+ label.setLabelFor(text == null || text.isEmpty() ? null : getLabelledInput(getSkinnable().getInputs()));
+ }
+
+ private Node getLabelledInput(List<Node> inputs) {
+ Node textInput = findInput(inputs, true);
+ return textInput != null ? textInput : findInput(inputs, false);
+ }
+
+ //Only value controls are labelled: a button or a value shown in a plain label after the field label is not what the label names
+ private Node findInput(List<Node> nodes, boolean textInputOnly) {
+ for(Node node : nodes) {
+ boolean input = node instanceof TextInputControl || (!textInputOnly && isValueControl(node));
+ if(input || (!(node instanceof Control) && node instanceof Parent)) {
+ watchVisibility(node);
+ }
+
+ if(!node.isVisible()) {
+ continue;
+ }
+
+ if(input) {
+ return node;
+ }
+
+ if(!(node instanceof Control) && node instanceof Parent parent) {
+ Node found = findInput(parent.getChildrenUnmodifiable(), textInputOnly);
+ if(found != null) {
+ return found;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private static boolean isValueControl(Node node) {
+ return node instanceof ComboBoxBase<?> || node instanceof ChoiceBox<?> || node instanceof Spinner<?> || node instanceof Slider || node instanceof RangeSlider
+ || node instanceof ToggleSwitch;
+ }
+
+ private void watchVisibility(Node node) {
+ if(!visibilityWatched.contains(node)) {
+ node.visibleProperty().addListener(labelForListener);
+ visibilityWatched.add(node);
+ }
+ }
+
+ private void unwatchVisibility() {
+ visibilityWatched.forEach(node -> node.visibleProperty().removeListener(labelForListener));
+ visibilityWatched.clear();
+ }
+}
### src/main/java/com/sparrowwallet/sparrow/control/RecentBlocksView.java
@@ -9,6 +9,9 @@
import javafx.animation.TranslateTransition;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
+import javafx.collections.FXCollections;
+import javafx.scene.AccessibleAttribute;
+import javafx.scene.AccessibleRole;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;
@@ -19,6 +22,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import static com.sparrowwallet.sparrow.AppServices.TARGET_BLOCKS_RANGE;
import static com.sparrowwallet.sparrow.control.BlockCube.CUBE_SIZE;
@@ -27,6 +32,7 @@ public class RecentBlocksView extends Pane {
private static final double CUBE_SPACING = 100;
private static final double ANIMATION_DURATION_MILLIS = 1000;
private static final double SEPARATOR_X = 74;
+ private static final Pattern ELAPSED_PATTERN = Pattern.compile("(\\d+)([mhd]) ago");
private final CompositeDisposable disposables = new CompositeDisposable();
@@ -54,6 +60,53 @@ public RecentBlocksView() {
feeRatesSource = (feeRatesSource == null ? FeeRatesSource.MEMPOOL_SPACE : feeRatesSource);
updateFeeRatesSource(feeRatesSource);
Tooltip.install(this, tooltip);
+ setAccessibleRole(AccessibleRole.TEXT);
+ }
+
+ @Override
+ public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
+ //Read as one summary rather than the individual heights, fee rates and times on the cubes
+ return switch(attribute) {
+ case TEXT -> getSummary();
+ case CHILDREN -> FXCollections.emptyObservableList();
+ default -> super.queryAccessibleAttribute(attribute, parameters);
+ };
+ }
+
+ private String getSummary() {
+ List<BlockCube> cubes = getCubes();
+ if(cubes.isEmpty()) {
+ return "Recent blocks, no blocks";
+ }
+
+ StringBuilder summary = new StringBuilder("Recent blocks");
+ for(BlockCube cube : cubes.subList(0, Math.min(3, cubes.size()))) {
+ summary.append(", ").append(cube.isConfirmed() ? "block " + cube.getHeight() : "next block");
+ if(cube.getMedianFee() >= 0.0d) {
+ summary.append(" ~").append(Math.round(Math.max(cube.getMedianFee(), 1.0d))).append(" sats/vB");
+ }
+ if(cube.isConfirmed()) {
+ summary.append(cube.getTxCount() > 0 ? " with " + cube.getTxCount() + " transactions " : " ").append(getSpokenElapsed(cube.getElapsed()));
+ } else {
+ summary.append(" in about 10 minutes");
+ }
+ }
+
+ return summary.toString();
+ }
+
+ private static String getSpokenElapsed(String elapsed) {
+ Matcher matcher = ELAPSED_PATTERN.matcher(elapsed);
+ if(matcher.matches()) {
+ String unit = switch(matcher.group(2)) {
+ case "m" -> "minute";
+ case "h" -> "hour";
+ default -> "day";
+ };
+ return matcher.group(1) + " " + unit + (matcher.group(1).equals("1") ? "" : "s") + " ago";
+ }
+
+ return elapsed.toLowerCase();
}
public void updateFeeRatesSource(FeeRatesSource feeRatesSource) {
### src/main/resources/com/sparrowwallet/sparrow/general.css
@@ -32,6 +32,10 @@
-fx-spacing: 10;
}
+.field {
+ -fx-skin: "com.sparrowwallet.sparrow.control.LabelledFieldSkin";
+}
+
.form .field {
-fx-padding: 3 5;
}
### src/main/resources/com/sparrowwallet/sparrow/wallet/payment.fxml
@@ -57,7 +57,7 @@
</FXCollections>
</items>
</ComboBox>
- <Label style="-fx-pref-width: 15" />
+ <Region style="-fx-pref-width: 15" />
<FiatLabel fx:id="fiatAmount" />
<Group managed="false" translateY="38">
<Label fx:id="amountStatus" text="Insufficient funds">
### src/main/resources/com/sparrowwallet/sparrow/wallet/send.fxml
@@ -127,7 +127,7 @@
</FXCollections>
</items>
</ComboBox>
- <Label style="-fx-pref-width: 15" />
+ <Region style="-fx-pref-width: 15" />
<FiatLabel fx:id="fiatFeeAmount" />
</Field>
</Fieldset>Why this scored 15/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.