Skip to content

Commit

Permalink
[1.2.0] Format maker fee for BTC and BSQ correctly (#3498)
Browse files Browse the repository at this point in the history
* Format maker fee for BTC and BSQ correctly

* Update tests
  • Loading branch information
ripcurlx authored Oct 28, 2019
1 parent 384766b commit 66d3f91
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ private void onRemoveOpenOffer(Offer offer) {
if (model.isBootstrappedOrShowPopup()) {
String key = "RemoveOfferWarning";
if (DontShowAgainLookup.showAgain(key)) {
new Popup<>().warning(Res.get("popup.warning.removeOffer", model.formatter.formatCoinWithCode(offer.getMakerFee())))
new Popup<>().warning(Res.get("popup.warning.removeOffer", model.getMakerFeeAsString(offer)))
.actionButtonText(Res.get("shared.removeOffer"))
.onAction(() -> doRemoveOffer(offer))
.closeButtonText(Res.get("shared.dontRemoveOffer"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.BsqFormatter;

import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
Expand Down Expand Up @@ -101,7 +102,8 @@ class OfferBookViewModel extends ActivatableViewModel {
private final FilterManager filterManager;
final AccountAgeWitnessService accountAgeWitnessService;
private final Navigation navigation;
final BSFormatter formatter;
private final BSFormatter btcFormatter;
private final BsqFormatter bsqFormatter;
final ObjectProperty<TableColumn.SortType> priceSortTypeProperty = new SimpleObjectProperty<>();


Expand Down Expand Up @@ -143,7 +145,8 @@ public OfferBookViewModel(User user,
FilterManager filterManager,
AccountAgeWitnessService accountAgeWitnessService,
Navigation navigation,
BSFormatter formatter) {
BSFormatter btcFormatter,
BsqFormatter bsqFormatter) {
super();

this.openOfferManager = openOfferManager;
Expand All @@ -156,7 +159,8 @@ public OfferBookViewModel(User user,
this.filterManager = filterManager;
this.accountAgeWitnessService = accountAgeWitnessService;
this.navigation = navigation;
this.formatter = formatter;
this.btcFormatter = btcFormatter;
this.bsqFormatter = bsqFormatter;

this.filteredItems = new FilteredList<>(offerBook.getOfferBookListItems());
this.sortedItems = new SortedList<>(filteredItems);
Expand Down Expand Up @@ -343,7 +347,7 @@ String getAmount(OfferBookListItem item) {
}

private String formatAmount(Offer offer, boolean decimalAligned) {
return DisplayUtils.formatAmount(offer, GUIUtil.AMOUNT_DECIMALS, decimalAligned, maxPlacesForAmount.get(), formatter);
return DisplayUtils.formatAmount(offer, GUIUtil.AMOUNT_DECIMALS, decimalAligned, maxPlacesForAmount.get(), btcFormatter);
}


Expand Down Expand Up @@ -625,4 +629,10 @@ public boolean hasSelectionAccountSigning() {
}
return true;
}

public String getMakerFeeAsString(Offer offer) {
return offer.isCurrencyForMakerFeeBtc() ?
btcFormatter.formatCoinWithCode(offer.getMakerFee()) :
bsqFormatter.formatCoinWithCode(offer.getMakerFee());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void onRemoveOpenOffer(OpenOffer openOffer) {
if (model.isBootstrappedOrShowPopup()) {
String key = "RemoveOfferWarning";
if (DontShowAgainLookup.showAgain(key)) {
new Popup<>().warning(Res.get("popup.warning.removeOffer", model.formatter.formatCoinWithCode(openOffer.getOffer().getMakerFee())))
new Popup<>().warning(Res.get("popup.warning.removeOffer", model.getMakerFeeAsString(openOffer)))
.actionButtonText(Res.get("shared.removeOffer"))
.onAction(() -> doRemoveOpenOffer(openOffer))
.closeButtonText(Res.get("shared.dontRemoveOffer"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import bisq.core.offer.Offer;
import bisq.core.offer.OpenOffer;
import bisq.core.util.BSFormatter;
import bisq.core.util.BsqFormatter;

import bisq.network.p2p.P2PService;

Expand All @@ -39,17 +40,20 @@

class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel> implements ViewModel {
private final P2PService p2PService;
final BSFormatter formatter;
private final BSFormatter btcFormatter;
private final BsqFormatter bsqFormatter;


@Inject
public OpenOffersViewModel(OpenOffersDataModel dataModel,
P2PService p2PService,
BSFormatter formatter) {
BSFormatter btcFormatter,
BsqFormatter bsqFormatter) {
super(dataModel);

this.p2PService = p2PService;
this.formatter = formatter;
this.btcFormatter = btcFormatter;
this.bsqFormatter = bsqFormatter;
}

void onActivateOpenOffer(OpenOffer openOffer, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
Expand All @@ -73,7 +77,7 @@ String getTradeId(OpenOfferListItem item) {
}

String getAmount(OpenOfferListItem item) {
return (item != null) ? DisplayUtils.formatAmount(item.getOffer(), formatter) : "";
return (item != null) ? DisplayUtils.formatAmount(item.getOffer(), btcFormatter) : "";
}

String getPrice(OpenOfferListItem item) {
Expand Down Expand Up @@ -121,4 +125,11 @@ boolean isDeactivated(OpenOfferListItem item) {
boolean isBootstrappedOrShowPopup() {
return GUIUtil.isBootstrappedOrShowPopup(p2PService);
}

public String getMakerFeeAsString(OpenOffer openOffer) {
Offer offer = openOffer.getOffer();
return offer.isCurrencyForMakerFeeBtc() ?
btcFormatter.formatCoinWithCode(offer.getMakerFee()) :
bsqFormatter.formatCoinWithCode(offer.getMakerFee());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.util.BSFormatter;
import bisq.core.util.BsqFormatter;

import javafx.beans.property.SimpleIntegerProperty;

Expand Down Expand Up @@ -225,7 +226,7 @@ public void testMaxCharactersForAmountWithNoOffes() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
assertEquals(0, model.maxPlacesForAmount.intValue());
}

Expand All @@ -239,7 +240,7 @@ public void testMaxCharactersForAmount() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
model.activate();

assertEquals(6, model.maxPlacesForAmount.intValue());
Expand All @@ -257,7 +258,7 @@ public void testMaxCharactersForAmountRange() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
model.activate();

assertEquals(15, model.maxPlacesForAmount.intValue());
Expand All @@ -276,7 +277,7 @@ public void testMaxCharactersForVolumeWithNoOffes() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
assertEquals(0, model.maxPlacesForVolume.intValue());
}

Expand All @@ -290,7 +291,7 @@ public void testMaxCharactersForVolume() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
model.activate();

assertEquals(8, model.maxPlacesForVolume.intValue());
Expand All @@ -308,7 +309,7 @@ public void testMaxCharactersForVolumeRange() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
model.activate();

assertEquals(15, model.maxPlacesForVolume.intValue());
Expand All @@ -327,7 +328,7 @@ public void testMaxCharactersForPriceWithNoOffers() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
assertEquals(0, model.maxPlacesForPrice.intValue());
}

Expand All @@ -341,7 +342,7 @@ public void testMaxCharactersForPrice() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
model.activate();

assertEquals(7, model.maxPlacesForPrice.intValue());
Expand All @@ -359,7 +360,7 @@ public void testMaxCharactersForPriceDistanceWithNoOffers() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue());
}

Expand Down Expand Up @@ -387,7 +388,7 @@ public void testMaxCharactersForPriceDistance() {
offerBookListItems.addAll(item1, item2);

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, priceFeedService,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());
model.activate();

assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue()); //" (1.97%)"
Expand All @@ -408,7 +409,7 @@ public void testGetPrice() {
when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true));

final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null,
null, null, null, null, new BSFormatter());
null, null, null, null, new BSFormatter(), new BsqFormatter());

final OfferBookListItem item = make(btcBuyItem.but(
with(useMarketBasedPrice, true),
Expand Down

0 comments on commit 66d3f91

Please sign in to comment.