Updated on 2026-08-14
This commit is contained in:
parent
39e8a00638
commit
37b4fa55f1
5 changed files with 231 additions and 121 deletions
|
|
@ -3,9 +3,12 @@ package com.tangem.presentation.activity
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
|
||||
import com.tangem.data.network.request.ElectrumRequest
|
||||
import com.tangem.data.network.request.InfuraRequest
|
||||
|
|
@ -13,9 +16,11 @@ import com.tangem.data.network.task.send_transaction.ConnectTask
|
|||
import com.tangem.data.network.task.send_transaction.ETHRequestTask
|
||||
import com.tangem.domain.wallet.Blockchain
|
||||
import com.tangem.domain.wallet.CoinEngineFactory
|
||||
import com.tangem.domain.wallet.LastSignStorage
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.presentation.fragment.LoadedWallet
|
||||
import com.tangem.wallet.R
|
||||
import org.json.JSONException
|
||||
import java.math.BigInteger
|
||||
|
||||
class SendTransactionActivity : AppCompatActivity() {
|
||||
|
||||
|
|
@ -25,9 +30,9 @@ class SendTransactionActivity : AppCompatActivity() {
|
|||
const val EXTRA_TX: String = "TX"
|
||||
}
|
||||
|
||||
private var serverApiHelper: ServerApiHelper? = null
|
||||
var card: TangemCard? = null
|
||||
private var tx: String? = null
|
||||
private var progressBar: ProgressBar? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -35,7 +40,7 @@ class SendTransactionActivity : AppCompatActivity() {
|
|||
|
||||
MainActivity.commonInit(applicationContext)
|
||||
|
||||
progressBar = findViewById(R.id.progressBar)
|
||||
serverApiHelper = ServerApiHelper()
|
||||
|
||||
val intent = intent
|
||||
card = TangemCard(getIntent().getStringExtra(EXTRA_UID))
|
||||
|
|
@ -44,11 +49,14 @@ class SendTransactionActivity : AppCompatActivity() {
|
|||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token) {
|
||||
val task = ETHRequestTask(this@SendTransactionActivity, card!!.blockchain)
|
||||
val req = InfuraRequest.SendTransaction(card!!.wallet, tx)
|
||||
req.id = 67
|
||||
req.setBlockchain(card!!.blockchain)
|
||||
task.execute(req)
|
||||
// val task = ETHRequestTask(this@SendTransactionActivity, card!!.blockchain)
|
||||
// val req = InfuraRequest.SendTransaction(card!!.wallet, tx)
|
||||
// req.id = 67
|
||||
// req.setBlockchain(card!!.blockchain)
|
||||
// task.execute(req)
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
|
||||
} else if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
val nodeAddress = engine!!.getNode(card)
|
||||
val nodePort = engine.getNodePort(card)
|
||||
|
|
@ -60,6 +68,66 @@ class SendTransactionActivity : AppCompatActivity() {
|
|||
val connectTask = ConnectTask(this@SendTransactionActivity, nodeAddress, nodePort, 3)
|
||||
connectTask.execute(ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
}
|
||||
|
||||
// request eth sendRawTransaction
|
||||
val infuraBodyListener: ServerApiHelper.InfuraBodyListener = object : ServerApiHelper.InfuraBodyListener {
|
||||
override fun onInfuraSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
when (method) {
|
||||
ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
try {
|
||||
var hashTX: String
|
||||
try {
|
||||
val tmp = infuraResponse.result
|
||||
hashTX = tmp
|
||||
} catch (e: JSONException) {
|
||||
// val msg = request.getAnswer()
|
||||
// val err = msg!!.getJSONObject("error")
|
||||
// hashTX = err.getString("message")
|
||||
// LastSignStorage.setLastMessage(card!!.wallet, hashTX)
|
||||
return@onInfuraSuccess
|
||||
}
|
||||
|
||||
if (hashTX.startsWith("0x") || hashTX.startsWith("0X")) {
|
||||
hashTX = hashTX.substring(2)
|
||||
}
|
||||
val bigInt = BigInteger(hashTX, 16) //TODO: очень плохой способ
|
||||
LastSignStorage.setTxWasSend(card!!.wallet)
|
||||
LastSignStorage.setLastMessage(card!!.wallet, "")
|
||||
Log.e("TX_RESULT", hashTX)
|
||||
|
||||
|
||||
val nonce = card!!.GetConfirmTXCount()
|
||||
nonce.add(BigInteger.valueOf(1))
|
||||
card!!.setConfirmTXCount(nonce)
|
||||
Log.e("TX_RESULT", hashTX)
|
||||
|
||||
finishWithSuccess()
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInfuraFail(method: String, message: String) {
|
||||
when (method) {
|
||||
ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION -> {
|
||||
finishWithError(message)
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
serverApiHelper!!.setInfuraResponse(infuraBodyListener)
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
|
|
@ -72,6 +140,10 @@ class SendTransactionActivity : AppCompatActivity() {
|
|||
return super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
||||
private fun requestInfura(method: String, contract: String) {
|
||||
serverApiHelper!!.infura(method, 67, card!!.wallet, contract, tx)
|
||||
}
|
||||
|
||||
fun finishWithError(message: String) {
|
||||
val intent = Intent()
|
||||
intent.putExtra("message", String.format(getString(R.string.try_again_failed_to_send_transaction), message))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue