Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sorting on bonded roles view #6002

Merged
merged 1 commit into from Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,59 @@
import bisq.core.dao.DaoFacade;
import bisq.core.dao.governance.bond.BondState;
import bisq.core.dao.governance.bond.role.BondedRole;
import bisq.core.dao.state.model.governance.BondedRoleType;
import bisq.core.dao.state.model.governance.Role;
import bisq.core.locale.Res;

import java.util.Date;

import lombok.Value;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Value
class RolesListItem {
private final DaoFacade daoFacade;
private final BondedRole bondedRole;
private final Role role;
private final String buttonText;
private final boolean isButtonVisible;
private final BondState bondState;
private final String bondStateString;
private final String lockupTxId;
private final Date lockupDate;

RolesListItem(BondedRole bondedRole,
DaoFacade daoFacade) {
RolesListItem(BondedRole bondedRole, DaoFacade daoFacade) {
this.daoFacade = daoFacade;
this.bondedRole = bondedRole;
}

public String getLockupTxId() {
return this.bondedRole.getLockupTxId();
}

public Role getRole() {
return this.bondedRole.getBondedAsset();
}

public String getName() {
return this.getRole().getName();
}

public String getLink() {
return this.getRole().getLink();
}

role = bondedRole.getBondedAsset();
boolean isMyRole = daoFacade.isMyRole(role);
bondState = bondedRole.getBondState();
lockupTxId = bondedRole.getLockupTxId();
lockupDate = new Date(bondedRole.getLockupDate());
bondStateString = Res.get("dao.bond.bondState." + bondedRole.getBondState().name());
public BondedRoleType getType() {
return this.getRole().getBondedRoleType();
}

boolean showLockup = bondedRole.getBondState() == BondState.READY_FOR_LOCKUP;
boolean showRevoke = bondedRole.getBondState() == BondState.LOCKUP_TX_CONFIRMED;
if (showLockup) {
buttonText = Res.get("dao.bond.table.button.lockup");
} else if (showRevoke) {
buttonText = Res.get("dao.bond.table.button.revoke");
} else {
buttonText = "";
}
public String getTypeAsString() {
return this.getRole().getBondedRoleType().getDisplayString();
}

public long getLockupDate() {
return this.bondedRole.getLockupDate();
}

public String getBondStateAsString() {
return Res.get("dao.bond.bondState." + bondedRole.getBondState().name());
}

public boolean isLockupButtonVisible() {
return this.daoFacade.isMyRole(this.getRole()) && (this.bondedRole.getBondState() == BondState.READY_FOR_LOCKUP);
}

isButtonVisible = isMyRole && (showLockup || showRevoke);
public boolean isRevokeButtonVisible() {
return this.daoFacade.isMyRole(this.getRole()) && (this.bondedRole.getBondState() == BondState.LOCKUP_TX_CONFIRMED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import bisq.desktop.util.GUIUtil;

import bisq.core.dao.DaoFacade;
import bisq.core.dao.governance.bond.BondState;
import bisq.core.dao.governance.bond.role.BondedRole;
import bisq.core.dao.state.model.governance.BondedRoleType;
import bisq.core.dao.state.model.governance.RoleProposal;
import bisq.core.locale.Res;
import bisq.core.user.Preferences;
import bisq.core.util.coin.BsqFormatter;
Expand All @@ -57,7 +54,6 @@
import javafx.util.Callback;

import java.util.Comparator;
import java.util.Optional;
import java.util.stream.Collectors;

@FxmlView
Expand Down Expand Up @@ -133,47 +129,45 @@ private void updateList() {
///////////////////////////////////////////////////////////////////////////////////////////

private void createColumns() {
TableColumn<RolesListItem, RolesListItem> column;

column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.name"));
column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setMinWidth(80);
column.getStyleClass().add("first-column");
column.setCellFactory(
TableColumn<RolesListItem, RolesListItem> nameColumn = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.name"));
nameColumn.setComparator(Comparator.comparing(RolesListItem::getName, String.CASE_INSENSITIVE_ORDER));
nameColumn.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
nameColumn.setMinWidth(80);
nameColumn.getStyleClass().add("first-column");
nameColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem,
RolesListItem> column) {
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem, RolesListItem> column) {
return new TableCell<>() {
@Override
public void updateItem(final RolesListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
setText(item.getRole().getName());
setText(item.getName());
} else
setText("");
}
};
}
});
tableView.getColumns().add(column);
tableView.getColumns().add(nameColumn);

column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.link"));
column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setMinWidth(60);
column.setCellFactory(
TableColumn<RolesListItem, RolesListItem> linkColumn = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.link"));
linkColumn.setComparator(Comparator.comparing(RolesListItem::getLink));
linkColumn.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
linkColumn.setMinWidth(60);
linkColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem,
RolesListItem> column) {
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem, RolesListItem> column) {
return new TableCell<>() {
private HyperlinkWithIcon hyperlinkWithIcon;

@Override
public void updateItem(final RolesListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
String link = item.getRole().getLink();
String link = item.getLink();
hyperlinkWithIcon = new ExternalHyperlink(link);
hyperlinkWithIcon.setOnAction(event -> GUIUtil.openWebPage(link));
hyperlinkWithIcon.setTooltip(new Tooltip(Res.get("shared.openURL", link)));
Expand All @@ -187,32 +181,31 @@ public void updateItem(final RolesListItem item, boolean empty) {
};
}
});
tableView.getColumns().add(column);
tableView.getColumns().add(linkColumn);

column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.bondType"));
column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setMinWidth(80);
column.setCellFactory(
TableColumn<RolesListItem, RolesListItem> bondTypeColumn = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.bondType"));
bondTypeColumn.setComparator(Comparator.comparing(RolesListItem::getTypeAsString));
bondTypeColumn.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
bondTypeColumn.setMinWidth(80);
bondTypeColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem,
RolesListItem> column) {
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem, RolesListItem> column) {
return new TableCell<>() {
private Hyperlink hyperlink;

@Override
public void updateItem(final RolesListItem item, boolean empty) {
super.updateItem(item, empty);

if (item != null && !empty) {
BondedRoleType bondedRoleType = item.getRole().getBondedRoleType();
String type = bondedRoleType.getDisplayString();
hyperlink = new Hyperlink(type);
hyperlink.setOnAction(event -> {
Optional<RoleProposal> roleProposal = bondingViewUtils.getAcceptedBondedRoleProposal(item.getRole());
new RoleDetailsWindow(bondedRoleType, roleProposal, daoFacade, bsqFormatter).show();
});
hyperlink.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails", type)));
hyperlink = new Hyperlink(item.getTypeAsString());
hyperlink.setOnAction(event -> new RoleDetailsWindow(
item.getType(),
bondingViewUtils.getAcceptedBondedRoleProposal(item.getRole()),
daoFacade,
bsqFormatter
).show());
hyperlink.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails", item.getTypeAsString())));
setGraphic(hyperlink);
} else {
setGraphic(null);
Expand All @@ -223,16 +216,16 @@ public void updateItem(final RolesListItem item, boolean empty) {
};
}
});
tableView.getColumns().add(column);
tableView.getColumns().add(bondTypeColumn);

column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.lockupTxId"));
column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setMinWidth(80);
column.setCellFactory(
TableColumn<RolesListItem, RolesListItem> lockupTxIdColumn = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.lockupTxId"));
lockupTxIdColumn.setComparator(Comparator.comparing(RolesListItem::getLockupTxId, Comparator.nullsFirst(Comparator.naturalOrder())));
lockupTxIdColumn.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
lockupTxIdColumn.setMinWidth(80);
lockupTxIdColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem,
RolesListItem> column) {
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem, RolesListItem> column) {
return new TableCell<>() {
private HyperlinkWithIcon hyperlinkWithIcon;
private Label label;
Expand All @@ -242,11 +235,11 @@ public void updateItem(final RolesListItem item, boolean empty) {
super.updateItem(item, empty);

if (item != null && !empty) {
String transactionId = item.getBondedRole().getLockupTxId();
if (transactionId != null) {
hyperlinkWithIcon = new ExternalHyperlink(transactionId);
hyperlinkWithIcon.setOnAction(event -> GUIUtil.openTxInBsqBlockExplorer(transactionId, preferences));
hyperlinkWithIcon.setTooltip(new Tooltip(Res.get("tooltip.openBlockchainForTx", transactionId)));
String lockupTxId = item.getLockupTxId();
if (lockupTxId != null) {
hyperlinkWithIcon = new ExternalHyperlink(lockupTxId);
hyperlinkWithIcon.setOnAction(event -> GUIUtil.openTxInBsqBlockExplorer(lockupTxId, preferences));
hyperlinkWithIcon.setTooltip(new Tooltip(Res.get("tooltip.openBlockchainForTx", lockupTxId)));
setGraphic(hyperlinkWithIcon);
} else {
label = new Label("-");
Expand All @@ -263,58 +256,58 @@ public void updateItem(final RolesListItem item, boolean empty) {
};
}
});
tableView.getColumns().add(column);
tableView.getColumns().add(lockupTxIdColumn);

column = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.bondState"));
column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setMinWidth(120);
column.setCellFactory(
TableColumn<RolesListItem, RolesListItem> bondStateColumn = new AutoTooltipTableColumn<>(Res.get("dao.bond.table.column.bondState"));
bondStateColumn.setComparator(Comparator.comparing(RolesListItem::getBondStateAsString));
bondStateColumn.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
bondStateColumn.setMinWidth(120);
bondStateColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem,
RolesListItem> column) {
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem, RolesListItem> column) {
return new TableCell<>() {
@Override
public void updateItem(final RolesListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
setText(item.getBondStateString());
setText(item.getBondStateAsString());
} else
setText("");
}
};
}
});
tableView.getColumns().add(column);

column = new TableColumn<>();
column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
column.setMinWidth(80);
column.getStyleClass().add("last-column");
column.setCellFactory(
tableView.getColumns().add(bondStateColumn);

TableColumn<RolesListItem, RolesListItem> actionColumn = new TableColumn<>();
actionColumn.setComparator(Comparator.comparing(RolesListItem::isLockupButtonVisible).thenComparing(RolesListItem::isRevokeButtonVisible));
actionColumn.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
actionColumn.setMinWidth(80);
actionColumn.getStyleClass().add("last-column");
actionColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem,
RolesListItem> column) {
public TableCell<RolesListItem, RolesListItem> call(TableColumn<RolesListItem, RolesListItem> column) {
return new TableCell<>() {
AutoTooltipButton button;

@Override
public void updateItem(final RolesListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty && item.isButtonVisible()) {
if (item != null && !empty && (item.isLockupButtonVisible() || item.isRevokeButtonVisible())) {
if (button == null) {
button = new AutoTooltipButton(item.getButtonText());
button = new AutoTooltipButton(
item.isLockupButtonVisible()
? Res.get("dao.bond.table.button.lockup")
: Res.get("dao.bond.table.button.revoke")
);
button.setMinWidth(70);
button.setOnAction(e -> {
if (item.getBondState() == BondState.READY_FOR_LOCKUP) {
bondingViewUtils.lockupBondForBondedRole(item.getRole(),
txId -> {
});
} else if (item.getBondState() == BondState.LOCKUP_TX_CONFIRMED) {
bondingViewUtils.unLock(item.getLockupTxId(),
txId -> {
});
if (item.isLockupButtonVisible() ) {
bondingViewUtils.lockupBondForBondedRole(item.getRole(), txId -> {});
} else if (item.isRevokeButtonVisible()) {
bondingViewUtils.unLock(item.getLockupTxId(), txId -> {});
}
});
setGraphic(button);
Expand All @@ -330,6 +323,6 @@ public void updateItem(final RolesListItem item, boolean empty) {
};
}
});
tableView.getColumns().add(column);
tableView.getColumns().add(actionColumn);
}
}