Updated on 2026-08-14
This commit is contained in:
parent
4aea39f62a
commit
540f78ef03
7 changed files with 62 additions and 216 deletions
|
|
@ -12,48 +12,38 @@ import android.text.TextWatcher
|
|||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import com.tangem.Constant
|
||||
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.presentation.event.ConfirmPaymentFinishWithError
|
||||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.tangemcard.data.TangemCard
|
||||
import com.tangem.tangemcard.data.loadFromBundle
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_confirm_payment.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
companion object {
|
||||
private const val REQUEST_CODE_SIGN_PAYMENT = 1
|
||||
private const val REQUEST_CODE_REQUEST_PIN2 = 2
|
||||
}
|
||||
|
||||
private var nfcManager: NfcManager? = null
|
||||
|
||||
// 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
|
||||
|
||||
// private var feeRequestSuccess = false
|
||||
// private var balanceRequestSuccess = false
|
||||
private var isIncludeFee: Boolean = true
|
||||
private var requestPIN2Count = 0
|
||||
private var nodeCheck = true
|
||||
private var dtVerified: Date? = null
|
||||
// private var calcSize: Int = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_confirm_payment)
|
||||
|
||||
// MainActivity.commonInit(applicationContext)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
|
@ -85,8 +75,6 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
etFee.setText("")
|
||||
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
// feeRequestSuccess = false
|
||||
// balanceRequestSuccess = false
|
||||
|
||||
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token ||
|
||||
ctx.blockchain == Blockchain.BitcoinCash || ctx.blockchain == Blockchain.Litecoin) {
|
||||
|
|
@ -175,10 +163,10 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
requestPIN2Count = 0
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_FEE_INCLUDED, isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_)
|
||||
}
|
||||
|
||||
val coinEngine = CoinEngineFactory.create(ctx)
|
||||
|
|
@ -189,13 +177,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
object : CoinEngine.BlockchainRequestsCallbacks {
|
||||
override fun onComplete(success: Boolean) {
|
||||
if (success) {
|
||||
|
||||
onProgress()
|
||||
|
||||
// etFee.error = null
|
||||
|
||||
// feeRequestSuccess = true
|
||||
// balanceRequestSuccess = true
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
dtVerified = Date()
|
||||
} else {
|
||||
|
|
@ -213,134 +195,6 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
},
|
||||
etWallet.text.toString(),
|
||||
amount)
|
||||
|
||||
|
||||
// request electrum listener
|
||||
// val electrumBodyListener: ServerApiHelperElectrum.ElectrumRequestDataListener = object : ServerApiHelperElectrum.ElectrumRequestDataListener {
|
||||
// override fun onSuccess(electrumRequest: ElectrumRequest?) {
|
||||
// if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
// try {
|
||||
// if (etFee.text.toString().isEmpty()) etFee.setText(getString(R.string.empty))
|
||||
// val engine = CoinEngineFactory.create(ctx)
|
||||
// val balance = engine.convertToAmount(CoinEngine.InternalAmount(electrumRequest.result.getLong("confirmed") + electrumRequest.result.getLong("unconfirmed"), "Satoshi"))
|
||||
// val amount = CoinEngine.Amount(etAmount.text.toString(), ctx.blockchain.currency)
|
||||
// if (balance < amount) {
|
||||
// etFee.error = getString(R.string.not_enough_funds)
|
||||
// } else {
|
||||
// etFee.error = null
|
||||
// balanceRequestSuccess = true
|
||||
// if (feeRequestSuccess && balanceRequestSuccess) {
|
||||
// btnSend.visibility = View.VISIBLE
|
||||
// }
|
||||
// dtVerified = Date()
|
||||
// nodeCheck = true
|
||||
// }
|
||||
// } catch (e: JSONException) {
|
||||
// e.printStackTrace()
|
||||
//// requestElectrum(ctx.card!!, ElectrumRequest.checkBalance(ctx.card!!.wallet))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onFail(message: String?) {
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_check_balance_no_connection_with_blockchain_nodes))
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// serverApiHelperElectrum.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request infura eth gasPrice listener
|
||||
// val infuraBodyListener: ServerApiInfura.InfuraBodyListener = object : ServerApiInfura.InfuraBodyListener {
|
||||
// override fun onSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
// when (method) {
|
||||
// ServerApiInfura.INFURA_ETH_GAS_PRICE -> {
|
||||
// var gasPrice = infuraResponse.result
|
||||
// gasPrice = gasPrice.substring(2)
|
||||
// //TODO - remove Gwei
|
||||
// // rounding gas price to integer gwei
|
||||
// val l = BigInteger(gasPrice, 16).divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L))
|
||||
//
|
||||
// //val m = if (ctx.blockchain==Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
|
||||
// val m = if (amount.currency != "ETH") BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
|
||||
// val weiMinFee = CoinEngine.InternalAmount(l.multiply(m), "wei")
|
||||
// val weiNormalFee = CoinEngine.InternalAmount(weiMinFee.multiply(BigDecimal.valueOf(12)).divide(BigDecimal.valueOf(10)), "wei")
|
||||
// val weiMaxFee = CoinEngine.InternalAmount(weiMinFee.multiply(BigDecimal.valueOf(15)).divide(BigDecimal.valueOf(10)), "wei")
|
||||
//
|
||||
// minFee = engine.convertToAmount(weiMinFee)
|
||||
// normalFee = engine.convertToAmount(weiNormalFee)
|
||||
// maxFee = engine.convertToAmount(weiMaxFee)
|
||||
// doSetFee(rgFee.checkedRadioButtonId)
|
||||
// //etFee.setText(weiNormalFee.toValueString())
|
||||
// etFee.error = null
|
||||
// btnSend.visibility = View.VISIBLE
|
||||
// feeRequestSuccess = true
|
||||
//// balanceRequestSuccess = true
|
||||
// dtVerified = Date()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onFail(method: String, message: String) {
|
||||
// when (method) {
|
||||
// ServerApiInfura.INFURA_ETH_GAS_PRICE -> {
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// serverApiInfura.setInfuraResponse(infuraBodyListener)
|
||||
|
||||
// // request estimate fee listener
|
||||
// val estimateFeeListener: ServerApiCommon.EstimateFeeListener = object : ServerApiCommon.EstimateFeeListener {
|
||||
// override fun onSuccess(blockCount: Int, estimateFeeResponse: String?) {
|
||||
// var fee: BigDecimal?
|
||||
// fee = BigDecimal(estimateFeeResponse) // BTC per 1 kb
|
||||
//
|
||||
// if (fee == BigDecimal.ZERO) {
|
||||
// progressBar.visibility = View.INVISIBLE
|
||||
// requestEstimateFee()
|
||||
// }
|
||||
//
|
||||
// if (calcSize.toLong() != 0L) {
|
||||
// fee = fee.multiply(BigDecimal(calcSize.toLong())).divide(BigDecimal(1024)) // per Kb -> per byte
|
||||
// } else {
|
||||
// requestEstimateFee()
|
||||
// }
|
||||
//
|
||||
// progressBar.visibility = View.INVISIBLE
|
||||
//
|
||||
// fee = fee!!.setScale(8, RoundingMode.DOWN)
|
||||
//
|
||||
// when (blockCount) {
|
||||
// ServerApiCommon.ESTIMATE_FEE_MINIMAL -> {
|
||||
// minFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
// if (rgFee.checkedRadioButtonId == R.id.rbMinimalFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
// }
|
||||
//
|
||||
// ServerApiCommon.ESTIMATE_FEE_NORMAL -> {
|
||||
// normalFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
// if (rgFee.checkedRadioButtonId == R.id.rbNormalFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
// }
|
||||
//
|
||||
// ServerApiCommon.ESTIMATE_FEE_PRIORITY -> {
|
||||
// maxFee = CoinEngine.Amount(fee, engine.feeCurrency)
|
||||
// if (rgFee.checkedRadioButtonId == R.id.rbMaximumFee) doSetFee(rgFee.checkedRadioButtonId)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// etFee.error = null
|
||||
// feeRequestSuccess = true
|
||||
// if (feeRequestSuccess)
|
||||
//// if (feeRequestSuccess && balanceRequestSuccess)
|
||||
// btnSend.visibility = View.VISIBLE
|
||||
// dtVerified = Date()
|
||||
// }
|
||||
//
|
||||
// override fun onFail(message: String?) {
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_calculate_fee_wrong_data_received_from_node))
|
||||
// }
|
||||
// }
|
||||
// serverApiCommon.setEstimateFee(estimateFeeListener)
|
||||
}
|
||||
|
||||
public override fun onResume() {
|
||||
|
|
@ -360,7 +214,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == REQUEST_CODE_SIGN_PAYMENT) {
|
||||
if (requestCode == Constant.REQUEST_CODE_SIGN_PAYMENT) {
|
||||
if (data != null && data.extras != null) {
|
||||
if (data.extras!!.containsKey("UID") && data.extras!!.containsKey("Card")) {
|
||||
val updatedCard = TangemCard(data.getStringExtra("UID"))
|
||||
|
|
@ -371,15 +225,15 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (resultCode == SignPaymentActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_FEE_INCLUDED, isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_)
|
||||
return
|
||||
}
|
||||
setResult(resultCode, data)
|
||||
finish()
|
||||
} else if (requestCode == REQUEST_CODE_REQUEST_PIN2) {
|
||||
} else if (requestCode == Constant.REQUEST_CODE_REQUEST_PIN2_) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val intent = Intent(baseContext, SignPaymentActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
|
|
@ -389,7 +243,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
intent.putExtra(SignPaymentActivity.EXTRA_FEE, etFee.text.toString())
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_FEE_CURRENCY, tvCurrency2.text.toString())
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_FEE_INCLUDED, isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_SIGN_PAYMENT)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_SIGN_PAYMENT)
|
||||
} else
|
||||
Toast.makeText(baseContext, R.string.pin_2_is_required_to_sign_the_payment, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
|
@ -415,38 +269,6 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO - move to BtcEngine
|
||||
// @Throws(Exception::class)
|
||||
|
||||
// private fun requestElectrum(ctx: TangemContext, electrumRequest: ElectrumRequest) {
|
||||
// if (UtilHelper.isOnline(this)) {
|
||||
// serverApiElectrum.electrumRequestData(ctx, electrumRequest)
|
||||
// } else
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
// }
|
||||
|
||||
// private fun requestInfura(method: String) {
|
||||
// if (UtilHelper.isOnline(this)) {
|
||||
// serverApiInfura.infura(method, 67, ctx.coinData!!.wallet, "", "")
|
||||
// } else
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
// }
|
||||
|
||||
// private fun requestEstimateFee() {
|
||||
// if (calcSize == 0) {
|
||||
// calcSize = 256
|
||||
// try {
|
||||
//
|
||||
// calcSize = buildSize(etWallet!!.text.toString(), "0.00", etAmount.text.toString())
|
||||
// } catch (ex: Exception) {
|
||||
// Log.e("Build Fee error", ex.message)
|
||||
// }
|
||||
// }
|
||||
// serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_PRIORITY)
|
||||
// serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_NORMAL)
|
||||
// serverApiCommon.estimateFee(ServerApiCommon.ESTIMATE_FEE_MINIMAL)
|
||||
// }
|
||||
|
||||
private fun doSetFee(checkedRadioButtonId: Int) {
|
||||
var txtFee = ""
|
||||
when (checkedRadioButtonId) {
|
||||
|
|
@ -454,7 +276,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (ctx.coinData.minFee != null) {
|
||||
txtFee = ctx.coinData.minFee!!.toValueString()
|
||||
btnSend.visibility = View.VISIBLE
|
||||
}else {
|
||||
} else {
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
|
|
@ -462,7 +284,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (ctx.coinData.normalFee != null) {
|
||||
txtFee = ctx.coinData.normalFee!!.toValueString()
|
||||
btnSend.visibility = View.VISIBLE
|
||||
}else {
|
||||
} else {
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
|
|
@ -470,7 +292,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (ctx.coinData.maxFee != null) {
|
||||
txtFee = ctx.coinData.maxFee!!.toValueString()
|
||||
btnSend.visibility = View.VISIBLE
|
||||
}else {
|
||||
} else {
|
||||
// finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
btnSend.visibility = View.INVISIBLE
|
||||
}
|
||||
|
|
@ -479,6 +301,10 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
private fun finishWithError(errorCode: Int, message: String) {
|
||||
val confirmPaymentFinishWithError = ConfirmPaymentFinishWithError()
|
||||
confirmPaymentFinishWithError.message = message
|
||||
EventBus.getDefault().post(confirmPaymentFinishWithError)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", message)
|
||||
setResult(errorCode, intent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue