Skip to content

Commit

Permalink
Merge pull request #2867 from HenrikJannsen/remove-min-required-reput…
Browse files Browse the repository at this point in the history
…ation-score-field

Remove min required reputation score field
  • Loading branch information
HenrikJannsen authored Sep 29, 2024
2 parents 14afccb + 1fd747d commit 916b656
Show file tree
Hide file tree
Showing 54 changed files with 103 additions and 578 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import bisq.bonded_roles.security_manager.alert.AuthorizedAlertData;
import bisq.bonded_roles.security_manager.difficulty_adjustment.AuthorizedDifficultyAdjustmentData;
import bisq.bonded_roles.security_manager.difficulty_adjustment.DifficultyAdjustmentService;
import bisq.bonded_roles.security_manager.min_reputation_score.AuthorizedMinRequiredReputationScoreData;
import bisq.bonded_roles.security_manager.min_reputation_score.MinRequiredReputationScoreService;
import bisq.common.observable.Pin;
import bisq.common.util.StringUtils;
import bisq.desktop.ServiceProvider;
Expand All @@ -42,7 +40,6 @@
import bisq.user.identity.UserIdentityService;
import bisq.user.profile.UserProfile;
import bisq.user.profile.UserProfileService;
import bisq.user.reputation.ReputationScore;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.fxmisc.easybind.EasyBind;
Expand All @@ -61,19 +58,16 @@ public class SecurityManagerController implements Controller {
private final UserProfileService userProfileService;
private final AuthorizedBondedRolesService authorizedBondedRolesService;
private final DifficultyAdjustmentService difficultyAdjustmentService;
private final MinRequiredReputationScoreService minRequiredReputationScoreService;
private Pin userIdentityPin, alertsPin, bondedRoleSetPin, difficultyAdjustmentListItemsPin,
minRequiredReputationScoreListItemsPin;
private Pin userIdentityPin, alertsPin, bondedRoleSetPin, difficultyAdjustmentListItemsPin;
private Subscription messagePin, requireVersionForTradingPin, minVersionPin, selectedBondedRolePin,
difficultyAdjustmentPin, minRequiredReputationScorePin;
difficultyAdjustmentPin;

public SecurityManagerController(ServiceProvider serviceProvider) {
securityManagerService = serviceProvider.getSupportService().getSecurityManagerService();
userIdentityService = serviceProvider.getUserService().getUserIdentityService();
userProfileService = serviceProvider.getUserService().getUserProfileService();
alertService = serviceProvider.getBondedRolesService().getAlertService();
difficultyAdjustmentService = serviceProvider.getBondedRolesService().getDifficultyAdjustmentService();
minRequiredReputationScoreService = serviceProvider.getBondedRolesService().getMinRequiredReputationScoreService();
authorizedBondedRolesService = serviceProvider.getBondedRolesService().getAuthorizedBondedRolesService();
RoleInfo roleInfo = new RoleInfo(serviceProvider);
model = new SecurityManagerModel();
Expand Down Expand Up @@ -107,16 +101,6 @@ public void onActivate() {
difficultyAdjustmentPin = EasyBind.subscribe(model.getDifficultyAdjustmentFactor(), difficultyAdjustmentFactor ->
model.getDifficultyAdjustmentFactorButtonDisabled().set(difficultyAdjustmentFactor == null ||
!isValidDifficultyAdjustmentFactor(difficultyAdjustmentFactor.doubleValue())));

minRequiredReputationScoreListItemsPin = FxBindings.<AuthorizedMinRequiredReputationScoreData,
SecurityManagerView.MinRequiredReputationScoreListItem>bind(model.getMinRequiredReputationScoreListItems())
.map(SecurityManagerView.MinRequiredReputationScoreListItem::new)
.to(minRequiredReputationScoreService.getAuthorizedMinRequiredReputationScoreDataSet());

model.getMinRequiredReputationScore().set(minRequiredReputationScoreService.getMostRecentValueOrDefault().get());
minRequiredReputationScorePin = EasyBind.subscribe(model.getMinRequiredReputationScore(), minRequiredReputationScore ->
model.getMinRequiredReputationScoreButtonDisabled().set(minRequiredReputationScore == null ||
!isValidMinRequiredRequiredReputationScore(minRequiredReputationScore.doubleValue())));
}

@Override
Expand All @@ -125,13 +109,11 @@ public void onDeactivate() {
bondedRoleSetPin.unbind();
alertsPin.unbind();
difficultyAdjustmentListItemsPin.unbind();
minRequiredReputationScoreListItemsPin.unbind();
messagePin.unsubscribe();
requireVersionForTradingPin.unsubscribe();
minVersionPin.unsubscribe();
selectedBondedRolePin.unsubscribe();
difficultyAdjustmentPin.unsubscribe();
minRequiredReputationScorePin.unsubscribe();
}

void onSelectAlertType(AlertType alertType) {
Expand Down Expand Up @@ -220,48 +202,20 @@ void onPublishDifficultyAdjustmentFactor() {
}
}

void onPublishMinRequiredReputationScore() {
long minRequiredReputationScore = model.getMinRequiredReputationScore().get();
if (isValidMinRequiredRequiredReputationScore(minRequiredReputationScore)) {
securityManagerService.publishMinRequiredReputationScore(minRequiredReputationScore)
.whenComplete((result, throwable) -> UIThread.run(() -> {
if (throwable != null) {
new Popup().error(throwable).show();
} else {
model.getMinRequiredReputationScore().set(minRequiredReputationScoreService.getMostRecentValueOrDefault().get());
}
}));
}
}

private static boolean isValidDifficultyAdjustmentFactor(double difficultyAdjustmentFactor) {
return difficultyAdjustmentFactor >= 0 && difficultyAdjustmentFactor <= NetworkLoad.MAX_DIFFICULTY_ADJUSTMENT;
}

private static boolean isValidMinRequiredRequiredReputationScore(double minRequiredReputationScore) {
return minRequiredReputationScore >= 0 && minRequiredReputationScore <= ReputationScore.MAX_VALUE;
}

boolean isRemoveDifficultyAdjustmentButtonVisible(AuthorizedDifficultyAdjustmentData data) {
return userIdentityService.getSelectedUserIdentity().getId().equals(data.getSecurityManagerProfileId());
}

boolean isRemoveMinRequiredReputationScoreButtonVisible(AuthorizedMinRequiredReputationScoreData data) {
return userIdentityService.getSelectedUserIdentity().getId().equals(data.getSecurityManagerProfileId());
}

void onRemoveDifficultyAdjustmentListItem(SecurityManagerView.DifficultyAdjustmentListItem item) {
UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity();
securityManagerService.removeDifficultyAdjustment(item.getData(), userIdentity.getNetworkIdWithKeyPair().getKeyPair());
model.getDifficultyAdjustmentFactor().set(difficultyAdjustmentService.getMostRecentValueOrDefault().get());
}

void onRemoveMinRequiredReputationScoreListItem(SecurityManagerView.MinRequiredReputationScoreListItem item) {
UserIdentity userIdentity = userIdentityService.getSelectedUserIdentity();
securityManagerService.removeMinRequiredReputationScore(item.getData(), userIdentity.getNetworkIdWithKeyPair().getKeyPair());
model.getMinRequiredReputationScore().set(minRequiredReputationScoreService.getMostRecentValueOrDefault().get());
}

private void applySelectAlertType(AlertType alertType) {
model.getSelectedAlertType().set(alertType);
switch (alertType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import bisq.desktop.main.content.authorized_role.security_manager.SecurityManagerView.AlertListItem;
import bisq.desktop.main.content.authorized_role.security_manager.SecurityManagerView.BondedRoleListItem;
import bisq.desktop.main.content.authorized_role.security_manager.SecurityManagerView.DifficultyAdjustmentListItem;
import bisq.desktop.main.content.authorized_role.security_manager.SecurityManagerView.MinRequiredReputationScoreListItem;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand All @@ -34,11 +33,8 @@
@Getter
public class SecurityManagerModel implements Model {
private final DoubleProperty difficultyAdjustmentFactor = new SimpleDoubleProperty();
private final LongProperty minRequiredReputationScore = new SimpleLongProperty();
private final BooleanProperty difficultyAdjustmentFactorButtonDisabled = new SimpleBooleanProperty();
private final BooleanProperty minRequiredReputationScoreButtonDisabled = new SimpleBooleanProperty();
private final ObservableList<DifficultyAdjustmentListItem> difficultyAdjustmentListItems = FXCollections.observableArrayList();
private final ObservableList<MinRequiredReputationScoreListItem> minRequiredReputationScoreListItems = FXCollections.observableArrayList();

private final ObjectProperty<AlertType> selectedAlertType = new SimpleObjectProperty<>();
private final ObservableList<AlertType> alertTypes = FXCollections.observableArrayList();
Expand Down
Loading

0 comments on commit 916b656

Please sign in to comment.