Updated on 2026-08-14
This commit is contained in:
parent
12583818ec
commit
dfd8bd0594
6 changed files with 62 additions and 29 deletions
|
|
@ -1,7 +1,5 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import static com.tangem.data.network.Server.ApiTangem.URL_TANGEM;
|
||||
|
||||
public class Server {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -113,9 +113,11 @@ public class ServerApiHelper {
|
|||
* Infura
|
||||
* <p>
|
||||
* eth_getBalance
|
||||
* eth_getTransactionCount
|
||||
* eth_gasPrice
|
||||
*/
|
||||
public static final String INFURA_ETH_GET_BALANCE = "eth_getBalance";
|
||||
public static final String INFURA_ETH_GET_TRANSACTION_COUNT = "eth_getTransactionCount";
|
||||
public static final String INFURA_ETH_GAS_PRICE = "eth_gasPrice";
|
||||
private InfuraBodyListener infuraBodyListener;
|
||||
|
||||
|
|
@ -138,6 +140,7 @@ public class ServerApiHelper {
|
|||
InfuraBody infuraBody;
|
||||
switch (method) {
|
||||
case INFURA_ETH_GET_BALANCE:
|
||||
case INFURA_ETH_GET_TRANSACTION_COUNT:
|
||||
infuraBody = new InfuraBody(method, new String[]{wallet, "latest"}, id);
|
||||
break;
|
||||
|
||||
|
|
@ -246,11 +249,12 @@ public class ServerApiHelper {
|
|||
for (RateInfoResponse rateInfoMode : rateInfoModelList) {
|
||||
if (rateInfoMode.getId().equals(cryptoId)) {
|
||||
rateInfoDataListener.onRateInfoDataData(rateInfoMode);
|
||||
Log.i("rateInfoData", rateInfoMode.getId());
|
||||
Log.i("rateInfoData", rateInfoMode.getPriceUsd());
|
||||
Log.i(TAG, "rateInfoData " + cryptoId + " onResponse " + "200");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
Log.e(TAG, "rateInfoData " + cryptoId + " onResponse " + "Empty");
|
||||
|
||||
},
|
||||
// handle error
|
||||
Throwable::printStackTrace);
|
||||
|
|
@ -411,7 +415,7 @@ public class ServerApiHelper {
|
|||
call.enqueue(new Callback<ResponseBody>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
|
||||
Log.i(TAG, "LastVersion onResponse " + response.code());
|
||||
Log.i(TAG, "lastVersion onResponse " + response.code());
|
||||
if (response.code() == 200) {
|
||||
String stringResponse;
|
||||
try {
|
||||
|
|
@ -425,7 +429,7 @@ public class ServerApiHelper {
|
|||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, "LastVersion onFailure " + t.getMessage());
|
||||
Log.e(TAG, "lastVersion onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class ETHRequestTask extends InfuraTask {
|
|||
nonce = nonce.substring(2);
|
||||
BigInteger count = new BigInteger(nonce, 16);
|
||||
|
||||
loadedWallet.getCard().SetConfirmTXCount(count);
|
||||
loadedWallet.getCard().setConfirmTXCount(count);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ public class ETHRequestTask extends InfuraTask {
|
|||
|
||||
BigInteger nonce = loadedWallet.getCard().GetConfirmTXCount();
|
||||
nonce.add(BigInteger.valueOf(1));
|
||||
loadedWallet.getCard().SetConfirmTXCount(nonce);
|
||||
loadedWallet.getCard().setConfirmTXCount(nonce);
|
||||
Log.e("TX_RESULT", hashTX);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class ETHRequestTask extends InfuraTask {
|
|||
LastSignStorage.setLastMessage(sendTransactionActivity.getCard().getWallet(), "");
|
||||
BigInteger nonce = sendTransactionActivity.getCard().GetConfirmTXCount();
|
||||
nonce.add(BigInteger.valueOf(1));
|
||||
sendTransactionActivity.getCard().SetConfirmTXCount(nonce);
|
||||
sendTransactionActivity.getCard().setConfirmTXCount(nonce);
|
||||
Log.e("TX_RESULT", hashTX);
|
||||
sendTransactionActivity.finishWithSuccess();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class TangemCard {
|
|||
return countConfirmTX;
|
||||
}
|
||||
|
||||
public void SetConfirmTXCount(BigInteger count) {
|
||||
public void setConfirmTXCount(BigInteger count) {
|
||||
countConfirmTX = count;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -240,11 +240,31 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// Log.i(TAG, "setRateInfoData $rate")
|
||||
}
|
||||
|
||||
// request eth get balance listener
|
||||
// request eth get balance, eth get transaction count listener
|
||||
serverApiHelper!!.setInfura { method, infuraResponse ->
|
||||
if (method == ServerApiHelper.INFURA_ETH_GET_BALANCE) {
|
||||
var balanceCap = infuraResponse.result
|
||||
balanceCap = balanceCap.substring(2)
|
||||
val l = BigInteger(balanceCap, 16)
|
||||
val d = l.divide(BigInteger("1000000000000000000", 10))
|
||||
val balance = d.toLong()
|
||||
|
||||
// Log.i("eth_get_balance", gasPrice)
|
||||
card!!.setBalanceConfirmed(balance)
|
||||
card!!.balanceUnconfirmed = 0L
|
||||
if (card!!.blockchain != Blockchain.Token)
|
||||
card!!.decimalBalance = l.toString(10)
|
||||
card!!.decimalBalanceAlter = l.toString(10)
|
||||
|
||||
// Log.i("eth_get_balance", balanceCap)
|
||||
}
|
||||
|
||||
if (method == ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT) {
|
||||
var nonce = infuraResponse.result
|
||||
nonce = nonce.substring(2)
|
||||
val count = BigInteger(nonce, 16)
|
||||
card!!.setConfirmTXCount(count)
|
||||
|
||||
// Log.i("eth_getTransactionCount", nonce)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -661,37 +681,48 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// Ethereum
|
||||
else if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet) {
|
||||
|
||||
// requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE)
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE)
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT)
|
||||
|
||||
val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
|
||||
val reqETH = InfuraRequest.GetBalance(card!!.wallet)
|
||||
reqETH.id = 67
|
||||
reqETH.setBlockchain(card!!.blockchain)
|
||||
// val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
|
||||
|
||||
val reqNonce = InfuraRequest.GetOutTransactionCount(card!!.wallet)
|
||||
reqNonce.id = 67
|
||||
reqNonce.setBlockchain(card!!.blockchain)
|
||||
// val reqETH = InfuraRequest.GetBalance(card!!.wallet)
|
||||
// reqETH.id = 67
|
||||
// reqETH.setBlockchain(card!!.blockchain)
|
||||
|
||||
updateETH.execute(reqETH, reqNonce)
|
||||
// val reqNonce = InfuraRequest.GetOutTransactionCount(card!!.wallet)
|
||||
// reqNonce.id = 67
|
||||
// reqNonce.setBlockchain(card!!.blockchain)
|
||||
|
||||
// updateETH.execute(reqETH, reqNonce)
|
||||
// updateETH.execute(reqNonce)
|
||||
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
|
||||
// Token
|
||||
else if (card!!.blockchain == Blockchain.Token) {
|
||||
|
||||
val updateETH = ETHRequestTask(this@LoadedWallet, card!!.blockchain)
|
||||
|
||||
val reqETH = InfuraRequest.GetTokenBalance(card!!.wallet, engine!!.getContractAddress(card), engine.getTokenDecimals(card))
|
||||
reqETH.id = 67
|
||||
reqETH.setBlockchain(card!!.blockchain)
|
||||
|
||||
val reqBalance = InfuraRequest.GetBalance(card!!.wallet)
|
||||
reqBalance.id = 67
|
||||
reqBalance.setBlockchain(card!!.blockchain)
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE)
|
||||
|
||||
val reqNonce = InfuraRequest.GetOutTransactionCount(card!!.wallet)
|
||||
reqNonce.id = 67
|
||||
reqNonce.setBlockchain(card!!.blockchain)
|
||||
updateETH.execute(reqETH, reqNonce, reqBalance)
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT)
|
||||
|
||||
// val reqBalance = InfuraRequest.GetBalance(card!!.wallet)
|
||||
// reqBalance.id = 67
|
||||
// reqBalance.setBlockchain(card!!.blockchain)
|
||||
|
||||
// val reqNonce = InfuraRequest.GetOutTransactionCount(card!!.wallet)
|
||||
// reqNonce.id = 67
|
||||
// reqNonce.setBlockchain(card!!.blockchain)
|
||||
|
||||
// updateETH.execute(reqETH, reqNonce, reqBalance)
|
||||
updateETH.execute(reqETH)
|
||||
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue