Updated on 2026-08-14
This commit is contained in:
commit
6c6913f8ce
7 changed files with 23 additions and 13 deletions
|
|
@ -89,7 +89,7 @@ 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) {
|
||||
|
|
|
|||
|
|
@ -166,6 +166,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 +177,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) {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
rawResponse = isoDep?.transceive(data)
|
||||
} catch (exception: TagLostException) {
|
||||
callback?.invoke(CompletionResult.Failure(TangemSdkError.TagLost()))
|
||||
|
|
@ -85,7 +87,7 @@ class NfcReader : CardReader {
|
|||
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 +105,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