allow any linked paynym contact to be renamed

This commit is contained in:
Craig Raw 2022-03-17 13:11:45 +02:00
parent 281fad5970
commit c02da607e7
3 changed files with 22 additions and 14 deletions

View file

@ -89,7 +89,7 @@ public class PayNymCell extends ListCell<PayNym> {
setText(null);
setGraphic(pane);
if(payNymController != null && payNym.nymId() == null) {
if(payNymController != null && payNymController.isLinked(payNym)) {
setContextMenu(new PayNymCellContextMenu(payNym));
} else {
setContextMenu(null);

View file

@ -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;
}
}

View file

@ -317,25 +317,24 @@ public class PayNymController {
followingPayNyms.addAll(walletPayNym.following());
}
Map<PaymentCode, PayNym> followingPayNymMap = followingPayNyms.stream().collect(Collectors.toMap(PayNym::paymentCode, Function.identity()));
followingPayNyms.addAll(getExistingWalletPayNyms(followingPayNymMap));
followingList.setItems(FXCollections.observableList(followingPayNyms));
Map<PaymentCode, PayNym> payNymMap = followingPayNyms.stream().collect(Collectors.toMap(PayNym::paymentCode, Function.identity(), (u, v) -> u, LinkedHashMap::new));
followingList.setItems(FXCollections.observableList(getExistingWalletPayNyms(payNymMap)));
}
private List<PayNym> getExistingWalletPayNyms(Map<PaymentCode, PayNym> followingPayNymMap) {
Map<PaymentCode, PayNym> existingPayNyms = new LinkedHashMap<>();
private List<PayNym> getExistingWalletPayNyms(Map<PaymentCode, PayNym> payNymMap) {
List<Wallet> 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<PayNym> following) {