Updated on 2026-08-14

This commit is contained in:
Tangem 2018-10-30 12:25:49 +03:00
parent f2fc3e9886
commit e122ccd0eb
20 changed files with 615 additions and 472 deletions

View file

@ -49,7 +49,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
private var maxFee: String? = null
private var normalFee: String? = null
private var isIncludeFee: Boolean = true
private var minFeeInInternalUnits: CoinEngine.InternalAmount? = CoinEngine.InternalAmount(0)
private var minFeeInInternalUnits: CoinEngine.InternalAmount? = CoinEngine.InternalAmount(0, "")
private var requestPIN2Count = 0
private var nodeCheck = false
private var dtVerified: Date? = null
@ -163,8 +163,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
return@setOnClickListener
}
val txFee = engineCoin.convertToAmount(etFee.text.toString())
val txAmount = engineCoin.convertToAmount(etAmount.text.toString())
val txFee = engineCoin.convertToAmount(etFee.text.toString(), tvCurrency2.text.toString())
val txAmount = engineCoin.convertToAmount(etAmount.text.toString(), tvCurrency.text.toString())
if (!engineCoin.hasBalanceInfo()) {
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_check_balance_no_connection_with_blockchain_nodes))
@ -200,7 +200,10 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
if (electrumRequest!!.isMethod(ElectrumRequest.METHOD_GetBalance)) {
try {
etFee.setText(getString(R.string.empty))
if ((electrumRequest.result.getInt("confirmed") + electrumRequest.result.getInt("unconfirmed")) / ctx.blockchain.multiplier * 1000000.0 < java.lang.Float.parseFloat(etAmount.text.toString())) {
val engine = CoinEngineFactory.create(ctx)
val balance= engine.convertToAmount(CoinEngine.InternalAmount(electrumRequest.result.getLong("confirmed") + electrumRequest.result.getLong("unconfirmed"), "Satoshi"))
val amount = CoinEngine.Amount(etAmount.text.toString(), ctx.blockchain.currency)
if (balance < amount) {
etFee.error = getString(R.string.not_enough_funds)
} else {
etFee.error = null
@ -232,6 +235,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
ServerApiHelper.INFURA_ETH_GAS_PRICE -> {
var gasPrice = infuraResponse.result
gasPrice = gasPrice.substring(2)
//TODO - remove Gwei
// rounding gas price to integer gwei
val l = BigInteger(gasPrice, 16).divide(BigInteger.valueOf(1000000000L)).multiply(BigInteger.valueOf(1000000000L))
@ -249,7 +253,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
feeRequestSuccess = true
balanceRequestSuccess = true
dtVerified = Date()
minFeeInInternalUnits = CoinEngine.InternalAmount(normalFeeInGwei)
minFeeInInternalUnits = CoinEngine.InternalAmount(normalFeeInGwei,"Gwei")
}
}
}
@ -292,7 +296,8 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
when (blockCount) {
ServerApiHelper.ESTIMATE_FEE_MINIMAL -> {
minFee = strFee
minFeeInInternalUnits = CoinEngine.InternalAmount(strFee)
//TODO - we must know currency of fee
minFeeInInternalUnits = CoinEngine.InternalAmount(strFee, tvCurrency2.text.toString())
}
ServerApiHelper.ESTIMATE_FEE_NORMAL -> {

View file

@ -60,7 +60,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
tvCurrency.text = Html.fromHtml(engine.balanceCurrencyHTML)
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toString())
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toEditString())
etAmount.filters=engine.amountInputFilters
// set listeners

View file

@ -60,7 +60,7 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
tvCurrency.text = Html.fromHtml(engine.balanceCurrencyHTML)
tvFeeCurrency.text = tvCurrency.text
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toString())
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toEditString())
etAmount.filters=engine.amountInputFilters
etAmount.setOnEditorActionListener { lv, actionId, event ->

View file

@ -66,7 +66,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
tvCurrency.text = Html.fromHtml(engine.balanceCurrencyHTML)
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toString())
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toEditString())
etAmount.filters=engine.amountInputFilters
etAmount.setOnEditorActionListener { lv, actionId, event ->

View file

@ -9,17 +9,13 @@ import android.nfc.Tag
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.Html
import android.text.InputFilter
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import com.tangem.domain.cardReader.NfcManager
import com.tangem.domain.wallet.Blockchain
import com.tangem.domain.wallet.CoinEngineFactory
import com.tangem.domain.wallet.TangemCard
import com.tangem.domain.wallet.TangemContext
import com.tangem.util.DecimalDigitsInputFilter
import com.tangem.util.FormatUtil
import com.tangem.wallet.R
import kotlinx.android.synthetic.main.activity_prepare_payment.*
import java.io.IOException
@ -64,7 +60,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
etAmount.isEnabled = false
tvCurrency.text = engine.balance.currency
etAmount.setText(engine.balance.stringToEdit)
etAmount.setText(engine.balance.toEditString())
// limit number of symbols after comma
etAmount.filters = engine.amountInputFilters
@ -85,7 +81,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
val engine1 = CoinEngineFactory.create(ctx.card!!.blockchain)
val strAmount: String = etAmount.text.toString().replace(",", ".")
val amount=engine1.convertToAmount(etAmount.text.toString())
val amount=engine1.convertToAmount(etAmount.text.toString(), tvCurrency.text.toString())
try {
if (!engine.checkNewTransactionAmount(amount))

View file

@ -203,6 +203,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
btnExtract.setOnClickListener {
val engine=CoinEngineFactory.create(ctx)
if (UtilHelper.isOnline(activity)) {
// TODO - move checks to engine
if (!engine!!.hasBalanceInfo()) {
showSingleToast(R.string.cannot_obtain_data_from_blockchain)
} else if (!engine!!.isBalanceNotZero)
@ -237,7 +238,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
ctx.coinData!!.isBalanceReceived = true
(ctx.coinData!! as BtcData).setBalanceConfirmed(confBalance)
(ctx.coinData!! as BtcData).balanceUnconfirmed = unconfirmedBalance
(ctx.coinData!! as BtcData).decimalBalance = confBalance.toString()
(ctx.coinData!! as BtcData).validationNodeDescription = serverApiHelperElectrum.validationNodeDescription
} catch (e: JSONException) {
e.printStackTrace()
@ -312,15 +312,19 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
var balanceCap = infuraResponse.result
balanceCap = balanceCap.substring(2)
val l = BigInteger(balanceCap, 16)
val d = l.divide(BigInteger("1000000000000000000", 10))
val balance = d.toLong()
// val d = l.divide(BigInteger("1000000000000000000", 10))
// val balance = d.toLong()
ctx.coinData!!.setBalanceConfirmed(balance)
ctx.coinData!!.balanceUnconfirmed = 0L
ctx.coinData!!.isBalanceReceived = true
if (ctx.coinData!!.blockchain != Blockchain.Token)
ctx.coinData!!.decimalBalance = l.toString(10)
ctx.coinData!!.decimalBalanceAlter = l.toString(10)
// (ctx.coinData!! as EthData).setBalanceConfirmed(balance)
// (ctx.coinData!! as EthData).balanceUnconfirmed = 0L
if (ctx.blockchain != Blockchain.Token) {
(ctx.coinData!! as EthData).isBalanceReceived = true
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),"wei")
}else{
(ctx.coinData!! as TokenData).isBalanceReceived = true
(ctx.coinData!! as TokenData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
(ctx.coinData!! as TokenData).balanceAlterInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(), "wei")
}
// Log.i("$TAG eth_get_balance", balanceCap)
}
@ -329,7 +333,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
var nonce = infuraResponse.result
nonce = nonce.substring(2)
val count = BigInteger(nonce, 16)
ctx.coinData!!.confirmedTXCount = count
(ctx.coinData!! as EthData).confirmedTXCount = count
// Log.i("$TAG eth_getTransCount", nonce)
}
@ -338,7 +343,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
var pending = infuraResponse.result
pending = pending.substring(2)
val count = BigInteger(pending, 16)
ctx.coinData!!.unconfirmedTXCount = count
(ctx.coinData!! as EthData).unconfirmedTXCount = count
// Log.i("$TAG eth_getPendingTxCount", pending)
}
@ -353,7 +358,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
ctx.card!!.blockchainID = Blockchain.Ethereum.id
ctx.card!!.addTokenToBlockchainName()
ctx.blockchain=Blockchain.Ethereum
//TODO check
//ctx.blockchain=Blockchain.Ethereum
requestCounter--
if (requestCounter == 0) srl!!.isRefreshing = false
@ -363,9 +369,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
requestInfura(ServerApiHelper.INFURA_ETH_GET_PENDING_COUNT, "")
return
}
ctx.coinData!!.setBalanceConfirmed(balance)
ctx.coinData!!.balanceUnconfirmed = 0L
ctx.coinData!!.decimalBalance = l.toString(10)
(ctx.coinData!! as EthData).balanceInInternalUnits = CoinEngine.InternalAmount(l.toBigDecimal(),ctx.card.tokenSymbol)
// Log.i("$TAG eth_call", balanceCap)
@ -397,9 +401,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
Log.e("$TAG TX_RESULT", hashTX)
val nonce = ctx.coinData!!.confirmedTXCount
val nonce = (ctx.coinData!! as EthData).confirmedTXCount
nonce.add(BigInteger.valueOf(1))
ctx.coinData!!.confirmedTXCount = nonce
(ctx.coinData!! as EthData).confirmedTXCount = nonce
Log.e("$TAG TX_RESULT", hashTX)
@ -649,7 +653,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
REQUEST_CODE_SEND_PAYMENT, REQUEST_CODE_RECEIVE_PAYMENT -> {
if (resultCode == Activity.RESULT_OK) {
ctx.coinData!!.clearInfo()
ctx.card.clearInfo();
srl!!.postDelayed({ this.refresh() }, 5000)
srl!!.isRefreshing = true
updateViews()
@ -779,7 +782,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
tvBalanceEquivalent.text = ""
} else {
val validator = BalanceValidator()
validator.Check(ctx.card, false)
validator.Check(ctx, false)
tvBalanceLine1.setTextColor(ContextCompat.getColor(activity, validator.color))
tvBalanceLine1.text = validator.firstLine
tvBalanceLine2.text = validator.getSecondLine(false)
@ -828,8 +831,6 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
// clear all card data and request again
srl!!.isRefreshing = true
ctx.coinData.clearInfo();
ctx.card!!.clearInfo()
//engine=engine!!.swithToBaseEngine()
ctx.error = null
ctx.message = null
requestCounter = 0
@ -917,8 +918,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
private fun openVerifyCard(cardProtocol: CardProtocol) {
val intent = Intent(activity, VerifyCardActivity::class.java)
intent.putExtra(TangemCard.EXTRA_UID, cardProtocol.card.uid)
intent.putExtra(TangemCard.EXTRA_CARD, cardProtocol.card.asBundle)
ctx.saveToBundle(intent.extras)
startActivityForResult(intent, REQUEST_CODE_VERIFY_CARD)
}