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());
}
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());
}
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());
}
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());
}
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();
}
}
Aggregations