Updated on 2026-08-14
This commit is contained in:
parent
fbed37fe24
commit
7fa19e7bb2
2 changed files with 16 additions and 30 deletions
|
|
@ -92,7 +92,7 @@ public class ServerApiCommon {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestRateInfo(String cryptoId) {
|
public void requestRateInfo(String cryptoId) {
|
||||||
CoinmarketApi coinmarketApi = App.getNetworkComponent().getRetrofitCoinmarketcap().create(CoinmarketApi.class);
|
CoinmarketApi coinmarketApi = App.Companion.getNetworkComponent().getRetrofitCoinmarketcap().create(CoinmarketApi.class);
|
||||||
|
|
||||||
Call<RateInfoResponse> call = coinmarketApi.getRateInfo(1, cryptoId);
|
Call<RateInfoResponse> call = coinmarketApi.getRateInfo(1, cryptoId);
|
||||||
|
|
||||||
|
|
@ -100,17 +100,17 @@ public class ServerApiCommon {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<RateInfoResponse> call, @NonNull Response<RateInfoResponse> response) {
|
public void onResponse(@NonNull Call<RateInfoResponse> call, @NonNull Response<RateInfoResponse> response) {
|
||||||
if (response.code() == 200) {
|
if (response.code() == 200) {
|
||||||
rateInfoDataListener.onSuccess(response.body());
|
rateInfoListener.onSuccess(response.body());
|
||||||
Log.i(TAG, "coinmarketcap onResponse " + response.code());
|
Log.i(TAG, "coinmarketcap onResponse " + response.code());
|
||||||
} else {
|
} else {
|
||||||
rateInfoDataListener.onFail("Rate info error:" + String.valueOf(response.code()));
|
rateInfoListener.onFail("Rate info error:" + String.valueOf(response.code()));
|
||||||
Log.e(TAG, "coinmarketcap onResponse " + response.code());
|
Log.e(TAG, "coinmarketcap onResponse " + response.code());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<RateInfoResponse> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<RateInfoResponse> call, @NonNull Throwable t) {
|
||||||
rateInfoDataListener.onFail(String.valueOf(t.getMessage()));
|
rateInfoListener.onFail(String.valueOf(t.getMessage()));
|
||||||
Log.e(TAG, "coinmarketcap onFailure " + t.getMessage());
|
Log.e(TAG, "coinmarketcap onFailure " + t.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import com.tangem.data.Blockchain
|
import com.tangem.data.Blockchain
|
||||||
import com.tangem.data.network.ServerApiCommon
|
import com.tangem.data.network.ServerApiCommon
|
||||||
|
import com.tangem.data.network.ServerApiCommon.RateInfoListener
|
||||||
|
import com.tangem.data.network.model.RateInfoResponse
|
||||||
import com.tangem.wallet.TangemContext
|
import com.tangem.wallet.TangemContext
|
||||||
|
|
||||||
class LoadedWalletViewModel : ViewModel() {
|
class LoadedWalletViewModel : ViewModel() {
|
||||||
|
|
@ -23,34 +25,18 @@ class LoadedWalletViewModel : ViewModel() {
|
||||||
fun requestRateInfo(ctx: TangemContext) {
|
fun requestRateInfo(ctx: TangemContext) {
|
||||||
this.ctx = ctx
|
this.ctx = ctx
|
||||||
// TODO - move loadRateInfo to CoinEngine
|
// TODO - move loadRateInfo to CoinEngine
|
||||||
val cryptoId: String = when (ctx.blockchain) {
|
serverApiCommon.requestRateInfo(ctx.blockchain.currency)
|
||||||
Blockchain.Bitcoin -> "bitcoin"
|
|
||||||
Blockchain.BitcoinTestNet -> "bitcoin"
|
|
||||||
Blockchain.Ethereum -> "ethereum"
|
|
||||||
Blockchain.EthereumTestNet -> "ethereum"
|
|
||||||
Blockchain.Token -> "ethereum"
|
|
||||||
Blockchain.NftToken -> "ethereum"
|
|
||||||
Blockchain.BitcoinCash -> "bitcoin-cash"
|
|
||||||
Blockchain.Litecoin -> "litecoin"
|
|
||||||
Blockchain.Rootstock -> "bitcoin"
|
|
||||||
Blockchain.RootstockToken -> "bitcoin"
|
|
||||||
Blockchain.Cardano -> "cardano"
|
|
||||||
Blockchain.Ripple -> "ripple"
|
|
||||||
Blockchain.Binance -> "binance-coin"
|
|
||||||
Blockchain.BinanceTestNet -> "binance-coin"
|
|
||||||
Blockchain.Matic -> "bitcoin"
|
|
||||||
Blockchain.MaticTestNet -> "bitcoin"
|
|
||||||
else -> {
|
|
||||||
throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
serverApiCommon.requestRateInfo(cryptoId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadRateInfo() {
|
private fun loadRateInfo() {
|
||||||
serverApiCommon.setRateInfoListener {
|
serverApiCommon.setRateInfoListener(object: RateInfoListener{
|
||||||
val rate = it.priceUsd.toFloat()
|
override fun onSuccess(rateInfoResponse: RateInfoResponse?) {
|
||||||
this.rate.value = rate
|
rate.value = rateInfoResponse!!.data!!.quote!!.usd!!.price
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onFail(message: String?) {
|
||||||
|
ctx.error = message
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue