Search in sources :

Example 6 with BSFormatter

use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testMaxCharactersForPriceDistanceWithNoOffers.

@Test
public void testMaxCharactersForPriceDistanceWithNoOffers() {
    OfferBook offerBook = mock(OfferBook.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null, null, null, null, null, new BSFormatter());
    assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue());
}
Also used : BSFormatter(bisq.desktop.util.BSFormatter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with BSFormatter

use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testMaxCharactersForPriceDistance.

@Test
public void testMaxCharactersForPriceDistance() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    final Maker<OfferBookListItem> item = btcItem.but(with(useMarketBasedPrice, true));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    when(priceFeedService.getMarketPrice(anyString())).thenReturn(null);
    when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
    final OfferBookListItem item1 = make(item);
    item1.getOffer().setPriceFeedService(priceFeedService);
    final OfferBookListItem item2 = make(item.but(with(marketPriceMargin, 0.0197)));
    item2.getOffer().setPriceFeedService(priceFeedService);
    final OfferBookListItem item3 = make(item.but(with(marketPriceMargin, 0.1)));
    item3.getOffer().setPriceFeedService(priceFeedService);
    final OfferBookListItem item4 = make(item.but(with(marketPriceMargin, -0.1)));
    item4.getOffer().setPriceFeedService(priceFeedService);
    offerBookListItems.addAll(item1, item2);
    final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, priceFeedService, null, null, null, null, null, new BSFormatter());
    model.activate();
    // " (1.97%)"
    assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue());
    offerBookListItems.addAll(item3);
    // " (10.00%)"
    assertEquals(9, model.maxPlacesForMarketPriceMargin.intValue());
    offerBookListItems.addAll(item4);
    // " (-10.00%)"
    assertEquals(10, model.maxPlacesForMarketPriceMargin.intValue());
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with BSFormatter

use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testMaxCharactersForPrice.

@Test
public void testMaxCharactersForPrice() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcItem));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, new BSFormatter());
    model.activate();
    assertEquals(7, model.maxPlacesForPrice.intValue());
    // 14955.8240
    offerBookListItems.addAll(make(btcItem.but(with(price, 149558240L))));
    assertEquals(10, model.maxPlacesForPrice.intValue());
    // 1495.58240
    offerBookListItems.addAll(make(btcItem.but(with(price, 14955824L))));
    assertEquals(10, model.maxPlacesForPrice.intValue());
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) BSFormatter(bisq.desktop.util.BSFormatter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with BSFormatter

use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testMaxCharactersForVolumeRange.

@Test
public void testMaxCharactersForVolumeRange() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcItemWithRange));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null, null, null, null, null, new BSFormatter());
    model.activate();
    assertEquals(15, model.maxPlacesForVolume.intValue());
    offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 2000000000L))));
    assertEquals(17, model.maxPlacesForVolume.intValue());
    offerBookListItems.addAll(make(btcItemWithRange.but(with(minAmount, 30000000000L), with(amount, 30000000000L))));
    assertEquals(25, model.maxPlacesForVolume.intValue());
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) BSFormatter(bisq.desktop.util.BSFormatter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with BSFormatter

use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.

the class BuyerStep4View method reviewWithdrawal.

@SuppressWarnings("PointlessBooleanExpression")
private void reviewWithdrawal() {
    Coin amount = trade.getPayoutAmount();
    BtcWalletService walletService = model.dataModel.btcWalletService;
    AddressEntry fromAddressesEntry = walletService.getOrCreateAddressEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT);
    String fromAddresses = fromAddressesEntry.getAddressString();
    String toAddresses = withdrawAddressTextField.getText();
    if (new BtcAddressValidator().validate(toAddresses).isValid) {
        Coin balance = walletService.getBalanceForAddress(fromAddressesEntry.getAddress());
        try {
            Transaction feeEstimationTransaction = walletService.getFeeEstimationTransaction(fromAddresses, toAddresses, amount, AddressEntry.Context.TRADE_PAYOUT);
            Coin fee = feeEstimationTransaction.getFee();
            // noinspection UnusedAssignment
            Coin receiverAmount = amount.subtract(fee);
            if (balance.isZero()) {
                new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.alreadyWithdrawn")).show();
                model.dataModel.tradeManager.addTradeToClosedTrades(trade);
            } else {
                if (toAddresses.isEmpty()) {
                    validateWithdrawAddress();
                } else if (Restrictions.isAboveDust(amount, fee)) {
                    BSFormatter formatter = model.btcFormatter;
                    int txSize = feeEstimationTransaction.bitcoinSerialize().length;
                    double feePerByte = CoinUtil.getFeePerByte(fee, txSize);
                    double kb = txSize / 1000d;
                    String recAmount = formatter.formatCoinWithCode(receiverAmount);
                    new Popup<>().headLine(Res.get("portfolio.pending.step5_buyer.confirmWithdrawal")).confirmation(Res.get("shared.sendFundsDetailsWithFee", formatter.formatCoinWithCode(amount), fromAddresses, toAddresses, formatter.formatCoinWithCode(fee), feePerByte, kb, recAmount)).actionButtonText(Res.get("shared.yes")).onAction(() -> doWithdrawal(amount, fee)).closeButtonText(Res.get("shared.cancel")).onClose(() -> {
                        useSavingsWalletButton.setDisable(false);
                        withdrawToExternalWalletButton.setDisable(false);
                    }).show();
                } else {
                    new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.amountTooLow")).show();
                }
            }
        } catch (AddressFormatException e) {
            validateWithdrawAddress();
        } catch (AddressEntryException e) {
            log.error(e.getMessage());
        } catch (InsufficientFundsException e) {
            log.error(e.getMessage());
            e.printStackTrace();
            new Popup<>().warning(e.getMessage()).show();
        }
    } else {
        new Popup<>().warning(Res.get("validation.btc.invalidAddress")).show();
    }
}
Also used : BtcAddressValidator(bisq.desktop.util.validation.BtcAddressValidator) Coin(org.bitcoinj.core.Coin) AddressFormatException(org.bitcoinj.core.AddressFormatException) AddressEntryException(bisq.core.btc.AddressEntryException) Transaction(org.bitcoinj.core.Transaction) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) AddressEntry(bisq.core.btc.AddressEntry) Popup(bisq.desktop.main.overlays.popups.Popup) InsufficientFundsException(bisq.core.btc.InsufficientFundsException) BSFormatter(bisq.desktop.util.BSFormatter)

Aggregations

BSFormatter (bisq.desktop.util.BSFormatter)27 Test (org.junit.Test)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 OfferBook (bisq.desktop.main.offer.offerbook.OfferBook)12 OfferBookListItem (bisq.desktop.main.offer.offerbook.OfferBookListItem)12 PriceFeedService (bisq.core.provider.price.PriceFeedService)9 OpenOfferManager (bisq.core.offer.OpenOfferManager)7 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)4 AddressEntry (bisq.core.btc.AddressEntry)2 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)2 MarketPrice (bisq.core.provider.price.MarketPrice)2 Popup (bisq.desktop.main.overlays.popups.Popup)2 Coin (org.bitcoinj.core.Coin)2 Transaction (org.bitcoinj.core.Transaction)2 AddressEntryException (bisq.core.btc.AddressEntryException)1 InsufficientFundsException (bisq.core.btc.InsufficientFundsException)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)1 ChangeBelowDustException (bisq.core.btc.wallet.ChangeBelowDustException)1