Updated on 2026-08-14
This commit is contained in:
commit
707b8ae517
38 changed files with 271 additions and 124 deletions
|
|
@ -105,4 +105,25 @@ public enum Blockchain {
|
|||
return getImageResource();
|
||||
}
|
||||
|
||||
public String getUriScheme() {
|
||||
String scheme = null;
|
||||
switch (this) {
|
||||
case Bitcoin:
|
||||
case BitcoinDual:
|
||||
scheme = "bitcoin";
|
||||
break;
|
||||
case Ethereum:
|
||||
case Token:
|
||||
case TokenEmv:
|
||||
scheme = "ethereum";
|
||||
break;
|
||||
case Litecoin:
|
||||
scheme = "litecoin";
|
||||
break;
|
||||
case Ripple:
|
||||
scheme = "ripple";
|
||||
}
|
||||
return scheme;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ public class ServerApiBinance {
|
|||
BinanceAssetData binanceAssetData = (BinanceAssetData) binanceData;
|
||||
for (Balance balance : account.getBalances()) {
|
||||
if (balance.getSymbol().equals(ctx.getCard().getContractAddress())) {
|
||||
binanceAssetData.setBalanceReceived(true);
|
||||
binanceAssetData.setAssetBalance(balance.getFree());
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,10 +197,11 @@ public abstract class CoinEngine {
|
|||
public abstract Uri getShareWalletUri();
|
||||
|
||||
public Uri getShareWalletUriEx(){
|
||||
if (ctx.getBlockchain() == Blockchain.BitcoinCash)
|
||||
return getShareWalletUri();
|
||||
String scheme = ctx.getBlockchain().getUriScheme();
|
||||
if (scheme != null)
|
||||
return Uri.parse(scheme + ":" + getShareWalletUri());
|
||||
else
|
||||
return Uri.parse(ctx.getBlockchain().name().toLowerCase() + ":" + getShareWalletUri().toString());
|
||||
return getShareWalletUri();
|
||||
}
|
||||
|
||||
public abstract boolean checkNewTransactionAmount(Amount amount);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class TangemContext {
|
|||
if (blockchain == Blockchain.NftToken) {
|
||||
return card.getTokenSymbol().substring(4) + "<br><small><small> " + getBlockchain().getOfficialName() + " non-fungible token</small></small>";
|
||||
}
|
||||
if (blockchain == Blockchain.StellarAsset) {
|
||||
if (blockchain == Blockchain.StellarAsset || blockchain == Blockchain.BinanceAsset) {
|
||||
return card.getTokenSymbol() + "<br><small><small> " + getBlockchain().getOfficialName() + " asset</small></small>";
|
||||
}
|
||||
if (blockchain == Blockchain.StellarTag) {
|
||||
|
|
|
|||
|
|
@ -89,13 +89,13 @@ public class BinanceAssetEngine extends CoinEngine {
|
|||
|
||||
@Override
|
||||
public String getBalanceHTML() {
|
||||
Amount balance = getBalance();
|
||||
Amount balance = coinData.getBalance();
|
||||
Amount assetBalance = coinData.getAssetBalance();
|
||||
if (balance != null) {
|
||||
if (assetBalance != null) {
|
||||
return assetBalance.toDescriptionString(getDecimals()) + "<br><small><small>+ " + balance.toDescriptionString(getDecimals()) + " for fee</small></small>";
|
||||
}
|
||||
return balance.toDescriptionString(getDecimals());
|
||||
return new Amount(BigDecimal.ZERO, ctx.getCard().tokenSymbol).toDescriptionString(getDecimals()) + "<br><small><small>+ " + balance.toDescriptionString(getDecimals()) + " for fee</small></small>";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ public class BinanceAssetEngine extends CoinEngine {
|
|||
@Override
|
||||
public boolean hasBalanceInfo() {
|
||||
if (coinData == null) return false;
|
||||
return coinData.hasBalanceInfo();
|
||||
return coinData.hasBalanceInfo() || coinData.isError404();
|
||||
}
|
||||
|
||||
public boolean isExtractPossible() {
|
||||
|
|
@ -135,6 +135,8 @@ public class BinanceAssetEngine extends CoinEngine {
|
|||
ctx.setMessage(R.string.general_wallet_empty);
|
||||
} else if (awaitingConfirmation()) {
|
||||
ctx.setMessage(R.string.loaded_wallet_message_wait);
|
||||
} else if (coinData.getBalance() == null || coinData.getBalance().isZero()) {
|
||||
ctx.setMessage(ctx.getString(R.string.confirm_transaction_error_not_enough_eth_for_fee));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class BinanceEngine extends CoinEngine {
|
|||
@Override
|
||||
public boolean hasBalanceInfo() {
|
||||
if (coinData == null) return false;
|
||||
return coinData.hasBalanceInfo();
|
||||
return coinData.hasBalanceInfo() || coinData.isError404();
|
||||
}
|
||||
|
||||
public boolean isExtractPossible() {
|
||||
|
|
|
|||
|
|
@ -154,17 +154,8 @@ class PrepareTransactionFragment : BaseFragment(), NavigationResultListener, Nfc
|
|||
val schemeSplit = code!!.split(":")
|
||||
when (schemeSplit.size) {
|
||||
2 -> {
|
||||
if (ctx.blockchain.officialName.toLowerCase(Locale.ROOT).replace("\\s", "") == schemeSplit[0]) {
|
||||
val uri = Uri.parse(schemeSplit[1])
|
||||
etWallet?.setText(uri.path)
|
||||
// val amount = uri.getQueryParameter("amount") //TODO: enable after redesign
|
||||
// if (amount != null) {
|
||||
// etAmount?.setText(amount)
|
||||
// rgIncFee.check(R.id.rbFeeOut)
|
||||
// }
|
||||
} else if (ctx.blockchain == Blockchain.Ripple && schemeSplit[0] == "ripple") {
|
||||
val uri = Uri.parse(schemeSplit[1])
|
||||
etWallet?.setText(uri.path)
|
||||
if (schemeSplit[0] == ctx.blockchain.uriScheme) {
|
||||
etWallet?.setText(schemeSplit[1])
|
||||
} else {
|
||||
etWallet?.setText(code)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.tangem.blockchain.blockchains.binance.client.domain.broadcast.Transfe
|
|||
import com.tangem.blockchain.blockchains.binance.client.encoding.message.MessageType
|
||||
import com.tangem.blockchain.blockchains.binance.client.encoding.message.TransactionRequestAssemblerExtSign
|
||||
import com.tangem.blockchain.blockchains.binance.client.encoding.message.TransferMessage
|
||||
import com.tangem.blockchain.common.AmountType
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.blockchain.extensions.Result
|
||||
|
|
@ -28,13 +29,14 @@ class BinanceTransactionBuilder(
|
|||
private var transferMessage: TransferMessage? = null
|
||||
|
||||
fun buildToSign(transactionData: TransactionData): Result<ByteArray> {
|
||||
val amount = transactionData.amount
|
||||
|
||||
if (!transactionData.amount.isAboveZero()) return Result.Failure(Exception("Transaction amount is not defined"))
|
||||
if (!amount.isAboveZero()) return Result.Failure(Exception("Transaction amount is not defined"))
|
||||
val accountNumber = accountNumber ?: return Result.Failure(Exception("No account number"))
|
||||
val sequence = sequence ?: return Result.Failure(Exception("No sequence"))
|
||||
|
||||
val transfer = Transfer()
|
||||
transfer.coin = transactionData.amount.currencySymbol
|
||||
transfer.coin = if (amount.type == AmountType.Coin) amount.currencySymbol else amount.address
|
||||
transfer.fromAddress = transactionData.sourceAddress
|
||||
transfer.toAddress = transactionData.destinationAddress
|
||||
transfer.amount = transactionData.amount.value!!
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.tangem.blockchain.blockchains.binance
|
||||
|
||||
import android.util.Log
|
||||
import com.tangem.blockchain.blockchains.binance.network.BinanceInfoResponse
|
||||
import com.tangem.blockchain.blockchains.binance.network.BinanceNetworkManager
|
||||
import com.tangem.blockchain.common.*
|
||||
import com.tangem.blockchain.extensions.Result
|
||||
import com.tangem.blockchain.extensions.SimpleResult
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.blockchain.blockchains.binance.network.BinanceInfoResponse
|
||||
|
||||
class BinanceWalletManager(
|
||||
cardId: String,
|
||||
|
|
@ -18,7 +18,7 @@ class BinanceWalletManager(
|
|||
private val blockchain = wallet.blockchain
|
||||
|
||||
override suspend fun update() {
|
||||
val result = networkManager.getInfo(wallet.address)
|
||||
val result = networkManager.getInfo(wallet.address, wallet.amounts[AmountType.Token]?.address)
|
||||
when (result) {
|
||||
is Result.Success -> updateWallet(result.data)
|
||||
is Result.Failure -> updateError(result.error)
|
||||
|
|
@ -28,6 +28,7 @@ class BinanceWalletManager(
|
|||
private fun updateWallet(response: BinanceInfoResponse) {
|
||||
Log.d(this::class.java.simpleName, "Balance is ${response.balance}")
|
||||
wallet.amounts[AmountType.Coin]?.value = response.balance
|
||||
wallet.amounts[AmountType.Token]?.value = response.assetBalance
|
||||
|
||||
transactionBuilder.accountNumber = response.accountNumber
|
||||
transactionBuilder.sequence = response.sequence
|
||||
|
|
|
|||
|
|
@ -25,20 +25,22 @@ class BinanceNetworkManager(isTestNet: Boolean = false) {
|
|||
)
|
||||
}
|
||||
|
||||
suspend fun getInfo(address: String): Result<BinanceInfoResponse> {
|
||||
suspend fun getInfo(address: String, assetCode: String? = null): Result<BinanceInfoResponse> {
|
||||
return try {
|
||||
val accountData = retryIO { client.getAccount(address) }
|
||||
|
||||
var coinBalance = BigDecimal.ZERO
|
||||
var assetBalance = BigDecimal.ZERO
|
||||
for (balance in accountData.balances) {
|
||||
if (balance.symbol == "BNB") {
|
||||
coinBalance = balance.free.toBigDecimal()
|
||||
break
|
||||
when (balance.symbol) {
|
||||
"BNB" -> coinBalance = balance.free.toBigDecimal()
|
||||
assetCode -> assetBalance = balance.free.toBigDecimal()
|
||||
}
|
||||
}
|
||||
|
||||
Result.Success(BinanceInfoResponse(
|
||||
balance = coinBalance,
|
||||
assetBalance = assetBalance,
|
||||
accountNumber = accountData.accountNumber.toLong(),
|
||||
sequence = accountData.sequence
|
||||
))
|
||||
|
|
@ -46,6 +48,7 @@ class BinanceNetworkManager(isTestNet: Boolean = false) {
|
|||
if (exception.message == "account not found") {
|
||||
Result.Success(BinanceInfoResponse(
|
||||
balance = BigDecimal.ZERO, //TODO check account not found logic
|
||||
assetBalance = null,
|
||||
accountNumber = null,
|
||||
sequence = null
|
||||
))
|
||||
|
|
@ -88,7 +91,8 @@ class BinanceNetworkManager(isTestNet: Boolean = false) {
|
|||
}
|
||||
|
||||
data class BinanceInfoResponse(
|
||||
val balance: BigDecimal?,
|
||||
val balance: BigDecimal,
|
||||
val assetBalance: BigDecimal?,
|
||||
val accountNumber: Long?,
|
||||
val sequence: Long?
|
||||
)
|
||||
|
|
@ -37,7 +37,7 @@ interface CardSessionRunnable<T : CommandResponse> {
|
|||
* @property viewDelegate is an interface that allows interaction with users and shows relevant UI.
|
||||
* @property cardId ID, Unique Tangem card ID number. If not null, the SDK will check that you the card
|
||||
* with which you tapped a phone has this [cardId] and SDK will return
|
||||
* the [TangemSdkError.WrongCard] otherwise.
|
||||
* the [TangemSdkError.WrongCardNumber] otherwise.
|
||||
* @property initialMessage A custom description that will be shown at the beginning of the NFC session.
|
||||
* If null, a default header and text body will be used.
|
||||
*/
|
||||
|
|
@ -77,7 +77,16 @@ class CardSession(
|
|||
runnable.run(this) { result ->
|
||||
when (result) {
|
||||
is CompletionResult.Success -> stop()
|
||||
is CompletionResult.Failure -> stopWithError(result.error)
|
||||
is CompletionResult.Failure -> {
|
||||
if (result.error is TangemSdkError.ExtendedLengthNotSupported) {
|
||||
if (session.environment.terminalKeys != null) {
|
||||
session.environment.terminalKeys = null
|
||||
startWithRunnable(runnable, callback)
|
||||
return@run
|
||||
}
|
||||
}
|
||||
stopWithError(result.error)
|
||||
}
|
||||
}
|
||||
callback(result)
|
||||
}
|
||||
|
|
@ -133,8 +142,8 @@ class CardSession(
|
|||
is CompletionResult.Success -> {
|
||||
val receivedCardId = result.data.cardId
|
||||
if (cardId != null && receivedCardId != cardId) {
|
||||
stopWithError(TangemSdkError.WrongCard())
|
||||
callback(CompletionResult.Failure(TangemSdkError.WrongCard()))
|
||||
stopWithError(TangemSdkError.WrongCardNumber())
|
||||
callback(CompletionResult.Failure(TangemSdkError.WrongCardNumber()))
|
||||
return@run
|
||||
}
|
||||
val allowedCardTypes = environment.cardFilter.allowedCardTypes
|
||||
|
|
@ -166,6 +175,8 @@ class CardSession(
|
|||
* @param error An error that will be shown.
|
||||
*/
|
||||
private fun stopWithError(error: Exception) {
|
||||
if (!isBusy) return
|
||||
|
||||
reader.closeSession()
|
||||
isBusy = false
|
||||
|
||||
|
|
@ -175,9 +186,12 @@ class CardSession(
|
|||
error.localizedMessage
|
||||
}
|
||||
if (error !is TangemSdkError.UserCancelled) {
|
||||
Log.e("tag", "Finishing with error: $errorMessage")
|
||||
Log.e(tag, "Finishing with error: $errorMessage")
|
||||
viewDelegate.onError(errorMessage)
|
||||
} else {
|
||||
Log.i(tag, "User cancelled NFC session")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun send(apdu: CommandApdu, callback: (result: CompletionResult<ResponseApdu>) -> Unit) {
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ data class SessionEnvironment(
|
|||
var pin1: ByteArray = DEFAULT_PIN.calculateSha256(),
|
||||
var pin2: ByteArray = DEFAULT_PIN2.calculateSha256(),
|
||||
var card: Card? = null,
|
||||
val terminalKeys: KeyPair? = null,
|
||||
var terminalKeys: KeyPair? = null,
|
||||
var encryptionMode: EncryptionMode = EncryptionMode.NONE,
|
||||
var encryptionKey: ByteArray? = null,
|
||||
val cvc: ByteArray? = null,
|
||||
var cvc: ByteArray? = null,
|
||||
var cardFilter: CardFilter = CardFilter(),
|
||||
val handleErrors: Boolean = true
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ class TangemSdk(
|
|||
* @runnable: A custom task, adopting [CardSessionRunnable] protocol
|
||||
* @cardId: CID, Unique Tangem card ID number. If not null, the SDK will check that you the card
|
||||
* with which you tapped a phone has this [cardId] and SDK will return
|
||||
* the [TangemSdkError.WrongCard] otherwise.
|
||||
* the [TangemSdkError.WrongCardNumber] otherwise.
|
||||
* @initialMessage: A custom description that shows at the beginning of the NFC session.
|
||||
* If null, default message will be used.
|
||||
* @callback: Standard [TangemSdk] callback.
|
||||
|
|
@ -365,7 +365,7 @@ class TangemSdk(
|
|||
|
||||
* @cardId: CID, Unique Tangem card ID number. If not null, the SDK will check that you the card
|
||||
* with which you tapped a phone has this [cardId] and SDK will return
|
||||
* the [TangemSdkError.WrongCard] otherwise.
|
||||
* the [TangemSdkError.WrongCardNumber] otherwise.
|
||||
* @initialMessage: A custom description that shows at the beginning of the NFC session.
|
||||
* If null, default message will be used.
|
||||
* @callback: At first, you should check that the [TangemSdkError] is not null,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ sealed class TangemSdkError(val code: Int) : Exception(code.toString()) {
|
|||
* (e.g. a user detaches card from the phone's NFC module) while the NFC session is in progress.
|
||||
*/
|
||||
class TagLost : TangemSdkError(10001)
|
||||
/**
|
||||
* This error is returned when NFC driver on an Android device does not support sending more than 261 bytes.
|
||||
*/
|
||||
class ExtendedLengthNotSupported : TangemSdkError(10002)
|
||||
|
||||
|
||||
class SerializeCommandError : TangemSdkError(20001)
|
||||
|
|
@ -67,16 +71,6 @@ sealed class TangemSdkError(val code: Int) : Exception(code.toString()) {
|
|||
|
||||
//Read Errors
|
||||
class Pin1Required : TangemSdkError(40401)
|
||||
/**
|
||||
* This error is returned when a [Task] expects a user to use a particular card,
|
||||
* but the user tries to use a different card.
|
||||
*/
|
||||
class WrongCard : TangemSdkError(40403)
|
||||
/**
|
||||
* This error is returned when a user scans a card of a [com.tangem.common.extensions.CardType]
|
||||
* that is not specified in [Config.cardFilter].
|
||||
*/
|
||||
class WrongCardType : TangemSdkError(40404)
|
||||
|
||||
//CreateWallet Errors
|
||||
class AlreadyCreated : TangemSdkError(40501)
|
||||
|
|
@ -128,11 +122,6 @@ sealed class TangemSdkError(val code: Int) : Exception(code.toString()) {
|
|||
class OverwritingDataIsProhibited : TangemSdkError(40008)
|
||||
class DataCannotBeWritten : TangemSdkError(40009)
|
||||
class MissingIssuerPubicKey : TangemSdkError(40010)
|
||||
/**
|
||||
* This error is returned when a [ScanTask] returns a [Card] without some of the essential fields.
|
||||
*/
|
||||
class CardError : TangemSdkError(40011)
|
||||
|
||||
|
||||
//SDK Errors
|
||||
class UnknownError: TangemSdkError(50001)
|
||||
|
|
@ -150,7 +139,20 @@ sealed class TangemSdkError(val code: Int) : Exception(code.toString()) {
|
|||
* is executed before performing other commands.
|
||||
*/
|
||||
class MissingPreflightRead : TangemSdkError(50004)
|
||||
|
||||
/**
|
||||
* This error is returned when a [Task] expects a user to use a particular card,
|
||||
* but the user tries to use a different card.
|
||||
*/
|
||||
class WrongCardNumber : TangemSdkError(50005)
|
||||
/**
|
||||
* This error is returned when a user scans a card of a [com.tangem.common.extensions.CardType]
|
||||
* that is not specified in [Config.cardFilter].
|
||||
*/
|
||||
class WrongCardType : TangemSdkError(50006)
|
||||
/**
|
||||
* This error is returned when a [ScanTask] returns a [Card] without some of the essential fields.
|
||||
*/
|
||||
class CardError : TangemSdkError(50007)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ abstract class Command<T : CommandResponse> : CardSessionRunnable<T> {
|
|||
abstract fun deserialize(environment: SessionEnvironment, apdu: ResponseApdu): T
|
||||
|
||||
override fun run(session: CardSession, callback: (result: CompletionResult<T>) -> Unit) {
|
||||
Log.i("Command", "Sending ${this::class.java.simpleName}")
|
||||
Log.i("Command", "Initializing ${this::class.java.simpleName}")
|
||||
if (session.environment.handleErrors) {
|
||||
if (performPreCheck(session, callback)) return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class TlvBuilder {
|
|||
|
||||
fun serialize(): ByteArray {
|
||||
Log.v("TLV",
|
||||
"List of encoded TLVs:\n${tlvs.joinToString("\n")}")
|
||||
"Data encoded to TLVs:\n${tlvs.joinToString("\n")}")
|
||||
return tlvs.serialize()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class TlvDecoder(val tlvList: List<Tlv>) {
|
|||
|
||||
init {
|
||||
Log.v("TLV",
|
||||
"List of decoded TLVs:\n${tlvList.joinToString("\n")}")
|
||||
"Decoding data from TLV:\n${tlvList.joinToString("\n")}")
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +33,7 @@ class TlvDecoder(val tlvList: List<Tlv>) {
|
|||
*/
|
||||
inline fun <reified T> decodeOptional(tag: TlvTag): T? =
|
||||
try {
|
||||
decode<T>(tag)
|
||||
decode<T>(tag, false)
|
||||
} catch (exception: TangemSdkError.DecodingFailedMissingTag) {
|
||||
null
|
||||
}
|
||||
|
|
@ -47,14 +47,18 @@ class TlvDecoder(val tlvList: List<Tlv>) {
|
|||
*
|
||||
* @return [Tlv] value converted to a nullable type [T].
|
||||
*
|
||||
* @throws [TaskError.MissingTag] exception if no [Tlv] is found by the Tag.
|
||||
* @throws [TangemSdkError.DecodingFailedMissingTag] exception if no [Tlv] is found by the Tag.
|
||||
*/
|
||||
inline fun <reified T> decode(tag: TlvTag): T {
|
||||
inline fun <reified T> decode(tag: TlvTag, logError: Boolean = true): T {
|
||||
val tlvValue: ByteArray = tlvList.find { it.tag == tag }?.value
|
||||
?: if (tag.valueType() == TlvValueType.BoolValue && T::class == Boolean::class) {
|
||||
return false as T
|
||||
} else {
|
||||
Log.e(this::class.simpleName!!, "Tag $tag not found")
|
||||
if (logError) {
|
||||
Log.e(this::class.simpleName!!, "TLV $tag not found")
|
||||
} else {
|
||||
Log.v(this::class.simpleName!!, "TLV $tag not found, but it is not required")
|
||||
}
|
||||
throw TangemSdkError.DecodingFailedMissingTag()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.content.ClipData
|
|||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
|
||||
/**
|
||||
|
|
@ -17,11 +16,7 @@ fun Context.copyToClipboard(value: Any, label: String = "") {
|
|||
clipboard.setPrimaryClip(clip)
|
||||
}
|
||||
|
||||
fun Fragment.shareText(text: String) {
|
||||
requireActivity().shareText(text)
|
||||
}
|
||||
|
||||
fun ComponentActivity.shareText(text: String) {
|
||||
fun Context.shareText(text: String) {
|
||||
val sendIntent: Intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, text)
|
||||
|
|
@ -29,4 +24,8 @@ fun ComponentActivity.shareText(text: String) {
|
|||
}
|
||||
val shareIntent = Intent.createChooser(sendIntent, null)
|
||||
startActivity(shareIntent)
|
||||
}
|
||||
|
||||
fun Fragment.shareText(text: String) {
|
||||
requireContext().shareText(text)
|
||||
}
|
||||
|
|
@ -7,10 +7,7 @@ import com.tangem.devkit.commons.Store
|
|||
import com.tangem.devkit.ucase.domain.actions.PersonalizeAction
|
||||
import com.tangem.devkit.ucase.domain.paramsManager.ActionCallback
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationConfigConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationJsonConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationConfig
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationJson
|
||||
import ru.dev.gbixahue.eu4d.lib.android.global.log.Log
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -30,27 +27,6 @@ class PersonalizationItemsManager(
|
|||
action.executeMainAction(this, getAttrsForAction(tangemSdk), callback)
|
||||
}
|
||||
|
||||
fun importJsonConfig(jsonString: String) {
|
||||
if (jsonString.isEmpty()) return
|
||||
|
||||
val jsonDto = try {
|
||||
PersonalizationJson.getJsonConverter().fromJson(jsonString, PersonalizationJson::class.java)
|
||||
} catch (ex: Exception) {
|
||||
Log.e(this, "Can't convert imported string to Json object. Error: $ex")
|
||||
return
|
||||
}
|
||||
|
||||
val config = PersonalizationJsonConverter().aToB(jsonDto)
|
||||
updateByItemList(converter.convert(config))
|
||||
}
|
||||
|
||||
fun exportJsonConfig(): String {
|
||||
val config = converter.convert(itemList, PersonalizationConfig.default())
|
||||
val jsonDto = PersonalizationJsonConverter().bToA(config)
|
||||
val jsonString = PersonalizationJson.getJsonConverter().toJson(jsonDto)
|
||||
return jsonString
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
fun onDestroy() {
|
||||
val config = converter.convert(itemList, PersonalizationConfig.default())
|
||||
|
|
|
|||
|
|
@ -106,8 +106,8 @@ internal class Helper {
|
|||
KeyValue("RSK", "RSK"),
|
||||
KeyValue("XPR", "XPR"),
|
||||
KeyValue("CARDANO", "CARDANO"),
|
||||
KeyValue("BNB", "BNB"),
|
||||
KeyValue("XTZ", "XTZ"),
|
||||
KeyValue("BNB", "BINANCE"),
|
||||
KeyValue("XTZ", "TEZOS"),
|
||||
KeyValue("DUC", "DUC")
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,9 @@ class ItemsToPersonalizationConfig : ItemsToModel<PersonalizationConfig> {
|
|||
export.requireTerminalTxSignature = getTyped(SignHashExPropId.RequireTerminalTxSig)
|
||||
export.checkPIN3onCard = getTyped(SignHashExPropId.CheckPin3)
|
||||
export.itsToken = getTyped(TokenId.ItsToken)
|
||||
export.cardData.token_symbol = getTyped(TokenId.Symbol)
|
||||
export.cardData.token_contract_address = getTyped(TokenId.ContractAddress)
|
||||
export.cardData.token_decimal = getTyped(TokenId.Decimal)
|
||||
export.cardData.token_symbol = getTypedUnsafe(TokenId.Symbol)
|
||||
export.cardData.token_contract_address = getTypedUnsafe(TokenId.ContractAddress)
|
||||
export.cardData.token_decimal = getTypedUnsafe(TokenId.Decimal)
|
||||
export.cardData = export.cardData.apply { this.product_note = getTyped(ProductMaskId.Note) }
|
||||
export.cardData = export.cardData.apply { this.product_tag = getTyped(ProductMaskId.Tag) }
|
||||
export.cardData = export.cardData.apply { this.product_id_card = getTyped(ProductMaskId.IdCard) }
|
||||
|
|
@ -114,6 +114,10 @@ class ItemsToPersonalizationConfig : ItemsToModel<PersonalizationConfig> {
|
|||
return getTypedBy<Type>(valuesHolder, id)!!
|
||||
}
|
||||
|
||||
private inline fun <reified Type> getTypedUnsafe(id: Id): Type? {
|
||||
return getTypedBy<Type>(valuesHolder, id)
|
||||
}
|
||||
|
||||
private inline fun <reified Type> getTypedBy(holder: ConfigValuesHolder, id: Id): Type? {
|
||||
Log.d(this, "getTyped for id: $id")
|
||||
var typedValue = holder.get(id)?.get()
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ internal class JsonToConfig : Converter<PersonalizationJson, PersonalizationConf
|
|||
val jsonCardData = jsonDto.cardData
|
||||
|
||||
// copy whole object and then checking tricky places
|
||||
config.cardData = jsonCardData
|
||||
config.cardData.copyFrom(jsonCardData)
|
||||
|
||||
config.itsToken = jsonCardData.token_contract_address?.isNotEmpty() ?: false
|
||||
|| jsonCardData.token_symbol?.isNotEmpty() ?: false
|
||||
|
|
|
|||
|
|
@ -200,6 +200,19 @@ class CardData {
|
|||
var product_id_card = false
|
||||
var product_id_issuer = false
|
||||
|
||||
fun copyFrom(applyData: CardData) {
|
||||
date = applyData.date
|
||||
batch = applyData.batch
|
||||
blockchain = applyData.blockchain
|
||||
token_symbol = applyData.token_symbol
|
||||
token_contract_address = applyData.token_contract_address
|
||||
token_decimal = applyData.token_decimal
|
||||
product_note = applyData.product_note
|
||||
product_tag = applyData.product_tag
|
||||
product_id_card = applyData.product_id_card
|
||||
product_id_issuer = applyData.product_id_issuer
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun default(): CardData {
|
||||
return CardData().apply {
|
||||
|
|
|
|||
|
|
@ -65,6 +65,16 @@ class PersonalizationJson {
|
|||
val builder = GsonBuilder().setPrettyPrinting()
|
||||
return builder.create()
|
||||
}
|
||||
|
||||
fun clarifyJson(json: String): String {
|
||||
val unsupportedQuotes = mutableListOf("“", "”", "«", "»")
|
||||
var clearedJson = json
|
||||
unsupportedQuotes.forEach {
|
||||
if (clearedJson.contains(it)) clearedJson = clearedJson.replace(it, "\"")
|
||||
}
|
||||
// 160 is 00A0 symbol (No-Break Space)
|
||||
return clearedJson.replace(160.toChar().toString(), "").trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DividerItemDecoration
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.transition.Fade
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.tangem.commands.Card
|
||||
import com.tangem.devkit.R
|
||||
import com.tangem.devkit._arch.structure.Id
|
||||
|
|
@ -25,6 +26,7 @@ import com.tangem.devkit.commons.DialogController
|
|||
import com.tangem.devkit.commons.view.MultiActionView
|
||||
import com.tangem.devkit.commons.view.ViewAction
|
||||
import com.tangem.devkit.extensions.copyToClipboard
|
||||
import com.tangem.devkit.extensions.shareText
|
||||
import com.tangem.devkit.extensions.view.beginDelayedTransition
|
||||
import com.tangem.devkit.ucase.domain.paramsManager.ItemsManager
|
||||
import com.tangem.devkit.ucase.domain.paramsManager.PayloadKey
|
||||
|
|
@ -132,6 +134,7 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
fun initImportExportJson(parent: ViewGroup) {
|
||||
val tvJsonExport = parent.findViewById<EditText>(R.id.et_json_export)
|
||||
val btnExportJson = parent.findViewById<Button>(R.id.btn_export_json)
|
||||
val presetManager = PersonalizationPresetManager(itemsManager, this)
|
||||
|
||||
tvJsonExport.setOnClickListener {
|
||||
val jsonString = tvJsonExport.text
|
||||
|
|
@ -139,13 +142,13 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
requireContext().copyToClipboard(jsonString, "Exported Json")
|
||||
}
|
||||
btnExportJson.setOnClickListener {
|
||||
tvJsonExport.setText(personalizationItemsManager.exportJsonConfig())
|
||||
tvJsonExport.setText(presetManager.exportJsonConfig())
|
||||
}
|
||||
|
||||
val tvJsonImport = parent.findViewById<EditText>(R.id.et_json_import)
|
||||
val btnImportJson = parent.findViewById<Button>(R.id.btn_import_json)
|
||||
btnImportJson.setOnClickListener {
|
||||
personalizationItemsManager.importJsonConfig(tvJsonImport.text.toString().trim())
|
||||
presetManager.importJsonConfig(tvJsonImport.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -168,11 +171,13 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
val store = PersonalizationConfigStore(requireContext())
|
||||
val presetManager = PersonalizationPresetManager(itemsManager, store, this)
|
||||
val presetManager = PersonalizationPresetManager(itemsManager, this)
|
||||
val result = when (item.itemId) {
|
||||
R.id.action_reset -> presetManager.resetToDefault()
|
||||
R.id.action_save -> presetManager.savePreset()
|
||||
R.id.action_load -> presetManager.loadPreset()
|
||||
R.id.action_import_preset -> showImportPresetDialog(presetManager)
|
||||
R.id.action_share_preset -> shareText(presetManager.exportJsonConfig())
|
||||
R.id.action_reset -> presetManager.resetToDefault(store)
|
||||
R.id.action_save -> presetManager.savePreset(store)
|
||||
R.id.action_load -> presetManager.loadPreset(store)
|
||||
else -> null
|
||||
}
|
||||
return if (result == null) super.onOptionsItemSelected(item) else true
|
||||
|
|
@ -191,13 +196,16 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
override fun showSavePresetDialog(onOk: SafeValueChanged<String>) {
|
||||
val dlgController = DialogController()
|
||||
val dlg = dlgController.createAlert(requireActivity(), R.layout.dlg_personalization_preset_save)
|
||||
dlgController.view?.findViewById<TextInputLayout>(R.id.til_item)?.let {
|
||||
it.hint = getString(R.string.hint_enter_preset_name)
|
||||
}
|
||||
dlg.setTitle(R.string.menu_personalization_preset_save)
|
||||
dlg.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.btn_cancel)) { dialog, which -> }
|
||||
dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_ok)) { dialog, which ->
|
||||
val tvName = dlgController.view?.findViewById<EditText>(R.id.et_item)
|
||||
?: return@setButton
|
||||
val name = tvName.text.toString()
|
||||
if (name.isEmpty()) showSnackbar("Not saved")
|
||||
if (name.isEmpty()) showSnackbar(R.string.error_not_saved)
|
||||
else onOk.invoke(name)
|
||||
}
|
||||
dlgController.onShowCallback = {
|
||||
|
|
@ -235,4 +243,29 @@ class PersonalizationFragment : BaseCardActionFragment(), PersonalizationPresetV
|
|||
rvPresetNames.adapter = adapter
|
||||
dlgController.show()
|
||||
}
|
||||
|
||||
private fun showImportPresetDialog(presetManager: PersonalizationPresetManager) {
|
||||
val dlgController = DialogController()
|
||||
val dlg = dlgController.createAlert(requireActivity(), R.layout.dlg_personalization_preset_save)
|
||||
dlgController.view?.findViewById<TextInputLayout>(R.id.til_item)?.let {
|
||||
it.hint = getString(R.string.hint_paste)
|
||||
}
|
||||
dlg.setTitle(R.string.menu_personalization_preset_import)
|
||||
dlg.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.btn_cancel)) { dialog, which -> }
|
||||
dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_ok)) { dialog, which ->
|
||||
val tvName = dlgController.view?.findViewById<EditText>(R.id.et_item) ?: return@setButton
|
||||
val name = tvName.text.toString()
|
||||
presetManager.importJsonConfig(name)
|
||||
}
|
||||
dlgController.onShowCallback = {
|
||||
dlgController.view?.findViewById<TextView>(R.id.et_item)?.let {
|
||||
post(150) {
|
||||
it.requestFocus()
|
||||
val imm = getSystemService(requireContext(), InputMethodManager::class.java)
|
||||
imm?.showSoftInput(it, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
}
|
||||
dlgController.show()
|
||||
}
|
||||
}
|
||||
|
|
@ -4,22 +4,24 @@ import com.tangem.devkit.R
|
|||
import com.tangem.devkit.ucase.domain.paramsManager.ItemsManager
|
||||
import com.tangem.devkit.ucase.variants.personalize.PersonalizationConfigStore
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationConfigConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.converter.PersonalizationJsonConverter
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationConfig
|
||||
import com.tangem.devkit.ucase.variants.personalize.dto.PersonalizationJson
|
||||
import ru.dev.gbixahue.eu4d.lib.android.global.log.Log
|
||||
|
||||
class PersonalizationPresetManager(
|
||||
private val itemsManager: ItemsManager,
|
||||
private val store: PersonalizationConfigStore,
|
||||
private val view: PersonalizationPresetView
|
||||
) {
|
||||
|
||||
fun resetToDefault() {
|
||||
fun resetToDefault(store: PersonalizationConfigStore) {
|
||||
val config = PersonalizationConfig.default()
|
||||
val converter = PersonalizationConfigConverter()
|
||||
itemsManager.updateByItemList(converter.convert(config))
|
||||
store.save(config)
|
||||
}
|
||||
|
||||
fun loadPreset() {
|
||||
fun loadPreset(store: PersonalizationConfigStore) {
|
||||
val presets = store.restoreAll()
|
||||
presets.remove(PersonalizationConfigStore.defaultKey)
|
||||
val namesList = presets.map { it.key }.toMutableList()
|
||||
|
|
@ -37,11 +39,39 @@ class PersonalizationPresetManager(
|
|||
})
|
||||
}
|
||||
|
||||
fun savePreset() {
|
||||
fun savePreset(store: PersonalizationConfigStore) {
|
||||
view.showSavePresetDialog { name ->
|
||||
val converter = PersonalizationConfigConverter()
|
||||
val config = converter.convert(itemsManager.getItems(), PersonalizationConfig.default())
|
||||
store.save(name, config)
|
||||
}
|
||||
}
|
||||
|
||||
fun importJsonConfig(jsonString: String) {
|
||||
if (jsonString.isEmpty()) {
|
||||
view.showSnackbar(R.string.error_nothing_to_import)
|
||||
return
|
||||
}
|
||||
|
||||
val jsonDto = try {
|
||||
val preparedJson = PersonalizationJson.clarifyJson(jsonString)
|
||||
PersonalizationJson.getJsonConverter().fromJson(preparedJson, PersonalizationJson::class.java)
|
||||
} catch (ex: Exception) {
|
||||
view.showSnackbar(R.string.error_cant_convert_json)
|
||||
Log.e(this, ex)
|
||||
return
|
||||
}
|
||||
|
||||
val config = PersonalizationJsonConverter().aToB(jsonDto)
|
||||
val converter = PersonalizationConfigConverter()
|
||||
itemsManager.updateByItemList(converter.convert(config))
|
||||
}
|
||||
|
||||
fun exportJsonConfig(): String {
|
||||
val converter = PersonalizationConfigConverter()
|
||||
val config = converter.convert(itemsManager.getItems(), PersonalizationConfig.default())
|
||||
val jsonDto = PersonalizationJsonConverter().bToA(config)
|
||||
val jsonString = PersonalizationJson.getJsonConverter().toJson(jsonDto)
|
||||
return jsonString
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import com.tangem.devkit._arch.structure.impl.TextItem
|
|||
import com.tangem.devkit.ucase.variants.responses.CardDataId
|
||||
import com.tangem.devkit.ucase.variants.responses.CardId
|
||||
import com.tangem.devkit.ucase.variants.responses.item.TextHeaderItem
|
||||
import ru.dev.gbixahue.eu4d.lib.kotlin.stringOf
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -75,7 +76,7 @@ class CardConverter : BaseResponseConverter<Card>() {
|
|||
group.addItem(TextItem(CardDataId.manufacturerSignature, fieldConverter.byteArrayToHex(data.manufacturerSignature)))
|
||||
group.addItem(TextItem(CardDataId.tokenSymbol, data.tokenSymbol))
|
||||
group.addItem(TextItem(CardDataId.tokenContractAddress, data.tokenContractAddress))
|
||||
group.addItem(TextItem(CardDataId.tokenDecimal, data.tokenSymbol))
|
||||
group.addItem(TextItem(CardDataId.tokenDecimal, stringOf(data.tokenDecimal)))
|
||||
|
||||
val productMask = data.productMask ?: return
|
||||
|
||||
|
|
|
|||
12
tangem-devkit/src/main/res/drawable/ic_import.xml
Normal file
12
tangem-devkit/src/main/res/drawable/ic_import.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="20dp"
|
||||
android:height="20dp"
|
||||
android:viewportWidth="1000"
|
||||
android:viewportHeight="1000">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M881.1,10h-490C331,10 282.2,58.8 282.2,118.9v81.6H118.9C58.8,200.6 10,249.3 10,309.5v571.6C10,941.2 58.8,990 118.9,990h571.7c60.1,0 108.9,-48.8 108.9,-108.9V717.8h81.7c60.1,0 108.9,-48.8 108.9,-108.9v-490C990,58.8 941.2,10 881.1,10zM935.6,608.9c0,30.1 -24.4,54.5 -54.4,54.5h-81.7V380.1L745,434.5v446.6c0,30.1 -24.4,54.5 -54.4,54.5H118.9c-30.1,0 -54.4,-24.4 -54.4,-54.5V309.4c0,-30.1 24.4,-54.4 54.4,-54.4h446.5l54.5,-54.4H336.7v-81.7c0,-30.1 24.4,-54.4 54.4,-54.4h490c30.1,0 54.4,24.4 54.4,54.4V608.9z" />
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M753.4,209L310.2,652.1l0.9,-185.5c0,-15.1 -12.2,-27.2 -27.3,-27.2c-15.1,0 -27.2,12.2 -27.2,27.2l-1.3,250.7c0,15.1 12.2,27.3 27.3,27.3c3,0 5.8,-0.6 8.5,-1.6l242,0.1c14.9,0.1 26.9,-11.9 26.8,-26.8c-0.1,-14.9 -12.2,-27 -27.1,-27.1l-182.4,0l441.6,-441.6c10.6,-10.6 10.6,-27.9 0,-38.5C781.2,198.4 764,198.4 753.4,209z" />
|
||||
</vector>
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="18dp"
|
||||
android:height="18dp"
|
||||
android:width="20dp"
|
||||
android:height="20dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="@dimen/def_indent"
|
||||
android:paddingBottom="@dimen/def_half_indent">
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
<include
|
||||
layout="@layout/m_divider_h"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp" />
|
||||
android:layout_height="1.5dp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
app:boxBackgroundColor="@android:color/transparent"
|
||||
android:hint="Enter a preset name"
|
||||
tools:hint="Field name">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<group android:id="@+id/menu_group_personalization_preset">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_reset"
|
||||
android:title="@string/menu_personalization_preset_reset" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_save"
|
||||
android:title="@string/menu_personalization_preset_save" />
|
||||
|
|
@ -13,6 +15,18 @@
|
|||
android:id="@+id/action_load"
|
||||
android:title="@string/menu_personalization_preset_load" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_import_preset"
|
||||
android:icon="@drawable/ic_import"
|
||||
android:title="@string/menu_import"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_share_preset"
|
||||
android:icon="@drawable/ic_share_white_18dp"
|
||||
android:title="@string/menu_export"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</group>
|
||||
|
||||
</menu>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:icon="@drawable/ic_share_white_18dp"
|
||||
android:title="@string/menu_response_share"
|
||||
android:title="@string/menu_share"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
||||
|
|
@ -2,6 +2,9 @@
|
|||
<string name="app_name">Tangem DevKit</string>
|
||||
|
||||
<string name="menu_main_description">Description</string>
|
||||
<string name="menu_share">Share</string>
|
||||
<string name="menu_import">Import</string>
|
||||
<string name="menu_export">Export</string>
|
||||
|
||||
<string name="copy_to_clipboard">Copy to clipboard</string>
|
||||
<string name="btn_delete">Delete</string>
|
||||
|
|
|
|||
|
|
@ -2,8 +2,16 @@
|
|||
<resources>
|
||||
|
||||
<string name="menu_personalization_preset_reset">Reset to default</string>
|
||||
<string name="menu_personalization_preset_save">Save configuration</string>
|
||||
<string name="menu_personalization_preset_load">Load configuration</string>
|
||||
<string name="menu_personalization_preset_save">Save preset</string>
|
||||
<string name="menu_personalization_preset_load">Load preset</string>
|
||||
<string name="menu_personalization_preset_import">Import configuration</string>
|
||||
|
||||
<string name="hint_enter_preset_name">Enter a preset name</string>
|
||||
<string name="hint_paste">Paste</string>
|
||||
|
||||
<string name="error_nothing_to_import">Nothing to import</string>
|
||||
<string name="error_cant_convert_json">Can\'t convert imported string to Json object</string>
|
||||
<string name="error_not_saved">Not saved</string>
|
||||
|
||||
<string name="personalize">Personalize</string>
|
||||
<string name="depersonalize">Depersonalize</string>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="menu_response_share">Share</string>
|
||||
|
||||
<!-- Field names - Response: Card -->
|
||||
<string name="response_card_cid">CID</string>
|
||||
<string name="response_card_manufacturer_name">Manufacturer_Name</string>
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ class DefaultSessionViewDelegate(private val reader: NfcReader) : SessionViewDel
|
|||
readingDialog?.setOnCancelListener {
|
||||
reader.readingCancelled = true
|
||||
reader.closeSession()
|
||||
Log.i(this::class.simpleName!!, "readingCancelled is set to true")
|
||||
}
|
||||
readingDialog?.show()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class NfcReader : CardReader {
|
|||
if (field == null) {
|
||||
field = value
|
||||
// if tag is received, call connect first before transceiving data
|
||||
connect()
|
||||
if (value != null) connect()
|
||||
}
|
||||
if (value == null) field = value
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@ class NfcReader : CardReader {
|
|||
private var callback: ((response: CompletionResult<ResponseApdu>) -> Unit)? = null
|
||||
|
||||
override fun openSession() {
|
||||
Log.i(this::class.simpleName!!, "NFC reader is starting NFC session")
|
||||
readingActive = true
|
||||
readingCancelled = false
|
||||
manager?.disableReaderMode()
|
||||
|
|
@ -74,6 +75,7 @@ class NfcReader : CardReader {
|
|||
|
||||
val rawResponse: ByteArray?
|
||||
try {
|
||||
Log.i(this::class.simpleName!!, "Sending data to the card, size is ${data?.size}")
|
||||
rawResponse = isoDep?.transceive(data)
|
||||
} catch (exception: TagLostException) {
|
||||
callback?.invoke(CompletionResult.Failure(TangemSdkError.TagLost()))
|
||||
|
|
@ -81,11 +83,16 @@ class NfcReader : CardReader {
|
|||
return
|
||||
} catch (exception: Exception) {
|
||||
Log.i(this::class.simpleName!!, exception.localizedMessage ?: "Error tranceiving data")
|
||||
// The messages of errors can vary on different Android devices,
|
||||
// but we try to identify it by parsing the message.
|
||||
if (exception.message?.contains("length") == true) {
|
||||
callback?.invoke(CompletionResult.Failure(TangemSdkError.ExtendedLengthNotSupported()))
|
||||
}
|
||||
isoDep = null
|
||||
return
|
||||
}
|
||||
if (rawResponse != null) {
|
||||
Log.i(this::class.simpleName!!, "Nfc response is received")
|
||||
Log.i(this::class.simpleName!!, "Data from the card was received")
|
||||
data = null
|
||||
}
|
||||
rawResponse?.let { callback?.invoke(CompletionResult.Success(ResponseApdu(it))) }
|
||||
|
|
@ -103,7 +110,7 @@ class NfcReader : CardReader {
|
|||
isoDep?.close()
|
||||
isoDep?.connect()
|
||||
isoDep?.timeout = 240000
|
||||
Log.i(this::class.simpleName!!, "Nfc session is started")
|
||||
Log.i(this::class.simpleName!!, "NFC tag is connected")
|
||||
}
|
||||
|
||||
private fun onNfcVDiscovered(nfcV: NfcV) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue