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 List<CoinType> typesFromAddress(String address) throws AddressMalformedException { return GenericUtils.getPossibleTypes(address); }
public static boolean hasMultipleTypes(AbstractAddress address) { return hasMultipleTypes(address.toString()); }
private void updateLabel() { label = resolveLabel(receiveAddress); if (label != null) { addressLabelView.setText(label); addressLabelView.setTypeface(Typeface.DEFAULT); addressView.setText( GenericUtils.addressSplitToGroups(receiveAddress)); addressView.setVisibility(View.VISIBLE); } else { addressLabelView.setText( GenericUtils.addressSplitToGroupsMultiline(receiveAddress)); addressLabelView.setTypeface(Typeface.MONOSPACE); addressView.setVisibility(View.GONE); } }
@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()); } }
@Test public void getPossibleTypes() throws AddressMalformedException { List<CoinType> types = GenericUtils.getPossibleTypes("BPa5FmbZRGpmNfy4qaUzarXwSSFbJKFRMQ"); assertTrue(types.contains(BlackcoinMain.get())); assertTrue(types.contains(NuBitsMain.get())); assertTrue(GenericUtils.hasMultipleTypes("BPa5FmbZRGpmNfy4qaUzarXwSSFbJKFRMQ")); // Many coins share Bitcoin's multisig addresses... types = GenericUtils.getPossibleTypes("3Lp1ZbdoDfZF21BLMBpctM6CrM6j4t2JyU"); assertTrue(types.contains(BitcoinMain.get())); assertTrue(types.contains(LitecoinMain.get())); assertTrue(types.contains(FeathercoinMain.get())); assertTrue(types.contains(DigitalcoinMain.get())); assertTrue(GenericUtils.hasMultipleTypes("3Lp1ZbdoDfZF21BLMBpctM6CrM6j4t2JyU")); // Address method AbstractAddress address = BlackcoinMain.get().newAddress("BPa5FmbZRGpmNfy4qaUzarXwSSFbJKFRMQ"); types = GenericUtils.getPossibleTypes(address); assertTrue(types.contains(BlackcoinMain.get())); assertTrue(types.contains(NuBitsMain.get())); assertTrue(GenericUtils.hasMultipleTypes(address)); // Classic Bitcoin addresses should have only one type types = GenericUtils.getPossibleTypes("1AjnxP4frz7Nb4v2soLnhN2uV9UocqvaGH"); assertTrue(types.contains(BitcoinMain.get())); assertEquals(1, types.size()); assertFalse(GenericUtils.hasMultipleTypes("1AjnxP4frz7Nb4v2soLnhN2uV9UocqvaGH")); }
final int satoshis = (int) (absValue % units); if (isShiftPossible(units, satoshis, 100)) { formatedValue = String.format(Locale.US, "%d.%02d", coins, getShiftedCents(units, satoshis, 100)); } else if (isShiftPossible(units, satoshis, 10000)) { formatedValue = String.format(Locale.US, "%d.%04d", coins, getShiftedCents(units, satoshis, 10000)); } else if (isShiftPossible(units, satoshis, 1000000)) { formatedValue = String.format(Locale.US, "%d.%06d", coins, getShiftedCents(units, satoshis, 1000000)); return formatValue(unitExponent, value, plusSign, minusSign, precision + 2, shift, removeFinalZeroes);
public static String addressSplitToGroupsMultiline(final NxtAddress address) { // Nxt addresses are short, so no need to split them in multiple lines return addressSplitToGroups(address); }
public static String formatFiatValue(Value fiat) { return formatFiatValue(fiat, 2, 0); }
public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value, @Nonnull final String plusSign, @Nonnull final String minusSign, final int precision, final int shift) { return formatValue(type.getUnitExponent(), value, plusSign, minusSign, precision, shift, false); }
public static String addressSplitToGroupsMultiline(final AbstractAddress address) { if (address instanceof NxtAddress) { return addressSplitToGroupsMultiline((NxtAddress) address); } else if (address instanceof BitAddress) { return addressSplitToGroupsMultiline((BitAddress) address); } else { throw new RuntimeException("Unsupported address: " + address.getClass()); } }
parseAddress(GenericUtils.fixAddress(input)); updateView(); addressError.setVisibility(View.GONE); parseAddress(GenericUtils.fixAddress(input)); } else {
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); } }
private void updateView() { String label = AddressBookProvider.resolveLabel(getContext(), address); if (label != null) { addressLabelView.setText(label); addressLabelView.setTypeface(Typeface.DEFAULT); addressView.setText( GenericUtils.addressSplitToGroups(address)); addressView.setVisibility(View.VISIBLE); } else { if (isMultiLine) { addressLabelView.setText( GenericUtils.addressSplitToGroupsMultiline(address)); } else { addressLabelView.setText( GenericUtils.addressSplitToGroups(address)); } addressLabelView.setTypeface(Typeface.MONOSPACE); addressView.setVisibility(View.GONE); } if (isIconShown) { iconView.setVisibility(VISIBLE); iconView.setContentDescription((address.getType()).getName()); iconView.setImageResource(WalletUtils.getIconRes(address.getType())); } else { iconView.setVisibility(GONE); } } }
public static String addressSplitToGroups(final AbstractAddress address) { if (address instanceof NxtAddress) { return addressSplitToGroups((NxtAddress) address); } else if (address instanceof BitAddress) { return addressSplitToGroups((BitAddress) address); } else { throw new RuntimeException("Unsupported address: " + address.getClass()); } }
private void updateLocalRates() { if (localRates != null) { if (txVisualizer != null && localRates.containsKey(sourceType.getSymbol())) { txVisualizer.setExchangeRate(localRates.get(sourceType.getSymbol())); } if (tradeWithdrawAmount != null && localRates.containsKey(tradeWithdrawAmount.type.getSymbol())) { ExchangeRate rate = localRates.get(tradeWithdrawAmount.type.getSymbol()); Value fiatAmount = rate.convert(tradeWithdrawAmount); tradeWithdrawSendOutput.setAmountLocal(GenericUtils.formatFiatValue(fiatAmount)); tradeWithdrawSendOutput.setSymbolLocal(fiatAmount.type.getSymbol()); } } }
public static String formatFiatValue(final Value fiat, final int precision, final int shift) { return formatValue(fiat.smallestUnitExponent(), fiat, "", "-", precision, shift, false); }
@Override public void bindView(final View view, final Context context, final Cursor cursor) { final String label = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_LABEL)); final String coinId = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_COIN_ID)); final String addressStr = cursor.getString(cursor.getColumnIndexOrThrow(AddressBookProvider.KEY_ADDRESS)); CoinType type = CoinID.typeFromId(coinId); final ViewGroup viewGroup = (ViewGroup) view; final TextView labelView = (TextView) viewGroup.findViewById(R.id.address_book_row_label); labelView.setText(label); final TextView addressView = (TextView) viewGroup.findViewById(R.id.address_book_row_address); try { addressView.setText(GenericUtils.addressSplitToGroupsMultiline(type.newAddress(addressStr))); } catch (AddressMalformedException e) { ACRA.getErrorReporter().handleSilentException(e); addressView.setText(addressStr); } }
public static boolean hasMultipleTypes(String addressStr) { try { return getPossibleTypes(addressStr).size() > 1; } catch (AddressMalformedException e) { return false; } } }
public static String formatCoinValue(@Nonnull final ValueType type, @Nonnull final Monetary value) { return formatCoinValue(type, value, "", "-", 8, 0); }