Updated on 2026-08-14
This commit is contained in:
parent
78ef89d2cf
commit
bbed187fab
9 changed files with 168 additions and 73 deletions
|
|
@ -26,7 +26,7 @@ object Constant {
|
|||
|
||||
const val INTENT_TYPE_TEXT_PLAIN = "text/plain"
|
||||
|
||||
// LoadedWallet, VerifyCard
|
||||
// LoadedWalletFragment, VerifyCard
|
||||
const val REQUEST_CODE_SEND_TRANSACTION = 1
|
||||
const val REQUEST_CODE_PURGE = 2
|
||||
const val REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = 3
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import com.tangem.Constant
|
|||
import com.tangem.di.Navigator
|
||||
import com.tangem.di.ToastHelper
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.ui.fragment.LoadedWallet
|
||||
import com.tangem.ui.fragment.LoadedWalletFragment
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ class LoadedWalletActivity : AppCompatActivity() {
|
|||
if (intent.extras!!.containsKey(NfcAdapter.EXTRA_TAG)) {
|
||||
val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
|
||||
if (tag != null) {
|
||||
val fragment = supportFragmentManager.findFragmentById(R.id.loaded_wallet_fragment) as LoadedWallet
|
||||
val fragment = supportFragmentManager.findFragmentById(R.id.loaded_wallet_fragment) as LoadedWalletFragment
|
||||
fragment.onTagDiscovered(tag)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import android.nfc.tech.IsoDep
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
|
@ -20,6 +21,8 @@ import android.view.ViewGroup
|
|||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.data.Blockchain
|
||||
|
|
@ -63,11 +66,12 @@ import java.io.InputStream
|
|||
import java.util.*
|
||||
import kotlin.concurrent.timerTask
|
||||
|
||||
class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
companion object {
|
||||
val TAG: String = LoadedWallet::class.java.simpleName
|
||||
val TAG: String = LoadedWalletFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var viewModel: LoadedWalletViewModel
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var mpSecondScanSound: MediaPlayer
|
||||
|
|
@ -275,18 +279,40 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
|
|||
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
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
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")
|
||||
|
||||
ctx.coinData.rate = rate
|
||||
ctx.coinData.rateAlter = rate
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (timerHideErrorAndMessage != null) {
|
||||
|
|
@ -647,7 +673,11 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
|
|||
|
||||
requestBalanceAndUnspentTransactions()
|
||||
|
||||
requestRateInfo()
|
||||
// requestRateInfo()
|
||||
if (::viewModel.isInitialized) {
|
||||
viewModel.getRateInfo(ctx)
|
||||
Log.i(TAG, "isInitialized")
|
||||
}
|
||||
|
||||
if (requestCounter == 0) {
|
||||
// if no connection and no requests posted
|
||||
|
|
@ -709,34 +739,33 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback
|
|||
}
|
||||
}
|
||||
|
||||
private fun requestRateInfo() {
|
||||
if (UtilHelper.isOnline(context as Activity)) {
|
||||
LOG.i(TAG, "requestRateInfo")
|
||||
|
||||
// TODO - move requestRateInfo to CoinEngine
|
||||
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 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 {
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.tangem.ui.fragment
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
fun getRateInfo(ctx: TangemContext): LiveData<Float> {
|
||||
this.ctx = ctx
|
||||
return rate
|
||||
}
|
||||
|
||||
private fun requestRateInfo() {
|
||||
serverApiCommon.setRateInfoListener {
|
||||
val rate = it.priceUsd.toFloat()
|
||||
this.rate.value = rate
|
||||
}
|
||||
// TODO - move requestRateInfo to CoinEngine
|
||||
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)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
// getRateInfo(ctx).removeObservers()
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ import com.tangem.data.network.ServerApiCommon
|
|||
import com.tangem.wallet.BuildConfig
|
||||
|
||||
class MainViewModel : ViewModel() {
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
|
||||
private var versionName = MutableLiveData<String>()
|
||||
|
||||
fun getVersionName(): LiveData<String> {
|
||||
|
|
@ -17,8 +19,7 @@ class MainViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
private fun requestVersionName() {
|
||||
val apiHelper = ServerApiCommon()
|
||||
apiHelper.setLastVersionListener { response ->
|
||||
serverApiCommon.setLastVersionListener { response ->
|
||||
try {
|
||||
if (response.isNullOrEmpty())
|
||||
return@setLastVersionListener
|
||||
|
|
@ -32,6 +33,6 @@ class MainViewModel : ViewModel() {
|
|||
E.printStackTrace()
|
||||
}
|
||||
}
|
||||
apiHelper.requestLastVersion()
|
||||
serverApiCommon.requestLastVersion()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue