示例#1
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();
   }
 }
示例#2
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);
      }
    }
  }
示例#3
0
  @Override
  public void onPause() {
    if (pocket != null) pocket.removeEventListener(transactionChangeListener);
    transactionChangeListener.removeCallbacks();

    resolver.unregisterContentObserver(addressBookObserver);

    amountCalculatorLink.setListener(null);

    stopPolling();

    super.onPause();
  }
示例#4
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);
  }
示例#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
  @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.isEmpty()) pocket = accounts.get(0);
      }
      checkNotNull(pocket, "No account selected");
    } else {
      throw new RuntimeException("Must provide account ID or a payment URI");
    }
    sendAmountType = pocket.getCoinType();

    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);
  }
示例#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
 private void updateBalance() {
   if (pocket != null) {
     lastBalance = pocket.getBalance();
   }
 }
示例#10
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;
   }
 }