diff --git a/desktop/src/main/java/bisq/desktop/util/DisplayUtils.java b/desktop/src/main/java/bisq/desktop/util/DisplayUtils.java index bb5bc02119e..f1c9bce2c3f 100644 --- a/desktop/src/main/java/bisq/desktop/util/DisplayUtils.java +++ b/desktop/src/main/java/bisq/desktop/util/DisplayUtils.java @@ -116,6 +116,10 @@ public static String formatVolumeWithCode(Volume volume) { return formatVolume(volume, FIAT_VOLUME_FORMAT, true); } + static String formatAverageVolumeWithCode(Volume volume) { + return formatVolume(volume, FIAT_VOLUME_FORMAT.minDecimals(2), true); + } + public static String formatVolumeLabel(String currencyCode) { return formatVolumeLabel(currencyCode, ""); } diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index b46016264a5..71bc48102c5 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -949,7 +949,7 @@ public static void showBsqFeeInfoPopup(Coin fee, Coin miningFee, int txSize, Bsq showBsqFeeInfoPopup(fee, miningFee, null, txSize, bsqFormatter, btcFormatter, type, actionHandler); } - public static void setFitToRowsForTableView(TableView tableView, + public static void setFitToRowsForTableView(TableView tableView, int rowHeight, int headerHeight, int minNumRows, @@ -1100,7 +1100,7 @@ public static String getBsqInUsd(Price bsqPrice, Volume bsqAmountAsVolume = Volume.parse(bsqAmountAsString, "BSQ"); Coin requiredBtc = bsqPrice.getAmountByVolume(bsqAmountAsVolume); Volume volumeByAmount = usdPrice.getVolumeByAmount(requiredBtc); - return DisplayUtils.formatVolumeWithCode(volumeByAmount); + return DisplayUtils.formatAverageVolumeWithCode(volumeByAmount); } public static MaterialDesignIcon getIconForSignState(AccountAgeWitnessService.SignState state) { diff --git a/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java b/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java index e63cbf908dc..9f0c6c01edf 100644 --- a/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java +++ b/desktop/src/test/java/bisq/desktop/util/GUIUtilTest.java @@ -22,8 +22,12 @@ import bisq.core.locale.GlobalSettings; import bisq.core.locale.Res; import bisq.core.locale.TradeCurrency; +import bisq.core.monetary.Price; +import bisq.core.provider.price.MarketPrice; +import bisq.core.provider.price.PriceFeedService; import bisq.core.user.DontShowAgainLookup; import bisq.core.user.Preferences; +import bisq.core.util.coin.BsqFormatter; import org.bitcoinj.core.Coin; import org.bitcoinj.core.CoinMaker; @@ -51,7 +55,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - @Ignore public class GUIUtilTest { @@ -65,7 +68,7 @@ public void setup() { @Test public void testTradeCurrencyConverter() { - Map offerCounts = new HashMap() {{ + Map offerCounts = new HashMap<>() {{ put("BTC", 11); put("EUR", 10); }}; @@ -80,7 +83,7 @@ public void testTradeCurrencyConverter() { } @Test - public void testOpenURLWithCampaignParameters() throws Exception { + public void testOpenURLWithCampaignParameters() { Preferences preferences = mock(Preferences.class); DontShowAgainLookup.setPreferences(preferences); GUIUtil.setPreferences(preferences); @@ -101,7 +104,7 @@ public void testOpenURLWithCampaignParameters() throws Exception { } @Test - public void testOpenURLWithoutCampaignParameters() throws Exception { + public void testOpenURLWithoutCampaignParameters() { Preferences preferences = mock(Preferences.class); DontShowAgainLookup.setPreferences(preferences); GUIUtil.setPreferences(preferences); @@ -143,6 +146,18 @@ public void testAddressRegexValidator() { assertFalse(regexValidator.validate("12.34.56.78:").isValid); } + @Test + public void testGetBsqInUsd() { + PriceFeedService priceFeedService = mock(PriceFeedService.class); + when(priceFeedService.getMarketPrice("USD")) + .thenReturn(new MarketPrice("USD", 12345.6789, 0, true)); + + Coin oneBsq = Coin.valueOf(100); + Price avgPrice = Price.valueOf("BSQ", 10000); + + assertEquals("1.23 USD", GUIUtil.getBsqInUsd(avgPrice, oneBsq, priceFeedService, new BsqFormatter())); + } + @Test public void percentageOfTradeAmount_higherFeeAsMin() {