mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 08:55:22 -04:00
support USDT-ERC20 and USDT-TRC20
This commit is contained in:
parent
0450900b37
commit
2c3cd5208b
11 changed files with 176 additions and 7 deletions
|
@ -200,6 +200,8 @@ public class CurrencyUtil {
|
|||
result.add(new CryptoCurrency("BCH", "Bitcoin Cash"));
|
||||
result.add(new CryptoCurrency("ETH", "Ether"));
|
||||
result.add(new CryptoCurrency("LTC", "Litecoin"));
|
||||
result.add(new CryptoCurrency("USDT-ERC20", "Tether USD (ERC20)"));
|
||||
result.add(new CryptoCurrency("USDT-TRC20", "Tether USD (TRC20)"));
|
||||
result.sort(TradeCurrency::compareTo);
|
||||
return result;
|
||||
}
|
||||
|
@ -295,6 +297,9 @@ public class CurrencyUtil {
|
|||
if (currencyCode != null && isCryptoCurrencyMap.containsKey(currencyCode.toUpperCase())) {
|
||||
return isCryptoCurrencyMap.get(currencyCode.toUpperCase());
|
||||
}
|
||||
if (isCryptoCurrencyBase(currencyCode)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean isCryptoCurrency;
|
||||
if (currencyCode == null) {
|
||||
|
@ -321,6 +326,19 @@ public class CurrencyUtil {
|
|||
return isCryptoCurrency;
|
||||
}
|
||||
|
||||
private static boolean isCryptoCurrencyBase(String currencyCode) {
|
||||
if (currencyCode == null) return false;
|
||||
currencyCode = currencyCode.toUpperCase();
|
||||
return currencyCode.equals("USDT");
|
||||
}
|
||||
|
||||
public static String getCurrencyCodeBase(String currencyCode) {
|
||||
if (currencyCode == null) return null;
|
||||
currencyCode = currencyCode.toUpperCase();
|
||||
if (currencyCode.contains("USDT")) return "USDT";
|
||||
return currencyCode;
|
||||
}
|
||||
|
||||
public static Optional<CryptoCurrency> getCryptoCurrency(String currencyCode) {
|
||||
return Optional.ofNullable(cryptoCurrencyMapSupplier.get().get(currencyCode));
|
||||
}
|
||||
|
|
|
@ -292,15 +292,16 @@ public class PriceFeedService {
|
|||
@Nullable
|
||||
public MarketPrice getMarketPrice(String currencyCode) {
|
||||
synchronized (cache) {
|
||||
return cache.getOrDefault(currencyCode, null);
|
||||
return cache.getOrDefault(CurrencyUtil.getCurrencyCodeBase(currencyCode), null);
|
||||
}
|
||||
}
|
||||
|
||||
private void setHavenoMarketPrice(String currencyCode, Price price) {
|
||||
UserThread.execute(() -> {
|
||||
String currencyCodeBase = CurrencyUtil.getCurrencyCodeBase(currencyCode);
|
||||
synchronized (cache) {
|
||||
if (!cache.containsKey(currencyCode) || !cache.get(currencyCode).isExternallyProvidedPrice()) {
|
||||
cache.put(currencyCode, new MarketPrice(currencyCode,
|
||||
if (!cache.containsKey(currencyCodeBase) || !cache.get(currencyCodeBase).isExternallyProvidedPrice()) {
|
||||
cache.put(currencyCodeBase, new MarketPrice(currencyCodeBase,
|
||||
MathUtils.scaleDownByPowerOf10(price.getValue(), CurrencyUtil.isCryptoCurrency(currencyCode) ? CryptoMoney.SMALLEST_UNIT_EXPONENT : TraditionalMoney.SMALLEST_UNIT_EXPONENT),
|
||||
0,
|
||||
false));
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import haveno.common.app.Version;
|
||||
import haveno.common.util.MathUtils;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.provider.HttpClientProvider;
|
||||
import haveno.network.http.HttpClient;
|
||||
import haveno.network.p2p.P2PService;
|
||||
|
@ -63,6 +64,7 @@ public class PriceProvider extends HttpClientProvider {
|
|||
String baseCurrencyCode = (String) treeMap.get("baseCurrencyCode");
|
||||
String counterCurrencyCode = (String) treeMap.get("counterCurrencyCode");
|
||||
String currencyCode = baseCurrencyCode.equals("XMR") ? counterCurrencyCode : baseCurrencyCode;
|
||||
currencyCode = CurrencyUtil.getCurrencyCodeBase(currencyCode);
|
||||
double price = (Double) treeMap.get("price");
|
||||
// json uses double for our timestampSec long value...
|
||||
long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue