Updated on 2026-08-14
This commit is contained in:
parent
61ef397705
commit
bae8bd0e6c
30 changed files with 1686 additions and 1276 deletions
|
|
@ -40,14 +40,16 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
private var serverApiHelper: ServerApiHelper = ServerApiHelper()
|
||||
private var serverApiHelperElectrum: ServerApiHelperElectrum = ServerApiHelperElectrum()
|
||||
|
||||
private var card: TangemCard? = null
|
||||
//private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private var feeRequestSuccess = false
|
||||
private var balanceRequestSuccess = false
|
||||
private var minFee: String? = null
|
||||
private var maxFee: String? = null
|
||||
private var normalFee: String? = null
|
||||
private var isIncludeFee: Boolean = true
|
||||
private var minFeeInInternalUnits: Long? = 0L
|
||||
private var minFeeInInternalUnits: CoinEngine.InternalAmount? = CoinEngine.InternalAmount(0)
|
||||
private var requestPIN2Count = 0
|
||||
private var nodeCheck = false
|
||||
private var dtVerified: Date? = null
|
||||
|
|
@ -61,18 +63,14 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra("UID"))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle("Card"))
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
// card = TangemCard(intent.getStringExtra("UID"))
|
||||
// card!!.loadFromBundle(intent.extras!!.getBundle("Card"))
|
||||
//
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
|
||||
val balanceWithAlter = engine!!.getBalanceWithAlter(card).replace(",", ".")
|
||||
|
||||
if (card!!.blockchain == Blockchain.Token) {
|
||||
val html = Html.fromHtml(balanceWithAlter)
|
||||
val html = Html.fromHtml(engine!!.balanceHTML)
|
||||
tvBalance.text = html
|
||||
} else
|
||||
tvBalance.text = balanceWithAlter
|
||||
|
||||
isIncludeFee = intent.getBooleanExtra("IncFee", true)
|
||||
|
||||
|
|
@ -80,14 +78,14 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
tvIncFee.setText(R.string.including_fee)
|
||||
else
|
||||
tvIncFee.setText(R.string.not_including_fee)
|
||||
if (card!!.blockchain == Blockchain.Token)
|
||||
if (ctx.blockchain == Blockchain.Token)
|
||||
tvIncFee.visibility = View.INVISIBLE
|
||||
else
|
||||
tvIncFee.visibility = View.VISIBLE
|
||||
etAmount.setText(intent.getStringExtra(SignPaymentActivity.EXTRA_AMOUNT))
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
tvCurrency2.text = engine.feeCurrency
|
||||
tvCardID.text = card!!.cidDescription
|
||||
tvCurrency.text = Html.fromHtml(engine.balanceCurrencyHTML)
|
||||
tvCurrency2.text = Html.fromHtml(engine.feeCurrencyHTML)
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
etWallet.setText(intent.getStringExtra("Wallet"))
|
||||
etFee.setText("")
|
||||
|
||||
|
|
@ -95,7 +93,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
feeRequestSuccess = false
|
||||
balanceRequestSuccess = false
|
||||
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token) {
|
||||
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token) {
|
||||
rgFee.isEnabled = false
|
||||
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_GAS_PRICE)
|
||||
|
|
@ -103,7 +101,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
} else {
|
||||
rgFee.isEnabled = true
|
||||
|
||||
requestElectrum(card!!, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
requestElectrum(ctx.card, ElectrumRequest.checkBalance(ctx.card!!.wallet))
|
||||
|
||||
calcSize = 256
|
||||
try {
|
||||
|
|
@ -112,7 +110,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
Log.e("Build Fee error", ex.message)
|
||||
}
|
||||
|
||||
card!!.resetFailedBalanceRequestCounter()
|
||||
ctx.coinData!!.resetFailedBalanceRequestCounter()
|
||||
|
||||
progressBar.visibility = View.VISIBLE
|
||||
|
||||
|
|
@ -128,11 +126,11 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
try {
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
val eqFee = engine!!.evaluateFeeEquivalent(card, etFee!!.text.toString())
|
||||
val engine = CoinEngineFactory.create(ctx.blockchain)
|
||||
val eqFee = engine!!.evaluateFeeEquivalent(etFee!!.text.toString())
|
||||
tvFeeEquivalent.text = eqFee
|
||||
|
||||
if (!card!!.amountEquivalentDescriptionAvailable) {
|
||||
if (!ctx.coinData!!.amountEquivalentDescriptionAvailable) {
|
||||
tvFeeEquivalent.error = "Service unavailable"
|
||||
tvCurrency2.visibility = View.GONE
|
||||
tvFeeEquivalent.visibility = View.GONE
|
||||
|
|
@ -158,30 +156,30 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
return@setOnClickListener
|
||||
}
|
||||
|
||||
val engineCoin = CoinEngineFactory.create(card!!.blockchain)
|
||||
val engineCoin = CoinEngineFactory.create(ctx)
|
||||
|
||||
if (engineCoin!!.isNeedCheckNode && !nodeCheck) {
|
||||
Toast.makeText(baseContext, getString(R.string.cannot_reach_current_active_blockchain_node_try_again), Toast.LENGTH_LONG).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
val txFee = etFee.text.toString()
|
||||
val txAmount = etAmount.text.toString()
|
||||
val txFee = engineCoin.convertToAmount(etFee.text.toString())
|
||||
val txAmount = engineCoin.convertToAmount(etAmount.text.toString())
|
||||
|
||||
if (!engineCoin.hasBalanceInfo(card)) {
|
||||
if (!engineCoin.hasBalanceInfo()) {
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_check_balance_no_connection_with_blockchain_nodes))
|
||||
return@setOnClickListener
|
||||
|
||||
} else if (!engineCoin.isBalanceNotZero(card)) {
|
||||
} else if (!engineCoin.isBalanceNotZero) {
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.the_wallet_is_empty))
|
||||
return@setOnClickListener
|
||||
|
||||
} else if (!engineCoin.checkUnspentTransaction(card)) {
|
||||
} else if (!engineCoin.checkUnspentTransaction()) {
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.please_wait_for_confirmation_of_incoming_transaction))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (!engineCoin.checkAmountValue(card, txAmount, txFee, minFeeInInternalUnits, isIncludeFee)) {
|
||||
if (!engineCoin.checkNewTransactionAmountAndFee(txAmount, txFee, isIncludeFee, minFeeInInternalUnits)) {
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.not_enough_funds_on_your_card))
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
|
@ -189,8 +187,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
requestPIN2Count = 0
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra(TangemCard.EXTRA_UID, card!!.uid)
|
||||
intent.putExtra(TangemCard.EXTRA_CARD, card!!.asBundle)
|
||||
ctx.saveToBundle(intent.extras)
|
||||
// intent.putExtra(TangemCard.EXTRA_UID, card!!.uid)
|
||||
// intent.putExtra(TangemCard.EXTRA_CARD, card!!.asBundle)
|
||||
intent.putExtra("IncFee", isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
}
|
||||
|
|
@ -201,7 +200,7 @@ 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")) / card!!.blockchain.multiplier * 1000000.0 < java.lang.Float.parseFloat(etAmount.text.toString())) {
|
||||
if ((electrumRequest.result.getInt("confirmed") + electrumRequest.result.getInt("unconfirmed")) / ctx.blockchain.multiplier * 1000000.0 < java.lang.Float.parseFloat(etAmount.text.toString())) {
|
||||
etFee.error = getString(R.string.not_enough_funds)
|
||||
} else {
|
||||
etFee.error = null
|
||||
|
|
@ -214,7 +213,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
requestElectrum(card!!, ElectrumRequest.checkBalance(card!!.wallet))
|
||||
requestElectrum(ctx.card!!, ElectrumRequest.checkBalance(ctx.card!!.wallet))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -236,10 +235,10 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
// 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())
|
||||
val normalFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10)).multiply(m).toString())
|
||||
val maxFeeInGwei = card!!.getAmountInGwei(l.multiply(BigInteger.valueOf(15)).divide(BigInteger.valueOf(10)).multiply(m).toString())
|
||||
val m = if (ctx.blockchain == Blockchain.Token) BigInteger.valueOf(60000) else BigInteger.valueOf(21000)
|
||||
val minFeeInGwei = (ctx.coinData!! as EthData).getAmountInGwei(l.multiply(m).toString())
|
||||
val normalFeeInGwei = (ctx.coinData!! as EthData).getAmountInGwei(l.multiply(BigInteger.valueOf(12)).divide(BigInteger.valueOf(10)).multiply(m).toString())
|
||||
val maxFeeInGwei = (ctx.coinData!! as EthData).getAmountInGwei(l.multiply(BigInteger.valueOf(15)).divide(BigInteger.valueOf(10)).multiply(m).toString())
|
||||
|
||||
minFee = minFeeInGwei
|
||||
normalFee = normalFeeInGwei
|
||||
|
|
@ -250,7 +249,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
feeRequestSuccess = true
|
||||
balanceRequestSuccess = true
|
||||
dtVerified = Date()
|
||||
minFeeInInternalUnits = card!!.internalUnitsFromString(normalFeeInGwei)
|
||||
minFeeInInternalUnits = CoinEngine.InternalAmount(normalFeeInGwei)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -293,7 +292,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
when (blockCount) {
|
||||
ServerApiHelper.ESTIMATE_FEE_MINIMAL -> {
|
||||
minFee = strFee
|
||||
minFeeInInternalUnits = card!!.internalUnitsFromString(strFee)
|
||||
minFeeInInternalUnits = CoinEngine.InternalAmount(strFee)
|
||||
}
|
||||
|
||||
ServerApiHelper.ESTIMATE_FEE_NORMAL -> {
|
||||
|
|
@ -343,15 +342,16 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
if (data.extras!!.containsKey("UID") && data.extras!!.containsKey("Card")) {
|
||||
val updatedCard = TangemCard(data.getStringExtra("UID"))
|
||||
updatedCard.loadFromBundle(data.getBundleExtra("Card"))
|
||||
card = updatedCard
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
}
|
||||
if (resultCode == SignPaymentActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
ctx.saveToBundle(intent.extras)
|
||||
// intent.putExtra("UID", card!!.uid)
|
||||
// intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("IncFee", isIncludeFee)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
return
|
||||
|
|
@ -361,8 +361,9 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
} else if (requestCode == REQUEST_CODE_REQUEST_PIN2) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
val intent = Intent(baseContext, SignPaymentActivity::class.java)
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
ctx.saveToBundle(intent.extras)
|
||||
// intent.putExtra("UID", card!!.uid)
|
||||
// intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("Wallet", etWallet!!.text.toString())
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_AMOUNT, etAmount.text.toString())
|
||||
intent.putExtra("Fee", etFee.text.toString())
|
||||
|
|
@ -393,14 +394,15 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO - move to BtcEngine
|
||||
@Throws(Exception::class)
|
||||
internal fun buildSize(outputAddress: String, outFee: String, outAmount: String): Int {
|
||||
val myAddress = card!!.wallet
|
||||
val pbKey = card!!.walletPublicKey
|
||||
val pbComprKey = card!!.walletPublicKeyRar
|
||||
val myAddress = ctx.card!!.wallet
|
||||
val pbKey = ctx.card!!.walletPublicKey
|
||||
val pbComprKey = ctx.card!!.walletPublicKeyRar
|
||||
|
||||
// build script for our address
|
||||
val rawTxList = card!!.unspentTransactions
|
||||
val rawTxList = (ctx.coinData!! as BtcData).unspentTransactions
|
||||
val outputScriptWeAreAbleToSpend = Transaction.Script.buildOutput(myAddress).bytes
|
||||
|
||||
// collect unspent
|
||||
|
|
@ -466,7 +468,7 @@ class ConfirmPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
private fun requestInfura(method: String) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiHelper.infura(method, 67, card!!.wallet, "", "")
|
||||
serverApiHelper.infura(method, 67, ctx.card!!.wallet, "", "")
|
||||
} else
|
||||
finishWithError(Activity.RESULT_CANCELED, getString(R.string.cannot_obtain_data_from_blockchain))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.tangem.data.nfc.CreateNewWalletTask
|
|||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.domain.wallet.TangemContext
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.util.Util
|
||||
|
|
@ -30,7 +31,7 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
|
||||
}
|
||||
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var nfcManager: NfcManager? = null
|
||||
|
||||
private var createNewWalletTask: CreateNewWalletTask? = null
|
||||
|
|
@ -46,10 +47,9 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
tvCardId.text = card!!.cidDescription
|
||||
tvCardId.text = ctx.card!!.cidDescription
|
||||
|
||||
progressBar = findViewById(R.id.progressBar)
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
|
|
@ -65,13 +65,13 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
val sUID = Util.byteArrayToHexString(uid)
|
||||
// Log.v(TAG, "UID: " + sUID);
|
||||
|
||||
if (sUID == card!!.uid) {
|
||||
if (sUID == ctx.card!!.uid) {
|
||||
if (lastReadSuccess) {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 5000
|
||||
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 5000
|
||||
} else {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 65000
|
||||
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 65000
|
||||
}
|
||||
createNewWalletTask = CreateNewWalletTask(this, card, nfcManager, isoDep, this)
|
||||
createNewWalletTask = CreateNewWalletTask(this, ctx.card, nfcManager, isoDep, this)
|
||||
createNewWalletTask!!.start()
|
||||
} else {
|
||||
// Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + mCard.getUID() + ")");
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.tangem.data.nfc.VerifyCardTask
|
|||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.domain.wallet.TangemContext
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.util.Util
|
||||
|
|
@ -33,7 +34,7 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
}
|
||||
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var lastReadSuccess = true
|
||||
private var verifyCardTask: VerifyCardTask? = null
|
||||
private var requestPIN2Count = 0
|
||||
|
|
@ -46,21 +47,20 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
tvIssuer.text = card!!.issuerDescription
|
||||
//tvBlockchain.text = card!!.blockchainName
|
||||
if (card!!.tokenSymbol.length > 1) {
|
||||
val html = Html.fromHtml(card!!.blockchainName)
|
||||
tvIssuer.text = ctx.card!!.issuerDescription
|
||||
//tvBlockchain.text = ctx.card!!.blockchainName
|
||||
if (ctx.card!!.tokenSymbol.length > 1) {
|
||||
val html = Html.fromHtml(ctx.card!!.blockchainName)
|
||||
tvBlockchain.text = html
|
||||
} else
|
||||
tvBlockchain.text = card!!.blockchainName
|
||||
tvBlockchain.text = ctx.card!!.blockchainName
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
imgBlockchain.setImageResource(card!!.blockchain.getImageResource(this, card!!.tokenSymbol))
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
imgBlockchain.setImageResource(ctx.card!!.blockchain.getImageResource(this, ctx.card!!.tokenSymbol))
|
||||
|
||||
if (card!!.useDefaultPIN1()!!) {
|
||||
if (ctx.card!!.useDefaultPIN1()!!) {
|
||||
imgPIN.setImageResource(R.drawable.unlock_pin1)
|
||||
imgPIN.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_default_PIN1_code, Toast.LENGTH_LONG).show() }
|
||||
} else {
|
||||
|
|
@ -68,11 +68,11 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
imgPIN.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_user_PIN1_code, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
|
||||
if (card!!.pauseBeforePIN2 > 0 && (card!!.useDefaultPIN2()!! || !card!!.useSmartSecurityDelay())) {
|
||||
if (ctx.card!!.pauseBeforePIN2 > 0 && (ctx.card!!.useDefaultPIN2()!! || !ctx.card!!.useSmartSecurityDelay())) {
|
||||
imgPIN2orSecurityDelay.setImageResource(R.drawable.timer)
|
||||
imgPIN2orSecurityDelay.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, String.format(getString(R.string.this_banknote_will_enforce), card!!.pauseBeforePIN2 / 1000.0), Toast.LENGTH_LONG).show() }
|
||||
imgPIN2orSecurityDelay.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, String.format(getString(R.string.this_banknote_will_enforce), ctx.card!!.pauseBeforePIN2 / 1000.0), Toast.LENGTH_LONG).show() }
|
||||
|
||||
} else if (card!!.useDefaultPIN2()!!) {
|
||||
} else if (ctx.card!!.useDefaultPIN2()!!) {
|
||||
imgPIN2orSecurityDelay.setImageResource(R.drawable.unlock_pin2)
|
||||
imgPIN2orSecurityDelay.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_default_PIN2_code, Toast.LENGTH_LONG).show() }
|
||||
} else {
|
||||
|
|
@ -80,7 +80,7 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
imgPIN2orSecurityDelay.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_user_PIN2_code, Toast.LENGTH_LONG).show() }
|
||||
}
|
||||
|
||||
if (card!!.useDevelopersFirmware()!!) {
|
||||
if (ctx.card!!.useDevelopersFirmware()!!) {
|
||||
imgDeveloperVersion.setImageResource(R.drawable.ic_developer_version)
|
||||
imgDeveloperVersion.visibility = View.VISIBLE
|
||||
imgDeveloperVersion.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.unlocked_banknote_only_development_use, Toast.LENGTH_LONG).show() }
|
||||
|
|
@ -92,8 +92,8 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
requestPIN2Count = 0
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("UID", ctx.card!!.uid)
|
||||
intent.putExtra("Card", ctx.card!!.asBundle)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
}
|
||||
}
|
||||
|
|
@ -127,14 +127,14 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
if (data != null && data.extras!!.containsKey("UID") && data.extras!!.containsKey("Card")) {
|
||||
val updatedCard = TangemCard(data.getStringExtra("UID"))
|
||||
updatedCard.loadFromBundle(data.getBundleExtra("Card"))
|
||||
card = updatedCard
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("UID", ctx.card!!.uid)
|
||||
intent.putExtra("Card", ctx.card!!.asBundle)
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
|
||||
return
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
?: throw CardProtocol.TangemException(getString(R.string.wrong_tag_err))
|
||||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
if (card!!.uid != sUID) {
|
||||
if (ctx.card!!.uid != sUID) {
|
||||
// Log.d(TAG, "Invalid UID: " + sUID);
|
||||
nfcManager!!.ignoreTag(isoDep.tag)
|
||||
return
|
||||
|
|
@ -168,7 +168,7 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
isoDep.timeout = 65000
|
||||
}
|
||||
//lastTag = tag;
|
||||
verifyCardTask = VerifyCardTask(this, card, nfcManager, isoDep, this)
|
||||
verifyCardTask = VerifyCardTask(this, ctx.card, nfcManager, isoDep, this)
|
||||
verifyCardTask!!.start()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
|
@ -254,8 +254,8 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
private fun doCreateNewWallet() {
|
||||
val intent = Intent(this, CreateNewWalletActivity::class.java)
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
intent.putExtra("UID", ctx.card!!.uid)
|
||||
intent.putExtra("Card", ctx.card!!.asBundle)
|
||||
startActivityForResult(intent, REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -306,6 +306,7 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
rlProgressBar.post {
|
||||
rlProgressBar.visibility = View.GONE
|
||||
|
||||
// TODO - ??? remove save and load???
|
||||
val cardInfo = Bundle()
|
||||
cardInfo.putString("UID", cardProtocol.card.uid)
|
||||
val bCard = Bundle()
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.nfc.NfcAdapter
|
|||
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 com.tangem.data.network.Cryptonit_OtherAPI
|
||||
|
|
@ -15,6 +16,7 @@ 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.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_prepare_cryptonit_other_api_withdrawal.*
|
||||
|
|
@ -30,7 +32,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
private const val REQUEST_CODE_SCAN_QR_USER_ID = 3
|
||||
}
|
||||
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var cryptonit: Cryptonit_OtherAPI? = null
|
||||
|
||||
|
|
@ -44,8 +46,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
cryptonit = Cryptonit_OtherAPI(this)
|
||||
|
||||
|
|
@ -53,33 +54,14 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
tvUserID.text = cryptonit!!.userId
|
||||
tvSecret.text = cryptonit!!.secretDescription
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
tvWallet.text = card!!.wallet
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.card!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
when (card!!.blockchain) {
|
||||
Blockchain.Ethereum, Blockchain.EthereumTestNet -> {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
}
|
||||
Blockchain.Bitcoin, Blockchain.BitcoinTestNet, Blockchain.BitcoinCash, Blockchain.BitcoinCashTestNet -> {
|
||||
tvCurrency.text = card!!.blockchain.currency
|
||||
}
|
||||
else -> {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
}
|
||||
}
|
||||
tvCurrency.text = Html.fromHtml(engine.balanceCurrencyHTML)
|
||||
|
||||
etAmount.setText(engine.convertByteArrayToAmount(card!!, card!!.denomination))
|
||||
when (card!!.blockchain) {
|
||||
Blockchain.Bitcoin ->
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(5))
|
||||
Blockchain.BitcoinCash ->
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))
|
||||
Blockchain.Ethereum ->
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(18))
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toString())
|
||||
etAmount.filters=engine.amountInputFilters
|
||||
|
||||
// set listeners
|
||||
btnLoad.setOnClickListener {
|
||||
|
|
@ -93,7 +75,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_withdrawal)
|
||||
|
||||
cryptonit!!.requestCryptoWithdrawal(card!!.blockchain.currency, dblAmount.toString(), card!!.wallet)
|
||||
cryptonit!!.requestCryptoWithdrawal(ctx.blockchain.currency, dblAmount.toString(), ctx.card!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
|
|
@ -122,7 +104,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
ivRefreshBalance.setOnClickListener { doRequestBalance() }
|
||||
|
||||
cryptonit!!.setBalanceListener { response ->
|
||||
when (card!!.blockchain) {
|
||||
when (ctx.blockchain) {
|
||||
Blockchain.Ethereum, Blockchain.EthereumTestNet -> {
|
||||
tvBalance.text = response.eth_available
|
||||
}
|
||||
|
|
@ -133,7 +115,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
}
|
||||
}
|
||||
|
||||
tvBalanceCurrency.text = card!!.blockchain.currency
|
||||
tvBalanceCurrency.text = ctx.blockchain.currency
|
||||
tvBalance.setTextColor(Color.BLACK)
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
btnLoad.isActivated = true
|
||||
|
|
@ -161,7 +143,7 @@ class PrepareCryptonitOtherAPIWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_balance)
|
||||
tvError.visibility = View.INVISIBLE
|
||||
cryptonit!!.requestBalance(card!!.blockchain.currency, "USD")
|
||||
cryptonit!!.requestBalance(ctx.blockchain.currency, "USD")
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = getString(R.string.cryptonit_not_enough_account_data)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.nfc.NfcAdapter
|
|||
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
|
||||
|
|
@ -17,6 +18,7 @@ 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.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_prepare_cryptonit_withdrawal.*
|
||||
|
|
@ -29,7 +31,7 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
val TAG: String = PrepareCryptonitWithdrawalActivity::class.java.simpleName
|
||||
}
|
||||
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var cryptonit: Cryptonit? = null
|
||||
|
||||
|
|
@ -43,8 +45,7 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
cryptonit = Cryptonit(this)
|
||||
|
||||
|
|
@ -52,24 +53,16 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
etPassword.setText(cryptonit!!.password)
|
||||
etFee.setText(cryptonit!!.fee)
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
tvWallet.text = card!!.wallet
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.card!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
when (card!!.blockchain) {
|
||||
Blockchain.Ethereum -> {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
}
|
||||
Blockchain.Bitcoin, Blockchain.BitcoinCash -> {
|
||||
tvCurrency.text = card!!.blockchain.currency
|
||||
}
|
||||
else -> {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
}
|
||||
}
|
||||
tvCurrency.text = Html.fromHtml(engine.balanceCurrencyHTML)
|
||||
tvFeeCurrency.text = tvCurrency.text
|
||||
|
||||
etAmount.setText(engine.convertByteArrayToAmount(card!!, card!!.denomination))
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toString())
|
||||
etAmount.filters=engine.amountInputFilters
|
||||
|
||||
etAmount.setOnEditorActionListener { lv, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
val imm = lv.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
|
@ -79,7 +72,7 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
false
|
||||
}
|
||||
}
|
||||
when (card!!.blockchain) {
|
||||
when (ctx.blockchain) {
|
||||
Blockchain.Bitcoin -> {
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(5))
|
||||
etFee.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(5))
|
||||
|
|
@ -109,7 +102,7 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_withdrawal)
|
||||
|
||||
cryptonit!!.requestWithdrawCoins(card!!.blockchain.currency, dblAmount, card!!.wallet)
|
||||
cryptonit!!.requestWithdrawCoins(ctx.blockchain.currency, dblAmount, ctx.card!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
|
|
@ -154,7 +147,7 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_balance)
|
||||
tvError.visibility = View.INVISIBLE
|
||||
cryptonit!!.requestBalance(card!!.blockchain.currency)
|
||||
cryptonit!!.requestBalance(ctx.card!!.blockchain.currency)
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = getString(R.string.cryptonit_not_enough_account_data)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import android.nfc.NfcAdapter
|
|||
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
|
||||
|
|
@ -21,6 +22,7 @@ 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.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_prepare_kraken_withdrawal.*
|
||||
|
|
@ -37,7 +39,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
private const val REQUEST_CODE_SCAN_QR = 1
|
||||
}
|
||||
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var kraken: Kraken? = null
|
||||
private var fee: BigDecimal? = null
|
||||
|
|
@ -51,42 +53,21 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
kraken = Kraken(this)
|
||||
|
||||
tvKey.text = kraken!!.key
|
||||
tvSecret.text = kraken!!.secretDescription
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
tvWallet.text = card!!.wallet
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.card!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
when (card!!.blockchain) {
|
||||
Blockchain.Ethereum, Blockchain.EthereumTestNet -> {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
tvCurrency.text = Html.fromHtml(engine.balanceCurrencyHTML)
|
||||
|
||||
}
|
||||
Blockchain.Bitcoin, Blockchain.BitcoinTestNet, Blockchain.BitcoinCash, Blockchain.BitcoinCashTestNet -> {
|
||||
tvCurrency.text = card!!.blockchain.currency
|
||||
}
|
||||
else -> {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
}
|
||||
}
|
||||
|
||||
etAmount.setText(engine.convertByteArrayToAmount(card!!, card!!.denomination))
|
||||
when (card!!.blockchain) {
|
||||
Blockchain.Bitcoin ->
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(5))
|
||||
Blockchain.BitcoinCash ->
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))
|
||||
Blockchain.Ethereum ->
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(18))
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toString())
|
||||
etAmount.filters=engine.amountInputFilters
|
||||
|
||||
etAmount.setOnEditorActionListener { lv, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
|
|
@ -108,7 +89,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.kraken_request_withdrawal)
|
||||
|
||||
kraken!!.requestWithdrawInfo(card!!.blockchain.currency, dblAmount.toString(), card!!.wallet)
|
||||
kraken!!.requestWithdrawInfo(ctx.blockchain.currency, dblAmount.toString(), ctx.card!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
|
|
@ -126,7 +107,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = Arrays.toString(response.error)
|
||||
} else {
|
||||
when (card!!.blockchain) {
|
||||
when (ctx.blockchain) {
|
||||
Blockchain.Ethereum -> {
|
||||
tvBalance.text = response.result.XETH.trimEnd('0')
|
||||
}
|
||||
|
|
@ -140,7 +121,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
tvBalance.text = "???"
|
||||
}
|
||||
}
|
||||
tvBalanceCurrency.text = card!!.blockchain.currency
|
||||
tvBalanceCurrency.text = ctx.blockchain.currency
|
||||
tvBalance.setTextColor(Color.BLACK)
|
||||
btnLoad.visibility = View.VISIBLE
|
||||
}
|
||||
|
|
@ -190,7 +171,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
builder.setTitle("Please confirm withdraw")
|
||||
|
||||
// Set a message for alert dialog
|
||||
builder.setMessage(String.format("Continue with fee %s %s?", fee!!.toString().trimEnd('0'), card!!.blockchain.currency))
|
||||
builder.setMessage(String.format("Continue with fee %s %s?", fee!!.toString().trimEnd('0'), ctx.blockchain.currency))
|
||||
|
||||
// On click listener for dialog buttons
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
|
|
@ -207,7 +188,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
tvProgressDescription.text = getString(R.string.kraken_request_withdrawal)
|
||||
|
||||
//Toast.makeText(this, String.format("Withdraw %s!",dblAmount.toString()), Toast.LENGTH_LONG).show()
|
||||
kraken!!.requestWithdraw(card!!.blockchain.currency, dblAmount.toString(), card!!.wallet)
|
||||
kraken!!.requestWithdraw(ctx.blockchain.currency, dblAmount.toString(), ctx.card!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ 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
|
||||
|
|
@ -32,8 +33,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
private const val REQUEST_CODE_SEND_PAYMENT = 2
|
||||
}
|
||||
|
||||
private var useCurrency: Boolean = false
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var nfcManager: NfcManager? = null
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
|
@ -45,59 +45,29 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx= TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
if (card!!.blockchain == Blockchain.Token) {
|
||||
val html = Html.fromHtml(engine!!.getBalanceWithAlter(card))
|
||||
tvBalance.text = html
|
||||
val html = Html.fromHtml(engine!!.balanceHTML)
|
||||
tvBalance.text = html
|
||||
|
||||
//TODO - to engine
|
||||
if (ctx.card!!.blockchain == Blockchain.Token) {
|
||||
rgIncFee!!.visibility = View.INVISIBLE
|
||||
} else {
|
||||
tvBalance.text = engine!!.getBalanceWithAlter(card)
|
||||
rgIncFee!!.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
if (card!!.remainingSignatures < 2)
|
||||
if (ctx.card!!.remainingSignatures < 2)
|
||||
etAmount.isEnabled = false
|
||||
|
||||
// Ethereum EthereumTestNet
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet) {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
useCurrency = false
|
||||
etAmount.setText(engine.getBalanceValue(card))
|
||||
}
|
||||
|
||||
// Bitcoin BitcoinTestNet
|
||||
else if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
val balance = engine.getBalanceLong(card)!! / (card!!.blockchain.multiplier)
|
||||
tvCurrency.text = card!!.blockchain.currency
|
||||
useCurrency = true
|
||||
val output = FormatUtil.DoubleToString(balance)
|
||||
etAmount.setText(output)
|
||||
}
|
||||
|
||||
// BitcoinCash BitcoinCashTestNet
|
||||
else if (card!!.blockchain == Blockchain.BitcoinCash || card!!.blockchain == Blockchain.BitcoinCashTestNet) {
|
||||
val balance = engine.getBalanceLong(card)!! / (card!!.blockchain.multiplier)
|
||||
tvCurrency.text = card!!.blockchain.currency
|
||||
useCurrency = true
|
||||
val output = FormatUtil.DoubleToString(balance)
|
||||
} else {
|
||||
tvCurrency.text = engine.getBalanceCurrency(card)
|
||||
useCurrency = false
|
||||
etAmount.setText(engine.getBalanceValue(card))
|
||||
}
|
||||
tvCurrency.text = engine.balance.currency
|
||||
etAmount.setText(engine.balance.stringToEdit)
|
||||
|
||||
// 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))
|
||||
etAmount.filters = engine.amountInputFilters
|
||||
|
||||
// set listeners
|
||||
etAmount.setOnEditorActionListener { lv, actionId, event ->
|
||||
|
|
@ -111,12 +81,14 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
}
|
||||
btnVerify.setOnClickListener {
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
|
||||
val engine1 = CoinEngineFactory.create(card!!.blockchain)
|
||||
val engine1 = CoinEngineFactory.create(ctx.card!!.blockchain)
|
||||
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
val amount=engine1.convertToAmount(etAmount.text.toString())
|
||||
|
||||
try {
|
||||
if (!engine.checkAmount(card, etAmount.text.toString()))
|
||||
if (!engine.checkNewTransactionAmount(amount))
|
||||
etAmount.error = getString(R.string.not_enough_funds_on_your_card)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
|
|
@ -124,7 +96,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
var checkAddress = false
|
||||
if (engine1 != null)
|
||||
checkAddress = engine1.validateAddress(etWallet.text.toString(), card)
|
||||
checkAddress = engine1.validateAddress(etWallet.text.toString())
|
||||
|
||||
// check wallet address
|
||||
if (!checkAddress) {
|
||||
|
|
@ -132,20 +104,20 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (etWallet.text.toString() == card!!.wallet) {
|
||||
if (etWallet.text.toString() == ctx.card!!.wallet) {
|
||||
etWallet.error = getString(R.string.destination_wallet_address_equal_source_address)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
// check enough funds
|
||||
if (etAmount.text.toString().replace(",", ".").toDouble() > engine.getBalanceValue(card).replace(",", ".").toDouble()) {
|
||||
etAmount.error = getString(R.string.not_enough_funds_on_your_card)
|
||||
return@setOnClickListener
|
||||
}
|
||||
// TODO - double with engin.checkAmount
|
||||
// if (etAmount.text.toString().replace(",", ".").toDouble() > engine.getBalanceValue(card).replace(",", ".").toDouble()) {
|
||||
// etAmount.error = getString(R.string.not_enough_funds_on_your_card)
|
||||
// return@setOnClickListener
|
||||
// }
|
||||
|
||||
val intent = Intent(baseContext, ConfirmPaymentActivity::class.java)
|
||||
intent.putExtra("UID", card!!.uid)
|
||||
intent.putExtra("Card", card!!.asBundle)
|
||||
ctx.saveToBundle(intent.extras)
|
||||
intent.putExtra("Wallet", etWallet!!.text.toString())
|
||||
intent.putExtra("IncFee", (rgIncFee!!.checkedRadioButtonId == R.id.rbFeeIn))
|
||||
intent.putExtra(SignPaymentActivity.EXTRA_AMOUNT, strAmount)
|
||||
|
|
@ -176,7 +148,7 @@ class PreparePaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == REQUEST_CODE_SCAN_QR && resultCode == Activity.RESULT_OK && data != null && data.extras!!.containsKey("QRCode")) {
|
||||
var code = data.getStringExtra("QRCode")
|
||||
when (card!!.blockchain) {
|
||||
when (ctx.card!!.blockchain) {
|
||||
Blockchain.Bitcoin -> {
|
||||
if (code.contains("bitcoin:")) {
|
||||
val tmp = code.split("bitcoin:".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.tangem.data.nfc.PurgeTask
|
|||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.domain.wallet.TangemContext
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.util.Util
|
||||
|
|
@ -29,7 +30,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
|
||||
}
|
||||
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var purgeTask: PurgeTask? = null
|
||||
|
||||
|
|
@ -43,10 +44,9 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
|
||||
MainActivity.commonInit(applicationContext)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
progressBar.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
}
|
||||
|
|
@ -82,9 +82,9 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
val sUID = Util.byteArrayToHexString(uid)
|
||||
// Log.v(TAG, "UID: $sUID")
|
||||
|
||||
if (sUID == card!!.uid) {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 65000
|
||||
purgeTask = PurgeTask(this, card, nfcManager, isoDep, this)
|
||||
if (sUID == ctx.card!!.uid) {
|
||||
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 65000
|
||||
purgeTask = PurgeTask(this, ctx.card, nfcManager, isoDep, this)
|
||||
purgeTask!!.start()
|
||||
} else {
|
||||
// this Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card.getUID() + ")");
|
||||
|
|
|
|||
|
|
@ -12,9 +12,7 @@ import com.tangem.data.network.ServerApiHelper
|
|||
import com.tangem.data.network.ServerApiHelperElectrum
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
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.*
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.R
|
||||
import org.json.JSONException
|
||||
|
|
@ -30,7 +28,7 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
private var serverApiHelper: ServerApiHelper = ServerApiHelper()
|
||||
private var serverApiHelperElectrum: ServerApiHelperElectrum = ServerApiHelperElectrum()
|
||||
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
private var tx: String? = null
|
||||
private var nfcManager: NfcManager? = null
|
||||
|
||||
|
|
@ -42,19 +40,18 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
val intent = intent
|
||||
card = TangemCard(getIntent().getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
|
||||
ctx=TangemContext.loadFromBundle(this, intent.extras)
|
||||
tx = intent.getStringExtra(EXTRA_TX)
|
||||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
if (card!!.blockchain == Blockchain.Ethereum || card!!.blockchain == Blockchain.EthereumTestNet || card!!.blockchain == Blockchain.Token)
|
||||
if (ctx.blockchain == Blockchain.Ethereum || ctx.blockchain == Blockchain.EthereumTestNet || ctx.blockchain == Blockchain.Token)
|
||||
requestInfura(ServerApiHelper.INFURA_ETH_SEND_RAW_TRANSACTION, "")
|
||||
else if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet)
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
else if (card!!.blockchain == Blockchain.BitcoinCash || card!!.blockchain == Blockchain.BitcoinCashTestNet)
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
else if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet)
|
||||
requestElectrum(ctx.card!!, ElectrumRequest.broadcast(ctx.card!!.wallet, tx))
|
||||
else if (ctx.blockchain == Blockchain.BitcoinCash || ctx.blockchain == Blockchain.BitcoinCashTestNet)
|
||||
requestElectrum(ctx.card!!, ElectrumRequest.broadcast(ctx.card!!.wallet, tx))
|
||||
|
||||
// request electrum listener
|
||||
val electrumBodyListener: ServerApiHelperElectrum.ElectrumRequestDataListener = object : ServerApiHelperElectrum.ElectrumRequestDataListener {
|
||||
|
|
@ -69,11 +66,11 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
finishWithSuccess()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
requestElectrum(ctx.card!!, ElectrumRequest.broadcast(ctx.card!!.wallet, tx))
|
||||
}
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
requestElectrum(card!!, ElectrumRequest.broadcast(card!!.wallet, tx))
|
||||
requestElectrum(ctx.card!!, ElectrumRequest.broadcast(ctx.card!!.wallet, tx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,9 +101,9 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
hashTX = hashTX.substring(2)
|
||||
}
|
||||
|
||||
val nonce = card!!.confirmedTXCount
|
||||
val nonce = (ctx.coinData!! as EthData).confirmedTXCount
|
||||
nonce.add(BigInteger.valueOf(1))
|
||||
card!!.confirmedTXCount = nonce
|
||||
(ctx.coinData!! as EthData).confirmedTXCount = nonce
|
||||
|
||||
finishWithSuccess()
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -163,7 +160,7 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
|
||||
private fun requestInfura(method: String, contract: String) {
|
||||
if (UtilHelper.isOnline(this)) {
|
||||
serverApiHelper.infura(method, 67, card!!.wallet, contract, tx)
|
||||
serverApiHelper.infura(method, 67, ctx.card!!.wallet, contract, tx)
|
||||
} else
|
||||
finishWithError(getString(R.string.no_connection))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import com.tangem.data.nfc.SignPaymentTask
|
|||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.domain.wallet.TangemContext
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.util.Util
|
||||
|
|
@ -36,7 +37,7 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
}
|
||||
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var card: TangemCard? = null
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private var signPaymentTask: SignPaymentTask? = null
|
||||
|
||||
|
|
@ -56,15 +57,14 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
nfcManager = NfcManager(this, this)
|
||||
|
||||
card = TangemCard(intent.getStringExtra(TangemCard.EXTRA_UID))
|
||||
card!!.loadFromBundle(intent.extras!!.getBundle(TangemCard.EXTRA_CARD))
|
||||
ctx=TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
amountStr = intent.getStringExtra(EXTRA_AMOUNT)
|
||||
feeStr = intent.getStringExtra("Fee")
|
||||
isIncludeFee = intent.getBooleanExtra("IncFee", true)
|
||||
outAddressStr = intent.getStringExtra("Wallet")
|
||||
|
||||
tvCardID.text = card!!.cidDescription
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
|
||||
progressBar = findViewById(R.id.progressBar)
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
|
|
@ -121,13 +121,13 @@ class SignPaymentActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
val sUID = Util.byteArrayToHexString(uid)
|
||||
// Log.v(TAG, "UID: $sUID")
|
||||
|
||||
if (sUID == card!!.uid) {
|
||||
if (sUID == ctx.card!!.uid) {
|
||||
if (lastReadSuccess) {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 5000
|
||||
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 5000
|
||||
} else {
|
||||
isoDep.timeout = card!!.pauseBeforePIN2 + 65000
|
||||
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 65000
|
||||
}
|
||||
signPaymentTask = SignPaymentTask(this, card, nfcManager, isoDep, this, amountStr, feeStr, isIncludeFee, outAddressStr)
|
||||
signPaymentTask = SignPaymentTask(this, ctx, nfcManager, isoDep, this, amountStr, feeStr, isIncludeFee, outAddressStr)
|
||||
signPaymentTask!!.start()
|
||||
} else {
|
||||
// Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card!!.uid + ")")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue