Updated on 2026-08-14
This commit is contained in:
parent
819f4c6a98
commit
75f6f589d2
8 changed files with 55 additions and 108 deletions
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
|
|
@ -1,5 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
|
|
|
|||
|
|
@ -17,10 +17,11 @@ 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.presentation.event.TransactionFinishWithError
|
||||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.tangemcard.data.TangemCard
|
||||
import com.tangem.tangemcard.data.loadFromBundle
|
||||
import com.tangem.util.LOG
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_confirm_payment.*
|
||||
|
|
@ -219,6 +220,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
finish()
|
||||
} else if (requestCode == Constant.REQUEST_CODE_REQUEST_PIN2_) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
LOG.i("SDSDW", "sdwwd")
|
||||
val intent = Intent(baseContext, SignPaymentActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
intent.putExtra(Constant.EXTRA_TARGET_ADDRESS, etWallet!!.text.toString())
|
||||
|
|
@ -281,9 +283,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
private fun finishWithError(errorCode: Int, message: String) {
|
||||
val confirmPaymentFinishWithError = ConfirmPaymentFinishWithError()
|
||||
confirmPaymentFinishWithError.message = message
|
||||
EventBus.getDefault().post(confirmPaymentFinishWithError)
|
||||
val transactionFinishWithError = TransactionFinishWithError()
|
||||
transactionFinishWithError.message = message
|
||||
EventBus.getDefault().post(transactionFinishWithError)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", message)
|
||||
|
|
|
|||
|
|
@ -9,13 +9,12 @@ import android.view.KeyEvent
|
|||
import android.widget.Toast
|
||||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
import com.tangem.domain.wallet.eth.EthData
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.presentation.event.TransactionFinishWithError
|
||||
import com.tangem.presentation.event.TransactionFinishWithSuccess
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.R
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
import java.math.BigInteger
|
||||
|
||||
class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
||||
|
|
@ -23,19 +22,14 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
const val EXTRA_TX: String = "TX"
|
||||
}
|
||||
|
||||
// private var serverApiInfura: ServerApiInfura = ServerApiInfura()
|
||||
// private var serverApiElectrum: ServerApiElectrum = ServerApiElectrum()
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private var tx: ByteArray? = null
|
||||
private var nfcManager: NfcManager? = null
|
||||
private lateinit var nfcManager: NfcManager
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_send_transaction)
|
||||
|
||||
// MainActivity.commonInit(applicationContext)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
|
@ -46,11 +40,10 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
engine!!.requestSendTransaction(
|
||||
object : CoinEngine.BlockchainRequestsCallbacks {
|
||||
override fun onComplete(success: Boolean) {
|
||||
if (success) {
|
||||
if (success)
|
||||
finishWithSuccess()
|
||||
} else {
|
||||
else
|
||||
finishWithError(this@SendTransactionActivity.getString(R.string.try_again_failed_to_send_transaction))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProgress() {
|
||||
|
|
@ -63,65 +56,6 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
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)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
|
|
@ -136,42 +70,32 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
public override fun onResume() {
|
||||
super.onResume()
|
||||
nfcManager!!.onResume()
|
||||
nfcManager.onResume()
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
super.onPause()
|
||||
nfcManager!!.onPause()
|
||||
nfcManager.onPause()
|
||||
}
|
||||
|
||||
public override fun onStop() {
|
||||
super.onStop()
|
||||
nfcManager!!.onStop()
|
||||
nfcManager.onStop()
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager!!.ignoreTag(tag)
|
||||
nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
// 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 transactionFinishWithSuccess = TransactionFinishWithSuccess()
|
||||
transactionFinishWithSuccess.message = getString(R.string.transaction_has_been_successfully_signed)
|
||||
EventBus.getDefault().post(transactionFinishWithSuccess)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", getString(R.string.transaction_has_been_successfully_signed))
|
||||
setResult(RESULT_OK, intent)
|
||||
|
|
@ -179,6 +103,10 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
private fun finishWithError(message: String) {
|
||||
val transactionFinishWithError = TransactionFinishWithError()
|
||||
transactionFinishWithError.message = String.format(getString(R.string.try_again_failed_to_send_transaction), message)
|
||||
EventBus.getDefault().post(transactionFinishWithError)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", String.format(getString(R.string.try_again_failed_to_send_transaction), message))
|
||||
setResult(RESULT_CANCELED, intent)
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
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("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(Constant.RESULT_INVALID_PIN_, intent)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package com.tangem.presentation.event
|
||||
|
||||
class ConfirmPaymentFinishWithError {
|
||||
class TransactionFinishWithError {
|
||||
var message: String? = null
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.tangem.presentation.event
|
||||
|
||||
class TransactionFinishWithSuccess {
|
||||
var message: String? = null
|
||||
}
|
||||
|
|
@ -31,7 +31,8 @@ import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
|||
import com.tangem.presentation.dialog.PINSwapWarningDialog
|
||||
import com.tangem.presentation.dialog.ShowQRCodeDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.presentation.event.ConfirmPaymentFinishWithError
|
||||
import com.tangem.presentation.event.TransactionFinishWithError
|
||||
import com.tangem.presentation.event.TransactionFinishWithSuccess
|
||||
import com.tangem.tangemcard.android.reader.NfcManager
|
||||
import com.tangem.tangemcard.android.reader.NfcReader
|
||||
import com.tangem.tangemcard.data.EXTRA_TANGEM_CARD
|
||||
|
|
@ -298,8 +299,14 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
@Subscribe
|
||||
fun onConfirmPaymentFinishWithError(confirmPaymentFinishWithError: ConfirmPaymentFinishWithError) {
|
||||
ctx.error = confirmPaymentFinishWithError.message
|
||||
fun onTransactionFinishWithSuccess(transactionFinishWithSuccess: TransactionFinishWithSuccess) {
|
||||
ctx.message = transactionFinishWithSuccess.message
|
||||
updateViews()
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun onTransactionFinishWithError(transactionFinishWithError: TransactionFinishWithError) {
|
||||
ctx.error = transactionFinishWithError.message
|
||||
updateViews()
|
||||
}
|
||||
|
||||
|
|
@ -423,14 +430,14 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
updatedCard.loadFromBundle(data.getBundleExtra(EXTRA_TANGEM_CARD))
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
if (data.extras!!.containsKey("message")) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
ctx.message = data.getStringExtra("message")
|
||||
} else {
|
||||
ctx.error = data.getStringExtra("message")
|
||||
}
|
||||
}
|
||||
updateViews()
|
||||
// if (data.extras!!.containsKey("message")) {
|
||||
// if (resultCode == Activity.RESULT_OK) {
|
||||
// ctx.message = data.getStringExtra("message")
|
||||
// } else {
|
||||
// ctx.error = data.getStringExtra("message")
|
||||
// }
|
||||
// }
|
||||
// updateViews()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@
|
|||
<string name="please_wait">Please wait while the payment is sent…</string>
|
||||
<string name="transaction_has_been_successfully_signed">Transaction has been successfully signed and sent to blockchain node. Wallet balance will be updated in a while</string>
|
||||
<string name="try_again_failed_to_send_transaction">Try again. Failed to send transaction (%1$s)</string>
|
||||
<string name="cannot_sign_transaction._make_sure_you_enter_correct_pin_2">Cannot sign transaction. Make sure you enter correct PIN2!</string>
|
||||
<string name="cannot_sign_transaction_make_sure_you_enter_correct_pin_2">Cannot sign transaction. Make sure you enter correct PIN2!</string>
|
||||
<string name="cannot_sign_transaction_wrong_amount">Amount and fee exceed total wallet balance!</string>
|
||||
|
||||
<!-- PreparePaymentActivity -->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue