Пример #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    if (args != null) {
      if (args.containsKey(Constants.ARG_ACCOUNT_ID)) {
        String accountId = args.getString(Constants.ARG_ACCOUNT_ID);
        pocket = checkNotNull(application.getAccount(accountId));
      }

      if (args.containsKey(Constants.ARG_URI)) {
        try {
          processUri(args.getString(Constants.ARG_URI));
        } catch (CoinURIParseException e) {
          // TODO handle more elegantly
          Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
          ACRA.getErrorReporter().handleException(e);
        }
      }
      if (pocket == null) {
        List<WalletAccount> accounts = application.getAllAccounts();
        if (accounts.size() > 0) pocket = accounts.get(0);
        if (pocket == null) {
          ACRA.getErrorReporter()
              .putCustomData("wallet-exists", application.getWallet() == null ? "no" : "yes");
          Toast.makeText(getActivity(), R.string.no_such_pocket_error, Toast.LENGTH_LONG).show();
          getActivity().finish();
          return;
        }
      }
      checkNotNull(pocket, "No account selected");
    } else {
      throw new RuntimeException("Must provide account ID or a payment URI");
    }

    sendAmountType = pocket.getCoinType();

    messageFactory = pocket.getCoinType().getMessagesFactory();

    if (savedInstanceState != null) {
      address = (Address) savedInstanceState.getSerializable(STATE_ADDRESS);
      addressTypeCanChange = savedInstanceState.getBoolean(STATE_ADDRESS_CAN_CHANGE_TYPE);
      sendAmount = (Value) savedInstanceState.getSerializable(STATE_AMOUNT);
      sendAmountType = (CoinType) savedInstanceState.getSerializable(STATE_AMOUNT_TYPE);
    }

    updateBalance();
    setHasOptionsMenu(true);
    mNavigationDrawerFragment =
        (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);

    String localSymbol = config.getExchangeCurrencyCode();
    for (ExchangeRatesProvider.ExchangeRate rate : getRates(getActivity(), localSymbol)) {
      localRates.put(rate.currencyCodeId, rate.rate);
    }

    loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);
    loaderManager.initLoader(ID_RECEIVING_ADDRESS_LOADER, null, receivingAddressLoaderCallbacks);
  }
Пример #2
0
 private void startOrStopMarketRatePolling() {
   if (address != null && !pocket.isType(address)) {
     String pair = ShapeShift.getPair(pocket.getCoinType(), (CoinType) address.getParameters());
     if (timer == null) {
       startPolling(pair);
     } else {
       pollTask.updatePair(pair);
     }
   } else if (timer != null) {
     stopPolling();
   }
 }
Пример #3
0
  private void parseAddress(String addressStr) throws AddressFormatException {
    List<CoinType> possibleTypes = GenericUtils.getPossibleTypes(addressStr);
    if (possibleTypes.contains(pocket.getCoinType())) {
      setAddress(new Address(pocket.getCoinType(), addressStr), true);
      sendAmountType = pocket.getCoinType();
    } else if (possibleTypes.size() == 1) {
      setAddress(new Address(possibleTypes.get(0), addressStr), true);
      sendAmountType = possibleTypes.get(0);
    } else {
      // This address string could be more that one coin type so first check if this address
      // comes from an account to determine the type.
      List<WalletAccount> possibleAccounts = application.getAccounts(possibleTypes);
      Address addressOfAccount = null;
      for (WalletAccount account : possibleAccounts) {
        Address testAddress = new Address(account.getCoinType(), addressStr);
        if (account.isAddressMine(testAddress)) {
          addressOfAccount = testAddress;
          break;
        }
      }

      if (addressOfAccount != null) {
        // If address is from an account don't show a dialog. The type should not change as
        // we know 100% that is correct one
        setAddress(addressOfAccount, false);
        sendAmountType = (CoinType) addressOfAccount.getParameters();
      } else {
        // As a last resort let the use choose the correct coin type
        showPayToDialog(addressStr);
      }
    }
  }
Пример #4
0
  @Override
  public void onPause() {
    if (pocket != null) pocket.removeEventListener(transactionChangeListener);
    transactionChangeListener.removeCallbacks();

    resolver.unregisterContentObserver(addressBookObserver);

    amountCalculatorLink.setListener(null);

    stopPolling();

    super.onPause();
  }
Пример #5
0
 @Override
 public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
   final String constraint = args != null ? args.getString("constraint") : null;
   // TODO support addresses from other accounts
   Uri uri =
       AddressBookProvider.contentUri(application.getPackageName(), pocket.getCoinType());
   return new CursorLoader(
       application,
       uri,
       null,
       AddressBookProvider.SELECTION_QUERY,
       new String[] {constraint != null ? constraint : ""},
       null);
 }
Пример #6
0
  public void onMakeTransaction(Address 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, pocket.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;
  }
Пример #7
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();
  }
Пример #8
0
 private void clearAddress(boolean clearTextField) {
   address = null;
   if (clearTextField) setSendToAddressText(null);
   sendAmountType = pocket.getCoinType();
   addressTypeCanChange = false;
 }
Пример #9
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_send, container, false);

    sendToAddressView = (AutoCompleteTextView) view.findViewById(R.id.send_to_address);
    sendToAddressViewAdapter = new ReceivingAddressViewAdapter(application);
    sendToAddressView.setAdapter(sendToAddressViewAdapter);
    sendToAddressView.setOnFocusChangeListener(receivingAddressListener);
    sendToAddressView.addTextChangedListener(receivingAddressListener);

    sendToStaticAddressView = (AddressView) view.findViewById(R.id.send_to_address_static);
    sendToStaticAddressView.setOnClickListener(addressOnClickListener);

    sendCoinAmountView = (AmountEditView) view.findViewById(R.id.send_coin_amount);
    sendCoinAmountView.resetType(sendAmountType);
    if (sendAmount != null) sendCoinAmountView.setAmount(sendAmount, false);

    AmountEditView sendLocalAmountView = (AmountEditView) view.findViewById(R.id.send_local_amount);
    sendLocalAmountView.setFormat(FiatType.FRIENDLY_FORMAT);

    amountCalculatorLink = new CurrencyCalculatorLink(sendCoinAmountView, sendLocalAmountView);
    amountCalculatorLink.setExchangeDirection(config.getLastExchangeDirection());
    amountCalculatorLink.setExchangeRate(getCurrentRate());

    addressError = (TextView) view.findViewById(R.id.address_error_message);
    addressError.setVisibility(View.GONE);
    amountError = (TextView) view.findViewById(R.id.amount_error_message);
    amountError.setVisibility(View.GONE);
    amountWarning = (TextView) view.findViewById(R.id.amount_warning_message);
    amountWarning.setVisibility(View.GONE);

    scanQrCodeButton = (ImageButton) view.findViewById(R.id.scan_qr_code);
    scanQrCodeButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            handleScan();
          }
        });

    eraseAddressButton = (ImageButton) view.findViewById(R.id.erase_address);
    eraseAddressButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            clearAddress(true);
            updateView();
          }
        });

    txMessageButton = (Button) view.findViewById(R.id.tx_message_add_remove);
    txMessageLabel = (TextView) view.findViewById(R.id.tx_message_label);
    txMessageView = (EditText) view.findViewById(R.id.tx_message);
    txMessageCounter = (TextView) view.findViewById(R.id.tx_message_counter);

    if (pocket != null && pocket.getCoinType().canHandleMessages()) {
      enableTxMessage(view);
    }

    sendConfirmButton = (Button) view.findViewById(R.id.send_confirm);
    sendConfirmButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            validateAddress();
            validateAmount();
            if (everythingValid()) handleSendConfirm();
            else requestFocusFirst();
          }
        });

    return view;
  }
Пример #10
0
 private void updateBalance() {
   if (pocket != null) {
     lastBalance = pocket.getBalance();
   }
 }
Пример #11
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 (address != null
       && marketInfo.isPair(pocket.getCoinType(), (CoinType) address.getParameters())) {
     this.marketInfo = marketInfo;
   }
 }