Skip to content

Commit

Permalink
Show banned role tab in red and tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikJannsen committed Mar 6, 2025
1 parent 84d4ca8 commit 9a564c8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ protected Optional<? extends Controller> createController(NavigationTarget navig
private void onBondedRolesChanged() {
UIThread.run(() -> {
UserIdentity selectedUserIdentity = userIdentityService.getSelectedUserIdentity();

model.getBannedAuthorizedBondedRoles().clear();
model.getBannedAuthorizedBondedRoles().addAll(authorizedBondedRolesService.getBannedAuthorizedBondedRoleStream()
.filter(bondedRole -> selectedUserIdentity.getUserProfile().getId().equals(bondedRole.getProfileId()))
.map(AuthorizedBondedRole::getBondedRoleType)
.collect(Collectors.toSet()));
// If we got banned we still want to show the admin UI
model.getAuthorizedBondedRoles().setAll(authorizedBondedRolesService.getAuthorizedBondedRoleStream(true)
.filter(bondedRole -> selectedUserIdentity.getUserProfile().getId().equals(bondedRole.getProfileId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
import javafx.collections.ObservableList;
import lombok.Getter;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Getter
public class AuthorizedRoleModel extends ContentTabModel {
private final List<BondedRoleType> bondedRoleTypes;
private final ObservableList<BondedRoleType> authorizedBondedRoles = FXCollections.observableArrayList();
private final Set<BondedRoleType> bannedAuthorizedBondedRoles = new HashSet<>();

public AuthorizedRoleModel(List<BondedRoleType> bondedRoleTypes) {
this.bondedRoleTypes = bondedRoleTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
import bisq.bisq_easy.NavigationTarget;
import bisq.bonded_roles.BondedRoleType;
import bisq.desktop.common.view.*;
import bisq.desktop.components.controls.BisqTooltip;
import bisq.desktop.main.content.ContentTabView;
import bisq.desktop.main.content.authorized_role.mediator.MediatorView;
import bisq.i18n.Res;
import javafx.collections.ListChangeListener;
import javafx.scene.Parent;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;

@Slf4j
public class AuthorizedRoleView extends ContentTabView<AuthorizedRoleModel, AuthorizedRoleController> {
private final Map<BondedRoleType, TabButton> tabButtonByBondedRoleType = new HashMap<>();
private final ListChangeListener<BondedRoleType> listener;
@Nullable
private BisqTooltip isBannedTooltip;

public AuthorizedRoleView(AuthorizedRoleModel model, AuthorizedRoleController controller) {
super(model, controller);
Expand Down Expand Up @@ -74,9 +78,21 @@ protected void onViewDetached() {
private void updateVisibility() {
tabButtonByBondedRoleType.forEach((bondedRoleType, tabButton) -> {
boolean isVisible = model.getAuthorizedBondedRoles().contains(bondedRoleType);
boolean isBanned = model.getBannedAuthorizedBondedRoles().contains(bondedRoleType);
tabButton.setVisible(isVisible);
tabButton.setManaged(isVisible);

if (isBanned) {
tabButton.getLabel().getStyleClass().add("bisq-text-error");
if (isBannedTooltip == null) {
isBannedTooltip = new BisqTooltip(Res.get("authorizedRole.roleInfo.isBanned"));
}
BisqTooltip.install(tabButton, isBannedTooltip);
} else if (isBannedTooltip != null) {
tabButton.getLabel().getStyleClass().remove("bisq-text-error");
BisqTooltip.uninstall(tabButton, isBannedTooltip);
}

if (isVisible) {
model.getSelectedTabButton().set(tabButton);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ public Stream<AuthorizedBondedRole> getAuthorizedBondedRoleStream(boolean ignore
.map(BondedRole::getAuthorizedBondedRole);
}

public Stream<AuthorizedBondedRole> getBannedAuthorizedBondedRoleStream() {
return bondedRoles.stream()
.filter(BondedRole::isBanned)
.map(BondedRole::getAuthorizedBondedRole);
}

public boolean hasAuthorizedPubKey(AuthorizedData authorizedData, BondedRoleType authorizingBondedRoleType) {
AuthorizedDistributedData data = authorizedData.getAuthorizedDistributedData();
if (data.staticPublicKeysProvided()) {
Expand Down

0 comments on commit 9a564c8

Please sign in to comment.