public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value, final int precision, final int shift) { return formatCoinValue(type, value, "", "-", precision, shift); }
public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value) { return formatCoinValue(type, value, "", "-", 8, 0); }
public static String formatValue(@Nonnull final Value value) { return formatCoinValue(value.type, value.toCoin(), "", "-", 8, 0); }
builder.append(GenericUtils.formatCoinValue(type, amount, true)); questionMarkHasBeenOutput = true;
@Override public void bindView(final View view, final Context context, final Cursor cursor) { final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(cursor); final boolean isDefaultCurrency = exchangeRate.currencyCodeId.equals(defaultCurrency); view.setBackgroundResource(isDefaultCurrency ? R.color.bg_list_selected : R.color.bg_list); final TextView currencyCodeView = (TextView) view.findViewById(R.id.exchange_rate_row_currency_code); currencyCodeView.setText(exchangeRate.currencyCodeId); final TextView currencyNameView = (TextView) view.findViewById(R.id.exchange_rate_row_currency_name); String currencyName = WalletUtils.getCurrencyName(exchangeRate.currencyCodeId); if (currencyName != null) { currencyNameView.setText(currencyName); currencyNameView.setVisibility(View.VISIBLE); } else { currencyNameView.setText(null); currencyNameView.setVisibility(View.INVISIBLE); } final Amount rateAmountUnitView = (Amount) view.findViewById(R.id.exchange_rate_row_rate_unit); rateAmountUnitView.setAmount(GenericUtils.formatCoinValue(type, rateBase, true)); rateAmountUnitView.setSymbol(type.getSymbol()); final Amount rateAmountView = (Amount) view.findViewById(R.id.exchange_rate_row_rate); Value fiatAmount = exchangeRate.rate.convert(type, rateBase); rateAmountView.setAmount(GenericUtils.formatFiatValue(fiatAmount)); rateAmountView.setSymbol(fiatAmount.type.getSymbol()); } }
public void setAmount(Value value) { amount.setAmount(GenericUtils.formatCoinValue(value.type, value, true)); amount.setSymbol(value.type.getSymbol()); amount.setVisibility(View.VISIBLE); }
private void bindView(View row, WalletAccount account) { final ImageView icon = (ImageView) row.findViewById(R.id.account_icon); icon.setImageResource(Constants.COINS_ICONS.get(account.getCoinType())); final TextView rowLabel = (TextView) row.findViewById(R.id.account_description); rowLabel.setText(account.getDescriptionOrCoinName()); final Amount rowValue = (Amount) row.findViewById(R.id.account_balance); rowValue.setAmount(GenericUtils.formatFiatValue(account.getBalance(), 4, 0)); rowValue.setSymbol(account.getCoinType().getSymbol()); ExchangeRatesProvider.ExchangeRate rate = rates.get(account.getCoinType().getSymbol()); final Amount rowBalanceRateValue = (Amount) row.findViewById(R.id.account_balance_rate); if (rate != null && account.getCoinType() != null) { Value localAmount = rate.rate.convert(account.getBalance()); GenericUtils.formatCoinValue(localAmount.type, localAmount,true); rowBalanceRateValue.setAmount(GenericUtils.formatFiatValue(localAmount, 2, 0)); rowBalanceRateValue.setSymbol(localAmount.type.getSymbol()); rowBalanceRateValue.setVisibility(View.VISIBLE); } else { rowBalanceRateValue.setVisibility(View.GONE); } final Amount rowRateValue = (Amount) row.findViewById(R.id.exchange_rate_row_rate); if (rate != null && account.getCoinType() != null) { Value localAmount = rate.rate.convert(account.getCoinType().oneCoin()); GenericUtils.formatCoinValue(localAmount.type, localAmount, true); rowRateValue.setAmount(GenericUtils.formatFiatValue(localAmount, 2, 0)); rowRateValue.setSymbol(localAmount.type.getSymbol()); rowRateValue.setVisibility(View.VISIBLE); } else { rowRateValue.setVisibility(View.GONE); } }
output.setSymbol(null); } else if (hasFee) { output.setAmount(GenericUtils.formatCoinValue(type, feeAmount)); output.setSymbol(symbol); output.setIsFee(true); output.setAmount(GenericUtils.formatCoinValue(type, outputAmount)); output.setSymbol(symbol); output.setLabelAndAddress(txo.getAddress());
assertEquals("1.3370", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(133700000), 6, 0)); assertEquals("0.001337", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(133700), 6, 0)); assertEquals("1.3370", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(133700000), 4, 0)); assertEquals("0.0013", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(133700), 4, 0)); assertEquals("1.34", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(133700000), 2, 0)); assertEquals("1.34", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(133700000), 2, 0)); assertEquals("0.0013", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(133700), 2, 0)); assertEquals("1.00", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100000001), 6, 0)); assertEquals("1.00000001", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100000001), 8, 0)); assertEquals("1.00", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100000010), 6, 0)); assertEquals("1.00000010", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100000010), 8, 0)); assertEquals("1.000001", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100000100), 6, 0)); assertEquals("1.000001", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100000100), 8, 0)); assertEquals("1.000010", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100001000), 6, 0)); assertEquals("1.000010", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100001000), 8, 0)); assertEquals("1.0010", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100100001), 6, 0)); assertEquals("1.00100001", GenericUtils.formatCoinValue(BitcoinMain.get(), Coin.valueOf(100100001), 8, 0)); assertEquals("3.141592", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(3141592), 6, 0)); assertEquals("0.027182", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(27182), 6, 0)); assertEquals("3.1416", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(3141592), 4, 0)); assertEquals("0.0272", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(27182), 4, 0)); assertEquals("3.14", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(3141592), 2, 0)); assertEquals("0.03", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(27182), 2, 0)); assertEquals("1.00", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(1000001), 4, 0)); assertEquals("1.000001", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(1000001), 6, 0)); assertEquals("1.000001", GenericUtils.formatCoinValue(PeercoinMain.get(), Coin.valueOf(1000001), 8, 0));
output.setAmount(GenericUtils.formatCoinValue(type, outputAmount)); output.setSymbol(symbol); address = txo.getAddress(); if (isSending && feeAmount != null && !feeAmount.isZero()) { fee.setVisibility(View.VISIBLE); fee.setAmount(GenericUtils.formatCoinValue(type, feeAmount)); fee.setSymbol(symbol);
@Override public void updateView() { if (isRemoving() || isDetached()) return; if (currentBalance != null) { String newBalanceStr = GenericUtils.formatCoinValue(type, currentBalance, isFullAmount ? AMOUNT_FULL_PRECISION : AMOUNT_SHORT_PRECISION, AMOUNT_SHIFT); accountBalance.setAmount(newBalanceStr); } if (currentBalance != null && exchangeRate != null && getView() != null) { try { Value fiatAmount = exchangeRate.rate.convert(type, currentBalance); accountExchangedBalance.setAmount(GenericUtils.formatFiatValue(fiatAmount)); accountExchangedBalance.setSymbol(fiatAmount.type.getSymbol()); } catch (Exception e) { // Should not happen accountExchangedBalance.setAmount(""); accountExchangedBalance.setSymbol("ERROR"); } } swipeContainer.setRefreshing(pocket.isLoading()); if (adapter != null) adapter.clearLabelCache(); }
@Test public void testAltChainsGoodAmount() throws Exception { byte[] hash160 = BitAddress.from(BitcoinMain.get(), MAINNET_GOOD_ADDRESS).getHash160(); String goodAddressStr; BitAddress goodAddress; // Litecoin goodAddress = BitAddress.from(LTC, hash160); goodAddressStr = goodAddress.toString(); testObject = new CoinURI(LTC, "litecoin:" + goodAddressStr + "?amount=12.34"); assertEquals("12.34", GenericUtils.formatCoinValue(LTC, testObject.getAmount())); // Dogecoin goodAddress = BitAddress.from(DOGE, hash160); goodAddressStr = goodAddress.toString(); testObject = new CoinURI(DOGE, "dogecoin:" + goodAddressStr + "?amount=12.34"); assertEquals("12.34", GenericUtils.formatCoinValue(DOGE, testObject.getAmount())); // Peercoin goodAddress = BitAddress.from(PPC, hash160); goodAddressStr = goodAddress.toString(); testObject = new CoinURI(PPC, "peercoin:" + goodAddressStr + "?amount=12.34"); assertEquals("12.34", GenericUtils.formatCoinValue(PPC, testObject.getAmount())); // Darkcoin goodAddress = BitAddress.from(DASH, hash160); goodAddressStr = goodAddress.toString(); testObject = new CoinURI(DASH, "dash:" + goodAddressStr + "?amount=12.34"); assertEquals("12.34", GenericUtils.formatCoinValue(DASH, testObject.getAmount())); }