Updated on 2026-08-14
This commit is contained in:
parent
bbed187fab
commit
d70ec8b246
2 changed files with 15 additions and 77 deletions
|
|
@ -278,16 +278,6 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
}
|
||||
serverApiTangem.setArtworkListener(artworkListener)
|
||||
|
||||
// request rate info listener
|
||||
// serverApiCommon.setRateInfoListener {
|
||||
// if (activity == null || !UtilHelper.isOnline(activity!!)) return@setRateInfoListener
|
||||
// val rate = it.priceUsd.toFloat()
|
||||
// ctx.coinData!!.rate = rate
|
||||
// ctx.coinData!!.rateAlter = rate
|
||||
//
|
||||
// Log.i(TAG, "scscscsc222 " + rate)
|
||||
// }
|
||||
|
||||
refresh()
|
||||
|
||||
startVerify(lastTag)
|
||||
|
|
@ -298,19 +288,11 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
viewModel = ViewModelProviders.of(this).get(LoadedWalletViewModel::class.java)
|
||||
|
||||
// set rate info to CoinData
|
||||
// viewModel.getRateInfo(ctx).observe(this, Observer<Float> { rate ->
|
||||
// Log.i(TAG, "scscscsc111 " + rate)
|
||||
//
|
||||
// ctx.coinData.rate = rate
|
||||
// ctx.coinData.rateAlter = rate
|
||||
// })
|
||||
|
||||
viewModel.getRateInfo(ctx).observeForever { rate ->
|
||||
Log.i(TAG, "scscscsc111 $rate")
|
||||
|
||||
viewModel.getRateInfo().observe(this, Observer<Float> { rate ->
|
||||
ctx.coinData.rate = rate
|
||||
ctx.coinData.rateAlter = rate
|
||||
}
|
||||
})
|
||||
viewModel.requestRateInfo(ctx)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
|
@ -673,11 +655,8 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
|
||||
requestBalanceAndUnspentTransactions()
|
||||
|
||||
// requestRateInfo()
|
||||
if (::viewModel.isInitialized) {
|
||||
viewModel.getRateInfo(ctx)
|
||||
Log.i(TAG, "isInitialized")
|
||||
}
|
||||
if (::viewModel.isInitialized)
|
||||
viewModel.requestRateInfo(ctx)
|
||||
|
||||
if (requestCounter == 0) {
|
||||
// if no connection and no requests posted
|
||||
|
|
@ -739,34 +718,6 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
}
|
||||
}
|
||||
|
||||
// private fun requestRateInfo() {
|
||||
// if (UtilHelper.isOnline(context as Activity)) {
|
||||
// LOG.i(TAG, "requestRateInfo")
|
||||
//
|
||||
// val cryptoId: String = when (ctx.blockchain) {
|
||||
// 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"
|
||||
// else -> {
|
||||
// throw Exception("Can''t get rate for blockchain " + ctx.blockchainName)
|
||||
// }
|
||||
// }
|
||||
// serverApiCommon.requestRateInfo(cryptoId)
|
||||
// } else {
|
||||
// ctx.error = getString(R.string.no_connection)
|
||||
// updateViews()
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun startVerify(tag: Tag?) {
|
||||
try {
|
||||
val isoDep = IsoDep.get(tag)
|
||||
|
|
|
|||
|
|
@ -9,35 +9,20 @@ import com.tangem.wallet.TangemContext
|
|||
|
||||
class LoadedWalletViewModel : ViewModel() {
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
// private var rate = MutableLiveData<Float>()
|
||||
//
|
||||
// fun getRateInfo(ctx: TangemContext): LiveData<Float> {
|
||||
// this.ctx = ctx
|
||||
// rate = MutableLiveData()
|
||||
// requestRateInfo()
|
||||
// return rate
|
||||
// }
|
||||
|
||||
private val rate: MutableLiveData<Float> by lazy {
|
||||
MutableLiveData<Float>().also {
|
||||
requestRateInfo()
|
||||
loadRateInfo()
|
||||
}
|
||||
}
|
||||
|
||||
fun getRateInfo(ctx: TangemContext): LiveData<Float> {
|
||||
this.ctx = ctx
|
||||
fun getRateInfo(): LiveData<Float> {
|
||||
return rate
|
||||
}
|
||||
|
||||
private fun requestRateInfo() {
|
||||
serverApiCommon.setRateInfoListener {
|
||||
val rate = it.priceUsd.toFloat()
|
||||
this.rate.value = rate
|
||||
}
|
||||
// TODO - move requestRateInfo to CoinEngine
|
||||
fun requestRateInfo(ctx: TangemContext) {
|
||||
this.ctx = ctx
|
||||
// TODO - move loadRateInfo to CoinEngine
|
||||
val cryptoId: String = when (ctx.blockchain) {
|
||||
Blockchain.Bitcoin -> "bitcoin"
|
||||
Blockchain.BitcoinTestNet -> "bitcoin"
|
||||
|
|
@ -58,8 +43,10 @@ class LoadedWalletViewModel : ViewModel() {
|
|||
serverApiCommon.requestRateInfo(cryptoId)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
// getRateInfo(ctx).removeObservers()
|
||||
private fun loadRateInfo() {
|
||||
serverApiCommon.setRateInfoListener {
|
||||
val rate = it.priceUsd.toFloat()
|
||||
this.rate.value = rate
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue