Exemplo n.º 1
0
  private void validateAmount(boolean isTyping) {
    Value amountParsed = amountCalculatorLink.getPrimaryAmount();

    if (isAmountValid(amountParsed)) {
      sendAmount = amountParsed;
      amountError.setVisibility(View.GONE);
      // Show warning that fees apply when entered the full amount inside the pocket
      if (canCompare(sendAmount, lastBalance) && sendAmount.compareTo(lastBalance) == 0) {
        amountWarning.setText(R.string.amount_warn_fees_apply);
        amountWarning.setVisibility(View.VISIBLE);
      } else {
        amountWarning.setVisibility(View.GONE);
      }
    } else {
      amountWarning.setVisibility(View.GONE);
      // ignore printing errors for null and zero amounts
      if (shouldShowErrors(isTyping, amountParsed)) {
        sendAmount = null;
        if (amountParsed == null) {
          amountError.setText(R.string.amount_error);
        } else if (amountParsed.isNegative()) {
          amountError.setText(R.string.amount_error_negative);
        } else if (!isAmountWithinLimits(amountParsed)) {
          String message = getString(R.string.error_generic);
          // If the amount is dust or lower than the deposit limit
          if (isAmountTooSmall(amountParsed)) {
            Value minAmount = getLowestAmount(amountParsed.type);
            message = getString(R.string.amount_error_too_small, minAmount.toFriendlyString());
          } else {
            // If we have the amount
            if (canCompare(lastBalance, amountParsed) && amountParsed.compareTo(lastBalance) > 0) {
              message =
                  getString(R.string.amount_error_not_enough_money, lastBalance.toFriendlyString());
            }

            if (marketInfo != null
                && canCompare(marketInfo.limit, amountParsed)
                && amountParsed.compareTo(marketInfo.limit) > 0) {
              message =
                  getString(R.string.trade_error_max_limit, marketInfo.limit.toFriendlyString());
            }
          }
          amountError.setText(message);
        } else { // Should not happen, but show a generic error
          amountError.setText(R.string.amount_error);
        }
        amountError.setVisibility(View.VISIBLE);
      } else {
        amountError.setVisibility(View.GONE);
      }
    }
    updateView();
  }
Exemplo n.º 2
0
  public void onMakeTransaction(Address toAddress, Value amount) {
    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, pocket.getId());
    intent.putExtra(Constants.ARG_SEND_TO_ADDRESS, toAddress);

    startActivityForResult(intent, SIGN_TRANSACTION);
  }
Exemplo n.º 3
0
  /**
   * 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;
  }
Exemplo n.º 4
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;
 }