/** * Returns true if the monetary value represented by this instance is greater than that * of the given other Value, otherwise false. */ public boolean isGreaterThan(Value other) { return compareTo(other) > 0; }
/** * Returns true if the monetary value represented by this instance is less than that * of the given other Value, otherwise false. */ public boolean isLessThan(Value other) { return compareTo(other) < 0; }
public static Value max(Value value1, Value value2) { return value1.compareTo(value2) >= 0 ? value1 : value2; }
public static Value min(Value value1, Value value2) { return value1.compareTo(value2) <= 0 ? value1 : value2; }
/** * Check if amount is smaller than the dust limit or if applicable, the minimum deposit. */ private boolean isAmountTooSmall(Value amount) { return amount.compareTo(getLowestAmount(amount)) < 0; }
/** * Check if amount is smaller than the dust limit or if applicable, the minimum deposit. */ private boolean isAmountTooSmall(Value amount) { return amount.compareTo(getLowestAmount(amount.type)) < 0; }
public boolean isDust() { return compareTo(type.getMinNonDust()) < 0; }
public void onMakeTransaction(AbstractAddress toAddress, Value amount, @Nullable TxMessage txMessage) { Intent intent = new Intent(getActivity(), SignTransactionActivity.class); // Decide if emptying wallet or not if (canCompare(lastBalance, amount) && amount.compareTo(lastBalance) == 0) { intent.putExtra(Constants.ARG_EMPTY_WALLET, true); } else { intent.putExtra(Constants.ARG_SEND_VALUE, amount); } intent.putExtra(Constants.ARG_ACCOUNT_ID, account.getId()); intent.putExtra(Constants.ARG_SEND_TO_ADDRESS, toAddress); if (txMessage != null) intent.putExtra(Constants.ARG_TX_MESSAGE, txMessage); startActivityForResult(intent, SIGN_TRANSACTION); state = State.INPUT; }
void queueOnNewBalance() { checkState(lock.isHeldByCurrentThread(), "Lock is held by another thread"); final Value balance = getBalance(); // If balance changed, send event if (balance.compareTo(lastBalance) != 0) { lastBalance = balance; log.info("New balance {}", balance); for (final ListenerRegistration<WalletAccountEventListener> registration : listeners) { registration.executor.execute(new Runnable() { @Override public void run() { registration.listener.onNewBalance(balance); registration.listener.onWalletChanged(TransactionWatcherWallet.this); } }); } } }
/** * Decide if should show errors in the UI. */ private boolean shouldShowErrors(boolean isTyping, Value amountParsed) { if (canCompare(amountParsed, lastBalance) && amountParsed.compareTo(lastBalance) >= 0) { return true; } if (isTyping) return false; if (amountCalculatorLink.isEmpty()) return false; if (amountParsed != null && amountParsed.isZero()) return false; return true; }
@Override public void onMakeTrade(WalletAccount fromAccount, WalletAccount toAccount, Value amount) { Bundle args = new Bundle(); args.putString(Constants.ARG_ACCOUNT_ID, fromAccount.getId()); args.putString(Constants.ARG_SEND_TO_ACCOUNT_ID, toAccount.getId()); if (amount.type.equals(fromAccount.getCoinType())) { // TODO set the empty wallet flag in the fragment // Decide if emptying wallet or not Value lastBalance = fromAccount.getBalance(); if (amount.compareTo(lastBalance) == 0) { args.putSerializable(Constants.ARG_EMPTY_WALLET, true); } else { args.putSerializable(Constants.ARG_SEND_VALUE, amount); } } else if (amount.type.equals(toAccount.getCoinType())) { args.putSerializable(Constants.ARG_SEND_VALUE, amount); } else { throw new IllegalStateException("Amount does not have the expected type: " + amount.type); } replaceFragment(MakeTransactionFragment.newInstance(args), containerRes); }
amountError.setVisibility(View.GONE); if (canCompare(sendAmount, lastBalance) && sendAmount.compareTo(lastBalance) == 0) { amountWarning.setText(R.string.amount_warn_fees_apply); amountWarning.setVisibility(View.VISIBLE); amountParsed.compareTo(lastBalance) > 0) { message = getString(R.string.amount_error_not_enough_money, lastBalance.toFriendlyString()); amountParsed.compareTo(marketInfo.limit) > 0) { message = getString(R.string.trade_error_max_limit, marketInfo.limit.toFriendlyString());
/** * Check if amount is within the minimum and maximum deposit limits and if is dust or if is more * money than currently in the wallet */ private boolean isAmountWithinLimits(Value amount) { boolean isWithinLimits = amount != null && amount.isPositive() && !amount.isDust(); // Check if within min & max deposit limits if (isWithinLimits && marketInfo != null && canCompare(marketInfo.limit, amount)) { isWithinLimits = amount.within(marketInfo.minimum, marketInfo.limit); } // Check if we have the amount if (isWithinLimits && canCompare(lastBalance, amount)) { isWithinLimits = amount.compareTo(lastBalance) <= 0; } return isWithinLimits; }
/** * Check if amount is within the minimum and maximum deposit limits and if is dust or if is more * money than currently in the wallet */ private boolean isAmountWithinLimits(Value amount) { boolean isWithinLimits = !amount.isDust(); // Check if within min & max deposit limits if (isWithinLimits && minimumDeposit != null && maximumDeposit != null && minimumDeposit.isOfType(amount) && maximumDeposit.isOfType(amount)) { isWithinLimits = amount.within(minimumDeposit, maximumDeposit); } // Check if we have the amount if (isWithinLimits && canCompare(lastBalance, amount)) { isWithinLimits = amount.compareTo(lastBalance) <= 0; } return isWithinLimits; }
amountError.setVisibility(View.GONE); if (canCompare(lastBalance, depositAmount) && lastBalance.compareTo(depositAmount) == 0) { amountWarning.setText(R.string.amount_warn_fees_apply); amountWarning.setVisibility(View.VISIBLE); depositAmount.compareTo(lastBalance) > 0) { message = getString(R.string.amount_error_not_enough_money, lastBalance.toFriendlyString()); depositAmount.compareTo(maximumDeposit) > 0) {
boolean isReceiving = valueReceived.compareTo(valueSent) > 0;
/** * Updates the exchange rate and limits for the specific market. * Note: if the current pair is different that the marketInfo pair, do nothing */ private void onMarketUpdate(ShapeShiftMarketInfo marketInfo) { // If not current pair, do nothing if (!marketInfo.isPair(sourceAccount.getCoinType(), destinationType)) return; maximumDeposit = marketInfo.limit; minimumDeposit = marketInfo.minimum; lastRate = marketInfo.rate; amountCalculatorLink.setExchangeRate(lastRate); if (amountCalculatorLink.isEmpty() && lastRate != null) { Value hintValue = sourceAccount.getCoinType().oneCoin(); Value exchangedValue = lastRate.convert(hintValue); Value minerFee100 = marketInfo.rate.minerFee.multiply(100); // If hint value is too small, make it higher to get a no zero exchanged value and // at least 10 times higher than the miner fee for (int tries = 8; tries > 0 && (exchangedValue.isZero() || exchangedValue.compareTo(minerFee100) < 0); tries--) { hintValue = hintValue.multiply(10); exchangedValue = lastRate.convert(hintValue); } amountCalculatorLink.setExchangeRateHints(hintValue); } }