Skip to content

Commit

Permalink
Merge pull request #6160 from ripcurlx/fix-default-currency-usage
Browse files Browse the repository at this point in the history
Only use default currency if payment account available
  • Loading branch information
bisq-github-admin-3 authored Apr 26, 2022
2 parents fc6edaa + 21c3edd commit 6d42f72
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Predicate<OfferBookListItem> getCurrencyAndMethodPredicate(OfferDirection direct
TradeCurrency getDefaultTradeCurrency() {
TradeCurrency defaultTradeCurrency = GlobalSettings.getDefaultTradeCurrency();

if (CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode())) {
if (CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode()) && hasPaymentAccountForCurrency(defaultTradeCurrency)) {
return defaultTradeCurrency;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ TradeCurrency getDefaultTradeCurrency() {

if (!CurrencyUtil.isFiatCurrency(defaultTradeCurrency.getCode()) &&
!defaultTradeCurrency.equals(GUIUtil.BSQ) &&
!defaultTradeCurrency.equals(GUIUtil.TOP_ALTCOIN)) {
!defaultTradeCurrency.equals(GUIUtil.TOP_ALTCOIN) &&
hasPaymentAccountForCurrency(defaultTradeCurrency)) {
return defaultTradeCurrency;
}

Expand Down
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.trade.statistics.TradeStatisticsManager;
import bisq.core.user.User;
import bisq.core.util.PriceUtil;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.coin.CoinFormatter;
Expand Down Expand Up @@ -78,19 +79,23 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class OfferBookViewModelTest {
private final CoinFormatter coinFormatter = new ImmutableCoinFormatter(Config.baseCurrencyNetworkParameters().getMonetaryFormat());
private static final Logger log = LoggerFactory.getLogger(OfferBookViewModelTest.class);
private User user;

@Before
public void setUp() {
GlobalSettings.setDefaultTradeCurrency(usd);
Res.setBaseCurrencyCode(usd.getCode());
Res.setBaseCurrencyName(usd.getName());
user = mock(User.class);
when(user.hasPaymentAccountForCurrency(any())).thenReturn(true);
}

private PriceUtil getPriceUtil() {
Expand Down Expand Up @@ -252,7 +257,7 @@ public void testMaxCharactersForAmount() {

when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null);
model.activate();

Expand All @@ -270,7 +275,7 @@ public void testMaxCharactersForAmountRange() {

when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null);
model.activate();

Expand Down Expand Up @@ -303,7 +308,7 @@ public void testMaxCharactersForVolume() {

when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null);
model.activate();

Expand All @@ -321,7 +326,7 @@ public void testMaxCharactersForVolumeRange() {

when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null);
model.activate();

Expand Down Expand Up @@ -354,7 +359,7 @@ public void testMaxCharactersForPrice() {

when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);

final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null);
model.activate();

Expand Down Expand Up @@ -407,7 +412,7 @@ public void testMaxCharactersForPriceDistance() {
item4.getOffer().setPriceFeedService(priceFeedService);
offerBookListItems.addAll(item1, item2);

final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService,
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, priceFeedService,
null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null);
model.activate();

Expand All @@ -428,7 +433,7 @@ public void testGetPrice() {
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true));

final OfferBookViewModel model = new BtcOfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null);

final OfferBookListItem item = make(btcBuyItem.but(
Expand Down

0 comments on commit 6d42f72

Please sign in to comment.