public static CoinType[] parsePair(String pair) { String[] pairs = pair.split("_"); checkState(pairs.length == 2); return new CoinType[]{CoinID.typeFromSymbol(pairs[0]), CoinID.typeFromSymbol(pairs[1])}; } }
public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) { final String codeId = getCurrencyCodeId(cursor); final CoinType type = CoinID.typeFromSymbol(cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN_CODE))); final Value rateCoin = Value.valueOf(type, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN))); final String fiatCode = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT_CODE)); final Value rateFiat = FiatValue.valueOf(fiatCode, cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT))); final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE)); ExchangeRateBase rate = new ExchangeRateBase(rateCoin, rateFiat); return new ExchangeRate(rate, codeId, source); }
public ShapeShiftRate(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { String[] pairs = pair.split("_"); checkState(pairs.length == 2); CoinType typeFrom = CoinID.typeFromSymbol(pairs[0]); CoinType typeTo = CoinID.typeFromSymbol(pairs[1]); rate = new ShapeShiftExchangeRate(typeFrom, typeTo, data.getString("rate"), data.optString("minerFee", null)); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { rate = null; } } }
@Nullable public static String getCurrencyName(String code) { String currencyName = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { Currency currency = Currency.getInstance(code); currencyName = currency.getDisplayName(Locale.getDefault()); } catch (final IllegalArgumentException x) { /* ignore */ } } else { currencyName = Currencies.CURRENCY_NAMES.get(code); } // Try cryptocurrency codes if (currencyName == null) { try { CoinType cryptoCurrency = CoinID.typeFromSymbol(code); currencyName = cryptoCurrency.getName(); } catch (final IllegalArgumentException x) { /* ignore */ } } return currencyName; } }
public ShapeShiftCoins(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { ImmutableList.Builder<ShapeShiftCoin> listBuilder = ImmutableList.builder(); Iterator iter = data.keys(); while (iter.hasNext()) { String k = (String) iter.next(); listBuilder.add(new ShapeShiftCoin(data.getJSONObject(k))); } coins = listBuilder.build(); ImmutableList.Builder<CoinType> typesBuilder = ImmutableList.builder(); for (ShapeShiftCoin coin : coins) { if (coin.isAvailable && CoinID.isSymbolSupported(coin.symbol)) { typesBuilder.add(CoinID.typeFromSymbol(coin.symbol)); } } availableCoinTypes = typesBuilder.build(); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { coins = null; availableCoinTypes = null; } } }
CoinType type = isLocalToCrypto ? null : CoinID.typeFromSymbol(fromSymbol); for (final Iterator<String> i = json.keys(); i.hasNext(); ) { final String toSymbol = i.next(); if (rateStr != null) { try { if (isLocalToCrypto) type = CoinID.typeFromSymbol(toSymbol); String localSymbol = isLocalToCrypto ? fromSymbol : toSymbol; final Value rateCoin = type.oneCoin();
public ShapeShiftNormalTx(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { deposit = CoinID.typeFromSymbol(data.getString("depositType")). newAddress(data.getString("deposit")); withdrawal = CoinID.typeFromSymbol(data.getString("withdrawalType")). newAddress(data.getString("withdrawal")); pair = ShapeShift.getPair(deposit.getType(), withdrawal.getType()); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { deposit = null; withdrawal = null; pair = null; } } }
public ShapeShiftLimit(JSONObject data) throws ShapeShiftException { super(data); if (!isError) { try { String[] pairs = pair.split("_"); checkState(pairs.length == 2); CoinType typeFrom = CoinID.typeFromSymbol(pairs[0]); limit = parseValue(typeFrom, data.getString("limit"), RoundingMode.DOWN); minimum = parseValue(typeFrom, data.getString("min"), RoundingMode.UP); } catch (Exception e) { throw new ShapeShiftException("Could not parse object", e); } } else { limit = null; minimum = null; } } }
case "received": status = Status.RECEIVED; inType = CoinID.typeFromSymbol(data.getString("incomingType")); address = inType.newAddress(data.getString("address")); withdraw = null; case "complete": status = Status.COMPLETE; inType = CoinID.typeFromSymbol(data.getString("incomingType")); outType = CoinID.typeFromSymbol(data.getString("outgoingType")); address = inType.newAddress(data.getString("address")); withdraw = outType.newAddress(data.getString("withdraw"));