Java Code Examples for org.bitcoinj.core.Coin#divide()

The following examples show how to use org.bitcoinj.core.Coin#divide() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionDetailsActivity.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void setValue(long value) {
    Coin coin = Coin.valueOf(value);

    //for tokens where decimals not equals default value = 8
    int shift = decimals - 8;
    if (shift != 0) {
        BigInteger bi = BigInteger.TEN.pow(shift < 0 ? shift * -1 : shift);
        coin = shift < 0 ? coin.multiply(bi.longValue()) : coin.divide(bi.longValue());
    }

    String sum = WalletManager.getFriendlyBalance(coin) + " " + transaction.getTokenTicker().toUpperCase();
    etTrValue.setText(sum);
}
 
Example 2
Source File: TransHistoryAdapter.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onBindViewHolder(TransHistoryItemHolder holder, final int position) {
        final TransactionItem item = getTxByPosition(position);
        Long txSum = item.getValue();
        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.OnItemClick(position);
                }
            }
        });

        if (item.getConfirmations() < MIN_CONFIRMATIONS) {
//            enableLoader(holder);
            holder.tvTxStatus.setText(R.string.tx_status_wait);
        } else {
//            disableLoader(holder);
            holder.tvTxStatus.setVisibility(View.GONE);
            holder.viewIndicator.setBackground(view.getContext().getResources().getDrawable(R.drawable.transaction_indicator_green));
            holder.viewIndicator.setVisibility(View.VISIBLE);
        }

        Coin coin = Coin.valueOf(txSum);
        //String sumStr = coin.toPlainString() + " " + sharedManager.getCurrentCurrency().toUpperCase();

        //for tokens where decimals not equals default value = 8
        int shift = getDecimal(item, tokensToRequest) - 8;
        if (shift != 0) {
            BigInteger bi = BigInteger.TEN.pow(shift < 0 ? shift * -1 : shift);
            coin = shift < 0 ? coin.multiply(bi.longValue()) : coin.divide(bi.longValue());
        }

        String sumStr = coin.toPlainString();

        holder.tvTransactionSum.setText(item.isOut() ? "-" + sumStr + " " + item.getTokenTicker() : sumStr + " " + item.getTokenTicker());
        holder.tvDate.setText(CalendarHelper.parseDateToddMMyyyy(item.getTime() * 1000));

//        if (!item.isOut()) {
//            holder.viewIndicator.setBackground(view.getContext().getResources().getDrawable(R.drawable.transaction_indicator_green));
//        } else {
//            holder.viewIndicator.setBackground(view.getContext().getResources().getDrawable(R.drawable.transaction_indicator_red));
//        }

//        holder.tvTokenTicker.setText(item.getTokenTicker());
    }
 
Example 3
Source File: FiatAccountsView.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
private void onSaveNewAccount(PaymentAccount paymentAccount) {
    Coin maxTradeLimitAsCoin = paymentAccount.getPaymentMethod().getMaxTradeLimitAsCoin("USD");
    Coin maxTradeLimitSecondMonth = maxTradeLimitAsCoin.divide(2L);
    Coin maxTradeLimitFirstMonth = maxTradeLimitAsCoin.divide(4L);
    if (paymentAccount instanceof F2FAccount) {
        new Popup().information(Res.get("payment.f2f.info"))
                .width(700)
                .closeButtonText(Res.get("payment.f2f.info.openURL"))
                .onClose(() -> GUIUtil.openWebPage("https://docs.bisq.network/trading-rules.html#f2f-trading"))
                .actionButtonText(Res.get("shared.iUnderstand"))
                .onAction(() -> doSaveNewAccount(paymentAccount))
                .show();
    } else if (paymentAccount instanceof HalCashAccount) {
        // HalCash has no chargeback risk so we don't show the text from payment.limits.info.
        new Popup().information(Res.get("payment.halCash.info"))
                .width(700)
                .closeButtonText(Res.get("shared.cancel"))
                .actionButtonText(Res.get("shared.iUnderstand"))
                .onAction(() -> doSaveNewAccount(paymentAccount))
                .show();
    } else {

        String limitsInfoKey = "payment.limits.info";
        String initialLimit = formatter.formatCoinWithCode(maxTradeLimitFirstMonth);

        if (PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod(), paymentAccount.getTradeCurrencies())) {
            limitsInfoKey = "payment.limits.info.withSigning";
            initialLimit = formatter.formatCoinWithCode(OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT);
        }

        new Popup().information(Res.get(limitsInfoKey,
                initialLimit,
                formatter.formatCoinWithCode(maxTradeLimitSecondMonth),
                formatter.formatCoinWithCode(maxTradeLimitAsCoin)))
                .width(700)
                .closeButtonText(Res.get("shared.cancel"))
                .actionButtonText(Res.get("shared.iUnderstand"))
                .onAction(() -> {
                    final String currencyName = Config.baseCurrencyNetwork().getCurrencyName();
                    if (paymentAccount instanceof ClearXchangeAccount) {
                        new Popup().information(Res.get("payment.clearXchange.info", currencyName, currencyName))
                                .width(900)
                                .closeButtonText(Res.get("shared.cancel"))
                                .actionButtonText(Res.get("shared.iConfirm"))
                                .onAction(() -> doSaveNewAccount(paymentAccount))
                                .show();
                    } else if (paymentAccount instanceof WesternUnionAccount) {
                        new Popup().information(Res.get("payment.westernUnion.info"))
                                .width(700)
                                .closeButtonText(Res.get("shared.cancel"))
                                .actionButtonText(Res.get("shared.iUnderstand"))
                                .onAction(() -> doSaveNewAccount(paymentAccount))
                                .show();
                    } else if (paymentAccount instanceof MoneyGramAccount) {
                        new Popup().information(Res.get("payment.moneyGram.info"))
                                .width(700)
                                .closeButtonText(Res.get("shared.cancel"))
                                .actionButtonText(Res.get("shared.iUnderstand"))
                                .onAction(() -> doSaveNewAccount(paymentAccount))
                                .show();
                    } else if (paymentAccount instanceof CashDepositAccount) {
                        new Popup().information(Res.get("payment.cashDeposit.info"))
                                .width(700)
                                .closeButtonText(Res.get("shared.cancel"))
                                .actionButtonText(Res.get("shared.iConfirm"))
                                .onAction(() -> doSaveNewAccount(paymentAccount))
                                .show();
                    } else if (paymentAccount instanceof RevolutAccount) {
                        new Popup().information(Res.get("payment.revolut.info"))
                                .width(700)
                                .closeButtonText(Res.get("shared.cancel"))
                                .actionButtonText(Res.get("shared.iConfirm"))
                                .onAction(() -> doSaveNewAccount(paymentAccount))
                                .show();
                    } else if (paymentAccount instanceof USPostalMoneyOrderAccount) {
                        new Popup().information(Res.get("payment.usPostalMoneyOrder.info"))
                                .width(700)
                                .closeButtonText(Res.get("shared.cancel"))
                                .actionButtonText(Res.get("shared.iUnderstand"))
                                .onAction(() -> doSaveNewAccount(paymentAccount))
                                .show();
                    } else {
                        doSaveNewAccount(paymentAccount);
                    }
                })
                .show();
    }
}