mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-23 23:20:42 -04:00
add gold and silver, refactor money types to traditional and crypto
This commit is contained in:
parent
65bc78d3d7
commit
29706339ef
210 changed files with 2629 additions and 2373 deletions
|
@ -52,7 +52,7 @@ class ColumnHeaderConstants {
|
|||
static final String COL_HEADER_NAME = "Name";
|
||||
static final String COL_HEADER_PAYMENT_METHOD = "Payment Method";
|
||||
static final String COL_HEADER_PRICE = "Price in %-3s for 1 BTC";
|
||||
static final String COL_HEADER_PRICE_OF_ALTCOIN = "Price in BTC for 1 %-3s";
|
||||
static final String COL_HEADER_PRICE_OF_CRYPTO = "Price in BTC for 1 %-3s";
|
||||
static final String COL_HEADER_TRADE_AMOUNT = padStart("Amount(%-3s)", 12, ' ');
|
||||
static final String COL_HEADER_TRADE_BUYER_COST = padEnd("Buyer Cost(%-3s)", 15, ' ');
|
||||
static final String COL_HEADER_TRADE_DEPOSIT_CONFIRMED = "Deposit Confirmed";
|
||||
|
|
|
@ -35,7 +35,7 @@ public class CreateCryptoCurrencyPaymentAcctOptionParser extends AbstractMethodO
|
|||
final OptionSpec<String> currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "crypto currency code (xmr)")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "altcoin address")
|
||||
final OptionSpec<String> addressOpt = parser.accepts(OPT_ADDRESS, "crypto address")
|
||||
.withRequiredArg();
|
||||
|
||||
final OptionSpec<Boolean> tradeInstantOpt = parser.accepts(OPT_TRADE_INSTANT, "create trade instant account")
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.function.Predicate;
|
|||
*/
|
||||
abstract class AbstractTableBuilder {
|
||||
|
||||
protected final Predicate<OfferInfo> isFiatOffer = (o) -> o.getBaseCurrencyCode().equals("BTC");
|
||||
protected final Predicate<OfferInfo> isTraditionalOffer = (o) -> o.getBaseCurrencyCode().equals("XMR");
|
||||
|
||||
protected final TableType tableType;
|
||||
protected final List<?> protos;
|
||||
|
|
|
@ -91,7 +91,7 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
@Nullable
|
||||
protected final Column<Boolean> colIsPaymentReceivedMessageSent;
|
||||
@Nullable
|
||||
protected final Column<String> colAltcoinReceiveAddressColumn;
|
||||
protected final Column<String> colCryptoReceiveAddressColumn;
|
||||
|
||||
AbstractTradeListBuilder(TableType tableType, List<?> protos) {
|
||||
super(tableType, protos);
|
||||
|
@ -127,7 +127,7 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
this.colIsPaymentSentMessageSent = colSupplier.paymentSentMessageSentColumn.get();
|
||||
this.colIsPaymentReceivedMessageSent = colSupplier.paymentReceivedMessageSentColumn.get();
|
||||
//noinspection ConstantConditions
|
||||
this.colAltcoinReceiveAddressColumn = colSupplier.altcoinReceiveAddressColumn.get();
|
||||
this.colCryptoReceiveAddressColumn = colSupplier.cryptoReceiveAddressColumn.get();
|
||||
}
|
||||
|
||||
protected void validate() {
|
||||
|
@ -142,7 +142,7 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
// Helper Functions
|
||||
|
||||
private final Supplier<Boolean> isTradeDetailTblBuilder = () -> tableType.equals(TRADE_DETAIL_TBL);
|
||||
protected final Predicate<TradeInfo> isFiatTrade = (t) -> isFiatOffer.test(t.getOffer());
|
||||
protected final Predicate<TradeInfo> isTraditionalTrade = (t) -> isTraditionalOffer.test(t.getOffer());
|
||||
protected final Predicate<TradeInfo> isMyOffer = (t) -> t.getOffer().getIsMyOffer();
|
||||
protected final Predicate<TradeInfo> isTaker = (t) -> t.getRole().toLowerCase().contains("taker");
|
||||
protected final Predicate<TradeInfo> isSellOffer = (t) -> t.getOffer().getDirection().equals(SELL.name());
|
||||
|
@ -152,23 +152,23 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
|
||||
// Column Value Functions
|
||||
|
||||
// Altcoin volumes from server are string representations of decimals.
|
||||
// Crypto volumes from server are string representations of decimals.
|
||||
// Converting them to longs ("sats") requires shifting the decimal points
|
||||
// to left: 2 for BSQ, 8 for other altcoins.
|
||||
protected final Function<TradeInfo, Long> toAltcoinTradeVolumeAsLong = (t) -> new BigDecimal(t.getTradeVolume()).movePointRight(8).longValue();
|
||||
// to left: 2 for BSQ, 8 for other cryptos.
|
||||
protected final Function<TradeInfo, Long> toCryptoTradeVolumeAsLong = (t) -> new BigDecimal(t.getTradeVolume()).movePointRight(8).longValue();
|
||||
|
||||
protected final Function<TradeInfo, String> toTradeVolumeAsString = (t) ->
|
||||
isFiatTrade.test(t)
|
||||
isTraditionalTrade.test(t)
|
||||
? t.getTradeVolume()
|
||||
: formatSatoshis(t.getAmount());
|
||||
|
||||
protected final Function<TradeInfo, Long> toTradeVolumeAsLong = (t) ->
|
||||
isFiatTrade.test(t)
|
||||
isTraditionalTrade.test(t)
|
||||
? Long.parseLong(t.getTradeVolume())
|
||||
: toAltcoinTradeVolumeAsLong.apply(t);
|
||||
: toCryptoTradeVolumeAsLong.apply(t);
|
||||
|
||||
protected final Function<TradeInfo, Long> toTradeAmount = (t) ->
|
||||
isFiatTrade.test(t)
|
||||
isTraditionalTrade.test(t)
|
||||
? t.getAmount()
|
||||
: toTradeVolumeAsLong.apply(t);
|
||||
|
||||
|
@ -177,7 +177,7 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
+ t.getOffer().getCounterCurrencyCode();
|
||||
|
||||
protected final Function<TradeInfo, String> toPaymentCurrencyCode = (t) ->
|
||||
isFiatTrade.test(t)
|
||||
isTraditionalTrade.test(t)
|
||||
? t.getOffer().getCounterCurrencyCode()
|
||||
: t.getOffer().getBaseCurrencyCode();
|
||||
|
||||
|
@ -202,7 +202,7 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
};
|
||||
|
||||
protected final Function<TradeInfo, String> toOfferType = (t) -> {
|
||||
if (isFiatTrade.test(t)) {
|
||||
if (isTraditionalTrade.test(t)) {
|
||||
return t.getOffer().getDirection() + " " + t.getOffer().getBaseCurrencyCode();
|
||||
} else {
|
||||
if (t.getOffer().getDirection().equals("BUY")) {
|
||||
|
@ -213,8 +213,8 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
}
|
||||
};
|
||||
|
||||
protected final Predicate<TradeInfo> showAltCoinBuyerAddress = (t) -> {
|
||||
if (isFiatTrade.test(t)) {
|
||||
protected final Predicate<TradeInfo> showCryptoBuyerAddress = (t) -> {
|
||||
if (isTraditionalTrade.test(t)) {
|
||||
return false;
|
||||
} else {
|
||||
ContractInfo contract = t.getContract();
|
||||
|
@ -227,8 +227,8 @@ abstract class AbstractTradeListBuilder extends AbstractTableBuilder {
|
|||
}
|
||||
};
|
||||
|
||||
protected final Function<TradeInfo, String> toAltcoinReceiveAddress = (t) -> {
|
||||
if (showAltCoinBuyerAddress.test(t)) {
|
||||
protected final Function<TradeInfo, String> toCryptoReceiveAddress = (t) -> {
|
||||
if (showCryptoBuyerAddress.test(t)) {
|
||||
ContractInfo contract = t.getContract();
|
||||
boolean isBuyerMakerAndSellerTaker = contract.getIsBuyerMakerAndSellerTaker();
|
||||
return isBuyerMakerAndSellerTaker // (is BTC buyer / maker)
|
||||
|
|
|
@ -34,7 +34,7 @@ import java.util.stream.Collectors;
|
|||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_AMOUNT_RANGE;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_CREATION_DATE;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DETAILED_PRICE;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DETAILED_PRICE_OF_ALTCOIN;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DETAILED_PRICE_OF_CRYPTO;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DIRECTION;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_ENABLED;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_PAYMENT_METHOD;
|
||||
|
@ -56,7 +56,7 @@ import static protobuf.OfferDirection.SELL;
|
|||
*/
|
||||
class OfferTableBuilder extends AbstractTableBuilder {
|
||||
|
||||
// Columns common to both fiat and cryptocurrency offers.
|
||||
// Columns common to both traditional and cryptocurrency offers.
|
||||
private final Column<String> colOfferId = new StringColumn(COL_HEADER_UUID, LEFT);
|
||||
private final Column<String> colDirection = new StringColumn(COL_HEADER_DIRECTION, LEFT);
|
||||
private final Column<Long> colAmount = new SatoshiColumn("Temp Amount", NONE);
|
||||
|
@ -71,20 +71,20 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
@Override
|
||||
public Table build() {
|
||||
List<OfferInfo> offers = protos.stream().map(p -> (OfferInfo) p).collect(Collectors.toList());
|
||||
return isShowingFiatOffers.get()
|
||||
? buildFiatOfferTable(offers)
|
||||
return isShowingTraditionalOffers.get()
|
||||
? buildTraditionalOfferTable(offers)
|
||||
: buildCryptoCurrencyOfferTable(offers);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public Table buildFiatOfferTable(List<OfferInfo> offers) {
|
||||
public Table buildTraditionalOfferTable(List<OfferInfo> offers) {
|
||||
@Nullable
|
||||
Column<String> colEnabled = enabledColumn.get(); // Not boolean: "YES", "NO", or "PENDING"
|
||||
Column<String> colFiatPrice = new StringColumn(format(COL_HEADER_DETAILED_PRICE, fiatTradeCurrency.get()), RIGHT);
|
||||
Column<String> colVolume = new StringColumn(format("Temp Volume (%s)", fiatTradeCurrency.get()), NONE);
|
||||
Column<String> colMinVolume = new StringColumn(format("Temp Min Volume (%s)", fiatTradeCurrency.get()), NONE);
|
||||
Column<String> colTraditionalPrice = new StringColumn(format(COL_HEADER_DETAILED_PRICE, traditionalTradeCurrency.get()), RIGHT);
|
||||
Column<String> colVolume = new StringColumn(format("Temp Volume (%s)", traditionalTradeCurrency.get()), NONE);
|
||||
Column<String> colMinVolume = new StringColumn(format("Temp Min Volume (%s)", traditionalTradeCurrency.get()), NONE);
|
||||
@Nullable
|
||||
Column<String> colTriggerPrice = fiatTriggerPriceColumn.get();
|
||||
Column<String> colTriggerPrice = traditionalTriggerPriceColumn.get();
|
||||
|
||||
// Populate columns with offer info.
|
||||
|
||||
|
@ -93,7 +93,7 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
colEnabled.addRow(toEnabled.apply(o));
|
||||
|
||||
colDirection.addRow(o.getDirection());
|
||||
colFiatPrice.addRow(o.getPrice());
|
||||
colTraditionalPrice.addRow(o.getPrice());
|
||||
colMinAmount.addRow(o.getMinAmount());
|
||||
colAmount.addRow(o.getAmount());
|
||||
colVolume.addRow(o.getVolume());
|
||||
|
@ -109,7 +109,7 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
|
||||
ZippedStringColumns amountRange = zippedAmountRangeColumns.get();
|
||||
ZippedStringColumns volumeRange =
|
||||
new ZippedStringColumns(format(COL_HEADER_VOLUME_RANGE, fiatTradeCurrency.get()),
|
||||
new ZippedStringColumns(format(COL_HEADER_VOLUME_RANGE, traditionalTradeCurrency.get()),
|
||||
RIGHT,
|
||||
" - ",
|
||||
colMinVolume.asStringColumn(),
|
||||
|
@ -120,7 +120,7 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
if (isShowingMyOffers.get()) {
|
||||
return new Table(colEnabled.asStringColumn(),
|
||||
colDirection,
|
||||
colFiatPrice.justify(),
|
||||
colTraditionalPrice.justify(),
|
||||
amountRange.asStringColumn(EXCLUDE_DUPLICATES),
|
||||
volumeRange.asStringColumn(EXCLUDE_DUPLICATES),
|
||||
colTriggerPrice.justify(),
|
||||
|
@ -129,7 +129,7 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
colOfferId);
|
||||
} else {
|
||||
return new Table(colDirection,
|
||||
colFiatPrice.justify(),
|
||||
colTraditionalPrice.justify(),
|
||||
amountRange.asStringColumn(EXCLUDE_DUPLICATES),
|
||||
volumeRange.asStringColumn(EXCLUDE_DUPLICATES),
|
||||
colPaymentMethod,
|
||||
|
@ -142,11 +142,11 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
public Table buildCryptoCurrencyOfferTable(List<OfferInfo> offers) {
|
||||
@Nullable
|
||||
Column<String> colEnabled = enabledColumn.get(); // Not boolean: YES, NO, or PENDING
|
||||
Column<String> colBtcPrice = new StringColumn(format(COL_HEADER_DETAILED_PRICE_OF_ALTCOIN, altcoinTradeCurrency.get()), RIGHT);
|
||||
Column<String> colVolume = new StringColumn(format("Temp Volume (%s)", altcoinTradeCurrency.get()), NONE);
|
||||
Column<String> colMinVolume = new StringColumn(format("Temp Min Volume (%s)", altcoinTradeCurrency.get()), NONE);
|
||||
Column<String> colBtcPrice = new StringColumn(format(COL_HEADER_DETAILED_PRICE_OF_CRYPTO, cryptoTradeCurrency.get()), RIGHT);
|
||||
Column<String> colVolume = new StringColumn(format("Temp Volume (%s)", cryptoTradeCurrency.get()), NONE);
|
||||
Column<String> colMinVolume = new StringColumn(format("Temp Min Volume (%s)", cryptoTradeCurrency.get()), NONE);
|
||||
@Nullable
|
||||
Column<String> colTriggerPrice = altcoinTriggerPriceColumn.get();
|
||||
Column<String> colTriggerPrice = cryptoTriggerPriceColumn.get();
|
||||
|
||||
// Populate columns with offer info.
|
||||
|
||||
|
@ -171,7 +171,7 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
|
||||
ZippedStringColumns amountRange = zippedAmountRangeColumns.get();
|
||||
ZippedStringColumns volumeRange =
|
||||
new ZippedStringColumns(format(COL_HEADER_VOLUME_RANGE, altcoinTradeCurrency.get()),
|
||||
new ZippedStringColumns(format(COL_HEADER_VOLUME_RANGE, cryptoTradeCurrency.get()),
|
||||
RIGHT,
|
||||
" - ",
|
||||
colMinVolume.asStringColumn(),
|
||||
|
@ -214,11 +214,11 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
private final Function<String, String> toBlankOrNonZeroValue = (s) -> s.trim().equals("0") ? "" : s;
|
||||
private final Supplier<OfferInfo> firstOfferInList = () -> (OfferInfo) protos.get(0);
|
||||
private final Supplier<Boolean> isShowingMyOffers = () -> firstOfferInList.get().getIsMyOffer();
|
||||
private final Supplier<Boolean> isShowingFiatOffers = () -> isFiatOffer.test(firstOfferInList.get());
|
||||
private final Supplier<String> fiatTradeCurrency = () -> firstOfferInList.get().getCounterCurrencyCode();
|
||||
private final Supplier<String> altcoinTradeCurrency = () -> firstOfferInList.get().getBaseCurrencyCode();
|
||||
private final Supplier<Boolean> isShowingTraditionalOffers = () -> isTraditionalOffer.test(firstOfferInList.get());
|
||||
private final Supplier<String> traditionalTradeCurrency = () -> firstOfferInList.get().getCounterCurrencyCode();
|
||||
private final Supplier<String> cryptoTradeCurrency = () -> firstOfferInList.get().getBaseCurrencyCode();
|
||||
private final Supplier<Boolean> isShowingBsqOffers = () ->
|
||||
!isFiatOffer.test(firstOfferInList.get()) && altcoinTradeCurrency.get().equals("BSQ");
|
||||
!isTraditionalOffer.test(firstOfferInList.get()) && cryptoTradeCurrency.get().equals("BSQ");
|
||||
|
||||
@Nullable // Not a boolean column: YES, NO, or PENDING.
|
||||
private final Supplier<StringColumn> enabledColumn = () ->
|
||||
|
@ -226,14 +226,14 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
? new StringColumn(COL_HEADER_ENABLED, LEFT)
|
||||
: null;
|
||||
@Nullable
|
||||
private final Supplier<StringColumn> fiatTriggerPriceColumn = () ->
|
||||
private final Supplier<StringColumn> traditionalTriggerPriceColumn = () ->
|
||||
isShowingMyOffers.get()
|
||||
? new StringColumn(format(COL_HEADER_TRIGGER_PRICE, fiatTradeCurrency.get()), RIGHT)
|
||||
? new StringColumn(format(COL_HEADER_TRIGGER_PRICE, traditionalTradeCurrency.get()), RIGHT)
|
||||
: null;
|
||||
@Nullable
|
||||
private final Supplier<StringColumn> altcoinTriggerPriceColumn = () ->
|
||||
private final Supplier<StringColumn> cryptoTriggerPriceColumn = () ->
|
||||
isShowingMyOffers.get() && !isShowingBsqOffers.get()
|
||||
? new StringColumn(format(COL_HEADER_TRIGGER_PRICE, altcoinTradeCurrency.get()), RIGHT)
|
||||
? new StringColumn(format(COL_HEADER_TRIGGER_PRICE, cryptoTradeCurrency.get()), RIGHT)
|
||||
: null;
|
||||
|
||||
private final Function<OfferInfo, String> toEnabled = (o) -> {
|
||||
|
@ -244,7 +244,7 @@ class OfferTableBuilder extends AbstractTableBuilder {
|
|||
d.equalsIgnoreCase(BUY.name()) ? SELL.name() : BUY.name();
|
||||
|
||||
private final Function<OfferInfo, String> directionFormat = (o) -> {
|
||||
if (isFiatOffer.test(o)) {
|
||||
if (isTraditionalOffer.test(o)) {
|
||||
return o.getBaseCurrencyCode();
|
||||
} else {
|
||||
// Return "Sell BSQ (Buy BTC)", or "Buy BSQ (Sell BTC)".
|
||||
|
|
|
@ -46,7 +46,7 @@ class TableBuilderConstants {
|
|||
static final String COL_HEADER_DATE_TIME = "Date/Time (UTC)";
|
||||
static final String COL_HEADER_DETAILED_AMOUNT = "Amount(%-3s)";
|
||||
static final String COL_HEADER_DETAILED_PRICE = "Price in %-3s for 1 BTC";
|
||||
static final String COL_HEADER_DETAILED_PRICE_OF_ALTCOIN = "Price in BTC for 1 %-3s";
|
||||
static final String COL_HEADER_DETAILED_PRICE_OF_CRYPTO = "Price in BTC for 1 %-3s";
|
||||
static final String COL_HEADER_DIRECTION = "Buy/Sell";
|
||||
static final String COL_HEADER_ENABLED = "Enabled";
|
||||
static final String COL_HEADER_MARKET = "Market";
|
||||
|
@ -55,7 +55,7 @@ class TableBuilderConstants {
|
|||
static final String COL_HEADER_PAYMENT_METHOD = "Payment Method";
|
||||
static final String COL_HEADER_PRICE = "Price";
|
||||
static final String COL_HEADER_STATUS = "Status";
|
||||
static final String COL_HEADER_TRADE_ALTCOIN_BUYER_ADDRESS = "%-3s Buyer Address";
|
||||
static final String COL_HEADER_TRADE_CRYPTO_BUYER_ADDRESS = "%-3s Buyer Address";
|
||||
static final String COL_HEADER_TRADE_BUYER_COST = "Buyer Cost(%-3s)";
|
||||
static final String COL_HEADER_TRADE_DEPOSIT_CONFIRMED = "Deposit Confirmed";
|
||||
static final String COL_HEADER_TRADE_DEPOSIT_PUBLISHED = "Deposit Published";
|
||||
|
|
|
@ -66,8 +66,8 @@ class TradeDetailTableBuilder extends AbstractTradeListBuilder {
|
|||
colIsPaymentReceivedMessageSent.addRow(trade.getIsPaymentReceived());
|
||||
colIsPayoutPublished.addRow(trade.getIsPayoutPublished());
|
||||
colIsCompleted.addRow(trade.getIsCompleted());
|
||||
if (colAltcoinReceiveAddressColumn != null)
|
||||
colAltcoinReceiveAddressColumn.addRow(toAltcoinReceiveAddress.apply(trade));
|
||||
if (colCryptoReceiveAddressColumn != null)
|
||||
colCryptoReceiveAddressColumn.addRow(toCryptoReceiveAddress.apply(trade));
|
||||
}
|
||||
|
||||
private List<Column<?>> defineColumnList(TradeInfo trade) {
|
||||
|
@ -90,8 +90,8 @@ class TradeDetailTableBuilder extends AbstractTradeListBuilder {
|
|||
add(colIsCompleted.asStringColumn());
|
||||
}};
|
||||
|
||||
if (colAltcoinReceiveAddressColumn != null)
|
||||
columns.add(colAltcoinReceiveAddressColumn);
|
||||
if (colCryptoReceiveAddressColumn != null)
|
||||
columns.add(colCryptoReceiveAddressColumn);
|
||||
|
||||
return columns;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
package haveno.cli.table.builder;
|
||||
|
||||
import haveno.cli.table.column.AltcoinVolumeColumn;
|
||||
import haveno.cli.table.column.CryptoVolumeColumn;
|
||||
import haveno.cli.table.column.BooleanColumn;
|
||||
import haveno.cli.table.column.BtcColumn;
|
||||
import haveno.cli.table.column.Column;
|
||||
|
@ -43,14 +43,14 @@ import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_CURRENCY
|
|||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DATE_TIME;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DETAILED_AMOUNT;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DETAILED_PRICE;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DETAILED_PRICE_OF_ALTCOIN;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DETAILED_PRICE_OF_CRYPTO;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_DEVIATION;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_MARKET;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_OFFER_TYPE;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_PAYMENT_METHOD;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_PRICE;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_STATUS;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_TRADE_ALTCOIN_BUYER_ADDRESS;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_TRADE_CRYPTO_BUYER_ADDRESS;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_TRADE_BUYER_COST;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_TRADE_DEPOSIT_CONFIRMED;
|
||||
import static haveno.cli.table.builder.TableBuilderConstants.COL_HEADER_TRADE_DEPOSIT_PUBLISHED;
|
||||
|
@ -69,8 +69,8 @@ import static haveno.cli.table.builder.TableType.CLOSED_TRADES_TBL;
|
|||
import static haveno.cli.table.builder.TableType.FAILED_TRADES_TBL;
|
||||
import static haveno.cli.table.builder.TableType.OPEN_TRADES_TBL;
|
||||
import static haveno.cli.table.builder.TableType.TRADE_DETAIL_TBL;
|
||||
import static haveno.cli.table.column.AltcoinVolumeColumn.DISPLAY_MODE.ALTCOIN_VOLUME;
|
||||
import static haveno.cli.table.column.AltcoinVolumeColumn.DISPLAY_MODE.BSQ_VOLUME;
|
||||
import static haveno.cli.table.column.CryptoVolumeColumn.DISPLAY_MODE.CRYPTO_VOLUME;
|
||||
import static haveno.cli.table.column.CryptoVolumeColumn.DISPLAY_MODE.BSQ_VOLUME;
|
||||
import static haveno.cli.table.column.Column.JUSTIFICATION.LEFT;
|
||||
import static haveno.cli.table.column.Column.JUSTIFICATION.RIGHT;
|
||||
import static java.lang.String.format;
|
||||
|
@ -97,8 +97,8 @@ class TradeTableColumnSupplier {
|
|||
private final Supplier<Boolean> isClosedTradeTblBuilder = () -> getTableType().equals(CLOSED_TRADES_TBL);
|
||||
private final Supplier<Boolean> isFailedTradeTblBuilder = () -> getTableType().equals(FAILED_TRADES_TBL);
|
||||
private final Supplier<TradeInfo> firstRow = () -> getTrades().get(0);
|
||||
private final Predicate<OfferInfo> isFiatOffer = (o) -> o.getBaseCurrencyCode().equals("BTC");
|
||||
private final Predicate<TradeInfo> isFiatTrade = (t) -> isFiatOffer.test(t.getOffer());
|
||||
private final Predicate<OfferInfo> isTraditionalOffer = (o) -> o.getBaseCurrencyCode().equals("XMR");
|
||||
private final Predicate<TradeInfo> isTraditionalTrade = (t) -> isTraditionalOffer.test(t.getOffer());
|
||||
private final Predicate<TradeInfo> isTaker = (t) -> t.getRole().toLowerCase().contains("taker");
|
||||
|
||||
final Supplier<StringColumn> tradeIdColumn = () -> isTradeDetailTblBuilder.get()
|
||||
|
@ -114,9 +114,9 @@ class TradeTableColumnSupplier {
|
|||
: new StringColumn(COL_HEADER_MARKET);
|
||||
|
||||
private final Function<TradeInfo, Column<String>> toDetailedPriceColumn = (t) -> {
|
||||
String colHeader = isFiatTrade.test(t)
|
||||
String colHeader = isTraditionalTrade.test(t)
|
||||
? format(COL_HEADER_DETAILED_PRICE, t.getOffer().getCounterCurrencyCode())
|
||||
: format(COL_HEADER_DETAILED_PRICE_OF_ALTCOIN, t.getOffer().getBaseCurrencyCode());
|
||||
: format(COL_HEADER_DETAILED_PRICE_OF_CRYPTO, t.getOffer().getBaseCurrencyCode());
|
||||
return new StringColumn(colHeader, RIGHT);
|
||||
};
|
||||
|
||||
|
@ -135,13 +135,13 @@ class TradeTableColumnSupplier {
|
|||
private final Function<TradeInfo, Column<Long>> toDetailedAmountColumn = (t) -> {
|
||||
String headerCurrencyCode = t.getOffer().getBaseCurrencyCode();
|
||||
String colHeader = format(COL_HEADER_DETAILED_AMOUNT, headerCurrencyCode);
|
||||
AltcoinVolumeColumn.DISPLAY_MODE displayMode = headerCurrencyCode.equals("BSQ") ? BSQ_VOLUME : ALTCOIN_VOLUME;
|
||||
return isFiatTrade.test(t)
|
||||
CryptoVolumeColumn.DISPLAY_MODE displayMode = headerCurrencyCode.equals("BSQ") ? BSQ_VOLUME : CRYPTO_VOLUME;
|
||||
return isTraditionalTrade.test(t)
|
||||
? new SatoshiColumn(colHeader)
|
||||
: new AltcoinVolumeColumn(colHeader, displayMode);
|
||||
: new CryptoVolumeColumn(colHeader, displayMode);
|
||||
};
|
||||
|
||||
// Can be fiat, btc or altcoin amount represented as longs. Placing the decimal
|
||||
// Can be tradional or crypto amount represented as longs. Placing the decimal
|
||||
// in the displayed string representation is done in the Column implementation.
|
||||
final Supplier<Column<Long>> amountColumn = () -> isTradeDetailTblBuilder.get()
|
||||
? toDetailedAmountColumn.apply(firstRow.get())
|
||||
|
@ -222,7 +222,7 @@ class TradeTableColumnSupplier {
|
|||
};
|
||||
|
||||
final Function<TradeInfo, String> toPaymentCurrencyCode = (t) ->
|
||||
isFiatTrade.test(t)
|
||||
isTraditionalTrade.test(t)
|
||||
? t.getOffer().getCounterCurrencyCode()
|
||||
: t.getOffer().getBaseCurrencyCode();
|
||||
|
||||
|
@ -257,8 +257,8 @@ class TradeTableColumnSupplier {
|
|||
}
|
||||
};
|
||||
|
||||
final Predicate<TradeInfo> showAltCoinBuyerAddress = (t) -> {
|
||||
if (isFiatTrade.test(t)) {
|
||||
final Predicate<TradeInfo> showCryptoBuyerAddress = (t) -> {
|
||||
if (isTraditionalTrade.test(t)) {
|
||||
return false;
|
||||
} else {
|
||||
ContractInfo contract = t.getContract();
|
||||
|
@ -272,12 +272,12 @@ class TradeTableColumnSupplier {
|
|||
};
|
||||
|
||||
@Nullable
|
||||
final Supplier<Column<String>> altcoinReceiveAddressColumn = () -> {
|
||||
final Supplier<Column<String>> cryptoReceiveAddressColumn = () -> {
|
||||
if (isTradeDetailTblBuilder.get()) {
|
||||
TradeInfo t = firstRow.get();
|
||||
if (showAltCoinBuyerAddress.test(t)) {
|
||||
if (showCryptoBuyerAddress.test(t)) {
|
||||
String headerCurrencyCode = toPaymentCurrencyCode.apply(t);
|
||||
String colHeader = format(COL_HEADER_TRADE_ALTCOIN_BUYER_ADDRESS, headerCurrencyCode);
|
||||
String colHeader = format(COL_HEADER_TRADE_CRYPTO_BUYER_ADDRESS, headerCurrencyCode);
|
||||
return new StringColumn(colHeader);
|
||||
} else {
|
||||
return null;
|
||||
|
|
|
@ -24,23 +24,23 @@ import java.util.stream.IntStream;
|
|||
import static haveno.cli.table.column.Column.JUSTIFICATION.RIGHT;
|
||||
|
||||
/**
|
||||
* For displaying altcoin volume with appropriate precision.
|
||||
* For displaying crypto volume with appropriate precision.
|
||||
*/
|
||||
public class AltcoinVolumeColumn extends LongColumn {
|
||||
public class CryptoVolumeColumn extends LongColumn {
|
||||
|
||||
public enum DISPLAY_MODE {
|
||||
ALTCOIN_VOLUME,
|
||||
CRYPTO_VOLUME,
|
||||
BSQ_VOLUME,
|
||||
}
|
||||
|
||||
private final DISPLAY_MODE displayMode;
|
||||
|
||||
// The default AltcoinVolumeColumn JUSTIFICATION is RIGHT.
|
||||
public AltcoinVolumeColumn(String name, DISPLAY_MODE displayMode) {
|
||||
// The default CryptoVolumeColumn JUSTIFICATION is RIGHT.
|
||||
public CryptoVolumeColumn(String name, DISPLAY_MODE displayMode) {
|
||||
this(name, RIGHT, displayMode);
|
||||
}
|
||||
|
||||
public AltcoinVolumeColumn(String name,
|
||||
public CryptoVolumeColumn(String name,
|
||||
JUSTIFICATION justification,
|
||||
DISPLAY_MODE displayMode) {
|
||||
super(name, justification);
|
||||
|
@ -65,7 +65,7 @@ public class AltcoinVolumeColumn extends LongColumn {
|
|||
|
||||
@Override
|
||||
public StringColumn asStringColumn() {
|
||||
// We cached the formatted altcoin value strings, but we did
|
||||
// We cached the formatted crypto value strings, but we did
|
||||
// not know how much padding each string needed until now.
|
||||
IntStream.range(0, stringColumn.getRows().size()).forEach(rowIndex -> {
|
||||
String unjustified = stringColumn.getRow(rowIndex);
|
||||
|
@ -77,7 +77,7 @@ public class AltcoinVolumeColumn extends LongColumn {
|
|||
|
||||
private final BiFunction<Long, DISPLAY_MODE, String> toFormattedString = (value, displayMode) -> {
|
||||
switch (displayMode) {
|
||||
case ALTCOIN_VOLUME:
|
||||
case CRYPTO_VOLUME:
|
||||
return value > 0 ? new BigDecimal(value).movePointLeft(8).toString() : "";
|
||||
case BSQ_VOLUME:
|
||||
return value > 0 ? new BigDecimal(value).movePointLeft(2).toString() : "";
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* This file is part of Haveno.
|
||||
*
|
||||
* Haveno is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Haveno is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package haveno.cli.table.column;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static haveno.cli.CurrencyFormat.formatFiatVolume;
|
||||
import static haveno.cli.CurrencyFormat.formatPrice;
|
||||
import static haveno.cli.table.column.Column.JUSTIFICATION.RIGHT;
|
||||
import static haveno.cli.table.column.FiatColumn.DISPLAY_MODE.FIAT_PRICE;
|
||||
|
||||
/**
|
||||
* For displaying fiat volume or price with appropriate precision.
|
||||
*/
|
||||
public class FiatColumn extends LongColumn {
|
||||
|
||||
public enum DISPLAY_MODE {
|
||||
FIAT_PRICE,
|
||||
FIAT_VOLUME
|
||||
}
|
||||
|
||||
private final DISPLAY_MODE displayMode;
|
||||
|
||||
// The default FiatColumn JUSTIFICATION is RIGHT.
|
||||
// The default FiatColumn DISPLAY_MODE is PRICE.
|
||||
public FiatColumn(String name) {
|
||||
this(name, RIGHT, FIAT_PRICE);
|
||||
}
|
||||
|
||||
public FiatColumn(String name, DISPLAY_MODE displayMode) {
|
||||
this(name, RIGHT, displayMode);
|
||||
}
|
||||
|
||||
public FiatColumn(String name,
|
||||
JUSTIFICATION justification,
|
||||
DISPLAY_MODE displayMode) {
|
||||
super(name, justification);
|
||||
this.displayMode = displayMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRow(Long value) {
|
||||
rows.add(value);
|
||||
|
||||
String s = displayMode.equals(FIAT_PRICE) ? formatPrice(value) : formatFiatVolume(value);
|
||||
|
||||
stringColumn.addRow(s);
|
||||
|
||||
if (isNewMaxWidth.test(s))
|
||||
maxWidth = s.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRowAsFormattedString(int rowIndex) {
|
||||
return getRow(rowIndex).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StringColumn asStringColumn() {
|
||||
// We cached the formatted fiat price strings, but we did
|
||||
// not know how much padding each string needed until now.
|
||||
IntStream.range(0, stringColumn.getRows().size()).forEach(rowIndex -> {
|
||||
String unjustified = stringColumn.getRow(rowIndex);
|
||||
String justified = stringColumn.toJustifiedString(unjustified);
|
||||
stringColumn.updateRow(rowIndex, justified);
|
||||
});
|
||||
return this.stringColumn;
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ public abstract class AbstractCliTest {
|
|||
.map(Object::toString)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
protected final BiFunction<Double, Double, String> randomFixedAltcoinPrice = (min, max) -> {
|
||||
protected final BiFunction<Double, Double, String> randomFixedCryptoPrice = (min, max) -> {
|
||||
String random = Double.valueOf(ThreadLocalRandom.current().nextDouble(min, max)).toString();
|
||||
BigDecimal bd = new BigDecimal(random).setScale(8, HALF_UP);
|
||||
return bd.toPlainString();
|
||||
|
@ -114,7 +114,7 @@ public abstract class AbstractCliTest {
|
|||
log.info("NEW Console OUT:\n{}", tbl);
|
||||
}
|
||||
|
||||
protected List<OfferInfo> getMyAltcoinOffers(String currencyCode) {
|
||||
protected List<OfferInfo> getMyCryptoOffers(String currencyCode) {
|
||||
String[] args = getMyOffersCommand("buy", currencyCode);
|
||||
out.print(">>>>> haveno-cli ");
|
||||
stream(args).forEach(a -> out.print(a + " "));
|
||||
|
|
|
@ -28,16 +28,16 @@ public class EditXmrOffersSmokeTest extends AbstractCliTest {
|
|||
|
||||
test.doOfferPriceEdits();
|
||||
|
||||
List<OfferInfo> offers = test.getMyAltcoinOffers("xmr");
|
||||
List<OfferInfo> offers = test.getMyCryptoOffers("xmr");
|
||||
test.disableOffers(offers);
|
||||
|
||||
test.sleep(6);
|
||||
|
||||
offers = test.getMyAltcoinOffers("xmr");
|
||||
offers = test.getMyCryptoOffers("xmr");
|
||||
test.enableOffers(offers);
|
||||
|
||||
// A final look after last edit.
|
||||
test.getMyAltcoinOffers("xmr");
|
||||
test.getMyCryptoOffers("xmr");
|
||||
}
|
||||
|
||||
private void doOfferPriceEdits() {
|
||||
|
@ -48,7 +48,7 @@ public class EditXmrOffersSmokeTest extends AbstractCliTest {
|
|||
}
|
||||
|
||||
private void editPriceMargin() {
|
||||
var offers = getMyAltcoinOffers("xmr");
|
||||
var offers = getMyCryptoOffers("xmr");
|
||||
out.println("Edit XMR offers' price margin");
|
||||
var margins = randomMarginBasedPrices.apply(-301, 300);
|
||||
for (int i = 0; i < offers.size(); i++) {
|
||||
|
@ -59,7 +59,7 @@ public class EditXmrOffersSmokeTest extends AbstractCliTest {
|
|||
}
|
||||
|
||||
private void editTriggerPrice() {
|
||||
var offers = getMyAltcoinOffers("xmr");
|
||||
var offers = getMyCryptoOffers("xmr");
|
||||
out.println("Edit XMR offers' trigger price");
|
||||
for (int i = 0; i < offers.size(); i++) {
|
||||
var offer = offers.get(i);
|
||||
|
@ -74,7 +74,7 @@ public class EditXmrOffersSmokeTest extends AbstractCliTest {
|
|||
}
|
||||
|
||||
private void editPriceMarginAndTriggerPrice() {
|
||||
var offers = getMyAltcoinOffers("xmr");
|
||||
var offers = getMyCryptoOffers("xmr");
|
||||
out.println("Edit XMR offers' price margin and trigger price");
|
||||
for (int i = 0; i < offers.size(); i++) {
|
||||
var offer = offers.get(i);
|
||||
|
@ -89,10 +89,10 @@ public class EditXmrOffersSmokeTest extends AbstractCliTest {
|
|||
}
|
||||
|
||||
private void editFixedPrice() {
|
||||
var offers = getMyAltcoinOffers("xmr");
|
||||
var offers = getMyCryptoOffers("xmr");
|
||||
out.println("Edit XMR offers' fixed price");
|
||||
for (int i = 0; i < offers.size(); i++) {
|
||||
String randomFixedPrice = randomFixedAltcoinPrice.apply(0.004, 0.0075);
|
||||
String randomFixedPrice = randomFixedCryptoPrice.apply(0.004, 0.0075);
|
||||
editOfferFixedPrice(offers.get(i), randomFixedPrice, new Random().nextBoolean());
|
||||
sleep(5);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue