@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); }
@Override protected SignedMessage doInBackground(SignedMessage... params) { SignedMessage message = params[0]; try { if (signMessage) { KeyParameter key = null; if (account.isEncrypted() && account.getKeyCrypter() != null && password != null) { key = account.getKeyCrypter().deriveKey(password); } account.signMessage(message, key); } else { account.verifyMessage(message); } } catch (KeyCrypterException e) { message = new SignedMessage(message, SignedMessage.Status.KeyIsEncrypted); } catch (Exception e) { // Should not happen ACRA.getErrorReporter().handleSilentException(e); // Return the message with unknown status message = new SignedMessage(message, SignedMessage.Status.Unknown); } return message; }
public boolean isLoading() { for (WalletAccount account : accounts.values()) { if (account.isLoading()) { return true; } } return false; }
public void maybeConnectAccount(WalletAccount account) { if (!account.isConnected()) { coinServiceConnectIntent.putExtra(Constants.ARG_ACCOUNT_ID, account.getId()); startService(coinServiceConnectIntent); } } }
public void setAccount(WalletAccount account) { this.type = account.getCoinType(); title.setText(account.getDescriptionOrCoinName()); icon.setImageResource(WalletUtils.getIconRes(account)); }
public void addAccount(WalletAccount pocket) { lock.lock(); try { String id = pocket.getId(); CoinType type = pocket.getCoinType(); checkState(!accounts.containsKey(id), "Cannot replace an existing wallet pocket"); if (!accountsByType.containsKey(type)) { accountsByType.put(type, new ArrayList<WalletAccount>()); } accountsByType.get(type).add(pocket); accounts.put(pocket.getId(), pocket); pocket.setWallet(this); } finally { lock.unlock(); } }
public SweepWalletTask(Handler handler, ServerClients serverClients, WalletAccount sendToAccount, SerializedKey key, @Nullable String keyPassword) { this.handler = handler; this.serverClients = serverClients; this.key = key; this.sendToAccount = sendToAccount; this.type = sendToAccount.getCoinType(); this.keyPassword = keyPassword; }
@Override public long getItemId(final int position) { if (position == accounts.size()) return 0; return accounts.get(position).getId().hashCode(); }
private void createNavDrawerItems() { navDrawerItems.clear(); NavDrawerItem.addItem(navDrawerItems, ITEM_SECTION_TITLE, getString(R.string.navigation_drawer_services)); NavDrawerItem.addItem(navDrawerItems, ITEM_TRADE, getString(R.string.title_activity_trade), R.drawable.trade, null); NavDrawerItem.addItem(navDrawerItems, ITEM_SECTION_TITLE, getString(R.string.navigation_drawer_wallet)); NavDrawerItem.addItem(navDrawerItems, ITEM_OVERVIEW, getString(R.string.title_activity_overview), R.drawable.ic_launcher, null); for (WalletAccount account : getAllAccounts()) { NavDrawerItem.addItem(navDrawerItems, ITEM_COIN, account.getDescriptionOrCoinName(), Constants.COINS_ICONS.get(account.getCoinType()), account.getId()); } }
private void bindView(View row, WalletAccount account) { final ImageView icon = (ImageView) row.findViewById(R.id.account_icon); icon.setImageResource(Constants.COINS_ICONS.get(account.getCoinType())); final TextView rowLabel = (TextView) row.findViewById(R.id.account_description); rowLabel.setText(account.getDescriptionOrCoinName()); final Amount rowValue = (Amount) row.findViewById(R.id.account_balance); rowValue.setAmount(GenericUtils.formatFiatValue(account.getBalance(), 4, 0)); rowValue.setSymbol(account.getCoinType().getSymbol()); ExchangeRatesProvider.ExchangeRate rate = rates.get(account.getCoinType().getSymbol()); final Amount rowBalanceRateValue = (Amount) row.findViewById(R.id.account_balance_rate); if (rate != null && account.getCoinType() != null) { Value localAmount = rate.rate.convert(account.getBalance()); GenericUtils.formatCoinValue(localAmount.type, localAmount,true); rowBalanceRateValue.setAmount(GenericUtils.formatFiatValue(localAmount, 2, 0)); rowBalanceRateValue.setSymbol(localAmount.type.getSymbol()); rowBalanceRateValue.setVisibility(View.VISIBLE); } else { rowBalanceRateValue.setVisibility(View.GONE); } final Amount rowRateValue = (Amount) row.findViewById(R.id.exchange_rate_row_rate); if (rate != null && account.getCoinType() != null) { Value localAmount = rate.rate.convert(account.getCoinType().oneCoin()); GenericUtils.formatCoinValue(localAmount.type, localAmount, true); rowRateValue.setAmount(GenericUtils.formatFiatValue(localAmount, 2, 0)); rowRateValue.setSymbol(localAmount.type.getSymbol()); rowRateValue.setVisibility(View.VISIBLE); } else { rowRateValue.setVisibility(View.GONE); } }
private void parseAddress(String addressStr) throws AddressMalformedException { if (account.getCoinType() instanceof NxtFamily) { setAddress(account.getCoinType().newAddress(addressStr), true); sendAmountType = account.getCoinType(); return; AbstractAddress addressOfAccount = null; for (WalletAccount account : possibleAccounts) { AbstractAddress testAddress = account.getCoinType().newAddress(addressStr); if (account.isAddressMine(testAddress)) { addressOfAccount = testAddress; break;
public WalletAccount deleteAccount(String id) { lock.lock(); try { if (!accounts.containsKey(id)) { return null; } WalletAccount deletedAccount = accounts.remove(id); CoinType type = deletedAccount.getCoinType(); ArrayList<WalletAccount> sameTypeAccounts = accountsByType.get(type); if (sameTypeAccounts != null) { if (!sameTypeAccounts.remove(deletedAccount)) { log.warn("Could not find account in accounts by type index"); } if (sameTypeAccounts.size() == 0) { accountsByType.remove(type); } } deletedAccount.setWallet(null); deletedAccount.disconnect(); saveNow(); return deletedAccount; } finally { lock.unlock(); } }
@Override public boolean equals(WalletAccount other) { return other != null && getId().equals(other.getId()) && getCoinType().equals(other.getCoinType()); } }
private void calculateNewBalance() { currentBalance = null; for (WalletAccount w : wallet.getAllAccounts()) { ExchangeRate rate = exchangeRates.get(w.getCoinType().getSymbol()); if (rate == null) { log.info("Missing exchange rate for {}, skipping...", w.getCoinType().getName()); continue; } if (currentBalance != null) { currentBalance = currentBalance.add(rate.rate.convert(w.getBalance())); } else { currentBalance = rate.rate.convert(w.getBalance()); } } }
private void updateBalance() { if (account != null) { lastBalance = account.getBalance(); } }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (mNavigationDrawerFragment != null && !mNavigationDrawerFragment.isDrawerOpen() && isVisible() && account != null) { switch (viewPager.getCurrentItem()) { case RECEIVE: inflater.inflate(R.menu.request, menu); MenuItem newAddressItem = menu.findItem(R.id.action_new_address); if (newAddressItem != null) { newAddressItem.setVisible(account.canCreateNewAddresses()); } break; case BALANCE: inflater.inflate(R.menu.balance, menu); // Disable sign/verify for coins that don't support it menu.findItem(R.id.action_sign_verify_message) .setVisible(account.getCoinType().canSignVerifyMessages()); break; case SEND: inflater.inflate(R.menu.send, menu); break; } } }
@Override public void onClick(View v) { String accountId = null; for (WalletAccount account : accounts) { if (account.getTransaction(txId) != null) { accountId = account.getId(); break; } } if (accountId != null && txId != null) { Intent intent = new Intent(getActivity(), TransactionDetailsActivity.class); intent.putExtra(Constants.ARG_ACCOUNT_ID, accountId); intent.putExtra(Constants.ARG_TRANSACTION_ID, txId); startActivity(intent); } else { // Take to an external blockchain explorer if (Constants.COINS_BLOCK_EXPLORERS.containsKey(withdrawType)) { String url = String.format(Constants.COINS_BLOCK_EXPLORERS.get(withdrawType), txId); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } else { // Should not happen Toast.makeText(getActivity(), R.string.error_generic, Toast.LENGTH_SHORT).show(); } } } });
case R.id.action_account_details: Intent intent = new Intent(activity, AccountDetailsActivity.class); intent.putExtra(Constants.ARG_ACCOUNT_ID, account.getId()); activity.startActivity(intent); mode.finish(); new AlertDialog.Builder(activity) .setTitle(activity.getString(R.string.edit_account_delete_title, account.getDescriptionOrCoinName())) .setMessage(R.string.edit_account_delete_description) .setNegativeButton(R.string.button_cancel, null)
private void startOrStopMarketRatePolling() { if (address != null && !account.isType(address)) { String pair = ShapeShift.getPair(account.getCoinType(), address.getType()); if (timer == null) { startPolling(pair); } else { pollTask.updatePair(pair); } } else if (timer != null) { stopPolling(); } }