/** * Check if account exists */ public boolean isAccountExists(String accountId) { if (wallet != null) { return wallet.isAccountExists(accountId); } else { return false; } }
/** * Check if accounts exists for the spesific coin type */ public boolean isAccountExists(CoinType type) { return wallet != null && wallet.isAccountExists(type); }
/** * Get accounts for a specific coin type. Returns empty list if no account exists */ public List<WalletAccount> getAccounts(List<CoinType> types) { lock.lock(); try { ImmutableList.Builder<WalletAccount> builder = ImmutableList.builder(); for (CoinType type : types) { if (isAccountExists(type)) { builder.addAll(accountsByType.get(type)); } } return builder.build(); } finally { lock.unlock(); } }
/** * Get the last BIP44 account index of an account in this wallet. If no accounts found return -1 */ private int getLastAccountIndex(CoinType coinType) { if (!isAccountExists(coinType)) { return -1; } int lastIndex = -1; for (WalletAccount account : accountsByType.get(coinType)) { if (account instanceof WalletPocketHD) { int index = ((WalletPocketHD) account).getAccountIndex(); if (index > lastIndex) { lastIndex = index; } } } return lastIndex; }
/** * Get accounts that watch a specific address. Returns empty list if no account exists */ public List<WalletAccount> getAccounts(final AbstractAddress address) { lock.lock(); try { ImmutableList.Builder<WalletAccount> builder = ImmutableList.builder(); CoinType type = address.getType(); if (isAccountExists(type)) { for (WalletAccount account : accountsByType.get(type)) { if (account.isAddressMine(address)) { builder.add(account); } } } return builder.build(); } finally { lock.unlock(); } }
@Override public void onCoinSelection(Bundle args) { ArrayList<String> ids = args.getStringArrayList(Constants.ARG_MULTIPLE_COIN_IDS); // For new we add only one coin at a time selectedCoin = CoinID.typeFromId(ids.get(0)); if (wallet.isAccountExists(selectedCoin)) { new AlertDialog.Builder(this) .setTitle(getString(R.string.coin_already_added_title, selectedCoin.getName())) .setMessage(R.string.coin_already_added) .setPositiveButton(R.string.button_ok, null) .create().show(); return; } showAddCoinDialog(); }