mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
order available wallets to prioritise seed or usb keystores
This commit is contained in:
parent
194f0f5c1b
commit
63a9a798f3
1 changed files with 15 additions and 1 deletions
|
@ -837,7 +837,7 @@ public class HeadersController extends TransactionFormController implements Init
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void openWallets(OpenWalletsEvent event) {
|
public void openWallets(OpenWalletsEvent event) {
|
||||||
if(headersForm.getPsbt() != null && headersForm.getBlockTransaction() == null) {
|
if(headersForm.getPsbt() != null && headersForm.getBlockTransaction() == null) {
|
||||||
List<Wallet> availableWallets = event.getWallets().stream().filter(wallet -> wallet.canSign(headersForm.getPsbt())).collect(Collectors.toList());
|
List<Wallet> availableWallets = event.getWallets().stream().filter(wallet -> wallet.canSign(headersForm.getPsbt())).sorted(new WalletSignComparator()).collect(Collectors.toList());
|
||||||
Map<Wallet, Storage> availableWalletsMap = new LinkedHashMap<>(event.getWalletsMap());
|
Map<Wallet, Storage> availableWalletsMap = new LinkedHashMap<>(event.getWalletsMap());
|
||||||
availableWalletsMap.keySet().retainAll(availableWallets);
|
availableWalletsMap.keySet().retainAll(availableWallets);
|
||||||
headersForm.getAvailableWallets().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());
|
futureBlockWarning.setVisible(AppController.getCurrentBlockHeight() != null && locktimeBlock.getValue() > event.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class WalletSignComparator implements Comparator<Wallet> {
|
||||||
|
private static final List<KeystoreSource> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue