Updated on 2026-08-14
This commit is contained in:
parent
47874b90f3
commit
4c2f78c5ef
8 changed files with 93 additions and 66 deletions
8
.idea/misc.xml
generated
8
.idea/misc.xml
generated
|
|
@ -5,22 +5,26 @@
|
|||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="5">
|
||||
<list size="7">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<list size="6">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
|
|
|
|||
|
|
@ -94,9 +94,9 @@ public class ServerApiHelper {
|
|||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.code() == 200) {
|
||||
estimateFeeListener.onInfuraEthGasPrice(blockCount, response.body());
|
||||
Log.i(TAG, "estimateFee onResponse " + response.code());
|
||||
Log.i(TAG, "estimateFee onResponse " + response.code() + " " + response.body());
|
||||
} else
|
||||
Log.e(TAG, "estimateFee onResponse " + response.code());
|
||||
Log.e(TAG, "estimateFee onResponse " + response.code());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -82,6 +82,10 @@ public class ConnectFeeTask extends FeeTask {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
confirmPaymentActivity.getProgressBar().setVisibility(View.INVISIBLE);
|
||||
|
||||
DecimalFormat df = new DecimalFormat();
|
||||
|
|
@ -108,6 +112,9 @@ public class ConnectFeeTask extends FeeTask {
|
|||
}
|
||||
confirmPaymentActivity.setDtVerified(new Date());
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if (sharedCounter != null) {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ import com.tangem.util.Util
|
|||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_confirm_payment.*
|
||||
import java.io.IOException
|
||||
import java.math.BigDecimal
|
||||
import java.math.BigInteger
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
|
||||
class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
|
@ -51,7 +53,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
var minFee: String? = null
|
||||
var maxFee: String? = null
|
||||
var normalFee: String? = null
|
||||
var incFee: Boolean = true
|
||||
private var isIncludeFee: Boolean = true
|
||||
var minFeeInInternalUnits: Long? = 0L
|
||||
private var requestPIN2Count = 0
|
||||
var nodeCheck = false
|
||||
|
|
@ -85,8 +87,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
} else
|
||||
tvBalance.text = balanceWithAlter
|
||||
|
||||
incFee = intent.getBooleanExtra("IncFee", true)
|
||||
if (incFee)
|
||||
isIncludeFee = intent.getBooleanExtra("IncFee", true)
|
||||
if (isIncludeFee)
|
||||
tvIncFee.setText(R.string.including_fee)
|
||||
else
|
||||
tvIncFee.setText(R.string.not_including_fee)
|
||||
|
|
@ -139,17 +141,17 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
progressBar!!.visibility = View.VISIBLE
|
||||
|
||||
// serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_PRIORITY)
|
||||
// serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_NORMAL)
|
||||
// serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_MINIMAL)
|
||||
serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_PRIORITY)
|
||||
serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_NORMAL)
|
||||
serverApiHelper!!.estimateFee(ServerApiHelper.ESTIMATE_FEE_MINIMAL)
|
||||
|
||||
for (i in 0 until SharedData.COUNT_REQUEST) {
|
||||
val feeTask = ConnectFeeTask(this@ConfirmPaymentActivity, sharedFee)
|
||||
feeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.NORMAL),
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.MINIMAL),
|
||||
FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.PRIORITY))
|
||||
}
|
||||
// for (i in 0 until SharedData.COUNT_REQUEST) {
|
||||
// val feeTask = ConnectFeeTask(this@ConfirmPaymentActivity, sharedFee)
|
||||
// feeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
|
||||
// FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.NORMAL),
|
||||
// FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.MINIMAL),
|
||||
// FeeRequest.GetFee(card!!.wallet, calcSize.toLong(), FeeRequest.PRIORITY))
|
||||
// }
|
||||
}
|
||||
|
||||
// set listeners
|
||||
|
|
@ -214,7 +216,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (!engineCoin.checkAmountValue(card, txAmount, txFee, minFeeInInternalUnits, incFee)) {
|
||||
if (!engineCoin.checkAmountValue(card, txAmount, txFee, minFeeInInternalUnits, isIncludeFee)) {
|
||||
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.not_enough_funds_or_incorrect_amount))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
|
@ -224,26 +226,44 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("IncFee", incFee)
|
||||
intent.putExtra("IncFee", isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
}
|
||||
|
||||
|
||||
// request estimate fee listener
|
||||
serverApiHelper!!.setEstimateFee { blockCount, estimateFeeResponse ->
|
||||
|
||||
val fee = BigDecimal(estimateFeeResponse)
|
||||
|
||||
progressBar!!.visibility = View.INVISIBLE
|
||||
|
||||
val df = DecimalFormat()
|
||||
df.maximumFractionDigits = 7
|
||||
df.minimumFractionDigits = 3
|
||||
df.isGroupingUsed = false
|
||||
val strFee = df.format(fee)
|
||||
|
||||
when (blockCount) {
|
||||
ServerApiHelper.ESTIMATE_FEE_PRIORITY -> {
|
||||
// Log.i("estimate_fee_PRIORITY", estimateFeeResponse)
|
||||
maxFee = strFee
|
||||
}
|
||||
|
||||
ServerApiHelper.ESTIMATE_FEE_NORMAL -> {
|
||||
// Log.i("estimate_fee_NORMAL", estimateFeeResponse)
|
||||
normalFee = strFee
|
||||
}
|
||||
|
||||
ServerApiHelper.ESTIMATE_FEE_MINIMAL -> {
|
||||
// Log.i("estimate_fee_MINIMAL", estimateFeeResponse)
|
||||
minFee = strFee
|
||||
minFeeInInternalUnits = card!!.internalUnitsFromString(strFee)
|
||||
}
|
||||
}
|
||||
|
||||
// doSetFee(rgFee!!.checkedRadioButtonId)
|
||||
etFee!!.error = null
|
||||
feeRequestSuccess = true
|
||||
if (feeRequestSuccess && balanceRequestSuccess)
|
||||
btnSend!!.visibility = View.VISIBLE
|
||||
dtVerified = Date()
|
||||
}
|
||||
|
||||
// request eth gasPrice listener
|
||||
|
|
@ -253,8 +273,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
ServerApiHelper.INFURA_ETH_GAS_PRICE -> {
|
||||
var gasPrice = infuraResponse.result
|
||||
gasPrice = gasPrice.substring(2)
|
||||
// Rounding gas price to integer gweis
|
||||
var l = BigInteger(gasPrice, 16).divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L))
|
||||
// Rounding gas price to integer gwei
|
||||
val l = BigInteger(gasPrice, 16).divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L))
|
||||
|
||||
val m = if (card!!.blockchain == Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
|
||||
val minFeeInGwei = card!!.getAmountInGwei(l.multiply(m).toString())
|
||||
|
|
@ -332,7 +352,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("IncFee", incFee)
|
||||
intent.putExtra("IncFee", isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
return
|
||||
}
|
||||
|
|
@ -346,7 +366,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
intent.putExtra("Wallet", etWallet!!.text.toString())
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_AMOUNT, etAmount!!.text.toString())
|
||||
intent.putExtra("Fee", etFee!!.text.toString())
|
||||
intent.putExtra("IncFee", incFee)
|
||||
intent.putExtra("IncFee", isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_SIGN_PAYMENT)
|
||||
} else
|
||||
Toast.makeText(baseContext, R.string.pin_2_is_required_to_sign_the_payment, Toast.LENGTH_LONG).show()
|
||||
|
|
|
|||
|
|
@ -91,16 +91,15 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
etAmount.setText(engine.getBalanceValue(card))
|
||||
}
|
||||
|
||||
// limit number of symbols after comma
|
||||
if (card!!.blockchain == Blockchain.Bitcoin)
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))
|
||||
|
||||
if (card!!.blockchain == Blockchain.BitcoinCash)
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))
|
||||
|
||||
if (card!!.blockchain == Blockchain.Ethereum)
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(18))
|
||||
|
||||
|
||||
// set listeners
|
||||
etAmount.setOnEditorActionListener { lv, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
val imm = lv.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
|
@ -111,8 +110,6 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
false
|
||||
}
|
||||
}
|
||||
|
||||
// set listeners
|
||||
btnVerify.setOnClickListener {
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
|
||||
|
|
@ -154,7 +151,6 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
intent.putExtra(SignPaymentActivity.EXTRA_AMOUNT, strAmount)
|
||||
startActivityForResult(intent, REQUEST_CODE_SEND_PAYMENT)
|
||||
}
|
||||
|
||||
ivCamera.setOnClickListener {
|
||||
val intent = Intent(baseContext, QrScanActivity::class.java)
|
||||
startActivityForResult(intent, REQUEST_CODE_SCAN_QR)
|
||||
|
|
@ -209,7 +205,6 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
// Log.w(javaClass.name, "Ignore discovered tag!")
|
||||
nfcManager!!.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
|
|
|
|||
|
|
@ -65,11 +65,14 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback
|
|||
val nodePort = engine.getNodePort(card)
|
||||
val connectTask = ConnectTask(this@SendTransactionActivity, nodeAddress, nodePort, 3)
|
||||
connectTask.execute(ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
} else if (card!!.blockchain == Blockchain.BitcoinCash || card!!.blockchain == Blockchain.BitcoinCashTestNet) {
|
||||
val nodeAddress = engine!!.getNode(card)
|
||||
val nodePort = engine.getNodePort(card)
|
||||
val connectTask = ConnectTask(this@SendTransactionActivity, nodeAddress, nodePort, 3)
|
||||
connectTask.execute(ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
|
||||
|
||||
}
|
||||
|
||||
// request eth sendRawTransaction
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
private var amountStr: String? = null
|
||||
private var feeStr: String? = null
|
||||
private var incfeeBool = true
|
||||
private var isIncludeFee = true
|
||||
private var outAddressStr: String? = null
|
||||
private var lastReadSuccess = true
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
amountStr = intent.getStringExtra(EXTRA_AMOUNT)
|
||||
feeStr = intent.getStringExtra("Fee")
|
||||
incfeeBool = intent.getBooleanExtra("IncFee", true)
|
||||
isIncludeFee = intent.getBooleanExtra("IncFee", true)
|
||||
outAddressStr = intent.getStringExtra("Wallet")
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
|
|
@ -69,33 +69,6 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
progressBar!!.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
// get IsoDep handle and run cardReader thread
|
||||
val isoDep = IsoDep.get(tag)
|
||||
?: throw CardProtocol.TangemException(getString(R.string.wrong_tag_err))
|
||||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
// Log.v(TAG, "UID: $sUID")
|
||||
|
||||
if (sUID == card!!.uid) {
|
||||
if (lastReadSuccess) {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 5000
|
||||
} else {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 65000
|
||||
}
|
||||
signPaymentTask = SignPaymentTask(this, card, nfcManager, isoDep, this, amountStr, feeStr,incfeeBool, outAddressStr)
|
||||
signPaymentTask!!.start()
|
||||
} else {
|
||||
// Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card!!.uid + ")")
|
||||
nfcManager!!.ignoreTag(isoDep.tag)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
public override fun onResume() {
|
||||
super.onResume()
|
||||
nfcManager!!.onResume()
|
||||
|
|
@ -137,6 +110,33 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
return super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
// get IsoDep handle and run cardReader thread
|
||||
val isoDep = IsoDep.get(tag)
|
||||
?: throw CardProtocol.TangemException(getString(R.string.wrong_tag_err))
|
||||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
// Log.v(TAG, "UID: $sUID")
|
||||
|
||||
if (sUID == card!!.uid) {
|
||||
if (lastReadSuccess) {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 5000
|
||||
} else {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 65000
|
||||
}
|
||||
signPaymentTask = SignPaymentTask(this, card, nfcManager, isoDep, this, amountStr, feeStr, isIncludeFee, outAddressStr)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import android.content.res.ColorStateList
|
|||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.nfc.tech.IsoDep
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.preference.PreferenceManager
|
||||
import android.support.v4.app.Fragment
|
||||
|
|
@ -25,7 +24,6 @@ import com.google.zxing.WriterException
|
|||
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.task.loaded_wallet.UpdateWalletInfoTask
|
||||
import com.tangem.data.nfc.VerifyCardTask
|
||||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
|
|
@ -834,7 +832,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
|
||||
if (srlLoadedWallet!!.isRefreshing) {
|
||||
tvBalanceLine1.setTextColor(getResources().getColor(R.color.primary))
|
||||
tvBalanceLine1.setTextColor(resources.getColor(R.color.primary))
|
||||
tvBalanceLine1.text = "Verifying in blockchain..."
|
||||
tvBalanceLine2.text = ""
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue