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); } } }
private void processUri(String uri) throws CoinURIParseException { CoinURI coinUri = new CoinURI(uri); CoinType scannedType = coinUri.getType(); if (!Constants.SUPPORTED_COINS.contains(scannedType)) { String error = getResources().getString(R.string.unsupported_coin, scannedType.getName()); throw new CoinURIParseException(error); } setUri(coinUri); if (pocket == null) { List<WalletAccount> allAccounts = application.getAllAccounts(); List<WalletAccount> sendFromAccounts = application.getAccounts(coinUri.getType()); if (sendFromAccounts.size() == 1) { pocket = sendFromAccounts.get(0); } else if (allAccounts.size() == 1) { pocket = allAccounts.get(0); } else { throw new CoinURIParseException("No default account found"); } } }