Updated on 2026-08-14

This commit is contained in:
Tangem 2018-12-10 12:05:32 +03:00
parent d4e76c4a00
commit 7737b890bb
124 changed files with 1067 additions and 706 deletions

View file

@ -0,0 +1,102 @@
package com.tangem.data;
import com.tangem.tangemcard.R;
/**
* Created by dvol on 06.08.2017.
*/
public enum Blockchain {
Unknown("", "", 1.0, R.drawable.ic_logo_unknown, ""),
Bitcoin("BTC", "BTC", 100000000.0, R.drawable.ic_logo_bitcoin, "Bitcoin"),
BitcoinTestNet("BTC/test", "BTC", 100000000.0, R.drawable.ic_logo_bitcoin_testnet, "Bitcoin Testnet"),
Ethereum("ETH", "ETH", 1.0, R.drawable.ic_logo_ethereum, "Ethereum"),
EthereumTestNet("ETH/test", "ETH", 1.0, R.drawable.ic_logo_ethereum_testnet, "Ethereum Testnet"),
Token("Token", "ERC20", 1.0, R.drawable.ic_logo_bat_token, "Ethereum"),
BitcoinCash("BCH", "BCH", 100000000.0, R.drawable.ic_logo_bitcoin_cash, "Bitcoin Cash");
Blockchain(String ID, String currency, double multiplier, int imageResource, String officialName) {
mID = ID;
mCurrency = currency;
// mMultiplier = multiplier;
mImageResource = imageResource;
mOfficialName = officialName;
}
private String mID, mOfficialName;
//private double mMultiplier;
private String mCurrency;
private int mImageResource;
public String getID() {
return mID;
}
public String getOfficialName() {
return mOfficialName;
}
// public double getMultiplier() {
// return mMultiplier;
// }
public String getCurrency() {
return mCurrency;
}
public static Blockchain fromId(String id) {
for (Blockchain blockchain : values()) {
if (blockchain.getID().equals(id)) return blockchain;
}
return null;
}
public static Blockchain fromCurrency(String currency) {
for (Blockchain blockchain : values()) {
if (blockchain.getCurrency() == currency) return blockchain;
}
return null;
}
public static String[] getCurrencies() {
String[] result = new String[values().length - 1];
for (int i = 0; i < result.length - 1; i++) {
result[i] = values()[i + 1].getCurrency();
}
return result;
}
private int getImageResource() {
return mImageResource;
}
public int getImageResource(android.content.Context context, String name) {
if (name==null || name.isEmpty())
return getImageResource();
name = name.toLowerCase();
int resourceId = context.getResources().getIdentifier(name + "_token", "drawable", context.getPackageName());
if (resourceId <= 0)
return R.drawable.ic_logo_ethereum;
return resourceId;
}
public static int getLogoImageResource(String blockchainID, String symbolName) {
switch (blockchainID) {
case "BTC":
return R.drawable.ic_logo_bitcoin;
case "Token":
if (symbolName.equals("SEED"))
return R.drawable.ic_logo_seed;
else
return R.drawable.ic_logo_ethereum;
case "ETH":
return R.drawable.ic_logo_ethereum;
}
return R.drawable.tangem2;
}
}

View file

@ -8,7 +8,7 @@ import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyPermanentlyInvalidatedException;
import android.security.keystore.KeyProperties;
import com.tangem.tangemcard.data.local.PINStorage;
import com.tangem.tangemcard.android.data.PINStorage;
import com.tangem.presentation.activity.PinRequestActivity;
import java.io.IOException;

View file

@ -5,16 +5,7 @@ import android.support.annotation.NonNull;
import android.util.Log;
import com.tangem.App;
import com.tangem.tangemcard.data.network.TangemApi;
import com.tangem.tangemcard.data.network.model.CardVerifyAndGetInfo;
import com.tangem.data.network.model.RateInfoResponse;
import com.tangem.tangemcard.data.TangemCard;
import com.tangem.tangemcard.util.Util;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

View file

@ -3,8 +3,8 @@ package com.tangem.data.network;
import android.util.Log;
import com.tangem.App;
import com.tangem.tangemcard.data.Blockchain;
import com.tangem.tangemcard.data.TangemCard;
import com.tangem.domain.wallet.TangemContext;
import com.tangem.data.Blockchain;
import com.tangem.domain.wallet.bch.BitcoinCashNode;
import com.tangem.domain.wallet.btc.BitcoinNode;
import com.tangem.domain.wallet.btc.BitcoinNodeTestNet;
@ -62,9 +62,9 @@ public class ServerApiElectrum {
electrumRequestDataListener = listener;
}
public void electrumRequestData(TangemCard card, ElectrumRequest electrumRequest) {
public void electrumRequestData(TangemContext ctx, ElectrumRequest electrumRequest) {
Observable<ElectrumRequest> checkElectrumDataObserver = Observable.just(electrumRequest)
.doOnNext(electrumRequest1 -> doElectrumRequest(card, electrumRequest))
.doOnNext(electrumRequest1 -> doElectrumRequest(ctx, electrumRequest))
.flatMap(electrumRequest1 -> {
if (electrumRequest1.answerData == null) {
@ -106,11 +106,11 @@ public class ServerApiElectrum {
});
}
private List<ElectrumRequest> doElectrumRequest(TangemCard card, ElectrumRequest electrumRequest) {
private List<ElectrumRequest> doElectrumRequest(TangemContext ctx, ElectrumRequest electrumRequest) {
String host;
int port;
String proto;
if (card.getBlockchain() == Blockchain.BitcoinTestNet) {
if (ctx.getBlockchain() == Blockchain.BitcoinTestNet) {
BitcoinNodeTestNet bitcoinNodeTestNet = BitcoinNodeTestNet.values()[new Random().nextInt(BitcoinNodeTestNet.values().length)];
host = bitcoinNodeTestNet.getHost();
port = bitcoinNodeTestNet.getPort();
@ -120,7 +120,7 @@ public class ServerApiElectrum {
return doElectrumRequestTcp(electrumRequest, host, port);
} else if (card.getBlockchain() == Blockchain.BitcoinCash) {
} else if (ctx.getBlockchain() == Blockchain.BitcoinCash) {
BitcoinCashNode bitcoinCashNode = BitcoinCashNode.values()[new Random().nextInt(BitcoinCashNode.values().length)];
host = bitcoinCashNode.getHost();
port = bitcoinCashNode.getPort();
@ -135,7 +135,7 @@ public class ServerApiElectrum {
return doElectrumRequestSsl(electrumRequest, host, port);
}
} else if (card.getBlockchain() == Blockchain.Bitcoin) {
} else if (ctx.getBlockchain() == Blockchain.Bitcoin) {
BitcoinNode bitcoinNode = BitcoinNode.values()[new Random().nextInt(BitcoinNode.values().length)];
host = bitcoinNode.getHost();
port = bitcoinNode.getPort();