Add HashMap for removed assets that are still traded on Bisq to prevent displaying of "N/A"

This commit is contained in:
Christoph Atteneder 2019-01-22 18:26:32 +01:00
parent f8d77de642
commit 741df88f96
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
2 changed files with 31 additions and 8 deletions

View File

@ -144,6 +144,17 @@ public class CurrencyUtil {
return result;
}
public static List<CryptoCurrency> getRemovedCryptoCurrencies() {
final List<CryptoCurrency> currencies = new ArrayList<>();
currencies.add(new CryptoCurrency("BCH", "Bitcoin Cash"));
currencies.add(new CryptoCurrency("BCHC", "Bitcoin Clashic"));
currencies.add(new CryptoCurrency("ACH", "AchieveCoin"));
currencies.add(new CryptoCurrency("SC", "SpaceCash"));
currencies.add(new CryptoCurrency("PPI", "PiedPiper Coin"));
currencies.add(new CryptoCurrency("PEPECASH", "Pepe Cash"));
return currencies;
}
// At OKPay you can exchange internally those currencies
public static List<TradeCurrency> getAllAdvancedCashCurrencies() {
ArrayList<TradeCurrency> currencies = new ArrayList<>(Arrays.asList(
@ -388,7 +399,12 @@ public class CurrencyUtil {
if (isCryptoCurrency(currencyCode)) {
// We might not find the name in case we have a call for a removed asset.
// If BTC is the code (used in tests) we also want return Bitcoin as name.
String btcOrRemovedAsset = "BTC".equals(currencyCode) ? "Bitcoin" : Res.get("shared.na");
final Optional<CryptoCurrency> removedCryptoCurrency = getRemovedCryptoCurrencies().stream()
.filter(cryptoCurrency -> cryptoCurrency.getCode().equals(currencyCode))
.findAny();
String btcOrRemovedAsset = "BTC".equals(currencyCode) ? "Bitcoin" :
removedCryptoCurrency.isPresent() ? removedCryptoCurrency.get().getName() : Res.get("shared.na");
return getCryptoCurrency(currencyCode).map(TradeCurrency::getName).orElse(btcOrRemovedAsset);
}
try {

View File

@ -19,6 +19,11 @@ package bisq.core.locale;
import bisq.core.btc.BaseCurrencyNetwork;
import bisq.asset.Asset;
import bisq.asset.AssetRegistry;
import bisq.asset.Coin;
import bisq.asset.coins.Ether;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@ -34,18 +39,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import bisq.asset.Asset;
import bisq.asset.AssetRegistry;
import bisq.asset.Coin;
import bisq.asset.coins.Ether;
public class CurrencyUtilTest {
@Before
public void setup() {
Locale.setDefault(new Locale("en", "US"));
Res.setBaseCurrencyCode("BTC");
Res.setBaseCurrencyName("Bitcoin");
}
@Test
@ -128,6 +129,12 @@ public class CurrencyUtilTest {
assertEquals(Coin.Network.REGTEST, bsq.getNetwork());
}
@Test
public void testGetNameAndCodeOfRemovedAsset() {
assertEquals("Bitcoin Cash (BCH)", CurrencyUtil.getNameAndCode("BCH"));
assertEquals("N/A (XYZ)", CurrencyUtil.getNameAndCode("XYZ"));
}
class MockAssetRegistry extends AssetRegistry {
private List<Asset> registeredAssets = new ArrayList<>();