Updated on 2026-08-14
This commit is contained in:
parent
a943d462b7
commit
0500d454fb
7 changed files with 475 additions and 429 deletions
|
|
@ -10,7 +10,6 @@ import org.json.JSONArray;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
public class InfuraRequest {
|
||||
public static final String METHOD_ETH_GetBalance = "eth_getBalance";
|
||||
public static final String METHOD_ETH_GetOutTransactionCount = "eth_getTransactionCount";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,102 @@
|
|||
package com.tangem.data.network.task.main;
|
||||
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
import com.tangem.data.network.task.InfuraTask;
|
||||
import com.tangem.domain.wallet.Blockchain;
|
||||
import com.tangem.domain.wallet.TangemCard;
|
||||
import com.tangem.presentation.fragment.Main;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
public class ETHRequestTask extends InfuraTask {
|
||||
private WeakReference<Main> reference;
|
||||
|
||||
public ETHRequestTask(Main context, Blockchain blockchain) {
|
||||
super(blockchain);
|
||||
reference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
private void FinishWithError(String wallet, String message) {
|
||||
Main main = reference.get();
|
||||
main.mCardListAdapter.UpdateWalletError(wallet, "Cannot obtain data from blockchain");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<InfuraRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
Main main = reference.get();
|
||||
|
||||
for (InfuraRequest request : requests) {
|
||||
try {
|
||||
if (request.error == null) {
|
||||
|
||||
if (request.isMethod(InfuraRequest.METHOD_ETH_GetBalance)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
|
||||
String balanceCap = request.getResultString();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
BigInteger l = new BigInteger(balanceCap, 16);
|
||||
BigInteger d = l.divide(new BigInteger("1000000000000000000", 10));
|
||||
Long balance = d.longValue();
|
||||
if (request.getBlockchain() != Blockchain.Token)
|
||||
main.mCardListAdapter.UpdateWalletBalance(mWalletAddress, balance, l.toString(10), getValidationNodeDescription());
|
||||
main.mCardListAdapter.UpdateWalletBalanceOnlyAlter(mWalletAddress, l.toString(10));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_Call)) {
|
||||
try {
|
||||
String mWalletAddress = request.WalletAddress;
|
||||
|
||||
String balanceCap = request.getResultString();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
BigInteger l = new BigInteger(balanceCap, 16);
|
||||
Long balance = l.longValue();
|
||||
if (l.compareTo(BigInteger.ZERO) == 0) {
|
||||
main.mCardListAdapter.UpdateWalletBlockchain(mWalletAddress, Blockchain.Ethereum);
|
||||
main.mCardListAdapter.AddWalletBlockchainNameToken(mWalletAddress);
|
||||
TangemCard card = main.mCardListAdapter.getCardByWallet(request.WalletAddress);
|
||||
if (card != null) {
|
||||
main.refreshCard(card);
|
||||
}
|
||||
return;
|
||||
}
|
||||
main.mCardListAdapter.UpdateWalletBalance(mWalletAddress, balance, l.toString(10), getValidationNodeDescription());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_GetOutTransactionCount)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
|
||||
String nonce = request.getResultString();
|
||||
nonce = nonce.substring(2);
|
||||
BigInteger count = new BigInteger(nonce, 16);
|
||||
|
||||
main.mCardListAdapter.UpdateWalletCoutConfirmTx(mWalletAddress, count);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FinishWithError(request.WalletAddress, request.error);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.tangem.data.network.task.main;
|
||||
|
||||
import com.tangem.data.network.request.ExchangeRequest;
|
||||
import com.tangem.data.network.task.ExchangeTask;
|
||||
import com.tangem.presentation.fragment.Main;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class RateInfoTask extends ExchangeTask {
|
||||
private WeakReference<Main> reference;
|
||||
|
||||
public RateInfoTask(Main context) {
|
||||
reference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
protected void onPostExecute(List<ExchangeRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
Main main = reference.get();
|
||||
|
||||
for (ExchangeRequest request : requests) {
|
||||
if (request.error == null) {
|
||||
try {
|
||||
|
||||
JSONArray arr = request.getAnswerList();
|
||||
for (int i = 0; i < arr.length(); ++i) {
|
||||
JSONObject obj = arr.getJSONObject(i);
|
||||
String currency = obj.getString("id");
|
||||
|
||||
boolean stop = false;
|
||||
boolean stopAlter = false;
|
||||
if (currency.equals(request.currency)) {
|
||||
String usd = obj.getString("price_usd");
|
||||
|
||||
Float rate = Float.valueOf(usd);
|
||||
main.mCardListAdapter.UpdateRate(request.WalletAddress, rate);
|
||||
stop = true;
|
||||
}
|
||||
|
||||
if (currency.equals(request.currencyAlter)) {
|
||||
String usd = obj.getString("price_usd");
|
||||
|
||||
Float rate = Float.valueOf(usd);
|
||||
main.mCardListAdapter.UpdateRateAlter(request.WalletAddress, rate);
|
||||
stopAlter = true;
|
||||
}
|
||||
|
||||
if (stop && stopAlter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//mCardListAdapter.UpdateWalletBalance(mWalletAddress, balance, l.toString(10));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
package com.tangem.data.network.task.main;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.data.network.task.ElectrumTask;
|
||||
import com.tangem.domain.wallet.Blockchain;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
import com.tangem.domain.wallet.CoinEngineFactory;
|
||||
import com.tangem.domain.wallet.SharedData;
|
||||
import com.tangem.presentation.fragment.Main;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class RequestWalletInfoTask extends ElectrumTask {
|
||||
private WeakReference<Main> reference;
|
||||
|
||||
public RequestWalletInfoTask(Main context, String host, int port) {
|
||||
super(host, port);
|
||||
reference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
|
||||
public RequestWalletInfoTask(Main context, String host, int port, SharedData sharedData) {
|
||||
super(host, port, sharedData);
|
||||
reference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... values) {
|
||||
super.onProgressUpdate(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
super.onCancelled();
|
||||
Main main = reference.get();
|
||||
main.requestTasks.remove(this);
|
||||
}
|
||||
|
||||
private void FinishWithError(String wallet, String message) {
|
||||
Main main = reference.get();
|
||||
main.mCardListAdapter.UpdateWalletError(wallet, "Cannot obtain data from blockchain");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<ElectrumRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
Main main = reference.get();
|
||||
|
||||
main.requestTasks.remove(this);
|
||||
// Log.i("RequestWalletInfoTask", "onPostExecute[" + String.valueOf(requests.size()) + "]");
|
||||
|
||||
CoinEngine engine = CoinEngineFactory.Create(Blockchain.Bitcoin);
|
||||
|
||||
for (ElectrumRequest request : requests) {
|
||||
try {
|
||||
|
||||
if (request.error == null) {
|
||||
if (request.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
Long conf = request.getResult().getLong("confirmed");
|
||||
Long unconf = request.getResult().getLong("unconfirmed");
|
||||
if (sharedCounter != null) {
|
||||
int counter = sharedCounter.requestCounter.incrementAndGet();
|
||||
if (counter != 1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
main.mCardListAdapter.UpdateWalletBalance(mWalletAddress, conf, unconf, getValidationNodeDescription());
|
||||
} catch (JSONException e) {
|
||||
if (sharedCounter != null) {
|
||||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter == sharedCounter.allRequest) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_ListUnspent)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
main.mCardListAdapter.UpdateWalletUnspent(mWalletAddress, request.getResultArray());
|
||||
|
||||
JSONArray unspentList = request.getResultArray();
|
||||
|
||||
for (int i = 0; i < unspentList.length(); i++) {
|
||||
JSONObject jsUnspent = unspentList.getJSONObject(i);
|
||||
Integer height = jsUnspent.getInt("height");
|
||||
String hash = jsUnspent.getString("tx_hash");
|
||||
if (height != -1) {
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(main, request.Host, request.Port);
|
||||
main.requestTasks.add(task);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.GetHeader(mWalletAddress, String.valueOf(height)),
|
||||
ElectrumRequest.GetTransaction(mWalletAddress, hash));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetHistory)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
main.mCardListAdapter.UpdateWalletHistory(mWalletAddress, request.getResultArray());
|
||||
|
||||
JSONArray historyList = request.getResultArray();
|
||||
|
||||
for (int i = 0; i < historyList.length(); i++) {
|
||||
JSONObject jsUnspent = historyList.getJSONObject(i);
|
||||
Integer height = jsUnspent.getInt("height");
|
||||
String hash = jsUnspent.getString("tx_hash");
|
||||
if (height != -1) {
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(main, request.Host, request.Port);
|
||||
main.requestTasks.add(task);
|
||||
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.GetHeader(mWalletAddress, String.valueOf(height)),
|
||||
ElectrumRequest.GetTransaction(mWalletAddress, hash));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetHeader)) {
|
||||
try {
|
||||
String mWalletAddress = request.WalletAddress;
|
||||
|
||||
main.mCardListAdapter.UpdateWalletHeader(mWalletAddress, request.getResult());
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetTransaction)) {
|
||||
try {
|
||||
Log.e("MainActivityFragment_TX", request.TxHash);
|
||||
String mWalletAddress = request.WalletAddress;
|
||||
String tx = request.TxHash;
|
||||
String raw = request.getResultString();
|
||||
Log.e("MainActivityFragment_R", raw);
|
||||
main.mCardListAdapter.UpdateTransaction(mWalletAddress, tx, raw);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
main.mCardListAdapter.UpdateWalletError(request.WalletAddress, "Cannot obtain data from blockchain");
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sharedCounter != null) {
|
||||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter >= sharedCounter.allRequest) {
|
||||
FinishWithError(request.WalletAddress, request.error);
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else {
|
||||
FinishWithError(request.WalletAddress, request.error);
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
if (sharedCounter != null) {
|
||||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter >= sharedCounter.allRequest) {
|
||||
e.printStackTrace();
|
||||
main.mCardListAdapter.UpdateWalletError(request.WalletAddress, "Cannot obtain data from blockchain");
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
main.mCardListAdapter.UpdateWalletError(request.WalletAddress, "Cannot obtain data from blockchain");
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ import com.google.zxing.Result;
|
|||
|
||||
import me.dm7.barcodescanner.zxing.ZXingScannerView;
|
||||
|
||||
public class QRScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{
|
||||
public class QRScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
|
||||
|
||||
private ZXingScannerView mScannerView;
|
||||
|
||||
|
|
@ -22,15 +22,14 @@ public class QRScanActivity extends AppCompatActivity implements ZXingScannerVi
|
|||
super.onCreate(savedInstanceState);
|
||||
//setContentView(R.layout.activity_qrscan);
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.e("QRScanActivity","User hasn't granted permission to use camera");
|
||||
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA}, 1);
|
||||
}else {
|
||||
Log.e("QRScanActivity", "User hasn't granted permission to use camera");
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1);
|
||||
} else {
|
||||
runScanner();
|
||||
}
|
||||
}
|
||||
|
||||
void runScanner()
|
||||
{
|
||||
void runScanner() {
|
||||
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
|
||||
setContentView(mScannerView);
|
||||
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
|
||||
|
|
@ -38,21 +37,20 @@ public class QRScanActivity extends AppCompatActivity implements ZXingScannerVi
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case 1: {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
Log.i("QRScanActivity","permission was granted");
|
||||
Log.i("QRScanActivity", "permission was granted");
|
||||
// permission was granted, yay! Do the
|
||||
// contacts-related task you need to do.
|
||||
runScanner();
|
||||
|
||||
} else {
|
||||
Log.e("QRScanActivity","permission denied");
|
||||
Log.e("QRScanActivity", "permission denied");
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
|
||||
|
|
@ -67,24 +65,24 @@ public class QRScanActivity extends AppCompatActivity implements ZXingScannerVi
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleResult(Result result) {
|
||||
Intent data=new Intent();
|
||||
Intent data = new Intent();
|
||||
data.putExtra("QRCode", result.getText());
|
||||
setResult(Activity.RESULT_OK, data);
|
||||
setResult(Activity.RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if( mScannerView!=null ) mScannerView.stopCamera(); // Stop camera on pause
|
||||
if (mScannerView != null) mScannerView.stopCamera(); // Stop camera on pause
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if( mScannerView!=null ) mScannerView.startCamera();
|
||||
if (mScannerView != null) mScannerView.startCamera();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -50,11 +50,8 @@ public class RequestPINActivity extends AppCompatActivity implements NfcAdapter.
|
|||
|
||||
Mode mode;
|
||||
boolean allowFingerprint = false;
|
||||
|
||||
private NfcManager mNfcManager;
|
||||
|
||||
private TextView tvPIN;
|
||||
|
||||
private StartFingerprintReaderTask mStartFingerprintReaderTask;
|
||||
|
||||
public static final String KEY_ALIAS = "pinKey";
|
||||
|
|
@ -102,23 +99,15 @@ public class RequestPINActivity extends AppCompatActivity implements NfcAdapter.
|
|||
Button btn9 = findViewById(R.id.btn9);
|
||||
btn9.setOnClickListener(onButtonNClick);
|
||||
Button btnBS = findViewById(R.id.btnBackspace);
|
||||
btnBS.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String S = tvPIN.getText().toString();
|
||||
if (S.length() > 0) {
|
||||
tvPIN.setText(S.substring(0, S.length() - 1));
|
||||
}
|
||||
btnBS.setOnClickListener(view -> {
|
||||
String S = tvPIN.getText().toString();
|
||||
if (S.length() > 0) {
|
||||
tvPIN.setText(S.substring(0, S.length() - 1));
|
||||
}
|
||||
});
|
||||
|
||||
Button btnContinue = findViewById(R.id.btnContinue);
|
||||
btnContinue.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
doContinue();
|
||||
}
|
||||
});
|
||||
btnContinue.setOnClickListener(view -> doContinue());
|
||||
|
||||
mode = Mode.valueOf(getIntent().getStringExtra("mode"));
|
||||
TextView tvPrompt = findViewById(R.id.pin_prompt);
|
||||
|
|
@ -530,6 +519,4 @@ public class RequestPINActivity extends AppCompatActivity implements NfcAdapter.
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,9 +28,9 @@ import android.widget.Toast;
|
|||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.data.network.request.ExchangeRequest;
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
import com.tangem.data.network.task.ElectrumTask;
|
||||
import com.tangem.data.network.task.ExchangeTask;
|
||||
import com.tangem.data.network.task.InfuraTask;
|
||||
import com.tangem.data.network.task.main.ETHRequestTask;
|
||||
import com.tangem.data.network.task.main.RateInfoTask;
|
||||
import com.tangem.data.network.task.main.RequestWalletInfoTask;
|
||||
import com.tangem.data.nfc.ReadCardInfoTask;
|
||||
import com.tangem.domain.cardReader.CardProtocol;
|
||||
import com.tangem.domain.cardReader.NfcManager;
|
||||
|
|
@ -49,11 +49,6 @@ import com.tangem.presentation.dialog.WaitSecurityDelayDialog;
|
|||
import com.tangem.util.Util;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -75,310 +70,14 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
private ArrayList<String> slCardUIDs = new ArrayList<>();
|
||||
private RelativeLayout rlProgressBar;
|
||||
private ProgressBar progressBar;
|
||||
private CardListAdapter mCardListAdapter;
|
||||
public CardListAdapter mCardListAdapter;
|
||||
private ReadCardInfoTask readCardInfoTask;
|
||||
private List<RequestWalletInfoTask> requestTasks = new ArrayList<>();
|
||||
public List<RequestWalletInfoTask> requestTasks = new ArrayList<>();
|
||||
|
||||
private int unsuccessReadCount = 0;
|
||||
private Tag lastTag = null;
|
||||
private String lastRead_UID = "";
|
||||
|
||||
private class RateInfoTask extends ExchangeTask {
|
||||
protected void onPostExecute(List<ExchangeRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
for (ExchangeRequest request : requests) {
|
||||
if (request.error == null) {
|
||||
try {
|
||||
|
||||
JSONArray arr = request.getAnswerList();
|
||||
for (int i = 0; i < arr.length(); ++i) {
|
||||
JSONObject obj = arr.getJSONObject(i);
|
||||
String currency = obj.getString("id");
|
||||
|
||||
boolean stop = false;
|
||||
boolean stopAlter = false;
|
||||
if (currency.equals(request.currency)) {
|
||||
String usd = obj.getString("price_usd");
|
||||
|
||||
Float rate = Float.valueOf(usd);
|
||||
mCardListAdapter.UpdateRate(request.WalletAddress, rate);
|
||||
stop = true;
|
||||
}
|
||||
|
||||
if (currency.equals(request.currencyAlter)) {
|
||||
String usd = obj.getString("price_usd");
|
||||
|
||||
Float rate = Float.valueOf(usd);
|
||||
mCardListAdapter.UpdateRateAlter(request.WalletAddress, rate);
|
||||
stopAlter = true;
|
||||
}
|
||||
|
||||
if (stop && stopAlter) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//mCardListAdapter.UpdateWalletBalance(mWalletAddress, balance, l.toString(10));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class RequestWalletInfoTask extends ElectrumTask {
|
||||
public RequestWalletInfoTask(String host, int port) {
|
||||
super(host, port);
|
||||
}
|
||||
|
||||
|
||||
public RequestWalletInfoTask(String host, int port, SharedData sharedData) {
|
||||
super(host, port, sharedData);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... values) {
|
||||
super.onProgressUpdate(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
super.onCancelled();
|
||||
requestTasks.remove(this);
|
||||
}
|
||||
|
||||
void FinishWithError(String wallet, String message) {
|
||||
mCardListAdapter.UpdateWalletError(wallet, "Cannot obtain data from blockchain");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<ElectrumRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
requestTasks.remove(this);
|
||||
Log.i("RequestWalletInfoTask", "onPostExecute[" + String.valueOf(requests.size()) + "]");
|
||||
|
||||
CoinEngine engine = CoinEngineFactory.Create(Blockchain.Bitcoin);
|
||||
|
||||
for (ElectrumRequest request : requests) {
|
||||
try {
|
||||
|
||||
if (request.error == null) {
|
||||
if (request.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
Long conf = request.getResult().getLong("confirmed");
|
||||
Long unconf = request.getResult().getLong("unconfirmed");
|
||||
if (sharedCounter != null) {
|
||||
int counter = sharedCounter.requestCounter.incrementAndGet();
|
||||
if (counter != 1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
mCardListAdapter.UpdateWalletBalance(mWalletAddress, conf, unconf, getValidationNodeDescription());
|
||||
} catch (JSONException e) {
|
||||
if (sharedCounter != null) {
|
||||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter == sharedCounter.allRequest) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_ListUnspent)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
mCardListAdapter.UpdateWalletUnspent(mWalletAddress, request.getResultArray());
|
||||
|
||||
JSONArray unspentList = request.getResultArray();
|
||||
|
||||
for (int i = 0; i < unspentList.length(); i++) {
|
||||
JSONObject jsUnspent = unspentList.getJSONObject(i);
|
||||
Integer height = jsUnspent.getInt("height");
|
||||
String hash = jsUnspent.getString("tx_hash");
|
||||
if (height != -1) {
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(request.Host, request.Port);
|
||||
requestTasks.add(task);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.GetHeader(mWalletAddress, String.valueOf(height)),
|
||||
ElectrumRequest.GetTransaction(mWalletAddress, hash));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetHistory)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
mCardListAdapter.UpdateWalletHistory(mWalletAddress, request.getResultArray());
|
||||
|
||||
JSONArray historyList = request.getResultArray();
|
||||
|
||||
for (int i = 0; i < historyList.length(); i++) {
|
||||
JSONObject jsUnspent = historyList.getJSONObject(i);
|
||||
Integer height = jsUnspent.getInt("height");
|
||||
String hash = jsUnspent.getString("tx_hash");
|
||||
if (height != -1) {
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(request.Host, request.Port);
|
||||
requestTasks.add(task);
|
||||
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.GetHeader(mWalletAddress, String.valueOf(height)),
|
||||
ElectrumRequest.GetTransaction(mWalletAddress, hash));
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetHeader)) {
|
||||
try {
|
||||
String mWalletAddress = request.WalletAddress;
|
||||
|
||||
mCardListAdapter.UpdateWalletHeader(mWalletAddress, request.getResult());
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetTransaction)) {
|
||||
try {
|
||||
Log.e("MainActivityFragment_TX", request.TxHash);
|
||||
String mWalletAddress = request.WalletAddress;
|
||||
String tx = request.TxHash;
|
||||
String raw = request.getResultString();
|
||||
Log.e("MainActivityFragment_R", raw);
|
||||
mCardListAdapter.UpdateTransaction(mWalletAddress, tx, raw);
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
mCardListAdapter.UpdateWalletError(request.WalletAddress, "Cannot obtain data from blockchain");
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sharedCounter != null) {
|
||||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter >= sharedCounter.allRequest) {
|
||||
FinishWithError(request.WalletAddress, request.error);
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else {
|
||||
FinishWithError(request.WalletAddress, request.error);
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
if (sharedCounter != null) {
|
||||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter >= sharedCounter.allRequest) {
|
||||
e.printStackTrace();
|
||||
mCardListAdapter.UpdateWalletError(request.WalletAddress, "Cannot obtain data from blockchain");
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
mCardListAdapter.UpdateWalletError(request.WalletAddress, "Cannot obtain data from blockchain");
|
||||
engine.SwitchNode(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ETHRequestTask extends InfuraTask {
|
||||
ETHRequestTask(Blockchain blockchain) {
|
||||
super(blockchain);
|
||||
}
|
||||
|
||||
void FinishWithError(String wallet, String message) {
|
||||
mCardListAdapter.UpdateWalletError(wallet, "Cannot obtain data from blockchain");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<InfuraRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
for (InfuraRequest request : requests) {
|
||||
try {
|
||||
if (request.error == null) {
|
||||
|
||||
if (request.isMethod(InfuraRequest.METHOD_ETH_GetBalance)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
|
||||
String balanceCap = request.getResultString();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
BigInteger l = new BigInteger(balanceCap, 16);
|
||||
BigInteger d = l.divide(new BigInteger("1000000000000000000", 10));
|
||||
Long balance = d.longValue();
|
||||
if (request.getBlockchain() != Blockchain.Token)
|
||||
mCardListAdapter.UpdateWalletBalance(mWalletAddress, balance, l.toString(10), getValidationNodeDescription());
|
||||
mCardListAdapter.UpdateWalletBalanceOnlyAlter(mWalletAddress, l.toString(10));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_Call)) {
|
||||
try {
|
||||
String mWalletAddress = request.WalletAddress;
|
||||
|
||||
String balanceCap = request.getResultString();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
BigInteger l = new BigInteger(balanceCap, 16);
|
||||
Long balance = l.longValue();
|
||||
if (l.compareTo(BigInteger.ZERO) == 0) {
|
||||
mCardListAdapter.UpdateWalletBlockchain(mWalletAddress, Blockchain.Ethereum);
|
||||
mCardListAdapter.AddWalletBlockchainNameToken(mWalletAddress);
|
||||
TangemCard card = mCardListAdapter.getCardByWallet(request.WalletAddress);
|
||||
if (card != null) {
|
||||
refreshCard(card);
|
||||
}
|
||||
return;
|
||||
}
|
||||
mCardListAdapter.UpdateWalletBalance(mWalletAddress, balance, l.toString(10), getValidationNodeDescription());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_GetOutTransactionCount)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
|
||||
String nonce = request.getResultString();
|
||||
nonce = nonce.substring(2);
|
||||
BigInteger count = new BigInteger(nonce, 16);
|
||||
|
||||
mCardListAdapter.UpdateWalletCoutConfirmTx(mWalletAddress, count);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FinishWithError(request.WalletAddress, request.error);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Main() {
|
||||
}
|
||||
|
||||
|
|
@ -416,7 +115,7 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
|
||||
//Remove swiped item from list and notify the RecyclerView
|
||||
// remove swiped item from list and notify the RecyclerView
|
||||
int cardIndex = viewHolder.getAdapterPosition();
|
||||
if (cardIndex < 0 || cardIndex >= mCardListAdapter.getItemCount()) return;
|
||||
slCardUIDs.remove(mCardListAdapter.getCard(cardIndex).getUID());
|
||||
|
|
@ -714,6 +413,81 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
lastRead_UID = "";
|
||||
}
|
||||
|
||||
public void refreshCard(TangemCard card) {
|
||||
CoinEngine engine = CoinEngineFactory.Create(card.getBlockchain());
|
||||
if (card.getBlockchain() == Blockchain.Ethereum || card.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
ETHRequestTask task = new ETHRequestTask(Main.this, card.getBlockchain());
|
||||
InfuraRequest req = InfuraRequest.GetBalance(card.getWallet());
|
||||
req.setID(67);
|
||||
req.setBlockchain(card.getBlockchain());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
task.execute(req, reqNonce);
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask(Main.this);
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "ethereum", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
} else if (card.getBlockchain() == Blockchain.BitcoinTestNet || card.getBlockchain() == Blockchain.Bitcoin) {
|
||||
SharedData data = new SharedData(SharedData.COUNT_REQUEST);
|
||||
for (int i = 0; i < data.allRequest; ++i) {
|
||||
|
||||
String nodeAddress = engine.GetNextNode(card);
|
||||
int nodePort = engine.GetNextNodePort(card);
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort, data);
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.CheckBalance(card.getWallet()));
|
||||
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort);
|
||||
requestTasks.add(task);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.ListUnspent(card.getWallet()));//, ElectrumRequest.ListHistory(card.getWallet()));
|
||||
}
|
||||
|
||||
} else if (card.getBlockchain() == Blockchain.BitcoinCashTestNet || card.getBlockchain() == Blockchain.BitcoinCash) {
|
||||
SharedData data = new SharedData(SharedData.COUNT_REQUEST);
|
||||
for (int i = 0; i < data.allRequest; ++i) {
|
||||
|
||||
String nodeAddress = engine.GetNextNode(card);
|
||||
int nodePort = engine.GetNextNodePort(card);
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort, data);
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.CheckBalance(card.getWallet()));
|
||||
}
|
||||
|
||||
String nodeAddress = engine.GetNode(card);
|
||||
int nodePort = engine.GetNodePort(card);
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort);
|
||||
|
||||
requestTasks.add(task);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.ListUnspent(card.getWallet()));//, ElectrumRequest.ListHistory(card.getWallet()));
|
||||
RateInfoTask taskRate = new RateInfoTask(Main.this);
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "bitcoin-cash", "bitcoin-cash");
|
||||
taskRate.execute(rate);
|
||||
|
||||
} else if (card.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask updateETH = new ETHRequestTask(Main.this, card.getBlockchain());
|
||||
InfuraRequest reqETH = InfuraRequest.GetTokenBalance(card.getWallet(), engine.GetContractAddress(card), engine.GetTokenDecimals(card));
|
||||
reqETH.setID(67);
|
||||
reqETH.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
||||
InfuraRequest reqBalance = InfuraRequest.GetBalance(card.getWallet());
|
||||
reqBalance.setID(67);
|
||||
reqBalance.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask(Main.this);
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "basic-attention-token", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
updateETH.execute(reqETH, reqNonce, reqBalance);
|
||||
}
|
||||
}
|
||||
|
||||
private void addCard(final TangemCard card) {
|
||||
if (mCardListAdapter != null) {
|
||||
Objects.requireNonNull(getActivity()).runOnUiThread(() -> {
|
||||
|
|
@ -726,7 +500,7 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
if (card.getStatus() == TangemCard.Status.Loaded) {
|
||||
|
||||
if (card.getBlockchain() == Blockchain.Ethereum || card.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
ETHRequestTask task = new ETHRequestTask(card.getBlockchain());
|
||||
ETHRequestTask task = new ETHRequestTask(Main.this, card.getBlockchain());
|
||||
InfuraRequest req = InfuraRequest.GetBalance(card.getWallet());
|
||||
req.setID(67);
|
||||
req.setBlockchain(card.getBlockchain());
|
||||
|
|
@ -736,7 +510,7 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
|
||||
task.execute(req, reqNonce);
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
RateInfoTask taskRate = new RateInfoTask(Main.this);
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "ethereum", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
|
|
@ -747,19 +521,19 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
String nodeAddress = engine.GetNextNode(card);
|
||||
int nodePort = engine.GetNextNodePort(card);
|
||||
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(nodeAddress, nodePort, data);
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort, data);
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.CheckBalance(card.getWallet()));
|
||||
}
|
||||
|
||||
String nodeAddress = engine.GetNode(card);
|
||||
int nodePort = engine.GetNodePort(card);
|
||||
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(nodeAddress, nodePort);
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort);
|
||||
|
||||
requestTasks.add(task);
|
||||
// task.execute(ElectrumRequest.ListUnspent(card.getWallet()));//, ElectrumRequest.ListHistory(card.getWallet()));
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.ListUnspent(card.getWallet()));//, ElectrumRequest.ListHistory(card.getWallet()));
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
RateInfoTask taskRate = new RateInfoTask(Main.this);
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "bitcoin", "bitcoin");
|
||||
taskRate.execute(rate);
|
||||
|
||||
|
|
@ -770,23 +544,23 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
String nodeAddress = engine.GetNextNode(card);
|
||||
int nodePort = engine.GetNextNodePort(card);
|
||||
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(nodeAddress, nodePort, data);
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort, data);
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.CheckBalance(card.getWallet()));
|
||||
}
|
||||
|
||||
String nodeAddress = engine.GetNode(card);
|
||||
int nodePort = engine.GetNodePort(card);
|
||||
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(nodeAddress, nodePort);
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(Main.this, nodeAddress, nodePort);
|
||||
|
||||
requestTasks.add(task);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.ListUnspent(card.getWallet()));//, ElectrumRequest.ListHistory(card.getWallet()));
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
RateInfoTask taskRate = new RateInfoTask(Main.this);
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "bitcoin-cash", "bitcoin-cash");
|
||||
taskRate.execute(rate);
|
||||
|
||||
} else if (card.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask updateETH = new ETHRequestTask(card.getBlockchain());
|
||||
ETHRequestTask updateETH = new ETHRequestTask(Main.this, card.getBlockchain());
|
||||
InfuraRequest reqETH = InfuraRequest.GetTokenBalance(card.getWallet(), engine.GetContractAddress(card), engine.GetTokenDecimals(card));
|
||||
reqETH.setID(67);
|
||||
reqETH.setBlockchain(card.getBlockchain());
|
||||
|
|
@ -797,7 +571,7 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
reqBalance.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
RateInfoTask taskRate = new RateInfoTask(Main.this);
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "basic-attention-token", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
|
|
@ -815,81 +589,6 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
}
|
||||
}
|
||||
|
||||
private void refreshCard(TangemCard card) {
|
||||
CoinEngine engine = CoinEngineFactory.Create(card.getBlockchain());
|
||||
if (card.getBlockchain() == Blockchain.Ethereum || card.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
ETHRequestTask task = new ETHRequestTask(card.getBlockchain());
|
||||
InfuraRequest req = InfuraRequest.GetBalance(card.getWallet());
|
||||
req.setID(67);
|
||||
req.setBlockchain(card.getBlockchain());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
task.execute(req, reqNonce);
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "ethereum", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
} else if (card.getBlockchain() == Blockchain.BitcoinTestNet || card.getBlockchain() == Blockchain.Bitcoin) {
|
||||
SharedData data = new SharedData(SharedData.COUNT_REQUEST);
|
||||
for (int i = 0; i < data.allRequest; ++i) {
|
||||
|
||||
String nodeAddress = engine.GetNextNode(card);
|
||||
int nodePort = engine.GetNextNodePort(card);
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(nodeAddress, nodePort, data);
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.CheckBalance(card.getWallet()));
|
||||
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(nodeAddress, nodePort);
|
||||
requestTasks.add(task);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.ListUnspent(card.getWallet()));//, ElectrumRequest.ListHistory(card.getWallet()));
|
||||
}
|
||||
|
||||
} else if (card.getBlockchain() == Blockchain.BitcoinCashTestNet || card.getBlockchain() == Blockchain.BitcoinCash) {
|
||||
SharedData data = new SharedData(SharedData.COUNT_REQUEST);
|
||||
for (int i = 0; i < data.allRequest; ++i) {
|
||||
|
||||
String nodeAddress = engine.GetNextNode(card);
|
||||
int nodePort = engine.GetNextNodePort(card);
|
||||
RequestWalletInfoTask connectTaskEx = new RequestWalletInfoTask(nodeAddress, nodePort, data);
|
||||
connectTaskEx.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.CheckBalance(card.getWallet()));
|
||||
}
|
||||
|
||||
String nodeAddress = engine.GetNode(card);
|
||||
int nodePort = engine.GetNodePort(card);
|
||||
RequestWalletInfoTask task = new RequestWalletInfoTask(nodeAddress, nodePort);
|
||||
|
||||
requestTasks.add(task);
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ElectrumRequest.ListUnspent(card.getWallet()));//, ElectrumRequest.ListHistory(card.getWallet()));
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "bitcoin-cash", "bitcoin-cash");
|
||||
taskRate.execute(rate);
|
||||
|
||||
} else if (card.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask updateETH = new ETHRequestTask(card.getBlockchain());
|
||||
InfuraRequest reqETH = InfuraRequest.GetTokenBalance(card.getWallet(), engine.GetContractAddress(card), engine.GetTokenDecimals(card));
|
||||
reqETH.setID(67);
|
||||
reqETH.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
||||
InfuraRequest reqBalance = InfuraRequest.GetBalance(card.getWallet());
|
||||
reqBalance.setID(67);
|
||||
reqBalance.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "basic-attention-token", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
updateETH.execute(reqETH, reqNonce, reqBalance);
|
||||
}
|
||||
}
|
||||
|
||||
private void doEnterPIN() {
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN.toString());
|
||||
|
|
@ -899,7 +598,7 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
private void verifyPermissions() {
|
||||
NfcManager.verifyPermissions(getActivity());
|
||||
if (ActivityCompat.checkSelfPermission(Objects.requireNonNull(getActivity()), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.e("QRScanActivity", "User hasn't granted permission to use camera");
|
||||
// Log.e("QRScanActivity", "User hasn't granted permission to use camera");
|
||||
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA}, REQUEST_CODE_REQUEST_CAMERA_PERMISSIONS);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue