Пример #1
0
  private void validateAddress(boolean isTyping) {
    if (address == null) {
      String input = sendToAddressView.getText().toString().trim();

      try {
        if (!input.isEmpty()) {
          // Process fast the input string
          if (processInput(input)) return;

          // Try to fix address if needed
          parseAddress(GenericUtils.fixAddress(input));
        } else {
          // empty field should not raise error message
          clearAddress(false);
        }
        addressError.setVisibility(View.GONE);
      } catch (final AddressFormatException x) {
        // could not decode address at all
        if (!isTyping) {
          clearAddress(false);
          addressError.setText(R.string.address_error);
          addressError.setVisibility(View.VISIBLE);
        }
      }
      updateView();
    }
  }
Пример #2
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();
  }
Пример #3
0
 private void handleSendConfirm() {
   if (!everythingValid()) { // Sanity check
     log.error("Unexpected validity failure.");
     validateAmount();
     validateAddress();
     validateTxMessage();
     return;
   }
   state = State.PREPARATION;
   updateView();
   if (application.getWallet() != null) {
     onMakeTransaction(address, sendAmount, getTxMessage());
   }
 }
Пример #4
0
 private boolean processInput(String input) {
   input = input.trim();
   try {
     updateStateFrom(new CoinURI(input));
     return true;
   } catch (final CoinURIParseException x) {
     try {
       parseAddress(input);
       updateView();
       return true;
     } catch (AddressFormatException e) {
       return false;
     }
   }
 }
Пример #5
0
  public void reset() {
    // No-op if the view is not created
    if (getView() == null) return;

    clearAddress(true);
    hideTxMessage();
    sendToAddressView.setVisibility(View.VISIBLE);
    sendToStaticAddressView.setVisibility(View.GONE);
    amountCalculatorLink.setPrimaryAmount(null);
    sendAmount = null;
    state = State.INPUT;
    addressError.setVisibility(View.GONE);
    amountError.setVisibility(View.GONE);
    amountWarning.setVisibility(View.GONE);
    updateView();
  }
Пример #6
0
  @Override
  public void onResume() {
    super.onResume();

    amountCalculatorLink.setListener(amountsListener);

    resolver.registerContentObserver(
        AddressBookProvider.contentUri(getActivity().getPackageName()), true, addressBookObserver);

    if (pocket != null) {
      pocket.addEventListener(transactionChangeListener, Threading.SAME_THREAD);
    }

    updateBalance();
    updateView();
  }
Пример #7
0
 // FIXME crash when this dialog being restored from saved state
 @Override
 public void onAddressSelected(Address selectedAddress) {
   setAddress(selectedAddress, true);
   sendAmountType = (CoinType) selectedAddress.getParameters();
   updateView();
 }
Пример #8
0
 private void validateTxMessage() {
   if (isTxMessageAdded && messageFactory != null && txMessageView != null) {
     isTxMessageValid = txMessageView.getText().length() <= messageFactory.maxMessageSize();
     updateView();
   }
 }
Пример #9
0
 @Override
 public void onChange(final boolean selfChange) {
   updateView();
 }