Updated on 2026-08-14
This commit is contained in:
parent
71fe425c1b
commit
6ebb46c2a5
10 changed files with 711 additions and 492 deletions
|
|
@ -13,19 +13,21 @@ import android.view.KeyEvent
|
|||
import android.view.View
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.nfc.SignPaymentTask
|
||||
import com.tangem.tangemcard.reader.CardProtocol
|
||||
import com.tangem.tangemcard.reader.NfcManager
|
||||
import com.tangem.domain.wallet.BTCUtils
|
||||
import com.tangem.domain.wallet.CoinEngine
|
||||
import com.tangem.domain.wallet.CoinEngineFactory
|
||||
import com.tangem.domain.wallet.TangemContext
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.tangemcard.data.Blockchain
|
||||
import com.tangem.tangemcard.reader.CardProtocol
|
||||
import com.tangem.tangemcard.reader.NfcManager
|
||||
import com.tangem.tangemcard.tasks.SignTask
|
||||
import com.tangem.tangemcard.util.Util
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_sign_payment.*
|
||||
|
||||
|
||||
class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
|
||||
companion object {
|
||||
|
|
@ -136,129 +138,6 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
// signPaymentTask = SignPaymentTask(this, ctx, nfcManager, isoDep, this, amount, fee, isIncludeFee, outAddressStr)
|
||||
|
||||
val coinEngine= CoinEngineFactory.create(ctx) ?: throw CardProtocol.TangemException("Can't create CoinEngine!")
|
||||
val paymentToSign = coinEngine.constructPayment(amount, fee, isIncludeFee, outAddressStr)
|
||||
|
||||
// object: SignTask.PaymentToSign {
|
||||
// override fun call(context: String?) { println("Call: $context") }
|
||||
// override fun run(context: String?) { println("Run: $context") }
|
||||
// }
|
||||
signPaymentTask = SignTask(this, ctx.card, nfcManager, isoDep, this, paymentToSign)
|
||||
signPaymentTask!!.start()
|
||||
} else {
|
||||
// Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card!!.uid + ")")
|
||||
nfcManager!!.ignoreTag(isoDep.tag)
|
||||
}
|
||||
|
||||
} 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)
|
||||
}
|
||||
|
||||
}
|
||||
coinEngine.setOnNeedSendPayment { tx->
|
||||
if (tx != null) {
|
||||
// [REDACTED_TODO_COMMENT]
|
||||
Loading…
Add table
Add a link
Reference in a new issue