diff --git a/src/main/java/com/sparrowwallet/sparrow/control/PayNymCell.java b/src/main/java/com/sparrowwallet/sparrow/control/PayNymCell.java index d3c61957..a68f7278 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/PayNymCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/PayNymCell.java @@ -89,7 +89,7 @@ public class PayNymCell extends ListCell { setText(null); setGraphic(pane); - if(payNymController != null && payNym.nymId() == null) { + if(payNymController != null && payNymController.isLinked(payNym)) { setContextMenu(new PayNymCellContextMenu(payNym)); } else { setContextMenu(null); diff --git a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNym.java b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNym.java index 7b5eb361..cefd5089 100644 --- a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNym.java +++ b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNym.java @@ -84,14 +84,23 @@ public class PayNym { PaymentCode externalPaymentCode = bip47Wallet.getKeystores().get(0).getExternalPaymentCode(); String nymName = externalPaymentCode.toAbbreviatedString(); - if(bip47Wallet.getLabel() != null) { - String suffix = " " + bip47Wallet.getScriptType().getName(); - if(bip47Wallet.getLabel().endsWith(suffix)) { - nymName = bip47Wallet.getLabel().substring(0, bip47Wallet.getLabel().length() - suffix.length()); - } + String walletNymName = getNymName(bip47Wallet); + if(walletNymName != null) { + nymName = walletNymName; } boolean segwit = bip47Wallet.getScriptType() != ScriptType.P2PKH; return new PayNym(externalPaymentCode, null, nymName, segwit, Collections.emptyList(), Collections.emptyList()); } + + public static String getNymName(Wallet bip47Wallet) { + if(bip47Wallet.getLabel() != null) { + String suffix = " " + bip47Wallet.getScriptType().getName(); + if(bip47Wallet.getLabel().endsWith(suffix)) { + return bip47Wallet.getLabel().substring(0, bip47Wallet.getLabel().length() - suffix.length()); + } + } + + return null; + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java index 74d78116..2285d69f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java +++ b/src/main/java/com/sparrowwallet/sparrow/paynym/PayNymController.java @@ -317,25 +317,24 @@ public class PayNymController { followingPayNyms.addAll(walletPayNym.following()); } - Map followingPayNymMap = followingPayNyms.stream().collect(Collectors.toMap(PayNym::paymentCode, Function.identity())); - followingPayNyms.addAll(getExistingWalletPayNyms(followingPayNymMap)); - followingList.setItems(FXCollections.observableList(followingPayNyms)); + Map payNymMap = followingPayNyms.stream().collect(Collectors.toMap(PayNym::paymentCode, Function.identity(), (u, v) -> u, LinkedHashMap::new)); + followingList.setItems(FXCollections.observableList(getExistingWalletPayNyms(payNymMap))); } - private List getExistingWalletPayNyms(Map followingPayNymMap) { - Map existingPayNyms = new LinkedHashMap<>(); + private List getExistingWalletPayNyms(Map payNymMap) { List childWallets = new ArrayList<>(getMasterWallet().getChildWallets()); childWallets.sort(Comparator.comparingInt(o -> -o.getScriptType().ordinal())); for(Wallet childWallet : childWallets) { if(childWallet.isBip47()) { PaymentCode externalPaymentCode = childWallet.getKeystores().get(0).getExternalPaymentCode(); - if(!existingPayNyms.containsKey(externalPaymentCode) && !followingPayNymMap.containsKey(externalPaymentCode)) { - existingPayNyms.put(externalPaymentCode, PayNym.fromWallet(childWallet)); + String walletNymName = PayNym.getNymName(childWallet); + if(payNymMap.get(externalPaymentCode) == null || (walletNymName != null && !walletNymName.equals(payNymMap.get(externalPaymentCode).nymName()))) { + payNymMap.put(externalPaymentCode, PayNym.fromWallet(childWallet)); } } } - return new ArrayList<>(existingPayNyms.values()); + return new ArrayList<>(payNymMap.values()); } private void addWalletIfNotificationTransactionPresent(List following) {