Updated on 2026-08-14

This commit is contained in:
Tangem 2020-05-20 11:50:11 +00:00
commit ea92fac837
8 changed files with 105 additions and 12 deletions

View file

@ -185,7 +185,7 @@ class CardSession(
* Stops the current session on error.
* @param error An error that will be shown.
*/
private fun stopWithError(error: Exception) {
private fun stopWithError(error: TangemSdkError) {
if (!isBusy) return
reader.closeSession()
@ -198,7 +198,7 @@ class CardSession(
}
if (error !is TangemSdkError.UserCancelled) {
Log.e(tag, "Finishing with error: $errorMessage")
viewDelegate.onError(errorMessage)
viewDelegate.onError(error)
} else {
Log.i(tag, "User cancelled NFC session")
}

View file

@ -40,7 +40,7 @@ interface SessionViewDelegate {
/**
* It is called when some error occur during NFC session.
*/
fun onError(errorMessage: String)
fun onError(error: TangemSdkError)
/**
* It is called when a user is expected to enter pin code.

View file

@ -101,7 +101,10 @@ sealed class TangemSdkError(val code: Int) : Exception(code.toString()) {
* Tangem cards can sign currently up to 10 hashes during one [com.tangem.commands.SignCommand].
* This error is returned when a [com.tangem.commands.SignCommand] receives more than 10 hashes to sign.
*/
class TooManyhHashesInOneTransaction : TangemSdkError(40906)
class TooManyHashesInOneTransaction : TangemSdkError(40906)
//Write Extra Issuer Data Errors
class ExendedDataSizeTooLarge : TangemSdkError(41101)
//General Errors
class NotPersonalized() : TangemSdkError(40001)
@ -114,6 +117,7 @@ sealed class TangemSdkError(val code: Int) : Exception(code.toString()) {
*/
class VerificationFailed : TangemSdkError(40005)
class DataSizeTooLarge : TangemSdkError(40006)
/**
* This error is returned when [ReadIssuerDataTask] or [ReadIssuerExtraDataTask] expects a counter
* (when the card's requires it), but the counter is missing.

View file

@ -112,7 +112,7 @@ class SignCommand(private val hashes: Array<ByteArray>)
private fun checkForErrors() {
if (hashes.isEmpty()) throw TangemSdkError.EmptyHashes()
if (hashes.size > 10) throw TangemSdkError.TooManyhHashesInOneTransaction()
if (hashes.size > 10) throw TangemSdkError.TooManyHashesInOneTransaction()
if (hashes.any { it.size != hashSizes }) throw TangemSdkError.HashSizeMustBeEqual()
}

View file

@ -94,7 +94,7 @@ class WriteIssuerExtraDataCommand(
return true
}
if (issuerData.size > MAX_SIZE) {
callback(CompletionResult.Failure(TangemSdkError.DataSizeTooLarge()))
callback(CompletionResult.Failure(TangemSdkError.ExendedDataSizeTooLarge()))
return true
}
if (!isCounterValid(issuerDataCounter, card)) {

View file

@ -6,12 +6,10 @@ import android.view.HapticFeedbackConstants
import android.view.View
import android.view.animation.DecelerateInterpolator
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tangem.Log
import com.tangem.LoggerInterface
import com.tangem.Message
import com.tangem.SessionViewDelegate
import com.tangem.*
import com.tangem.common.CompletionResult
import com.tangem.tangem_sdk_new.extensions.hide
import com.tangem.tangem_sdk_new.extensions.localizedDescription
import com.tangem.tangem_sdk_new.extensions.show
import com.tangem.tangem_sdk_new.nfc.NfcReader
import com.tangem.tangem_sdk_new.ui.TouchCardAnimation
@ -142,14 +140,17 @@ class DefaultSessionViewDelegate(private val reader: NfcReader) : SessionViewDel
postUI(300) { readingDialog?.dismiss() }
}
override fun onError(errorMessage: String) {
override fun onError(error: TangemSdkError) {
postUI {
readingDialog?.lTouchCard?.hide()
readingDialog?.flSecurityDelay?.hide()
readingDialog?.flCompletion?.hide()
readingDialog?.flError?.show()
readingDialog?.tvTaskTitle?.text = activity.getText(R.string.dialog_error)
readingDialog?.tvTaskText?.text = errorMessage
readingDialog?.tvTaskText?.text = activity.getString(
R.string.error_message,
error.code.toString(), activity.getString(error.localizedDescription())
)
performHapticFeedback()
}
}

View file

@ -0,0 +1,56 @@
package com.tangem.tangem_sdk_new.extensions
import com.tangem.TangemSdkError
import com.tangem.tangem_sdk_new.R
fun TangemSdkError.localizedDescription(): Int {
return when (this) {
is TangemSdkError.TagLost -> R.string.error_tag_lost
is TangemSdkError.ExtendedLengthNotSupported -> R.string.error_operation
is TangemSdkError.SerializeCommandError -> R.string.error_operation
is TangemSdkError.DeserializeApduFailed -> R.string.error_operation
is TangemSdkError.EncodingFailedTypeMismatch -> R.string.error_operation
is TangemSdkError.EncodingFailed -> R.string.error_operation
is TangemSdkError.DecodingFailedMissingTag -> R.string.error_operation
is TangemSdkError.DecodingFailedTypeMismatch -> R.string.error_operation
is TangemSdkError.DecodingFailed -> R.string.error_operation
is TangemSdkError.UnknownStatus -> R.string.error_operation
is TangemSdkError.ErrorProcessingCommand -> R.string.error_operation
is TangemSdkError.InvalidState -> R.string.error_operation
is TangemSdkError.InsNotSupported -> R.string.error_operation
is TangemSdkError.InvalidParams -> R.string.error_operation
is TangemSdkError.NeedEncryption -> R.string.error_operation
is TangemSdkError.AlreadyPersonalized -> R.string.error_already_personalized
is TangemSdkError.CannotBeDepersonalized -> R.string.error_cannot_be_depersonalized
is TangemSdkError.Pin1Required -> R.string.error_operation
is TangemSdkError.AlreadyCreated -> R.string.error_already_created
is TangemSdkError.PurgeWalletProhibited -> R.string.error_purge_prohibited
is TangemSdkError.Pin1CannotBeChanged -> R.string.error_pin1_cannot_be_changed
is TangemSdkError.Pin2CannotBeChanged -> R.string.error_pin2_cannot_be_changed
is TangemSdkError.Pin1CannotBeDefault -> R.string.error_pin1_cannot_be_default
is TangemSdkError.NoRemainingSignatures -> R.string.error_no_remaining_signatures
is TangemSdkError.EmptyHashes -> R.string.error_empty_hashes
is TangemSdkError.HashSizeMustBeEqual -> R.string.error_cannot_be_signed
is TangemSdkError.CardIsEmpty -> R.string.error_card_is_empty
is TangemSdkError.SignHashesNotAvailable -> R.string.error_cannot_be_signed
is TangemSdkError.TooManyHashesInOneTransaction -> R.string.error_cannot_be_signed
is TangemSdkError.NotPersonalized -> R.string.error_not_personalized
is TangemSdkError.NotActivated -> R.string.error_not_activated
is TangemSdkError.CardIsPurged -> R.string.error_purged
is TangemSdkError.Pin2OrCvcRequired -> R.string.error_operation
is TangemSdkError.VerificationFailed -> R.string.error_verification_failed
is TangemSdkError.DataSizeTooLarge -> R.string.error_data_size_too_large
is TangemSdkError.ExendedDataSizeTooLarge -> R.string.error_data_size_too_large_extended
is TangemSdkError.MissingCounter -> R.string.error_missing_counter
is TangemSdkError.OverwritingDataIsProhibited -> R.string.error_data_cannot_be_written
is TangemSdkError.DataCannotBeWritten -> R.string.error_data_cannot_be_written
is TangemSdkError.MissingIssuerPubicKey -> R.string.error_missing_issuer_public_key
is TangemSdkError.UnknownError -> R.string.error_operation
is TangemSdkError.UserCancelled -> R.string.error_user_cancelled
is TangemSdkError.Busy -> R.string.error_busy
is TangemSdkError.MissingPreflightRead -> R.string.error_operation
is TangemSdkError.WrongCardNumber -> R.string.error_wrong_card_number
is TangemSdkError.WrongCardType -> R.string.error_wrong_card_type
is TangemSdkError.CardError -> R.string.error_card_error
}
}

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="error_message" translatable="false">%s: %s</string>
<string name="error_operation">An error occurred during the operation</string>
<string name="error_tag_lost">Tag lost.</string>
<string name="error_already_personalized">This card has already been personalized</string>
<string name="error_cannot_be_depersonalized">This card cannot be depersonalized</string>
<string name="error_already_created">A wallet has already been created</string>
<string name="error_purge_prohibited">This cards configuration does not allow you to erase the wallet</string>
<string name="error_pin1_cannot_be_changed">PIN1 Access Code cannot be changed</string>
<string name="error_pin2_cannot_be_changed">PIN2 Passcode cannot be changed</string>
<string name="error_pin1_cannot_be_default"> PIN1 Access Code cannot be changed to the default value. Please create a new PIN1 Access Code.</string>
<string name="error_no_remaining_signatures"> You cannot sign data with this wallet because the card has reached its signature limit</string>
<string name="error_empty_hashes">There is nothing to sign here</string>
<string name="error_cannot_be_signed"> This data cannot be signed</string>
<string name="error_card_is_empty">Please create a wallet to sign data</string>
<string name="error_not_personalized">This card has not been personalized</string>
<string name="error_not_activated">This card has not been activated</string>
<string name="error_purged">You cannot sign data with this wallet because the card has been purged</string>
<string name="error_verification_failed">Data verification failed</string>
<string name="error_data_size_too_large">Data size exceeds the max limit of 512 bytes</string>
<string name="error_data_size_too_large_extended">Data size exceeds the max limit of 32 Kbytes</string>
<string name="error_missing_counter">The data cannot be written to the card because there is no counter</string>
<string name="error_data_cannot_be_written">The data cannot be written to the card</string>
<string name="error_missing_issuer_public_key">The issuer public key is missing</string>
<string name="error_user_cancelled">The user cancelled the operation</string>
<string name="error_busy">The CardSession is running a command. Please wait and try again</string>
<string name="error_wrong_card_number">You tapped a different card. Please match the in-app Card ID to the your physical Card ID to continue this process.</string>
<string name="error_wrong_card_type">This card is configured for a different app. Please see the information on your card and download the related app.</string>
<string name="error_card_error">Your card is missing essential data</string>
</resources>