mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
allow any linked paynym contact to be renamed
This commit is contained in:
parent
281fad5970
commit
c02da607e7
3 changed files with 22 additions and 14 deletions
|
@ -89,7 +89,7 @@ public class PayNymCell extends ListCell<PayNym> {
|
||||||
setText(null);
|
setText(null);
|
||||||
setGraphic(pane);
|
setGraphic(pane);
|
||||||
|
|
||||||
if(payNymController != null && payNym.nymId() == null) {
|
if(payNymController != null && payNymController.isLinked(payNym)) {
|
||||||
setContextMenu(new PayNymCellContextMenu(payNym));
|
setContextMenu(new PayNymCellContextMenu(payNym));
|
||||||
} else {
|
} else {
|
||||||
setContextMenu(null);
|
setContextMenu(null);
|
||||||
|
|
|
@ -84,14 +84,23 @@ public class PayNym {
|
||||||
|
|
||||||
PaymentCode externalPaymentCode = bip47Wallet.getKeystores().get(0).getExternalPaymentCode();
|
PaymentCode externalPaymentCode = bip47Wallet.getKeystores().get(0).getExternalPaymentCode();
|
||||||
String nymName = externalPaymentCode.toAbbreviatedString();
|
String nymName = externalPaymentCode.toAbbreviatedString();
|
||||||
if(bip47Wallet.getLabel() != null) {
|
String walletNymName = getNymName(bip47Wallet);
|
||||||
String suffix = " " + bip47Wallet.getScriptType().getName();
|
if(walletNymName != null) {
|
||||||
if(bip47Wallet.getLabel().endsWith(suffix)) {
|
nymName = walletNymName;
|
||||||
nymName = bip47Wallet.getLabel().substring(0, bip47Wallet.getLabel().length() - suffix.length());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean segwit = bip47Wallet.getScriptType() != ScriptType.P2PKH;
|
boolean segwit = bip47Wallet.getScriptType() != ScriptType.P2PKH;
|
||||||
return new PayNym(externalPaymentCode, null, nymName, segwit, Collections.emptyList(), Collections.emptyList());
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,25 +317,24 @@ public class PayNymController {
|
||||||
followingPayNyms.addAll(walletPayNym.following());
|
followingPayNyms.addAll(walletPayNym.following());
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<PaymentCode, PayNym> followingPayNymMap = followingPayNyms.stream().collect(Collectors.toMap(PayNym::paymentCode, Function.identity()));
|
Map<PaymentCode, PayNym> payNymMap = followingPayNyms.stream().collect(Collectors.toMap(PayNym::paymentCode, Function.identity(), (u, v) -> u, LinkedHashMap::new));
|
||||||
followingPayNyms.addAll(getExistingWalletPayNyms(followingPayNymMap));
|
followingList.setItems(FXCollections.observableList(getExistingWalletPayNyms(payNymMap)));
|
||||||
followingList.setItems(FXCollections.observableList(followingPayNyms));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PayNym> getExistingWalletPayNyms(Map<PaymentCode, PayNym> followingPayNymMap) {
|
private List<PayNym> getExistingWalletPayNyms(Map<PaymentCode, PayNym> payNymMap) {
|
||||||
Map<PaymentCode, PayNym> existingPayNyms = new LinkedHashMap<>();
|
|
||||||
List<Wallet> childWallets = new ArrayList<>(getMasterWallet().getChildWallets());
|
List<Wallet> childWallets = new ArrayList<>(getMasterWallet().getChildWallets());
|
||||||
childWallets.sort(Comparator.comparingInt(o -> -o.getScriptType().ordinal()));
|
childWallets.sort(Comparator.comparingInt(o -> -o.getScriptType().ordinal()));
|
||||||
for(Wallet childWallet : childWallets) {
|
for(Wallet childWallet : childWallets) {
|
||||||
if(childWallet.isBip47()) {
|
if(childWallet.isBip47()) {
|
||||||
PaymentCode externalPaymentCode = childWallet.getKeystores().get(0).getExternalPaymentCode();
|
PaymentCode externalPaymentCode = childWallet.getKeystores().get(0).getExternalPaymentCode();
|
||||||
if(!existingPayNyms.containsKey(externalPaymentCode) && !followingPayNymMap.containsKey(externalPaymentCode)) {
|
String walletNymName = PayNym.getNymName(childWallet);
|
||||||
existingPayNyms.put(externalPaymentCode, PayNym.fromWallet(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) {
|
private void addWalletIfNotificationTransactionPresent(List<PayNym> following) {
|
||||||
|
|
Loading…
Reference in a new issue