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

Coin formatter interface #3634

Merged
merged 7 commits into from
Nov 20, 2019
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
6 changes: 6 additions & 0 deletions core/src/main/java/bisq/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import bisq.core.proto.persistable.CorePersistenceProtoResolver;
import bisq.core.trade.TradeModule;
import bisq.core.user.Preferences;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.ImmutableCoinFormatter;

import bisq.network.crypto.EncryptionServiceModule;
import bisq.network.p2p.P2PModule;
Expand Down Expand Up @@ -70,6 +73,9 @@ protected void configure() {
File storageDir = new File(environment.getRequiredProperty(Storage.STORAGE_DIR));
bind(File.class).annotatedWith(named(Storage.STORAGE_DIR)).toInstance(storageDir);

CoinFormatter btcFormatter = new ImmutableCoinFormatter(BisqEnvironment.getParameters().getMonetaryFormat());
bind(CoinFormatter.class).annotatedWith(named(FormattingUtils.BTC_FORMATTER_KEY)).toInstance(btcFormatter);

File keyStorageDir = new File(environment.getRequiredProperty(KeyStorage.KEY_STORAGE_DIR));
bind(File.class).annotatedWith(named(KeyStorage.KEY_STORAGE_DIR)).toInstance(keyStorageDir);

Expand Down
8 changes: 5 additions & 3 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;

import bisq.network.crypto.DecryptedDataTuple;
import bisq.network.crypto.EncryptionService;
Expand All @@ -82,6 +83,7 @@
import org.bitcoinj.core.Coin;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import com.google.common.net.InetAddresses;
Expand Down Expand Up @@ -184,7 +186,7 @@ default void onRequestWalletPassword() {
private final AssetService assetService;
private final TorSetup torSetup;
private final TradeLimits tradeLimits;
private final BSFormatter formatter;
private final CoinFormatter formatter;
@Setter
@Nullable
private Consumer<Runnable> displayTacHandler;
Expand Down Expand Up @@ -270,7 +272,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup,
AssetService assetService,
TorSetup torSetup,
TradeLimits tradeLimits,
BSFormatter formatter) {
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) {


this.p2PNetworkSetup = p2PNetworkSetup;
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/bisq/core/app/WalletAppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.locale.Res;
import bisq.core.user.Preferences;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;

import org.bitcoinj.core.VersionMessage;
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.store.ChainFileLockedException;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.fxmisc.easybind.EasyBind;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class WalletAppSetup {
private final WalletsSetup walletsSetup;
private final BisqEnvironment bisqEnvironment;
private final Preferences preferences;
private final BSFormatter formatter;
private final CoinFormatter formatter;

@SuppressWarnings("FieldCanBeLocal")
private MonadicBinding<String> btcInfoBinding;
Expand All @@ -84,7 +85,7 @@ public WalletAppSetup(WalletsManager walletsManager,
WalletsSetup walletsSetup,
BisqEnvironment bisqEnvironment,
Preferences preferences,
BSFormatter formatter) {
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) {
this.walletsManager = walletsManager;
this.walletsSetup = walletsSetup;
this.bisqEnvironment = bisqEnvironment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import bisq.core.locale.CurrencyUtil;
import bisq.core.trade.statistics.TradeStatistics2;
import bisq.core.trade.statistics.TradeStatisticsManager;
import bisq.core.util.BsqFormatter;
import bisq.core.util.coin.BsqFormatter;

import bisq.common.Timer;
import bisq.common.UserThread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import bisq.core.dao.state.model.governance.ChangeParamProposal;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.locale.Res;
import bisq.core.util.BsqFormatter;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.validation.BtcAddressValidator;
import bisq.core.util.validation.InputValidator;

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/bisq/core/dao/presentation/DaoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import bisq.core.dao.DaoFacade;
import bisq.core.dao.state.model.governance.DaoPhase;
import bisq.core.locale.Res;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;

import java.text.SimpleDateFormat;

Expand All @@ -33,7 +33,7 @@
*/
public class DaoUtil {

public static String getNextPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade, BSFormatter formatter) {
public static String getNextPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade, CoinFormatter formatter) {
final int currentCycleDuration = daoFacade.getCurrentCycleDuration();
long start = daoFacade.getFirstBlockOfPhaseForDisplay(height, phase) + currentCycleDuration;
long end = daoFacade.getLastBlockOfPhaseForDisplay(height, phase) + currentCycleDuration;
Expand All @@ -47,7 +47,7 @@ public static String getNextPhaseDuration(int height, DaoPhase.Phase phase, DaoF
return Res.get("dao.cycle.phaseDurationWithoutBlocks", start, end, startDateTime, endDateTime);
}

public static String getPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade, BSFormatter formatter) {
public static String getPhaseDuration(int height, DaoPhase.Phase phase, DaoFacade daoFacade, CoinFormatter formatter) {
long start = daoFacade.getFirstBlockOfPhaseForDisplay(height, phase);
long end = daoFacade.getLastBlockOfPhaseForDisplay(height, phase);
long duration = daoFacade.getDurationForPhaseForDisplay(phase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import bisq.core.dao.state.model.governance.Issuance;
import bisq.core.dao.state.model.governance.IssuanceType;
import bisq.core.dao.state.model.governance.ParamChange;
import bisq.core.util.BsqFormatter;
import bisq.core.util.coin.BsqFormatter;
import bisq.core.util.ParsingUtils;

import org.bitcoinj.core.Coin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;

import bisq.common.crypto.KeyRing;
import bisq.common.util.MathUtils;

import org.bitcoinj.utils.Fiat;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.List;
Expand All @@ -54,11 +55,11 @@ public class MarketAlerts {
private final User user;
private final PriceFeedService priceFeedService;
private final KeyRing keyRing;
private final BSFormatter formatter;
private final CoinFormatter formatter;

@Inject
public MarketAlerts(OfferBookService offerBookService, MobileNotificationService mobileNotificationService,
User user, PriceFeedService priceFeedService, KeyRing keyRing, BSFormatter formatter) {
User user, PriceFeedService priceFeedService, KeyRing keyRing, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) {
this.offerBookService = offerBookService;
this.mobileNotificationService = mobileNotificationService;
this.user = user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import bisq.core.provider.price.MarketPrice;
import bisq.core.provider.price.PriceFeedService;
import bisq.core.user.User;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;

import bisq.common.util.MathUtils;
Expand All @@ -44,14 +43,12 @@ public class PriceAlert {
private final PriceFeedService priceFeedService;
private final MobileNotificationService mobileNotificationService;
private final User user;
private final BSFormatter formatter;

@Inject
public PriceAlert(PriceFeedService priceFeedService, MobileNotificationService mobileNotificationService, User user, BSFormatter formatter) {
public PriceAlert(PriceFeedService priceFeedService, MobileNotificationService mobileNotificationService, User user) {
this.priceFeedService = priceFeedService;
this.user = user;
this.mobileNotificationService = mobileNotificationService;
this.formatter = formatter;
}

public void onAllServicesInitialized() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/offer/CreateOfferService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import bisq.core.trade.statistics.ReferralIdService;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.CoinUtil;
import bisq.core.util.coin.CoinUtil;

import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import bisq.core.provider.price.PriceFeedService;
import bisq.core.trade.statistics.ReferralIdService;
import bisq.core.user.Preferences;
import bisq.core.util.BsqFormatter;
import bisq.core.util.CoinUtil;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.CoinUtil;

import bisq.network.p2p.P2PService;

Expand Down Expand Up @@ -281,7 +281,7 @@ static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, int

public static Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee, boolean isCurrencyForMakerFeeBtc,
Preferences preferences, PriceFeedService priceFeedService,
BsqFormatter bsqFormatter) {
CoinFormatter bsqFormatter) {
String countryCode = preferences.getUserCountry().code;
String userCurrencyCode = CurrencyUtil.getCurrencyByCountryCode(countryCode).getCode();
return getFeeInUserFiatCurrency(makerFee,
Expand All @@ -293,7 +293,7 @@ public static Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee, boolean i

public static Optional<Volume> getFeeInUserFiatCurrency(Coin makerFee, boolean isCurrencyForMakerFeeBtc,
String userCurrencyCode, PriceFeedService priceFeedService,
BsqFormatter bsqFormatter) {
CoinFormatter bsqFormatter) {
// We use the users currency derived from his selected country.
// We don't use the preferredTradeCurrency from preferences as that can be also set to an altcoin.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
package bisq.core.presentation;

import bisq.core.btc.Balances;
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;
import bisq.core.util.coin.CoinFormatter;

import javax.inject.Inject;
import javax.inject.Named;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
Expand All @@ -38,7 +40,7 @@ public class BalancePresentation {
private final StringProperty lockedBalance = new SimpleStringProperty();

@Inject
public BalancePresentation(Balances balances, BSFormatter formatter) {
public BalancePresentation(Balances balances, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter) {
balances.getAvailableBalance().addListener((observable, oldValue, newValue) -> {
String value = formatter.formatCoinWithCode(newValue);
// If we get full precision the BTC postfix breaks layout so we omit it
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/util/FormattingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

@Slf4j
public class FormattingUtils {
public static final String BTC_FORMATTER_KEY = "BTC";

public final static String RANGE_SEPARATOR = " - ";

private static final MonetaryFormat fiatPriceFormat = new MonetaryFormat().shift(0).minDecimals(4).repeatOptionalDecimals(0, 0);
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/bisq/core/util/ParsingUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bisq.core.util;

import bisq.core.monetary.Price;
import bisq.core.util.coin.CoinFormatter;

import bisq.common.util.MathUtils;

Expand All @@ -13,8 +14,8 @@

@Slf4j
public class ParsingUtils {
public static Coin parseToCoin(String input, BSFormatter bsFormatter) {
return parseToCoin(input, bsFormatter.getMonetaryFormat());
public static Coin parseToCoin(String input, CoinFormatter coinFormatter) {
return parseToCoin(input, coinFormatter.getMonetaryFormat());
}

public static Coin parseToCoin(String input, MonetaryFormat coinFormat) {
Expand Down
Loading