diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 8b5101dc..fb37c9dd 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -837,7 +837,7 @@ public class HeadersController extends TransactionFormController implements Init @Subscribe public void openWallets(OpenWalletsEvent event) { if(headersForm.getPsbt() != null && headersForm.getBlockTransaction() == null) { - List availableWallets = event.getWallets().stream().filter(wallet -> wallet.canSign(headersForm.getPsbt())).collect(Collectors.toList()); + List availableWallets = event.getWallets().stream().filter(wallet -> wallet.canSign(headersForm.getPsbt())).sorted(new WalletSignComparator()).collect(Collectors.toList()); Map availableWalletsMap = new LinkedHashMap<>(event.getWalletsMap()); availableWalletsMap.keySet().retainAll(availableWallets); headersForm.getAvailableWallets().keySet().retainAll(availableWallets); @@ -1016,4 +1016,18 @@ public class HeadersController extends TransactionFormController implements Init futureBlockWarning.setVisible(AppController.getCurrentBlockHeight() != null && locktimeBlock.getValue() > event.getHeight()); } } + + private static class WalletSignComparator implements Comparator { + private static final List sourceOrder = List.of(KeystoreSource.SW_WATCH, KeystoreSource.HW_AIRGAPPED, KeystoreSource.HW_USB, KeystoreSource.SW_SEED); + + @Override + public int compare(Wallet wallet1, Wallet wallet2) { + return getHighestSourceIndex(wallet2) - getHighestSourceIndex(wallet1); + + } + + private int getHighestSourceIndex(Wallet wallet) { + return wallet.getKeystores().stream().map(keystore -> sourceOrder.indexOf(keystore.getSource())).mapToInt(v -> v).max().orElse(0); + } + } } \ No newline at end of file