Updated on 2026-08-14
This commit is contained in:
commit
2af8d5dc82
78 changed files with 646 additions and 575 deletions
|
|
@ -14,11 +14,13 @@ import android.view.KeyEvent
|
|||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.network.ElectrumRequest
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.network.ServerApiHelperElectrum
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.data.network.ServerApiElectrum
|
||||
import com.tangem.data.network.ServerApiInfura
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.domain.wallet.btc.BtcData
|
||||
import com.tangem.util.*
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_confirm_payment.*
|
||||
|
|
@ -37,8 +39,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
private var nfcManager: NfcManager? = null
|
||||
|
||||
private var serverApiHelper: ServerApiHelper = ServerApiHelper()
|
||||
private var serverApiHelperElectrum: ServerApiHelperElectrum = ServerApiHelperElectrum()
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
private var serverApiElectrum: ServerApiElectrum = ServerApiElectrum()
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var amount: CoinEngine.Amount
|
||||
|
|
@ -97,7 +100,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token) {
|
||||
rgFee.isEnabled = false
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GAS_PRICE)
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_GAS_PRICE)
|
||||
|
||||
} else {
|
||||
rgFee.isEnabled = true
|
||||
|
|
@ -228,10 +231,10 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
// serverApiHelperElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request infura eth gasPrice listener
|
||||
val infuraBodyListener: ServerApiHelper.InfuraBodyListener = object : ServerApiHelper.InfuraBodyListener {
|
||||
val infuraBodyListener: ServerApiInfura.InfuraBodyListener = object : ServerApiInfura.InfuraBodyListener {
|
||||
override fun onSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
when (method) {
|
||||
ServerApiHelper.INFURA_ETH_GAS_PRICE -> {
|
||||
ServerApiInfura.INFURA_ETH_GAS_PRICE -> {
|
||||
var gasPrice = infuraResponse.result
|
||||
gasPrice = gasPrice.substring(2)
|
||||
//TODO - remove Gwei
|
||||
|
|
@ -260,16 +263,16 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
override fun onFail(method: String, message: String) {
|
||||
when (method) {
|
||||
ServerApiHelper.INFURA_ETH_GAS_PRICE -> {
|
||||
ServerApiInfura.INFURA_ETH_GAS_PRICE -> {
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
serverApiHelper.setInfuraResponse(infuraBodyListener)
|
||||
serverApiInfura.setInfuraResponse(infuraBodyListener)
|
||||
|
||||
// request estimate fee listener
|
||||
val estimateFeeListener: ServerApiHelper.EstimateFeeListener = object : ServerApiHelper.EstimateFeeListener {
|
||||
val estimateFeeListener: ServerApiCommon.EstimateFeeListener = object : ServerApiCommon.EstimateFeeListener {
|
||||
override fun onSuccess(blockCount: Int, estimateFeeResponse: String?) {
|
||||
var fee: BigDecimal?
|
||||
fee = BigDecimal(estimateFeeResponse) // BTC per 1 kb
|
||||
|
|
@ -290,17 +293,17 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
fee = fee!!.setScale(8, RoundingMode.DOWN)
|
||||
|
||||
when (blockCount) {
|
||||
ServerApiHelper.ESTIMATE_FEE_MINIMAL -> {
|
||||
ServerApiCommon.ESTIMATE_FEE_MINIMAL -> {
|
||||
minFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
if (rgFee.checkedRadioButtonId == R.id.rbMinimalFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
}
|
||||
|
||||
ServerApiHelper.ESTIMATE_FEE_NORMAL -> {
|
||||
ServerApiCommon.ESTIMATE_FEE_NORMAL -> {
|
||||
normalFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
if (rgFee.checkedRadioButtonId == R.id.rbNormalFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
}
|
||||
|
||||
ServerApiHelper.ESTIMATE_FEE_PRIORITY -> {
|
||||
ServerApiCommon.ESTIMATE_FEE_PRIORITY -> {
|
||||
maxFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
if (rgFee.checkedRadioButtonId == R.id.rbMaximumFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
}
|
||||
|
|
@ -318,7 +321,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_calculate_fee_wrong_data_received_from_node))
|
||||
}
|
||||
}
|
||||
serverApiHelper.setEstimateFee(estimateFeeListener)
|
||||
serverApiCommon.setEstimateFee(estimateFeeListener)
|
||||
}
|
||||
|
||||
public override fun onResume() {
|
||||
|
|
@ -460,22 +463,22 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
private fun requestElectrum(card: TangemCard, electrumRequest: ElectrumRequest) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiHelperElectrum.electrumRequestData(card, electrumRequest)
|
||||
serverApiElectrum.electrumRequestData(card, electrumRequest)
|
||||
} else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
|
||||
private fun requestInfura(method: String) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiHelper.infura(method, 67, ctx.card!!.wallet, "", "")
|
||||
serverApiInfura.infura(method, 67, ctx.card!!.wallet, "", "")
|
||||
} else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
|
||||
private fun requestEstimateFee() {
|
||||
serverApiHelper.estimateFee(ServerApiHelper.ESTIMATE_FEE_PRIORITY)
|
||||
serverApiHelper.estimateFee(ServerApiHelper.ESTIMATE_FEE_NORMAL)
|
||||
serverApiHelper.estimateFee(ServerApiHelper.ESTIMATE_FEE_MINIMAL)
|
||||
serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_PRIORITY)
|
||||
serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_NORMAL)
|
||||
serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_MINIMAL)
|
||||
}
|
||||
|
||||
private fun doSetFee(checkedRadioButtonId: Int) {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package com.tangem.presentation.activity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import com.tangem.data.network.ServerApiHelperElectrum
|
||||
import com.tangem.App
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_logo.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class LogoActivity : AppCompatActivity() {
|
||||
|
||||
|
|
@ -18,14 +19,17 @@ class LogoActivity : AppCompatActivity() {
|
|||
const val MILLIS_AUTO_HIDE = 1000
|
||||
}
|
||||
|
||||
private var serverApiHelperElectrum: ServerApiHelperElectrum = ServerApiHelperElectrum()
|
||||
|
||||
private val hideRunnable = Runnable { this.hide() }
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_logo)
|
||||
|
||||
App.getNavigatorComponent().inject(this)
|
||||
|
||||
ivLogo.setOnClickListener { hide() }
|
||||
}
|
||||
|
||||
|
|
@ -43,8 +47,7 @@ class LogoActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun hide() {
|
||||
val intent = Intent(baseContext, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
navigator.showMain(this)
|
||||
finish()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,10 @@ import android.view.animation.Transformation
|
|||
import android.widget.RelativeLayout
|
||||
import android.widget.Toast
|
||||
import com.scottyab.rootbeer.RootBeer
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.Logger
|
||||
import com.tangem.data.db.PINStorage
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.data.nfc.DeviceNFCAntennaLocation
|
||||
import com.tangem.data.nfc.ReadCardInfoTask
|
||||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.FW
|
||||
|
|
@ -150,7 +153,7 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
fab.setOnClickListener { showMenu(it) }
|
||||
|
||||
|
||||
val apiHelper = ServerApiHelper()
|
||||
val apiHelper = ServerApiCommon()
|
||||
apiHelper.setLastVersionListener { response ->
|
||||
try {
|
||||
if (response.isNullOrEmpty()) return@setLastVersionListener
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ import android.text.TextUtils
|
|||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import com.tangem.data.network.task.request_pin.StartFingerprintReaderTask
|
||||
import com.tangem.data.fingerprint.StartFingerprintReaderTask
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.FingerprintHelper
|
||||
import com.tangem.domain.wallet.PINStorage
|
||||
import com.tangem.data.fingerprint.FingerprintHelper
|
||||
import com.tangem.data.db.PINStorage
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_pin_request.*
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ import android.text.TextUtils
|
|||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.network.task.save_pin.ConfirmWithFingerprintTask
|
||||
import com.tangem.domain.wallet.FingerprintHelper
|
||||
import com.tangem.domain.wallet.PINStorage
|
||||
import com.tangem.data.fingerprint.ConfirmWithFingerprintTask
|
||||
import com.tangem.data.fingerprint.FingerprintHelper
|
||||
import com.tangem.data.db.PINStorage
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_pin_save.*
|
||||
import kotlinx.android.synthetic.main.layout_pin_buttons.*
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import android.nfc.Tag
|
|||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import com.tangem.data.network.Cryptonit_OtherAPI
|
||||
import com.tangem.data.network.CryptonitOtherApi
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.Blockchain
|
||||
import com.tangem.domain.wallet.CoinEngineFactory
|
||||
|
|
@ -18,10 +18,10 @@ import com.tangem.wallet.R
|
|||
import kotlinx.android.synthetic.main.activity_prepare_cryptonit_other_api_withdrawal.*
|
||||
import java.io.IOException
|
||||
|
||||
class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
class PrepareCryptonitOtherApiWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = PrepareCryptonitOtherAPIWithdrawalActivity::class.java.simpleName
|
||||
val TAG: String = PrepareCryptonitOtherApiWithdrawalActivity::class.java.simpleName
|
||||
|
||||
private const val REQUEST_CODE_SCAN_QR_KEY = 1
|
||||
private const val REQUEST_CODE_SCAN_QR_SECRET = 2
|
||||
|
|
@ -30,7 +30,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
|
||||
private lateinit var ctx: TangemContext
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var cryptonit: Cryptonit_OtherAPI? = null
|
||||
private var cryptonit: CryptonitOtherApi? = null
|
||||
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
|
@ -44,7 +44,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
cryptonit = Cryptonit_OtherAPI(this)
|
||||
cryptonit = CryptonitOtherApi(this)
|
||||
|
||||
tvKey.text = cryptonit!!.key
|
||||
tvUserID.text = cryptonit!!.userId
|
||||
|
|
@ -54,7 +54,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
tvWallet.text = ctx.card!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvCurrency.text = engine.balanceCurrency
|
||||
tvCurrency.text = engine!!.balanceCurrency
|
||||
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toValueString())
|
||||
etAmount.filters=engine.amountInputFilters
|
||||
|
|
@ -55,7 +55,7 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
tvWallet.text = ctx.card!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvCurrency.text = engine.balanceCurrency
|
||||
tvCurrency.text = engine!!.balanceCurrency
|
||||
tvFeeCurrency.text = engine.feeCurrency
|
||||
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toValueString())
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
tvWallet.text = ctx.card!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvCurrency.text = engine.balanceCurrency
|
||||
tvCurrency.text = engine!!.balanceCurrency
|
||||
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toValueString())
|
||||
etAmount.filters=engine.amountInputFilters
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
val engine1 = CoinEngineFactory.create(ctx)
|
||||
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
val amount = engine1.convertToAmount(etAmount.text.toString(), tvCurrency.text.toString())
|
||||
val amount = engine1!!.convertToAmount(etAmount.text.toString(), tvCurrency.text.toString())
|
||||
|
||||
try {
|
||||
if (!engine.checkNewTransactionAmount(amount))
|
||||
|
|
|
|||
|
|
@ -53,23 +53,19 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
|
||||
public override fun onResume() {
|
||||
super.onResume()
|
||||
nfcManager!!.onResume()
|
||||
nfcManager?.onResume()
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
nfcManager!!.onPause()
|
||||
if (purgeTask != null) {
|
||||
purgeTask!!.cancel(true)
|
||||
}
|
||||
nfcManager?.onPause()
|
||||
purgeTask?.cancel(true)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
public override fun onStop() {
|
||||
// dismiss enable NFC dialog
|
||||
nfcManager!!.onStop()
|
||||
if (purgeTask != null) {
|
||||
purgeTask!!.cancel(true)
|
||||
}
|
||||
nfcManager?.onStop()
|
||||
purgeTask?.cancel(true)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +84,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
purgeTask!!.start()
|
||||
} else {
|
||||
// this Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card.getUID() + ")");
|
||||
nfcManager!!.ignoreTag(isoDep.tag)
|
||||
nfcManager?.ignoreTag(isoDep.tag)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -109,9 +105,9 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
}
|
||||
|
||||
override fun onReadStart(cardProtocol: CardProtocol) {
|
||||
progressBar!!.post {
|
||||
progressBar!!.visibility = View.VISIBLE
|
||||
progressBar!!.progress = 5
|
||||
progressBar.post {
|
||||
progressBar.visibility = View.VISIBLE
|
||||
progressBar.progress = 5
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ import android.support.v7.app.AppCompatActivity
|
|||
import android.view.KeyEvent
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.network.ElectrumRequest
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.network.ServerApiHelperElectrum
|
||||
import com.tangem.data.network.ServerApiElectrum
|
||||
import com.tangem.data.network.ServerApiInfura
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.domain.wallet.eth.EthData
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.R
|
||||
import org.json.JSONException
|
||||
import java.io.IOException
|
||||
import java.math.BigInteger
|
||||
|
||||
|
|
@ -25,8 +25,8 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
const val EXTRA_TX: String = "TX"
|
||||
}
|
||||
|
||||
private var serverApiHelper: ServerApiHelper = ServerApiHelper()
|
||||
private var serverApiHelperElectrum: ServerApiHelperElectrum = ServerApiHelperElectrum()
|
||||
private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
private var serverApiElectrum: ServerApiElectrum = ServerApiElectrum()
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private var tx: String? = null
|
||||
|
|
@ -46,14 +46,14 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token)
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
else if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet)
|
||||
requestElectrum(ctx.card!!, ElectrumRequest.broadcast(ctx.card!!.wallet, tx))
|
||||
else if (ctx.blockchain == Blockchain.BitcoinCash)
|
||||
requestElectrum(ctx.card!!, ElectrumRequest.broadcast(ctx.card!!.wallet, tx))
|
||||
|
||||
// request electrum listener
|
||||
val electrumBodyListener: ServerApiHelperElectrum.ElectrumRequestDataListener = object : ServerApiHelperElectrum.ElectrumRequestDataListener {
|
||||
val electrumBodyListener: ServerApiElectrum.ElectrumRequestDataListener = object : ServerApiElectrum.ElectrumRequestDataListener {
|
||||
override fun onSuccess(electrumRequest: ElectrumRequest?) {
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
if (electrumRequest.resultString.isEmpty())
|
||||
|
|
@ -67,13 +67,13 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
finishWithError(message!!)
|
||||
}
|
||||
}
|
||||
serverApiHelperElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
serverApiElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request infura listener
|
||||
val infuraBodyListener: ServerApiHelper.InfuraBodyListener = object : ServerApiHelper.InfuraBodyListener {
|
||||
val infuraBodyListener: ServerApiInfura.InfuraBodyListener = object : ServerApiInfura.InfuraBodyListener {
|
||||
override fun onSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
when (method) {
|
||||
ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
if (infuraResponse.result.isEmpty())
|
||||
finishWithError("Rejected by node: " + infuraResponse.error)
|
||||
else {
|
||||
|
|
@ -88,13 +88,13 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
override fun onFail(method: String, message: String) {
|
||||
when (method) {
|
||||
ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
finishWithError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
serverApiHelper.setInfuraResponse(infuraBodyListener)
|
||||
serverApiInfura.setInfuraResponse(infuraBodyListener)
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
|
|
@ -132,14 +132,14 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
private fun requestInfura(method: String, contract: String) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiHelper.infura(method, 67, ctx.card!!.wallet, contract, tx)
|
||||
serverApiInfura.infura(method, 67, ctx.card!!.wallet, contract, tx)
|
||||
} else
|
||||
finishWithError(getString(R.string.no_connection))
|
||||
}
|
||||
|
||||
private fun requestElectrum(card: TangemCard, electrumRequest: ElectrumRequest) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiHelperElectrum.electrumRequestData(card, electrumRequest)
|
||||
serverApiElectrum.electrumRequestData(card, electrumRequest)
|
||||
} else
|
||||
finishWithError(getString(R.string.no_connection))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,16 +19,23 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.db.LocalStorage
|
||||
import com.tangem.data.db.PINStorage
|
||||
import com.tangem.data.network.ElectrumRequest
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.network.ServerApiHelperElectrum
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.data.network.ServerApiElectrum
|
||||
import com.tangem.data.network.ServerApiInfura
|
||||
import com.tangem.data.network.model.CardVerifyAndGetInfo
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
import com.tangem.data.nfc.VerifyCardTask
|
||||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.domain.wallet.BitcoinCash.BtcCashEngine
|
||||
import com.tangem.domain.wallet.btc.BtcData
|
||||
import com.tangem.domain.wallet.eth.EthData
|
||||
import com.tangem.domain.wallet.token.TokenData
|
||||
import com.tangem.domain.wallet.token.TokenEngine
|
||||
import com.tangem.domain.wallet.bch.BtcCashEngine
|
||||
import com.tangem.presentation.activity.*
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.PINSwapWarningDialog
|
||||
|
|
@ -59,12 +66,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
private var nfcManager: NfcManager? = null
|
||||
|
||||
private var serverApiHelper: ServerApiHelper = ServerApiHelper()
|
||||
private var serverApiHelperElectrum: ServerApiHelperElectrum = ServerApiHelperElectrum()
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
private var serverApiElectrum: ServerApiElectrum = ServerApiElectrum()
|
||||
|
||||
private var singleToast: Toast? = null
|
||||
//private var card: TangemCard? = null
|
||||
//private var engine: CoinEngine? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private var lastTag: Tag? = null
|
||||
|
|
@ -87,11 +93,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
ctx = TangemContext.loadFromBundle(activity, activity.intent.extras)
|
||||
|
||||
// card = TangemCard(activity.intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
// card!!.loadFromBundle(activity.intent.extras.getBundle(TangemCard.EXTRA_CARD))
|
||||
//
|
||||
// engine = CoinEngineFactory.create(activity, card!!, activity.intent.extras.getBundle(CoinEngine.EXTRA_ENGINE))
|
||||
|
||||
lastTag = activity.intent.getParcelableExtra(MainActivity.EXTRA_LAST_DISCOVERED_TAG)
|
||||
|
||||
localStorage = LocalStorage(activity)
|
||||
|
|
@ -121,7 +122,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// set listeners
|
||||
srl!!.setOnRefreshListener { refresh() }
|
||||
btnLookup.setOnClickListener {
|
||||
val engine=CoinEngineFactory.create(ctx)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, engine!!.shareWalletUriExplorer)
|
||||
startActivity(browserIntent)
|
||||
}
|
||||
|
|
@ -137,7 +138,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
when (items[which]) {
|
||||
getString(R.string.in_app) -> {
|
||||
try {
|
||||
val engine=CoinEngineFactory.create(ctx)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
val intent = Intent(Intent.ACTION_VIEW, engine!!.shareWalletUri)
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
startActivity(intent)
|
||||
|
|
@ -149,11 +150,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
doShareWallet(true)
|
||||
}
|
||||
getString(R.string.load_via_qr) -> {
|
||||
val engine=CoinEngineFactory.create(ctx)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
ShowQRCodeDialog.show(activity, engine!!.shareWalletUri.toString())
|
||||
}
|
||||
// getString(R.string.via_cryptonit2) -> {
|
||||
// val intent = Intent(ctx, PrepareCryptonitOtherAPIWithdrawalActivity::class.java)
|
||||
// val intent = Intent(ctx, PrepareCryptonitOtherApiWithdrawalActivity::class.java)
|
||||
// intent.putExtra("UID", card!!.uid)
|
||||
// intent.putExtra("Card", card!!.asBundle)
|
||||
// startActivityForResult(intent, REQUEST_CODE_RECEIVE_PAYMENT)
|
||||
|
|
@ -178,7 +179,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
dlg.window.attributes = wlp
|
||||
} else {
|
||||
try {
|
||||
val engine=CoinEngineFactory.create(ctx)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
val intent = Intent(Intent.ACTION_VIEW, engine!!.shareWalletUri)
|
||||
intent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
startActivity(intent)
|
||||
|
|
@ -198,7 +199,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
startActivity(intent)
|
||||
}
|
||||
btnExtract.setOnClickListener {
|
||||
val engine=CoinEngineFactory.create(ctx)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
if (UtilHelper.isOnline(activity)) {
|
||||
if (!engine!!.isExtractPossible)
|
||||
showSingleToast(ctx.message)
|
||||
|
|
@ -214,7 +215,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
// request electrum listener
|
||||
val electrumBodyListener: ServerApiHelperElectrum.ElectrumRequestDataListener = object : ServerApiHelperElectrum.ElectrumRequestDataListener {
|
||||
val electrumBodyListener: ServerApiElectrum.ElectrumRequestDataListener = object : ServerApiElectrum.ElectrumRequestDataListener {
|
||||
override fun onSuccess(electrumRequest: ElectrumRequest?) {
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
|
|
@ -224,7 +225,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
ctx.coinData!!.isBalanceReceived = true
|
||||
(ctx.coinData!! as BtcData).setBalanceConfirmed(confBalance)
|
||||
(ctx.coinData!! as BtcData).balanceUnconfirmed = unconfirmedBalance
|
||||
(ctx.coinData!! as BtcData).validationNodeDescription = serverApiHelperElectrum.validationNodeDescription
|
||||
(ctx.coinData!! as BtcData).validationNodeDescription = serverApiElectrum.validationNodeDescription
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
Log.e(TAG, "FAIL METHOD_GetBalance JSONException")
|
||||
|
|
@ -288,13 +289,13 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
}
|
||||
}
|
||||
serverApiHelperElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
serverApiElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request infura listener
|
||||
val infuraBodyListener: ServerApiHelper.InfuraBodyListener = object : ServerApiHelper.InfuraBodyListener {
|
||||
val infuraBodyListener: ServerApiInfura.InfuraBodyListener = object : ServerApiInfura.InfuraBodyListener {
|
||||
override fun onSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
when (method) {
|
||||
ServerApiHelper.INFURA_ETH_GET_BALANCE -> {
|
||||
ServerApiInfura.INFURA_ETH_GET_BALANCE -> {
|
||||
var balanceCap = infuraResponse.result
|
||||
balanceCap = balanceCap.substring(2)
|
||||
val l = BigInteger(balanceCap, 16)
|
||||
|
|
@ -305,8 +306,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// (ctx.coinData!! as EthData).balanceUnconfirmed = 0L
|
||||
if (ctx.blockchain != Blockchain.Token) {
|
||||
(ctx.coinData!! as EthData).isBalanceReceived = true
|
||||
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),"wei")
|
||||
}else{
|
||||
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), "wei")
|
||||
} else {
|
||||
(ctx.coinData!! as TokenData).isBalanceReceived = true
|
||||
//(ctx.coinData!! as TokenData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
|
||||
(ctx.coinData!! as TokenData).balanceAlterInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), "wei")
|
||||
|
|
@ -315,7 +316,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// Log.i("$TAG eth_get_balance", balanceCap)
|
||||
}
|
||||
|
||||
ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT -> {
|
||||
ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT -> {
|
||||
var nonce = infuraResponse.result
|
||||
nonce = nonce.substring(2)
|
||||
val count = BigInteger(nonce, 16)
|
||||
|
|
@ -325,7 +326,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// Log.i("$TAG eth_getTransCount", nonce)
|
||||
}
|
||||
|
||||
ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT -> {
|
||||
ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT -> {
|
||||
var pending = infuraResponse.result
|
||||
pending = pending.substring(2)
|
||||
val count = BigInteger(pending, 16)
|
||||
|
|
@ -334,7 +335,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// Log.i("$TAG eth_getPendingTxCount", pending)
|
||||
}
|
||||
|
||||
ServerApiHelper.INFURA_ETH_CALL -> {
|
||||
ServerApiInfura.INFURA_ETH_CALL -> {
|
||||
try {
|
||||
var balanceCap = infuraResponse.result
|
||||
balanceCap = balanceCap.substring(2)
|
||||
|
|
@ -350,18 +351,18 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// requestCounter--
|
||||
// if (requestCounter == 0) srl!!.isRefreshing = false
|
||||
//
|
||||
// requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
// requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
// requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
// requestInfura(ServerApiCommon.INFURA_ETH_GET_BALANCE, "")
|
||||
// requestInfura(ServerApiCommon.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
// requestInfura(ServerApiCommon.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
// return
|
||||
// }
|
||||
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
|
||||
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), ctx.card.tokenSymbol)
|
||||
|
||||
// Log.i("$TAG eth_call", balanceCap)
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: NumberFormatException) {
|
||||
|
|
@ -371,7 +372,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
try {
|
||||
var hashTX: String
|
||||
try {
|
||||
|
|
@ -406,10 +407,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
}
|
||||
}
|
||||
serverApiHelper.setInfuraResponse(infuraBodyListener)
|
||||
serverApiInfura.setInfuraResponse(infuraBodyListener)
|
||||
|
||||
// request card verify and get info listener
|
||||
val cardVerifyAndGetInfoListener: ServerApiHelper.CardVerifyAndGetInfoListener = object : ServerApiHelper.CardVerifyAndGetInfoListener {
|
||||
val cardVerifyAndGetInfoListener: ServerApiCommon.CardVerifyAndGetInfoListener = object : ServerApiCommon.CardVerifyAndGetInfoListener {
|
||||
override fun onSuccess(cardVerifyAndGetArtworkResponse: CardVerifyAndGetInfo.Response?) {
|
||||
val result = cardVerifyAndGetArtworkResponse?.results!![0]
|
||||
if (result.error != null) {
|
||||
|
|
@ -435,7 +436,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
if (result.artwork != null && localStorage.checkNeedUpdateArtwork(result.artwork)) {
|
||||
Log.w(TAG, "Artwork '${result.artwork!!.id}' updated, need download")
|
||||
serverApiHelper.requestArtwork(result.artwork!!.id, result.artwork!!.getUpdateDate(), ctx.card!!)
|
||||
serverApiCommon.requestArtwork(result.artwork!!.id, result.artwork!!.getUpdateDate(), ctx.card!!)
|
||||
updateViews()
|
||||
}
|
||||
// Log.i(TAG, "setCardVerify " + it.results!![0].passed)
|
||||
|
|
@ -445,10 +446,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
}
|
||||
}
|
||||
serverApiHelper.setCardVerifyAndGetInfoListener(cardVerifyAndGetInfoListener)
|
||||
serverApiCommon.setCardVerifyAndGetInfoListener(cardVerifyAndGetInfoListener)
|
||||
|
||||
// request artwork listener
|
||||
val artworkListener: ServerApiHelper.ArtworkListener = object : ServerApiHelper.ArtworkListener {
|
||||
val artworkListener: ServerApiCommon.ArtworkListener = object : ServerApiCommon.ArtworkListener {
|
||||
override fun onSuccess(artworkId: String?, inputStream: InputStream?, updateDate: Date?) {
|
||||
localStorage.updateArtwork(artworkId!!, inputStream!!, updateDate!!)
|
||||
ivTangemCard.setImageBitmap(localStorage.getCardArtworkBitmap(ctx.card!!))
|
||||
|
|
@ -458,10 +459,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
}
|
||||
}
|
||||
serverApiHelper.setArtworkListener(artworkListener)
|
||||
serverApiCommon.setArtworkListener(artworkListener)
|
||||
|
||||
// request rate info listener
|
||||
serverApiHelper.setRateInfoData {
|
||||
serverApiCommon.setRateInfoData {
|
||||
val rate = it.priceUsd.toFloat()
|
||||
ctx.coinData!!.rate = rate
|
||||
ctx.coinData!!.rateAlter = rate
|
||||
|
|
@ -724,168 +725,160 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
fun updateViews() {
|
||||
try {
|
||||
if (timerHideErrorAndMessage != null) {
|
||||
timerHideErrorAndMessage!!.cancel()
|
||||
timerHideErrorAndMessage = null
|
||||
}
|
||||
if (timerHideErrorAndMessage != null) {
|
||||
timerHideErrorAndMessage!!.cancel()
|
||||
timerHideErrorAndMessage = null
|
||||
}
|
||||
|
||||
if (ctx.error == null || ctx.error.isEmpty()) {
|
||||
tvError.visibility = View.GONE
|
||||
tvError.text = ""
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = ctx.error
|
||||
}
|
||||
if (ctx.error == null || ctx.error.isEmpty()) {
|
||||
tvError.visibility = View.GONE
|
||||
tvError.text = ""
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = ctx.error
|
||||
}
|
||||
|
||||
if (ctx.message == null || ctx.message.isEmpty()) {
|
||||
tvMessage!!.text = ""
|
||||
tvMessage!!.visibility = View.GONE
|
||||
} else {
|
||||
tvMessage!!.text = ctx.message
|
||||
tvMessage!!.visibility = View.VISIBLE
|
||||
}
|
||||
if (ctx.message == null || ctx.message.isEmpty()) {
|
||||
tvMessage!!.text = ""
|
||||
tvMessage!!.visibility = View.GONE
|
||||
} else {
|
||||
tvMessage!!.text = ctx.message
|
||||
tvMessage!!.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
if (srl!!.isRefreshing) {
|
||||
tvBalanceLine1.setTextColor(resources.getColor(R.color.primary))
|
||||
tvBalanceLine1.text = getString(R.string.verifying_in_blockchain)
|
||||
tvBalanceLine2.text = ""
|
||||
tvBalance.text = ""
|
||||
tvBalanceEquivalent.text = ""
|
||||
} else {
|
||||
val validator = BalanceValidator()
|
||||
validator.Check(ctx, false)
|
||||
tvBalanceLine1.setTextColor(ContextCompat.getColor(activity, validator.color))
|
||||
tvBalanceLine1.text = validator.firstLine
|
||||
tvBalanceLine2.text = validator.getSecondLine(false)
|
||||
}
|
||||
if (srl!!.isRefreshing) {
|
||||
tvBalanceLine1.setTextColor(resources.getColor(R.color.primary))
|
||||
tvBalanceLine1.text = getString(R.string.verifying_in_blockchain)
|
||||
tvBalanceLine2.text = ""
|
||||
tvBalance.text = ""
|
||||
tvBalanceEquivalent.text = ""
|
||||
} else {
|
||||
val validator = BalanceValidator()
|
||||
validator.Check(ctx, false)
|
||||
tvBalanceLine1.setTextColor(ContextCompat.getColor(activity, validator.color))
|
||||
tvBalanceLine1.text = validator.firstLine
|
||||
tvBalanceLine2.text = validator.getSecondLine(false)
|
||||
}
|
||||
|
||||
val engine=CoinEngineFactory.create(ctx)
|
||||
if (engine!!.hasBalanceInfo() || ctx.card!!.offlineBalance == null) {
|
||||
val html = Html.fromHtml(engine!!.balanceHTML)
|
||||
tvBalance.text = html
|
||||
// TODO???
|
||||
tvBalanceEquivalent.text = engine!!.balanceEquivalent
|
||||
} else {
|
||||
// TODO
|
||||
val html = Html.fromHtml(engine!!.offlineBalanceHTML)
|
||||
tvBalance.text = html
|
||||
}
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
if (engine!!.hasBalanceInfo() || ctx.card!!.offlineBalance == null) {
|
||||
val html = Html.fromHtml(engine.balanceHTML)
|
||||
tvBalance.text = html
|
||||
// TODO???
|
||||
tvBalanceEquivalent.text = engine.balanceEquivalent
|
||||
} else {
|
||||
// TODO
|
||||
val html = Html.fromHtml(engine.offlineBalanceHTML)
|
||||
tvBalance.text = html
|
||||
}
|
||||
|
||||
tvWallet.text = ctx.card!!.wallet
|
||||
tvWallet.text = ctx.card!!.wallet
|
||||
// tvBlockchain.text = card!!.blockchainName
|
||||
|
||||
if (ctx.card!!.tokenSymbol.length > 1) {
|
||||
val html = Html.fromHtml(ctx.card!!.blockchainName)
|
||||
tvBlockchain.text = html
|
||||
} else
|
||||
tvBlockchain.text = ctx.card!!.blockchainName
|
||||
if (ctx.card!!.tokenSymbol.length > 1) {
|
||||
val html = Html.fromHtml(ctx.card!!.blockchainName)
|
||||
tvBlockchain.text = html
|
||||
} else
|
||||
tvBlockchain.text = ctx.card!!.blockchainName
|
||||
|
||||
if (engine!!.hasBalanceInfo()) {
|
||||
btnExtract.isEnabled = true
|
||||
btnExtract.backgroundTintList = activeColor
|
||||
} else {
|
||||
btnExtract.isEnabled = false
|
||||
btnExtract.backgroundTintList = inactiveColor
|
||||
}
|
||||
|
||||
ctx.error = null
|
||||
ctx.message = null
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
if (engine.hasBalanceInfo()) {
|
||||
btnExtract.isEnabled = true
|
||||
btnExtract.backgroundTintList = activeColor
|
||||
} else {
|
||||
btnExtract.isEnabled = false
|
||||
btnExtract.backgroundTintList = inactiveColor
|
||||
}
|
||||
|
||||
ctx.error = null
|
||||
ctx.message = null
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
if ((srl == null) || (ctx.card == null)) return;
|
||||
try {
|
||||
// clear all card data and request again
|
||||
srl!!.isRefreshing = true
|
||||
ctx.coinData.clearInfo();
|
||||
ctx.error = null
|
||||
ctx.message = null
|
||||
requestCounter = 0
|
||||
if (ctx.card == null) return
|
||||
|
||||
updateViews()
|
||||
// clear all card data and request again
|
||||
srl?.isRefreshing = true
|
||||
ctx.coinData.clearInfo()
|
||||
ctx.error = null
|
||||
ctx.message = null
|
||||
requestCounter = 0
|
||||
|
||||
requestVerifyAndGetInfo()
|
||||
updateViews()
|
||||
|
||||
requestVerifyAndGetInfo()
|
||||
|
||||
// Bitcoin
|
||||
if (ctx.blockchain == Blockchain.Bitcoin) {
|
||||
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet) {
|
||||
ctx.coinData.setIsBalanceEqual(true)
|
||||
|
||||
requestElectrum(ElectrumRequest.checkBalance(ctx.card!!.wallet))
|
||||
requestElectrum(ElectrumRequest.listUnspent(ctx.card!!.wallet))
|
||||
requestRateInfo("bitcoin")
|
||||
}
|
||||
requestElectrum(ElectrumRequest.checkBalance(ctx.card!!.wallet))
|
||||
requestElectrum(ElectrumRequest.listUnspent(ctx.card!!.wallet))
|
||||
requestRateInfo("bitcoin")
|
||||
}
|
||||
|
||||
// BitcoinCash
|
||||
else if (ctx.blockchain == Blockchain.BitcoinCash) {
|
||||
ctx.coinData.setIsBalanceEqual(true)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
requestElectrum(ElectrumRequest.checkBalance((engine as BtcCashEngine).convertToLegacyAddress(ctx.card!!.wallet)))
|
||||
requestElectrum(ElectrumRequest.listUnspent((engine as BtcCashEngine).convertToLegacyAddress(ctx.card!!.wallet)))
|
||||
requestRateInfo("bitcoin-cash")
|
||||
}
|
||||
requestElectrum(ElectrumRequest.checkBalance((engine as BtcCashEngine).convertToLegacyAddress(ctx.card!!.wallet)))
|
||||
requestElectrum(ElectrumRequest.listUnspent((engine as BtcCashEngine).convertToLegacyAddress(ctx.card!!.wallet)))
|
||||
requestRateInfo("bitcoin-cash")
|
||||
}
|
||||
|
||||
// Ethereum
|
||||
else if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet) {
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
// Ethereum
|
||||
else if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet) {
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_GET_BALANCE, "")
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_GET_TRANSACTION_COUNT, "")
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_GET_PENDING_COUNT, "")
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
|
||||
// Token
|
||||
else if (ctx.blockchain == Blockchain.Token) {
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_CALL, (engine as TokenEngine).getContractAddress(ctx.card))
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// Token
|
||||
else if (ctx.blockchain == Blockchain.Token) {
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_CALL, (engine as TokenEngine).getContractAddress(ctx.card))
|
||||
requestRateInfo("ethereum")
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestElectrum(electrumRequest: ElectrumRequest) {
|
||||
if (UtilHelper.isOnline(activity!!)) {
|
||||
requestCounter++
|
||||
serverApiHelperElectrum.electrumRequestData(ctx.card, electrumRequest)
|
||||
serverApiElectrum.electrumRequestData(ctx.card, electrumRequest)
|
||||
} else {
|
||||
Toast.makeText(activity!!, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
srl!!.isRefreshing = false
|
||||
srl?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestInfura(method: String, contract: String) {
|
||||
if (UtilHelper.isOnline(activity)) {
|
||||
requestCounter++
|
||||
serverApiHelper.infura(method, 67, ctx.card!!.wallet, contract, "")
|
||||
serverApiInfura.infura(method, 67, ctx.card!!.wallet, contract, "")
|
||||
} else {
|
||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
srl!!.isRefreshing = false
|
||||
srl?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestVerifyAndGetInfo() {
|
||||
if (UtilHelper.isOnline(activity)) {
|
||||
if ((ctx.card!!.isOnlineVerified == null || !ctx.card!!.isOnlineVerified)) {
|
||||
serverApiHelper.cardVerifyAndGetInfo(ctx.card)
|
||||
serverApiCommon.cardVerifyAndGetInfo(ctx.card)
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
srl!!.isRefreshing = false
|
||||
srl?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestRateInfo(cryptoId: String) {
|
||||
if (UtilHelper.isOnline(activity)) {
|
||||
serverApiHelper.rateInfoData(cryptoId)
|
||||
serverApiCommon.rateInfoData(cryptoId)
|
||||
} else {
|
||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
srl!!.isRefreshing = false
|
||||
srl?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.db.PINStorage
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.presentation.activity.CreateNewWalletActivity
|
||||
|
|
@ -285,7 +286,7 @@ class VerifyCard : Fragment(), NfcAdapter.ReaderCallback {
|
|||
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvInputs.text = engine.unspentInputsDescription
|
||||
tvInputs.text = engine!!.unspentInputsDescription
|
||||
|
||||
ivBlockchain.setImageResource(Blockchain.getLogoImageResource(ctx.card!!.blockchainID, ctx.card!!.tokenSymbol))
|
||||
|
||||
|
|
@ -467,7 +468,7 @@ class VerifyCard : Fragment(), NfcAdapter.ReaderCallback {
|
|||
private fun doPurge() {
|
||||
requestPIN2Count = 0
|
||||
val engine=CoinEngineFactory.create(ctx)
|
||||
if (!engine.hasBalanceInfo()) {
|
||||
if (!engine!!.hasBalanceInfo()) {
|
||||
return
|
||||
} else if (engine.isBalanceNotZero) {
|
||||
Toast.makeText(context, R.string.cannot_erase_wallet_with_non_zero_balance, Toast.LENGTH_LONG).show()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ package com.tangem.presentation.viewmodel
|
|||
|
||||
import android.arch.lifecycle.MutableLiveData
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import com.dmmatrix.epro.core.exception.Failure
|
||||
import com.tangem.data.network.exception.Failure
|
||||
|
||||
/**
|
||||
* Base ViewModel class with default Failure handling.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.presentation.viewmodel
|
||||
|
||||
import android.arch.lifecycle.MutableLiveData
|
||||
import com.dmmatrix.epro.core.exception.Failure
|
||||
import com.tangem.data.network.exception.Failure
|
||||
|
||||
class LoadedWalletViewModel : BaseViewModel() {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue