Java Code Examples for org.web3j.utils.Convert#fromWei()

The following examples show how to use org.web3j.utils.Convert#fromWei() . 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: Amount.java    From besu with Apache License 2.0 6 votes vote down vote up
public Amount subtract(final Amount subtracting) {

    final Unit denominator;
    if (unit.getWeiFactor().compareTo(subtracting.unit.getWeiFactor()) < 0) {
      denominator = unit;
    } else {
      denominator = subtracting.unit;
    }

    final BigDecimal result =
        Convert.fromWei(
            Convert.toWei(value, unit).subtract(Convert.toWei(subtracting.value, subtracting.unit)),
            denominator);

    return new Amount(result, denominator);
  }
 
Example 2
Source File: ConfirmationActivity.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private void onGasSettings(GasSettings gasSettings) {
    String gasPrice = BalanceUtils.weiToGwei(gasSettings.gasPrice) + " " + C.GWEI_UNIT;
    gasPriceText.setText(gasPrice);
    gasLimitText.setText(gasSettings.gasLimit.toString());

    BigDecimal networkFeeBD = new BigDecimal(gasSettings
                                                     .gasPrice.multiply(gasSettings.gasLimit));

    String networkFee = BalanceUtils.weiToEth(networkFeeBD).toPlainString() + " " + viewModel.getNetworkSymbol(chainId);
    networkFeeText.setText(networkFee);

    if (confirmationType == WEB3TRANSACTION)
    {
        //update amount
        BigDecimal ethValueBD = amount.add(networkFeeBD);

        //convert to ETH
        ethValueBD = Convert.fromWei(ethValueBD, Convert.Unit.ETHER);
        String valueUpdate = getEthString(ethValueBD.doubleValue());
        valueText.setText(valueUpdate);
    }
}
 
Example 3
Source File: TransHistoryAdapter.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private void retryTransaction(TransactionResponse item) {
    String transValue = "";
    BigInteger value = new BigInteger(item.getValue().substring(2));
    BigDecimal decimal = new BigDecimal(value);
    BigDecimal formatted = Convert.fromWei(decimal, Convert.Unit.ETHER);
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
    symbols.setDecimalSeparator('.');
    DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
    decimalFormat.setRoundingMode(RoundingMode.DOWN);
    transValue = decimalFormat.format(formatted);

    Intent intent = new Intent(context, SendingCurrencyActivity.class);
    intent.putExtra(Extras.WALLET_NUMBER, item.getTo());
    intent.putExtra(Extras.AMOUNT_TO_SEND, transValue);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 4
Source File: TransactionDetailsActivity.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.btn_repeat)
public void onRepeatTransactionClick() {
    String transValue = "";
    String valueWithoutPrefix = transaction.getValue().substring(2);
    BigInteger value = new BigInteger(valueWithoutPrefix, 16);
    BigDecimal decimal = new BigDecimal(value);
    BigDecimal formatted = Convert.fromWei(decimal, Convert.Unit.ETHER);
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
    symbols.setDecimalSeparator('.');
    DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN_EXT, symbols);
    transValue = decimalFormat.format(formatted);

    Intent intent = new Intent(this, SendingCurrencyActivity.class);
    intent.putExtra(Extras.WALLET_NUMBER, transaction.getTo());
    intent.putExtra(Extras.AMOUNT_TO_SEND, transValue);
    startActivity(intent);
    overridePendingTransition(R.anim.slide_in_left, R.anim.no_slide);
}
 
Example 5
Source File: TransHistoryAdapter.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private void retryTransaction(TransactionResponse item) {
    String transValue = "";
    BigInteger value = new BigInteger(item.getValue());
    BigDecimal decimal = new BigDecimal(value);
    BigDecimal formatted = Convert.fromWei(decimal, Convert.Unit.ETHER);
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
    symbols.setDecimalSeparator('.');
    DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
    decimalFormat.setRoundingMode(RoundingMode.DOWN);
    transValue = decimalFormat.format(formatted);

    Intent intent = new Intent(context, SendingCurrencyActivity.class);
    intent.putExtra(Extras.WALLET_NUMBER, item.getTo());
    intent.putExtra(Extras.AMOUNT_TO_SEND, transValue);
    if (item.getTicker() != null) {
        intent.putExtra(Extras.TOKEN_CODE_EXTRA, item.getTicker());
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 6
Source File: TransHistoryAdapter.java    From guarda-android-wallets with GNU General Public License v3.0 6 votes vote down vote up
private void retryTransaction(TransactionResponse item) {
    String transValue = "";
    BigInteger value = new BigInteger(item.getValue().substring(2));
    BigDecimal decimal = new BigDecimal(value);
    BigDecimal formatted = Convert.fromWei(decimal, Convert.Unit.ETHER);
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
    symbols.setDecimalSeparator('.');
    DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
    decimalFormat.setRoundingMode(RoundingMode.DOWN);
    transValue = decimalFormat.format(formatted);

    Intent intent = new Intent(context, SendingCurrencyActivity.class);
    intent.putExtra(Extras.WALLET_NUMBER, item.getTo());
    intent.putExtra(Extras.AMOUNT_TO_SEND, transValue);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 7
Source File: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
public static BigDecimal getBalanceInEther(Credentials credentials,
                                           Web3j web3j) throws Exception {
    EthGetBalance ethGetBalance = web3j.ethGetBalance(credentials.getAddress(),
                                                      DefaultBlockParameterName.LATEST).send();

    return Convert.fromWei(ethGetBalance.getBalance().toString(),
                           Convert.Unit.ETHER);
}
 
Example 8
Source File: SendingTokensActivity.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void updateFee() {

        BigInteger defaultGasLimit = BigInteger.valueOf(DEFAULT_GAS_LIMIT_FOR_CONTRACT);
        BigInteger fee = gasPrice.multiply(defaultGasLimit);
        currentFeeEth = Convert.fromWei(new BigDecimal(fee), Convert.Unit.ETHER);
        DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
        symbols.setDecimalSeparator('.');
        DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
        String feeStr = decimalFormat.format(currentFeeEth);
        etFeeAmount.setText(feeStr);
    }
 
Example 9
Source File: MainActivity.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 5 votes vote down vote up
public void GetFee(){
    setGasPrice(getGasPrice());
    setGasLimit(getGasLimit());

    BigDecimal fee = BigDecimal.valueOf(mGasPrice.doubleValue()*mGasLimit.doubleValue());
    BigDecimal feeresult = Convert.fromWei(fee.toString(),Convert.Unit.ETHER);
    tv_fee.setText(feeresult.toPlainString() + " ETH");
}
 
Example 10
Source File: TransactionDetailsActivity.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void setValue(String respValue) {
//        BigInteger value = (new BigDecimal(respValue).multiply(BigDecimal.valueOf(1000000000000000000.0))).toBigInteger();
        String valueWithoutPrefix = respValue.substring(2);
        BigInteger value = new BigInteger(valueWithoutPrefix, 16);
        BigDecimal decimal = new BigDecimal(value);
        BigDecimal formatted = Convert.fromWei(decimal, Convert.Unit.ETHER);
        DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
        symbols.setDecimalSeparator('.');
        DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN_EXT, symbols);
        decimalFormat.setRoundingMode(RoundingMode.DOWN);

        String valueStr = (isDebit(walletManager.getWalletFriendlyAddress(), transaction.getTo()) ? "+" : "-")
                + " " + decimalFormat.format(formatted);
        etTrValue.setText(String.format("%s %s", valueStr, Common.MAIN_CURRENCY.toUpperCase()));
    }
 
Example 11
Source File: SendingTokensActivity.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private void updateFee() {
    BigInteger defaultGasLimit = BigInteger.valueOf(DEFAULT_GAS_LIMIT_FOR_CONTRACT);
    BigInteger fee = gasPrice.multiply(defaultGasLimit);
    currentFeeEth = Convert.fromWei(new BigDecimal(fee), Convert.Unit.ETHER);
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
    symbols.setDecimalSeparator('.');
    DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
    String feeStr = decimalFormat.format(currentFeeEth);
    etFeeAmount.setText(feeStr);
}
 
Example 12
Source File: BalanceUtils.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
public static BigDecimal weiToEth(BigDecimal wei) {
    return Convert.fromWei(wei, Convert.Unit.ETHER);
}
 
Example 13
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) {
//        try {
            final TransactionResponse item = getTxByPosition(position);

            holder.rootView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (listener != null) {
                        listener.OnItemClick(position);
                    }
                }
            });

            if (item.getConfirmations() == null) {
//            enableLoader(holder);
                holder.tvTxStatus.setTextColor(view.getContext().getResources().getColor(R.color.txStatusGrey));
                holder.tvTxStatus.setText(R.string.tx_status_node);
//            holder.viewIndicator.setVisibility(View.INVISIBLE);
                if (repeatHandler == null || repeatHandler.isInterrupted()) {
//                startUpdateTask();
                }
            } else if (Integer.parseInt(item.getConfirmations()) < MIN_CONFIRMATIONS) {
//            starCheckTxTask(item.getHash());
//            enableLoader(holder);
//            holder.viewIndicator.setVisibility(View.INVISIBLE);
                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);
            }

//            BigInteger value = (new BigDecimal(item.getValue()).multiply(BigDecimal.valueOf(1000000000000000000.0))).toBigInteger();
            String valueWithoutPrefix = item.getValue().substring(2);

            BigInteger value = new BigInteger(valueWithoutPrefix, 16);
//            value = value.multiply(BigInteger.valueOf(100000000000000000l));
            BigDecimal decimal = new BigDecimal(value);
            BigDecimal formatted = Convert.fromWei(decimal, Convert.Unit.ETHER);
            DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
            symbols.setDecimalSeparator('.');
            DecimalFormat decimalFormat = new DecimalFormat(ETH_SHOW_PATTERN, symbols);
            decimalFormat.setRoundingMode(RoundingMode.DOWN);

            String valueStr = (isDebit(walletManager.getWalletFriendlyAddress(), item.getTo()) ? "+" : "-")
                    + " " + decimalFormat.format(formatted) + " " + Common.MAIN_CURRENCY.toUpperCase();
            holder.tvTransactionSum.setText(valueStr);

//        if (isDebit(walletManager.getWalletFriendlyAddress(), item.getTo())) {
//            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));
//        }
            long time = Long.parseLong(item.getTimeStamp()) * 1000;
            holder.tvDate.setText(CalendarHelper.parseDateToddMMyyyy(time));
//        } catch (Exception e) {
//            Log.e("flint", "TransHistoryAdapter.onBindViewHolder... exception: " + e.toString());
//        }
    }
 
Example 14
Source File: BalanceUtils.java    From trust-wallet-android-source with GNU General Public License v3.0 4 votes vote down vote up
public static BigDecimal weiToEth(BigInteger wei) {
    return Convert.fromWei(new BigDecimal(wei), Convert.Unit.ETHER);
}
 
Example 15
Source File: BalanceUtils.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
public static BigDecimal weiToGweiBI(BigInteger wei) {
    return Convert.fromWei(new BigDecimal(wei), Convert.Unit.GWEI);
}
 
Example 16
Source File: Balance.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 4 votes vote down vote up
public BigDecimal getInEther() {
    return Convert.fromWei(String.valueOf(mEtherbalance.getBalance()), Convert.Unit.ETHER);
}
 
Example 17
Source File: BalanceUtils.java    From ETHWallet with GNU General Public License v3.0 4 votes vote down vote up
public static BigDecimal weiToGweiBI(BigInteger wei) {
    return Convert.fromWei(new BigDecimal(wei), Convert.Unit.GWEI);
}
 
Example 18
Source File: BalanceUtils.java    From trust-wallet-android-source with GNU General Public License v3.0 4 votes vote down vote up
public static BigDecimal weiToGweiBI(BigInteger wei) {
    return Convert.fromWei(new BigDecimal(wei), Convert.Unit.GWEI);
}
 
Example 19
Source File: BalanceUtils.java    From Upchain-wallet with GNU Affero General Public License v3.0 4 votes vote down vote up
public static BigDecimal weiToGweiBI(BigInteger wei) {
    return Convert.fromWei(new BigDecimal(wei), Convert.Unit.GWEI);
}
 
Example 20
Source File: BalanceUtils.java    From Upchain-wallet with GNU Affero General Public License v3.0 4 votes vote down vote up
public static BigDecimal weiToEth(BigInteger wei) {
    return Convert.fromWei(new BigDecimal(wei), Convert.Unit.ETHER);
}