Updated on 2026-08-14
This commit is contained in:
parent
1ca72f81b4
commit
7a94fb82ee
4 changed files with 104 additions and 82 deletions
|
|
@ -217,28 +217,37 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
// request electrum listener
|
||||
serverApiHelperElectrum!!.setElectrumRequestData {
|
||||
if (it.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
etFee!!.setText("--")
|
||||
if ((it.result.getInt("confirmed") + it.result.getInt("unconfirmed")) / card!!.blockchain.multiplier * 1000000.0 < java.lang.Float.parseFloat(etAmount!!.text.toString())) {
|
||||
etFee!!.error = "Not enough funds"
|
||||
} else {
|
||||
etFee!!.error = null
|
||||
balanceRequestSuccess = true
|
||||
if (feeRequestSuccess && balanceRequestSuccess) {
|
||||
btnSend!!.visibility = View.VISIBLE
|
||||
val electrumBodyListener: ServerApiHelperElectrum.ElectrumRequestDataListener = object : ServerApiHelperElectrum.ElectrumRequestDataListener {
|
||||
override fun onElectrumSuccess(electrumRequest: ElectrumRequest?) {
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
etFee!!.setText("--")
|
||||
if ((electrumRequest.result.getInt("confirmed") + electrumRequest.result.getInt("unconfirmed")) / card!!.blockchain.multiplier * 1000000.0 < java.lang.Float.parseFloat(etAmount!!.text.toString())) {
|
||||
etFee!!.error = "Not enough funds"
|
||||
} else {
|
||||
etFee!!.error = null
|
||||
balanceRequestSuccess = true
|
||||
if (feeRequestSuccess && balanceRequestSuccess) {
|
||||
btnSend!!.visibility = View.VISIBLE
|
||||
}
|
||||
dtVerified = Date()
|
||||
nodeCheck = true
|
||||
}
|
||||
dtVerified = Date()
|
||||
nodeCheck = true
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_check_balance_no_connection_with_blockchain_nodes))
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_check_balance_no_connection_with_blockchain_nodes))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onElectrumFail(message: String?) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
serverApiHelperElectrum!!.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request estimate fee listener
|
||||
serverApiHelper!!.setEstimateFee { blockCount, estimateFeeResponse ->
|
||||
var fee: BigDecimal?
|
||||
|
|
|
|||
|
|
@ -68,10 +68,11 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
// request electrum listener
|
||||
serverApiHelperElectrum!!.setElectrumRequestData {
|
||||
if (it.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
val electrumBodyListener: ServerApiHelperElectrum.ElectrumRequestDataListener = object : ServerApiHelperElectrum.ElectrumRequestDataListener {
|
||||
override fun onElectrumSuccess(electrumRequest: ElectrumRequest?) {
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
try {
|
||||
var hashTX = it.resultString
|
||||
var hashTX = electrumRequest.resultString
|
||||
|
||||
try {
|
||||
if (hashTX.startsWith("0x") || hashTX.startsWith("0X")) {
|
||||
|
|
@ -91,8 +92,15 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onElectrumFail(message: String?) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
serverApiHelperElectrum!!.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request eth sendRawTransaction
|
||||
val infuraBodyListener: ServerApiHelper.InfuraBodyListener = object : ServerApiHelper.InfuraBodyListener {
|
||||
override fun onInfuraSuccess(method: String, infuraResponse: InfuraResponse) {
|
||||
|
|
@ -111,7 +119,6 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
hashTX = hashTX.substring(2)
|
||||
}
|
||||
|
||||
|
||||
val nonce = card!!.confirmedTXCount
|
||||
nonce.add(BigInteger.valueOf(1))
|
||||
card!!.confirmedTXCount = nonce
|
||||
|
|
|
|||
|
|
@ -220,80 +220,88 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
// request electrum listener
|
||||
serverApiHelperElectrum!!.setElectrumRequestData {
|
||||
val electrumBodyListener: ServerApiHelperElectrum.ElectrumRequestDataListener = object : ServerApiHelperElectrum.ElectrumRequestDataListener {
|
||||
override fun onElectrumSuccess(electrumRequest: ElectrumRequest?) {
|
||||
requestCounter--
|
||||
if (requestCounter == 0) srl.isRefreshing = false
|
||||
|
||||
requestCounter--
|
||||
if (requestCounter == 0) srl.isRefreshing = false
|
||||
|
||||
if (it.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
val walletAddress = it.params.getString(0)
|
||||
val confBalance = it.result.getLong("confirmed")
|
||||
val unconfirmedBalance = it.result.getLong("unconfirmed")
|
||||
card!!.isBalanceReceived = true
|
||||
card!!.setBalanceConfirmed(confBalance)
|
||||
card!!.balanceUnconfirmed = unconfirmedBalance
|
||||
card!!.decimalBalance = confBalance.toString()
|
||||
card!!.validationNodeDescription = serverApiHelperElectrum!!.validationNodeDescription
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
engine.switchNode(card)
|
||||
}
|
||||
}
|
||||
|
||||
if (it.isMethod(ElectrumRequest.METHOD_ListUnspent)) {
|
||||
try {
|
||||
val walletAddress = it.params.getString(0)
|
||||
val jsUnspentArray = it.resultArray
|
||||
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_GetBalance)) {
|
||||
try {
|
||||
card!!.unspentTransactions.clear()
|
||||
val walletAddress = electrumRequest.params.getString(0)
|
||||
val confBalance = electrumRequest.result.getLong("confirmed")
|
||||
val unconfirmedBalance = electrumRequest.result.getLong("unconfirmed")
|
||||
card!!.isBalanceReceived = true
|
||||
card!!.setBalanceConfirmed(confBalance)
|
||||
card!!.balanceUnconfirmed = unconfirmedBalance
|
||||
card!!.decimalBalance = confBalance.toString()
|
||||
card!!.validationNodeDescription = serverApiHelperElectrum!!.validationNodeDescription
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
Log.e(TAG, "FAIL METHOD_GetBalance JSONException")
|
||||
}
|
||||
}
|
||||
|
||||
if (electrumRequest.isMethod(ElectrumRequest.METHOD_ListUnspent)) {
|
||||
try {
|
||||
val walletAddress = electrumRequest.params.getString(0)
|
||||
val jsUnspentArray = electrumRequest.resultArray
|
||||
try {
|
||||
card!!.unspentTransactions.clear()
|
||||
for (i in 0 until jsUnspentArray.length()) {
|
||||
val jsUnspent = jsUnspentArray.getJSONObject(i)
|
||||
val trUnspent = TangemCard.UnspentTransaction()
|
||||
trUnspent.txID = jsUnspent.getString("tx_hash")
|
||||
trUnspent.Amount = jsUnspent.getInt("value")
|
||||
trUnspent.Height = jsUnspent.getInt("height")
|
||||
card!!.unspentTransactions.add(trUnspent)
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
Log.e(TAG, "FAIL METHOD_ListUnspent JSONException")
|
||||
}
|
||||
|
||||
for (i in 0 until jsUnspentArray.length()) {
|
||||
val jsUnspent = jsUnspentArray.getJSONObject(i)
|
||||
val trUnspent = TangemCard.UnspentTransaction()
|
||||
trUnspent.txID = jsUnspent.getString("tx_hash")
|
||||
trUnspent.Amount = jsUnspent.getInt("value")
|
||||
trUnspent.Height = jsUnspent.getInt("height")
|
||||
card!!.unspentTransactions.add(trUnspent)
|
||||
val height = jsUnspent.getInt("height")
|
||||
val hash = jsUnspent.getString("tx_hash")
|
||||
if (height != -1) {
|
||||
requestElectrum(card!!, ElectrumRequest.getTransaction(walletAddress, hash))
|
||||
}
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
for (i in 0 until jsUnspentArray.length()) {
|
||||
val jsUnspent = jsUnspentArray.getJSONObject(i)
|
||||
val height = jsUnspent.getInt("height")
|
||||
val hash = jsUnspent.getString("tx_hash")
|
||||
if (height != -1) {
|
||||
requestElectrum(card!!, ElectrumRequest.getTransaction(walletAddress, hash))
|
||||
if (electrumRequest.isMethod(ElectrumRequest.METHOD_GetTransaction)) {
|
||||
try {
|
||||
val txHash = electrumRequest.txHash
|
||||
val raw = electrumRequest.resultString
|
||||
val listTx = card!!.unspentTransactions
|
||||
for (tx in listTx) {
|
||||
if (tx.txID == txHash)
|
||||
tx.Raw = raw
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
if (it.isMethod(ElectrumRequest.METHOD_GetTransaction)) {
|
||||
try {
|
||||
val txHash = it.txHash
|
||||
val raw = it.resultString
|
||||
val listTx = card!!.unspentTransactions
|
||||
for (tx in listTx) {
|
||||
if (tx.txID == txHash)
|
||||
tx.Raw = raw
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
if (electrumRequest.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
|
||||
}
|
||||
|
||||
if (requestCounter == 0) updateViews()
|
||||
}
|
||||
|
||||
if (it.isMethod(ElectrumRequest.METHOD_SendTransaction)) {
|
||||
|
||||
override fun onElectrumFail(method: String?) {
|
||||
srl.isRefreshing = false
|
||||
Log.e(TAG, "FAIL $method")
|
||||
}
|
||||
|
||||
if (requestCounter == 0) updateViews()
|
||||
|
||||
}
|
||||
|
||||
serverApiHelperElectrum!!.setElectrumRequestData(electrumBodyListener)
|
||||
|
||||
// request card verify listener
|
||||
serverApiHelper!!.setCardVerifyAndGetInfoListener {
|
||||
requestCounter--
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue