Updated on 2026-08-14

This commit is contained in:
Tangem 2018-09-07 10:51:35 +03:00
commit 5c6ea5ca04
18 changed files with 195 additions and 57 deletions

View file

@ -130,6 +130,11 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
val sharedFee = SharedData(SharedData.COUNT_REQUEST)
progressBar!!.visibility = View.VISIBLE
// 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,
@ -203,8 +208,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
return@setOnClickListener
}
if (!engineCoin.checkAmountValue(card, txAmount, txFee, minFeeInInternalUnits)) {
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.not_enough_eth_for_transaction_fee))
if (!engineCoin.checkAmountValue(card, txAmount, txFee, minFeeInInternalUnits, incFee)) {
finishActivityWithError(Activity.RESULT_CANCELED, getString(R.string.not_enough_funds_or_incorrect_amount))
return@setOnClickListener
}
@ -223,7 +228,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
gasPrice = gasPrice.substring(2)
var l = BigInteger(gasPrice, 16)
val m = if (card!!.blockchain == Blockchain.Token) BigInteger.valueOf(55000) else BigInteger.valueOf(21000)
val m = if (card!!.blockchain == Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
l = l.multiply(m)
val minFeeInGwei = card!!.getAmountInGwei(l.toString())
val normalFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10)).toString())
@ -242,6 +247,23 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
// Log.i("eth_gas_price", feeInGwei)
}
// request estimate fee listener
serverApiHelper!!.setEstimateFee { blockCount, estimateFeeResponse ->
when (blockCount) {
ServerApiHelper.ESTIMATE_FEE_PRIORITY -> {
// Log.i("estimate_fee_PRIORITY", estimateFeeResponse)
}
ServerApiHelper.ESTIMATE_FEE_NORMAL -> {
// Log.i("estimate_fee_NORMAL", estimateFeeResponse)
}
ServerApiHelper.ESTIMATE_FEE_MINIMAL -> {
// Log.i("estimate_fee_MINIMAL", estimateFeeResponse)
}
}
}
}
public override fun onResume() {

View file

@ -73,6 +73,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
private val inactiveColor: ColorStateList by lazy { resources.getColorStateList(R.color.primary) }
private val activeColor: ColorStateList by lazy { resources.getColorStateList(R.color.colorAccent) }
private val timerRepeatRefresh = Timer()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
nfcManager = NfcManager(activity, this)
@ -112,21 +114,23 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
btnExtract.backgroundTintList = inactiveColor
updateViews()
// updateViews()
if (!card!!.hasBalanceInfo()) {
srlLoadedWallet!!.isRefreshing = true
srlLoadedWallet!!.postDelayed({ this.refresh() }, 1000)
}
// if (!card!!.hasBalanceInfo()) {
// srlLoadedWallet!!.isRefreshing = true
// srlLoadedWallet!!.postDelayed({ refresh() }, 1000)
// }
// requestCardVerify()
// repeatRefresh()
refresh()
startVerify(lastTag)
tvWallet.text = card!!.wallet
// set listeners
srlLoadedWallet!!.setOnRefreshListener { this.refresh() }
srlLoadedWallet!!.setOnRefreshListener { refresh() }
btnLookup.setOnClickListener {
val engineClick = CoinEngineFactory.create(card!!.blockchain)
val browserIntent = Intent(Intent.ACTION_VIEW, engineClick.getShareWalletUriExplorer(card))
@ -201,7 +205,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
} else if (!engine.isBalanceNotZero(card))
showSingleToast(R.string.wallet_empty)
else if (!engine.isBalanceAlterNotZero(card))
showSingleToast(R.string.not_enough_funds)
showSingleToast(R.string.not_enough_funds_or_incorrect_amount)
else if (engine.awaitingConfirmation(card))
showSingleToast(R.string.please_wait_while_previous)
else if (!engine.checkUnspentTransaction(card))
@ -249,9 +253,27 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
nfcManager!!.onResume()
}
private fun repeatRefresh() {
val getBalance = object : TimerTask() {
override fun run() {
activity!!.runOnUiThread {
refresh()
// Log.i("efgrgegsdfgsd", "repeatRefresh")
}
}
}
timerRepeatRefresh.schedule(getBalance, 0, 5000)
}
override fun onPause() {
super.onPause()
nfcManager!!.onPause()
try {
timerRepeatRefresh.cancel()
} catch (e: IllegalStateException) {
e.printStackTrace()
}
}
override fun onStop() {
@ -397,10 +419,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
REQUEST_CODE_SEND_PAYMENT, REQUEST_CODE_RECEIVE_PAYMENT -> {
if (resultCode == Activity.RESULT_OK) {
srlLoadedWallet!!.postDelayed({ this.refresh() }, 10000)
srlLoadedWallet!!.isRefreshing = true
// srlLoadedWallet!!.postDelayed({ refresh() }, 10000)
// srlLoadedWallet!!.isRefreshing = true
card!!.clearInfo()
updateViews()
repeatRefresh()
// updateViews()
}
if (data != null && data.extras != null) {