package org.knowm.xchange.bitfinex.v1;

import org.knowm.xchange.bitfinex.common.dto.BitfinexException;
import org.knowm.xchange.currency.CurrencyPair;

/** A central place for shared Bitfinex properties */
public final class BitfinexUtils {

  /** private Constructor */
  private BitfinexUtils() {}

  public static String adaptXchangeCurrency(String xchangeSymbol) {
    String currency = xchangeSymbol.toLowerCase();
    if (currency.equals("dash")) {
      currency = "dsh";
    }
    if (currency.equals("qtum")) {
      currency = "qtm";
    }
    return currency;
  }

  public static String toPairString(CurrencyPair currencyPair) {

    return adaptXchangeCurrency(currencyPair.base.toString())
        + adaptXchangeCurrency(currencyPair.counter.toString());
  }

  /**
   * From the reference documentation for field withdraw_type (2018-02-14); can be one of the
   * following ['bitcoin', 'litecoin', 'ethereum', 'ethereumc', 'mastercoin', 'zcash', 'monero',
   * 'wire', 'dash', 'ripple', 'eos', 'neo', 'aventus', 'qtum', 'eidoo'] From customer support via
   * email on 2018-02-27; "... After discussing with our developers, you can use API to withdraw BCH
   * and withdraw_type is bcash. ..."
   *
   * @param currency
   * @return
   */
  public static String convertToBitfinexWithdrawalType(String currency) {
    switch (currency.toUpperCase()) {
      case "BTC":
        return "bitcoin";
      case "LTC":
        return "litecoin";
      case "ETH":
        return "ethereum";
      case "ETC":
        return "ethereumc";
      case "ZEC":
        return "zcash";
      case "XMR":
        return "monero";
      case "USD":
        return "mastercoin";
      case "DASH":
        return "dash";
      case "XRP":
        return "ripple";
      case "EOS":
        return "eos";
      case "NEO":
        return "neo";
      case "AVT":
        return "aventus";
      case "QTUM":
        return "qtum";
      case "EDO":
        return "eidoo";
      case "BTG":
        return "bgold";
      case "BCH":
        return "bcash";
      case "USDT":
        return "tetheruso";
      default:
        throw new BitfinexException("Cannot determine withdrawal type.");
    }
  }
}

@@ -97,16 +97,60 @@
 eption;%0A
+import org.knowm.xchange.currency.Currency;%0A
 import o
@@ -383,22 +383,24 @@
 urrency(
-String
+Currency
  xchange
@@ -413,124 +413,67 @@
 ) %7B%0A
+%0A
     
-String currency = xchangeSymbol.toLowerCase();%0A    if (currency.equals(%22dash%22)) %7B%0A      currency = %22dsh%22
+if (xchangeSymbol == null) %7B%0A      return null
 ;%0A    %7D%0A
     
@@ -472,92 +472,58 @@
   %7D%0A
-    if (currency.equals(%22qtum%22)) %7B%0A      currency = %22qtm%22;%0A    %7D%0A    return currency
+%0A    return xchangeSymbol.toString().toLowerCase()
 ;%0A  
@@ -587,24 +587,82 @@
 ncyPair) %7B%0A%0A
+    if (currencyPair == null) %7B%0A      return null;%0A    %7D%0A%0A
     return a
@@ -702,28 +702,9 @@
 base
-.toString())%0A       
+)
  + a
@@ -743,27 +743,16 @@
 .counter
-.toString()
 );%0A  %7D%0A%0A

Remove symbols workaround in adaptation.