mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
add paynym contact from followers list
This commit is contained in:
parent
c02da607e7
commit
5324e5fcc2
2 changed files with 21 additions and 6 deletions
|
@ -17,14 +17,16 @@ import java.util.Optional;
|
||||||
|
|
||||||
public class PayNymCell extends ListCell<PayNym> {
|
public class PayNymCell extends ListCell<PayNym> {
|
||||||
private final PayNymController payNymController;
|
private final PayNymController payNymController;
|
||||||
|
private final boolean contact;
|
||||||
|
|
||||||
public PayNymCell(PayNymController payNymController) {
|
public PayNymCell(PayNymController payNymController, boolean contact) {
|
||||||
super();
|
super();
|
||||||
setAlignment(Pos.CENTER_LEFT);
|
setAlignment(Pos.CENTER_LEFT);
|
||||||
setContentDisplay(ContentDisplay.LEFT);
|
setContentDisplay(ContentDisplay.LEFT);
|
||||||
getStyleClass().add("paynym-cell");
|
getStyleClass().add("paynym-cell");
|
||||||
setPrefHeight(50);
|
setPrefHeight(50);
|
||||||
this.payNymController = payNymController;
|
this.payNymController = payNymController;
|
||||||
|
this.contact = contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +54,7 @@ public class PayNymCell extends ListCell<PayNym> {
|
||||||
labelBox.getChildren().add(label);
|
labelBox.getChildren().add(label);
|
||||||
pane.setLeft(labelBox);
|
pane.setLeft(labelBox);
|
||||||
|
|
||||||
if(getListView().getUserData() == Boolean.TRUE) {
|
if(getListView().getUserData() == Boolean.TRUE || (!contact && payNymController != null && payNymController.isFollowing(payNym) == Boolean.FALSE)) {
|
||||||
HBox hBox = new HBox();
|
HBox hBox = new HBox();
|
||||||
hBox.setAlignment(Pos.CENTER);
|
hBox.setAlignment(Pos.CENTER);
|
||||||
Button button = new Button("Add Contact");
|
Button button = new Button("Add Contact");
|
||||||
|
@ -62,7 +64,7 @@ public class PayNymCell extends ListCell<PayNym> {
|
||||||
button.setDisable(true);
|
button.setDisable(true);
|
||||||
payNymController.followPayNym(payNym.paymentCode());
|
payNymController.followPayNym(payNym.paymentCode());
|
||||||
});
|
});
|
||||||
} else if(payNymController != null) {
|
} else if(contact && payNymController != null) {
|
||||||
HBox hBox = new HBox();
|
HBox hBox = new HBox();
|
||||||
hBox.setAlignment(Pos.CENTER);
|
hBox.setAlignment(Pos.CENTER);
|
||||||
pane.setRight(hBox);
|
pane.setRight(hBox);
|
||||||
|
@ -89,7 +91,7 @@ public class PayNymCell extends ListCell<PayNym> {
|
||||||
setText(null);
|
setText(null);
|
||||||
setGraphic(pane);
|
setGraphic(pane);
|
||||||
|
|
||||||
if(payNymController != null && payNymController.isLinked(payNym)) {
|
if(contact && payNymController != null && payNymController.isLinked(payNym)) {
|
||||||
setContextMenu(new PayNymCellContextMenu(payNym));
|
setContextMenu(new PayNymCellContextMenu(payNym));
|
||||||
} else {
|
} else {
|
||||||
setContextMenu(null);
|
setContextMenu(null);
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class PayNymController {
|
||||||
findPayNym.setVisible(false);
|
findPayNym.setVisible(false);
|
||||||
|
|
||||||
followingList.setCellFactory(param -> {
|
followingList.setCellFactory(param -> {
|
||||||
return new PayNymCell(this);
|
return new PayNymCell(this, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
followingList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, payNym) -> {
|
followingList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, payNym) -> {
|
||||||
|
@ -159,7 +159,7 @@ public class PayNymController {
|
||||||
});
|
});
|
||||||
|
|
||||||
followersList.setCellFactory(param -> {
|
followersList.setCellFactory(param -> {
|
||||||
return new PayNymCell(null);
|
return new PayNymCell(this, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
followersList.setSelectionModel(new NoSelectionModel<>());
|
followersList.setSelectionModel(new NoSelectionModel<>());
|
||||||
|
@ -282,30 +282,43 @@ public class PayNymController {
|
||||||
public void followPayNym(PaymentCode contact) {
|
public void followPayNym(PaymentCode contact) {
|
||||||
PayNymService payNymService = AppServices.getPayNymService();
|
PayNymService payNymService = AppServices.getPayNymService();
|
||||||
Wallet masterWallet = getMasterWallet();
|
Wallet masterWallet = getMasterWallet();
|
||||||
|
retrievePayNymProgress.setVisible(true);
|
||||||
payNymService.getAuthToken(masterWallet, new HashMap<>()).subscribe(authToken -> {
|
payNymService.getAuthToken(masterWallet, new HashMap<>()).subscribe(authToken -> {
|
||||||
String signature = payNymService.getSignature(masterWallet, authToken);
|
String signature = payNymService.getSignature(masterWallet, authToken);
|
||||||
payNymService.followPaymentCode(contact, authToken, signature).subscribe(followMap -> {
|
payNymService.followPaymentCode(contact, authToken, signature).subscribe(followMap -> {
|
||||||
refresh();
|
refresh();
|
||||||
}, error -> {
|
}, error -> {
|
||||||
|
retrievePayNymProgress.setVisible(false);
|
||||||
log.error("Could not follow payment code", error);
|
log.error("Could not follow payment code", error);
|
||||||
Optional<ButtonType> optResponse = showErrorDialog("Error retrieving PayNym", "Could not follow payment code. Try again?", ButtonType.CANCEL, ButtonType.OK);
|
Optional<ButtonType> optResponse = showErrorDialog("Error retrieving PayNym", "Could not follow payment code. Try again?", ButtonType.CANCEL, ButtonType.OK);
|
||||||
if(optResponse.isPresent() && optResponse.get().equals(ButtonType.OK)) {
|
if(optResponse.isPresent() && optResponse.get().equals(ButtonType.OK)) {
|
||||||
followPayNym(contact);
|
followPayNym(contact);
|
||||||
} else {
|
} else {
|
||||||
followingList.refresh();
|
followingList.refresh();
|
||||||
|
followersList.refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, error -> {
|
}, error -> {
|
||||||
|
retrievePayNymProgress.setVisible(false);
|
||||||
log.error("Could not follow payment code", error);
|
log.error("Could not follow payment code", error);
|
||||||
Optional<ButtonType> optResponse = showErrorDialog("Error retrieving PayNym", "Could not follow payment code. Try again?", ButtonType.CANCEL, ButtonType.OK);
|
Optional<ButtonType> optResponse = showErrorDialog("Error retrieving PayNym", "Could not follow payment code. Try again?", ButtonType.CANCEL, ButtonType.OK);
|
||||||
if(optResponse.isPresent() && optResponse.get().equals(ButtonType.OK)) {
|
if(optResponse.isPresent() && optResponse.get().equals(ButtonType.OK)) {
|
||||||
followPayNym(contact);
|
followPayNym(contact);
|
||||||
} else {
|
} else {
|
||||||
followingList.refresh();
|
followingList.refresh();
|
||||||
|
followersList.refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isFollowing(PayNym payNym) {
|
||||||
|
if(followingList.getItems() != null) {
|
||||||
|
return followingList.getItems().stream().anyMatch(following -> payNym.paymentCode().equals(following.paymentCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isLinked(PayNym payNym) {
|
public boolean isLinked(PayNym payNym) {
|
||||||
PaymentCode externalPaymentCode = payNym.paymentCode();
|
PaymentCode externalPaymentCode = payNym.paymentCode();
|
||||||
return getMasterWallet().getChildWallet(externalPaymentCode, payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH) != null;
|
return getMasterWallet().getChildWallet(externalPaymentCode, payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH) != null;
|
||||||
|
|
Loading…
Reference in a new issue