Search in sources :

Example 16 with BSFormatter

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

the class SpreadViewModelTest method testMaxCharactersForAmount.

@Test
public void testMaxCharactersForAmount() {
    OfferBook offerBook = mock(OfferBook.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    offerBookListItems.addAll(make(OfferBookListItemMaker.btcItem));
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final SpreadViewModel model = new SpreadViewModel(offerBook, null, new BSFormatter());
    model.activate();
    // 0.001
    assertEquals(6, model.maxPlacesForAmount.intValue());
    offerBookListItems.addAll(make(btcItem.but(with(OfferBookListItemMaker.amount, 1403000000L))));
    // 14.0300
    assertEquals(7, model.maxPlacesForAmount.intValue());
}
Also used : OfferBook(bisq.desktop.main.offer.offerbook.OfferBook) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) BSFormatter(bisq.desktop.util.BSFormatter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with BSFormatter

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

the class MakeProposalView method publishProposal.

private void publishProposal(ProposalType type) {
    try {
        Proposal proposal = createProposal(type);
        Transaction tx = Objects.requireNonNull(proposal).getTx();
        Coin miningFee = Objects.requireNonNull(tx).getFee();
        int txSize = tx.bitcoinSerialize().length;
        validateInputs();
        new Popup<>().headLine(Res.get("dao.proposal.create.confirm")).confirmation(Res.get("dao.proposal.create.confirm.info", bsqFormatter.formatCoinWithCode(ProposalConsensus.getCreateCompensationRequestFee(readableBsqBlockChain)), btcFormatter.formatCoinWithCode(miningFee), CoinUtil.getFeePerByte(miningFee, txSize), (txSize / 1000d))).actionButtonText(Res.get("shared.yes")).onAction(() -> {
            proposalCollectionsService.publishProposal(proposal, new FutureCallback<Transaction>() {

                @Override
                public void onSuccess(@Nullable Transaction transaction) {
                    proposalDisplay.clearForm();
                    proposalTypeComboBox.getSelectionModel().clearSelection();
                    new Popup<>().confirmation(Res.get("dao.tx.published.success")).show();
                }

                @Override
                public void onFailure(@NotNull Throwable t) {
                    log.error(t.toString());
                    new Popup<>().warning(t.toString()).show();
                }
            });
        }).closeButtonText(Res.get("shared.cancel")).show();
    } catch (InsufficientMoneyException e) {
        BSFormatter formatter = e instanceof InsufficientBsqException ? bsqFormatter : btcFormatter;
        new Popup<>().warning(Res.get("dao.proposal.create.missingFunds", formatter.formatCoinWithCode(e.missing))).show();
    } catch (CompensationAmountException e) {
        new Popup<>().warning(Res.get("validation.bsq.amountBelowMinAmount", bsqFormatter.formatCoinWithCode(e.required))).show();
    } catch (TransactionVerificationException | WalletException e) {
        log.error(e.toString());
        e.printStackTrace();
        new Popup<>().warning(e.toString()).show();
    } catch (ChangeBelowDustException e) {
        // TODO
        e.printStackTrace();
    }
}
Also used : WalletException(bisq.core.btc.exceptions.WalletException) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) InsufficientMoneyException(org.bitcoinj.core.InsufficientMoneyException) BSFormatter(bisq.desktop.util.BSFormatter) CompensationAmountException(bisq.core.dao.proposal.compensation.CompensationAmountException) ChangeBelowDustException(bisq.core.btc.wallet.ChangeBelowDustException) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) InsufficientBsqException(bisq.core.btc.wallet.InsufficientBsqException) Popup(bisq.desktop.main.overlays.popups.Popup) Proposal(bisq.core.dao.proposal.Proposal)

Example 18 with BSFormatter

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

the class OfferBookChartViewModelTest method testMaxCharactersForBuyVolumeWithNoOffers.

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

Example 19 with BSFormatter

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

the class OfferBookChartViewModelTest method testMaxCharactersForSellPriceWithOfflinePriceFeedService.

@Test
public void testMaxCharactersForSellPriceWithOfflinePriceFeedService() {
    OfferBook offerBook = mock(OfferBook.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    final OfferBookListItem item = make(OfferBookListItemMaker.btcSellItem.but(with(OfferBookListItemMaker.useMarketBasedPrice, true)));
    item.getOffer().setPriceFeedService(priceFeedService);
    offerBookListItems.addAll(item);
    when(priceFeedService.getMarketPrice(anyString())).thenReturn(null);
    when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
    when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
    final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, priceFeedService, null, new BSFormatter());
    model.activate();
    assertEquals(0, model.maxPlacesForSellPrice.intValue());
}
Also used : OfferBook(bisq.desktop.main.offer.offerbook.OfferBook) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with BSFormatter

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

the class OfferBookChartViewModelTest method testMaxCharactersForSellVolumeWithNoOffers.

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

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