Updated on 2026-08-14
This commit is contained in:
parent
e7c57f1e11
commit
97c60b5f9d
18 changed files with 1098 additions and 611 deletions
|
|
@ -9,29 +9,20 @@ import android.support.v7.app.AppCompatActivity
|
|||
import android.text.Editable
|
||||
import android.text.Html
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.network.ElectrumRequest
|
||||
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.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.domain.wallet.btc.BtcData
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.domain.wallet.CoinEngine
|
||||
import com.tangem.domain.wallet.CoinEngineFactory
|
||||
import com.tangem.domain.wallet.TangemContext
|
||||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.tangemcard.data.TangemCard
|
||||
import com.tangem.tangemcard.data.loadFromBundle
|
||||
import com.tangem.tangemcard.util.Util
|
||||
import com.tangem.util.*
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_confirm_payment.*
|
||||
import java.io.IOException
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.math.RoundingMode
|
||||
import java.util.*
|
||||
|
||||
class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
|
@ -49,11 +40,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
private lateinit var ctx: TangemContext
|
||||
private lateinit var amount: CoinEngine.Amount
|
||||
|
||||
private var feeRequestSuccess = false
|
||||
// private var feeRequestSuccess = false
|
||||
// private var balanceRequestSuccess = false
|
||||
private var minFee: CoinEngine.Amount? = null
|
||||
private var maxFee: CoinEngine.Amount? = null
|
||||
private var normalFee: CoinEngine.Amount? = null
|
||||
private var isIncludeFee: Boolean = true
|
||||
private var requestPIN2Count = 0
|
||||
private var nodeCheck = true
|
||||
|
|
@ -97,7 +85,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
etFee.setText("")
|
||||
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
feeRequestSuccess = false
|
||||
// feeRequestSuccess = false
|
||||
// balanceRequestSuccess = false
|
||||
|
||||
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token) {
|
||||
|
|
@ -110,9 +98,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
// requestElectrum(ctx.card, ElectrumRequest.checkBalance(ctx.card!!.wallet))
|
||||
|
||||
ctx.coinData!!.resetFailedBalanceRequestCounter()
|
||||
// ctx.coinData!!.resetFailedBalanceRequestCounter()
|
||||
|
||||
progressBar.visibility = View.VISIBLE
|
||||
// progressBar.visibility = View.VISIBLE
|
||||
|
||||
// requestEstimateFee()
|
||||
}
|
||||
|
|
@ -193,30 +181,37 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
val coinEngine = CoinEngineFactory.create(ctx)
|
||||
|
||||
progressBar.visibility = View.VISIBLE
|
||||
|
||||
coinEngine!!.requestFee(
|
||||
object : CoinEngine.FeeRequestsNotifications {
|
||||
override fun onComplete(success: Boolean, minFee: CoinEngine.Amount?, normalFee: CoinEngine.Amount?, maxFee: CoinEngine.Amount?) {
|
||||
object : CoinEngine.BlockchainRequestsCallbacks {
|
||||
override fun onComplete(success: Boolean) {
|
||||
if (success) {
|
||||
this@ConfirmPaymentActivity.minFee = minFee
|
||||
this@ConfirmPaymentActivity.normalFee = normalFee
|
||||
this@ConfirmPaymentActivity.maxFee = maxFee
|
||||
doSetFee(rgFee.checkedRadioButtonId)
|
||||
etFee.error = null
|
||||
btnSend.visibility = View.VISIBLE
|
||||
feeRequestSuccess = true
|
||||
// balanceRequestSuccess = true
|
||||
|
||||
onProgress()
|
||||
|
||||
// etFee.error = null
|
||||
|
||||
// feeRequestSuccess = true
|
||||
// balanceRequestSuccess = true
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
dtVerified = Date()
|
||||
} else {
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
finishWithError(Activity.RESULT_CANCELED, ctx.error)
|
||||
}
|
||||
}
|
||||
|
||||
override fun needTerminate(): Boolean {
|
||||
return !UtilHelper.isOnline(this@ConfirmPaymentActivity)
|
||||
override fun onProgress() {
|
||||
doSetFee(rgFee.checkedRadioButtonId)
|
||||
}
|
||||
|
||||
override fun allowAdvance(): Boolean {
|
||||
return UtilHelper.isOnline(this@ConfirmPaymentActivity)
|
||||
}
|
||||
},
|
||||
amount
|
||||
)
|
||||
etWallet.text.toString(),
|
||||
amount)
|
||||
|
||||
|
||||
// request electrum listener
|
||||
|
|
@ -420,7 +415,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
// TODO - move to BtcEngine
|
||||
@Throws(Exception::class)
|
||||
// @Throws(Exception::class)
|
||||
|
||||
// private fun requestElectrum(ctx: TangemContext, electrumRequest: ElectrumRequest) {
|
||||
// if (UtilHelper.isOnline(this)) {
|
||||
|
|
@ -455,20 +450,29 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
var txtFee = ""
|
||||
when (checkedRadioButtonId) {
|
||||
R.id.rbMinimalFee ->
|
||||
if (minFee != null)
|
||||
txtFee = minFee!!.toValueString()
|
||||
else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
if (ctx.coinData.minFee != null) {
|
||||
txtFee = ctx.coinData.minFee!!.toValueString()
|
||||
btnSend.visibility = View.VISIBLE
|
||||
}else {
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
R.id.rbNormalFee ->
|
||||
if (normalFee != null)
|
||||
txtFee = normalFee!!.toValueString()
|
||||
else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
if (ctx.coinData.normalFee != null) {
|
||||
txtFee = ctx.coinData.normalFee!!.toValueString()
|
||||
btnSend.visibility = View.VISIBLE
|
||||
}else {
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
R.id.rbMaximumFee ->
|
||||
if (maxFee != null)
|
||||
txtFee = maxFee!!.toValueString()
|
||||
else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
if (ctx.coinData.maxFee != null) {
|
||||
txtFee = ctx.coinData.maxFee!!.toValueString()
|
||||
btnSend.visibility = View.VISIBLE
|
||||
}else {
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
etFee.setText(txtFee.replace(',', '.'))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@ import android.os.Bundle
|
|||
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.ServerApiElectrum
|
||||
import com.tangem.data.network.ServerApiInfura
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.domain.wallet.eth.EthData
|
||||
|
|
@ -27,11 +23,11 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
const val EXTRA_TX: String = "TX"
|
||||
}
|
||||
|
||||
private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
private var serverApiElectrum: ServerApiElectrum = ServerApiElectrum()
|
||||
// private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
// private var serverApiElectrum: ServerApiElectrum = ServerApiElectrum()
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private var tx: String? = null
|
||||
private var tx: ByteArray? = null
|
||||
private var nfcManager: NfcManager? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -43,71 +39,89 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
nfcManager = NfcManager(this, this)
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
tx = intent.getStringExtra(EXTRA_TX)
|
||||
tx = intent.getByteArrayExtra(EXTRA_TX)
|
||||
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token)
|
||||
requestInfura(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
else if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet)
|
||||
requestElectrum(ctx, ElectrumRequest.broadcast(ctx.coinData!!.wallet, tx))
|
||||
else if (ctx.blockchain == Blockchain.BitcoinCash)
|
||||
requestElectrum(ctx, ElectrumRequest.broadcast(ctx.coinData!!.wallet, tx))
|
||||
engine!!.requestSendTransaction(
|
||||
object : CoinEngine.BlockchainRequestsCallbacks {
|
||||
override fun onComplete(success: Boolean) {
|
||||
if (success) {
|
||||
finishWithSuccess()
|
||||
} else {
|
||||
finishWithError(this@SendTransactionActivity.getString(R.string.try_again_failed_to_send_transaction))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProgress() {
|
||||
}
|
||||
|
||||
override fun allowAdvance(): Boolean {
|
||||
return UtilHelper.isOnline(this@SendTransactionActivity)
|
||||
}
|
||||
},
|
||||
tx
|
||||
)
|
||||
|
||||
|
||||
// if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token)
|
||||
// requestInfura(ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
// else if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet)
|
||||
// requestElectrum(ctx, ElectrumRequest.broadcast(ctx.coinData!!.wallet, tx))
|
||||
// else if (ctx.blockchain == Blockchain.BitcoinCash)
|
||||
// requestElectrum(ctx, ElectrumRequest.broadcast(ctx.coinData!!.wallet, tx))
|
||||
|
||||
// request electrum listener
|
||||
val electrumBodyListener: ServerApiElectrum.ElectrumRequestDataListener = object : ServerApiElectrum.ElectrumRequestDataListener {
|
||||
override fun onSuccess(electrumRequest: ElectrumRequest?) {
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
try {
|
||||
if (electrumRequest.resultString.isNullOrEmpty())
|
||||
finishWithError("Rejected by node: " + electrumRequest.getError())
|
||||
else
|
||||
finishWithSuccess()
|
||||
}
|
||||
catch (e: Exception)
|
||||
{
|
||||
if( e.message!=null )
|
||||
{
|
||||
finishWithError(e.message!!)
|
||||
}else{
|
||||
finishWithError(e.javaClass.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFail(message: String?) {
|
||||
finishWithError(message!!)
|
||||
}
|
||||
}
|
||||
serverApiElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
// val electrumBodyListener: ServerApiElectrum.ElectrumRequestDataListener = object : ServerApiElectrum.ElectrumRequestDataListener {
|
||||
// override fun onSuccess(electrumRequest: ElectrumRequest?) {
|
||||
// if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
// try {
|
||||
// if (electrumRequest.resultString.isNullOrEmpty())
|
||||
// finishWithError("Rejected by node: " + electrumRequest.getError())
|
||||
// else
|
||||
// finishWithSuccess()
|
||||
// } catch (e: Exception) {
|
||||
// if (e.message != null) {
|
||||
// finishWithError(e.message!!)
|
||||
// } else {
|
||||
// finishWithError(e.javaClass.name)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onFail(message: String?) {
|
||||
// finishWithError(message!!)
|
||||
// }
|
||||
// }
|
||||
// serverApiElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request infura listener
|
||||
val infuraBodyListener: ServerApiInfura.InfuraBodyListener = object : ServerApiInfura.InfuraBodyListener {
|
||||
override fun onSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
when (method) {
|
||||
ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
if (infuraResponse.result.isEmpty())
|
||||
finishWithError("Rejected by node: " + infuraResponse.error)
|
||||
else {
|
||||
val nonce = (ctx.coinData!! as EthData).confirmedTXCount
|
||||
nonce.add(BigInteger.valueOf(1))
|
||||
(ctx.coinData!! as EthData).confirmedTXCount = nonce
|
||||
finishWithSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFail(method: String, message: String) {
|
||||
when (method) {
|
||||
ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
finishWithError(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
serverApiInfura.setInfuraResponse(infuraBodyListener)
|
||||
// val infuraBodyListener: ServerApiInfura.InfuraBodyListener = object : ServerApiInfura.InfuraBodyListener {
|
||||
// override fun onSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
// when (method) {
|
||||
// ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
// if (infuraResponse.result.isEmpty())
|
||||
// finishWithError("Rejected by node: " + infuraResponse.error)
|
||||
// else {
|
||||
// val nonce = (ctx.coinData!! as EthData).confirmedTXCount
|
||||
// nonce.add(BigInteger.valueOf(1))
|
||||
// (ctx.coinData!! as EthData).confirmedTXCount = nonce
|
||||
// finishWithSuccess()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onFail(method: String, message: String) {
|
||||
// when (method) {
|
||||
// ServerApiInfura.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
// finishWithError(message)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// serverApiInfura.setInfuraResponse(infuraBodyListener)
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
|
|
@ -143,20 +157,20 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
}
|
||||
|
||||
private fun requestInfura(method: String, contract: String) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiInfura.infura(method, 67, ctx.coinData!!.wallet, contract, tx)
|
||||
} else
|
||||
finishWithError(getString(R.string.no_connection))
|
||||
}
|
||||
|
||||
private fun requestElectrum(ctx: TangemContext, electrumRequest: ElectrumRequest) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiElectrum.electrumRequestData(ctx, electrumRequest)
|
||||
} else
|
||||
finishWithError(getString(R.string.no_connection))
|
||||
}
|
||||
// private fun requestInfura(method: String, contract: String) {
|
||||
// if (UtilHelper.isOnline(this)) {
|
||||
// serverApiInfura.infura(method, 67, ctx.coinData!!.wallet, contract, tx)
|
||||
// } else
|
||||
// finishWithError(getString(R.string.no_connection))
|
||||
// }
|
||||
|
||||
// private fun requestElectrum(ctx: TangemContext, electrumRequest: ElectrumRequest) {
|
||||
// if (UtilHelper.isOnline(this)) {
|
||||
// serverApiElectrum.electrumRequestData(ctx, electrumRequest)
|
||||
// } else
|
||||
// finishWithError(getString(R.string.no_connection))
|
||||
// }
|
||||
//
|
||||
private fun finishWithSuccess() {
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", getString(R.string.transaction_has_been_successfully_signed))
|
||||
|
|
|
|||
|
|
@ -144,4 +144,143 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
?: throw CardProtocol.TangemException("Can't create CoinEngine!")
|
||||
coinEngine.setOnNeedSendPayment { tx ->
|
||||
if (tx != null) {
|
||||
// [REDACTED_TODO_COMMENT]
|
||||
val intent = Intent(this, SendTransactionActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
intent.putExtra(SendTransactionActivity.EXTRA_TX, tx)
|
||||
startActivityForResult(intent, SignPaymentActivity.REQUEST_CODE_SEND_PAYMENT)
|
||||
}
|
||||
}
|
||||
val paymentToSign = coinEngine.constructPayment(amount, fee, isIncludeFee, outAddressStr)
|
||||
|
||||
signPaymentTask = SignTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this, paymentToSign)
|
||||
signPaymentTask!!.start()
|
||||
} else {
|
||||
// Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card!!.uid + ")")
|
||||
nfcManager!!.ignoreTag(isoDep.tag)
|
||||
}
|
||||
|
||||
}catch (e: CardProtocol.TangemException_WrongAmount)
|
||||
{
|
||||
try {
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", getString(R.string.cannot_sign_transaction_wrong_amount))
|
||||
intent.putExtra("UID", ctx.card.uid)
|
||||
intent.putExtra("Card", ctx.card.asBundle)
|
||||
setResult(Activity.RESULT_CANCELED, intent)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadStart(cardProtocol: CardProtocol) {
|
||||
progressBar!!.post {
|
||||
progressBar!!.visibility = View.VISIBLE
|
||||
progressBar!!.progress = 5
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadProgress(protocol: CardProtocol, progress: Int) {
|
||||
progressBar!!.post { progressBar!!.progress = progress }
|
||||
}
|
||||
|
||||
override fun onReadFinish(cardProtocol: CardProtocol?) {
|
||||
signPaymentTask = null
|
||||
if (cardProtocol != null) {
|
||||
if (cardProtocol.error == null) {
|
||||
progressBar!!.post {
|
||||
progressBar!!.progress = 100
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.GREEN)
|
||||
}
|
||||
} else {
|
||||
lastReadSuccess = false
|
||||
if (cardProtocol.error.javaClass == CardProtocol.TangemException_InvalidPIN::class.java) {
|
||||
progressBar!!.post {
|
||||
progressBar!!.progress = 100
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
progressBar!!.postDelayed({
|
||||
try {
|
||||
progressBar!!.progress = 0
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar!!.visibility = View.INVISIBLE
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", getString(R.string.cannot_sign_transaction__make_sure_you_enter_correct_pin_2))
|
||||
intent.putExtra("UID", cardProtocol.card.uid)
|
||||
intent.putExtra("Card", cardProtocol.card.asBundle)
|
||||
setResult(RESULT_INVALID_PIN, intent)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
} else {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_WrongAmount) {
|
||||
try {
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", getString(R.string.cannot_sign_transaction_wrong_amount))
|
||||
intent.putExtra("UID", cardProtocol.card.uid)
|
||||
intent.putExtra("Card", cardProtocol.card.asBundle)
|
||||
setResult(Activity.RESULT_CANCELED, intent)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
progressBar!!.post {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed) {
|
||||
NoExtendedLengthSupportDialog.message = getText(R.string.the_nfc_adapter_length_apdu).toString() + "\n" + getText(R.string.the_nfc_adapter_length_apdu_advice).toString()
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(baseContext, R.string.try_to_scan_again, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
progressBar!!.progress = 100
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
progressBar!!.postDelayed({
|
||||
try {
|
||||
progressBar!!.progress = 0
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar!!.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadCancel() {
|
||||
signPaymentTask = null
|
||||
|
||||
progressBar!!.postDelayed({
|
||||
try {
|
||||
progressBar!!.progress = 0
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar!!.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.OnReadWait(this, msec)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -69,7 +69,17 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private var cardProtocol: CardProtocol? = null
|
||||
private val inactiveColor: ColorStateList by lazy { resources.getColorStateList(R.color.btn_dark) }
|
||||
private val activeColor: ColorStateList by lazy { resources.getColorStateList(R.color.colorAccent) }
|
||||
private var requestCounter = 0
|
||||
private var requestCounter: Int = 0
|
||||
set(value)
|
||||
{
|
||||
field=value
|
||||
Log.i(TAG, "requestCounter, set $field")
|
||||
if (field <= 0 && srl!=null && srl.isRefreshing ) {
|
||||
Log.e(TAG, "+++++++++++ FINISH REFRESH")
|
||||
if (srl != null) srl!!.isRefreshing = false
|
||||
//updateViews()
|
||||
}
|
||||
}
|
||||
private var timerRepeatRefresh: Timer? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -395,6 +405,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// request card verify and get info listener
|
||||
val cardVerifyAndGetInfoListener: ServerApiTangem.CardVerifyAndGetInfoListener = object : ServerApiTangem.CardVerifyAndGetInfoListener {
|
||||
override fun onSuccess(cardVerifyAndGetArtworkResponse: CardVerifyAndGetInfo.Response?) {
|
||||
Log.i(TAG,"cardVerifyAndGetInfoListener onSuccess")
|
||||
val result = cardVerifyAndGetArtworkResponse?.results!![0]
|
||||
if (result.error != null) {
|
||||
ctx.card!!.isOnlineVerified = false
|
||||
|
|
@ -402,7 +413,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
ctx.card!!.isOnlineVerified = result.passed
|
||||
|
||||
if (requestCounter == 0) updateViews()
|
||||
// if (requestCounter == 0)
|
||||
requestCounter--
|
||||
updateViews()
|
||||
|
||||
if (!result.passed) return
|
||||
|
||||
|
|
@ -421,6 +434,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
if (result.artwork != null && App.localStorage.checkNeedUpdateArtwork(result.artwork)) {
|
||||
Log.w(TAG, "Artwork '${result.artwork!!.id}' updated, need download")
|
||||
requestCounter++
|
||||
serverApiTangem.requestArtwork(result.artwork!!.id, result.artwork!!.getUpdateDate(), ctx.card!!)
|
||||
updateViews()
|
||||
}
|
||||
|
|
@ -428,7 +442,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
override fun onFail(message: String?) {
|
||||
|
||||
Log.i(TAG,"cardVerifyAndGetInfoListener onFail")
|
||||
requestCounter--
|
||||
updateViews()
|
||||
}
|
||||
}
|
||||
serverApiTangem.setCardVerifyAndGetInfoListener(cardVerifyAndGetInfoListener)
|
||||
|
|
@ -436,12 +452,17 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// request artwork listener
|
||||
val artworkListener: ServerApiTangem.ArtworkListener = object : ServerApiTangem.ArtworkListener {
|
||||
override fun onSuccess(artworkId: String?, inputStream: InputStream?, updateDate: Date?) {
|
||||
Log.i(TAG,"artworkListener onSuccess")
|
||||
App.localStorage.updateArtwork(artworkId!!, inputStream!!, updateDate!!)
|
||||
requestCounter--
|
||||
ivTangemCard.setImageBitmap(App.localStorage.getCardArtworkBitmap(ctx.card!!))
|
||||
updateViews()
|
||||
}
|
||||
|
||||
override fun onFail(message: String?) {
|
||||
|
||||
Log.i(TAG,"artworkListener onFail")
|
||||
requestCounter--
|
||||
updateViews()
|
||||
}
|
||||
}
|
||||
serverApiTangem.setArtworkListener(artworkListener)
|
||||
|
|
@ -454,14 +475,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
private fun counterMinus() {
|
||||
requestCounter--
|
||||
if (requestCounter == 0) {
|
||||
if (srl != null) srl!!.isRefreshing = false
|
||||
updateViews()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
nfcManager!!.onResume()
|
||||
|
|
@ -714,12 +727,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
timerHideErrorAndMessage = null
|
||||
}
|
||||
|
||||
if (ctx.error == null || ctx.error.isEmpty()) {
|
||||
tvError.visibility = View.GONE
|
||||
tvError.text = ""
|
||||
} else {
|
||||
if (ctx.hasError()) {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = ctx.error
|
||||
} else {
|
||||
tvError.visibility = View.GONE
|
||||
tvError.text = ""
|
||||
}
|
||||
|
||||
if (ctx.message == null || ctx.message.isEmpty()) {
|
||||
|
|
@ -775,19 +788,22 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
btnExtract.backgroundTintList = inactiveColor
|
||||
}
|
||||
|
||||
ctx.error = null
|
||||
ctx.message = null
|
||||
//TODO why ???
|
||||
// ctx.error = null
|
||||
// ctx.message = null
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
if (ctx.card == null) return
|
||||
|
||||
// clear all card data and request again
|
||||
srl?.isRefreshing = true
|
||||
ctx.coinData.clearInfo()
|
||||
ctx.error = null
|
||||
ctx.message = null
|
||||
|
||||
Log.e(TAG, "============= START REFRESH")
|
||||
requestCounter = 0
|
||||
srl?.isRefreshing = true
|
||||
|
||||
updateViews()
|
||||
|
||||
|
|
@ -796,14 +812,24 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
val coinEngine = CoinEngineFactory.create(ctx)
|
||||
requestCounter++
|
||||
coinEngine!!.requestBalanceAndUnspentTransactions(
|
||||
object : CoinEngine.BalanceAndUnspentTransactionsNotifications {
|
||||
override fun onComplete(success: Boolean?) {
|
||||
counterMinus()
|
||||
object : CoinEngine.BlockchainRequestsCallbacks {
|
||||
override fun onComplete(success: Boolean) {
|
||||
Log.i(TAG, "requestBalanceAndUnspentTransactions onComplete: "+success.toString()+", request counter "+requestCounter.toString())
|
||||
requestCounter--
|
||||
if(! success)
|
||||
{
|
||||
Log.e(TAG, "ctx.error: "+ctx.error)
|
||||
}
|
||||
updateViews()
|
||||
}
|
||||
|
||||
override fun needTerminate(): Boolean {
|
||||
return !UtilHelper.isOnline(context as Activity)
|
||||
override fun onProgress() {
|
||||
Log.i(TAG, "requestBalanceAndUnspentTransactions onProgress")
|
||||
updateViews()
|
||||
}
|
||||
|
||||
override fun allowAdvance(): Boolean {
|
||||
return UtilHelper.isOnline(context as Activity)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
@ -867,19 +893,24 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private fun requestVerifyAndGetInfo() {
|
||||
if (UtilHelper.isOnline(context as Activity)) {
|
||||
if ((ctx.card!!.isOnlineVerified == null || !ctx.card!!.isOnlineVerified)) {
|
||||
Log.i(TAG, "requestVerifyAndGetInfo")
|
||||
requestCounter++
|
||||
serverApiTangem.cardVerifyAndGetInfo(ctx.card)
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
Log.e(TAG, "+++++++++++ Hide refresh 1")
|
||||
srl?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestRateInfo(cryptoId: String) {
|
||||
if (UtilHelper.isOnline(context as Activity)) {
|
||||
Log.i(TAG, "requestRateInfo")
|
||||
serverApiCommon.rateInfoData(cryptoId)
|
||||
} else {
|
||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
Log.e(TAG, "+++++++++++ Hide refresh 2")
|
||||
srl?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue