Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use default currency if payment account available #6160

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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