diff --git a/tangem-core/src/main/java/com/tangem/CardSession.kt b/tangem-core/src/main/java/com/tangem/CardSession.kt index b2971b2758..c7fa4559e7 100644 --- a/tangem-core/src/main/java/com/tangem/CardSession.kt +++ b/tangem-core/src/main/java/com/tangem/CardSession.kt @@ -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") } diff --git a/tangem-core/src/main/java/com/tangem/SessionViewDelegate.kt b/tangem-core/src/main/java/com/tangem/SessionViewDelegate.kt index c372b1730c..969b147b8f 100644 --- a/tangem-core/src/main/java/com/tangem/SessionViewDelegate.kt +++ b/tangem-core/src/main/java/com/tangem/SessionViewDelegate.kt @@ -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. diff --git a/tangem-core/src/main/java/com/tangem/TangemSdkError.kt b/tangem-core/src/main/java/com/tangem/TangemSdkError.kt index bcf51d0617..4aabb3da6b 100644 --- a/tangem-core/src/main/java/com/tangem/TangemSdkError.kt +++ b/tangem-core/src/main/java/com/tangem/TangemSdkError.kt @@ -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. diff --git a/tangem-core/src/main/java/com/tangem/commands/SignCommand.kt b/tangem-core/src/main/java/com/tangem/commands/SignCommand.kt index 607ad41cd7..fc926be116 100644 --- a/tangem-core/src/main/java/com/tangem/commands/SignCommand.kt +++ b/tangem-core/src/main/java/com/tangem/commands/SignCommand.kt @@ -112,7 +112,7 @@ class SignCommand(private val hashes: Array) 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() } diff --git a/tangem-core/src/main/java/com/tangem/commands/WriteIssuerExtraDataCommand.kt b/tangem-core/src/main/java/com/tangem/commands/WriteIssuerExtraDataCommand.kt index 8cb0dfc949..84e0b50851 100644 --- a/tangem-core/src/main/java/com/tangem/commands/WriteIssuerExtraDataCommand.kt +++ b/tangem-core/src/main/java/com/tangem/commands/WriteIssuerExtraDataCommand.kt @@ -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)) { diff --git a/tangem-sdk/src/main/java/com/tangem/tangem_sdk_new/DefaultSessionViewDelegate.kt b/tangem-sdk/src/main/java/com/tangem/tangem_sdk_new/DefaultSessionViewDelegate.kt index a15f16521e..d8ca2ad645 100644 --- a/tangem-sdk/src/main/java/com/tangem/tangem_sdk_new/DefaultSessionViewDelegate.kt +++ b/tangem-sdk/src/main/java/com/tangem/tangem_sdk_new/DefaultSessionViewDelegate.kt @@ -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() } } diff --git a/tangem-sdk/src/main/java/com/tangem/tangem_sdk_new/extensions/TangemSdkError.kt b/tangem-sdk/src/main/java/com/tangem/tangem_sdk_new/extensions/TangemSdkError.kt new file mode 100644 index 0000000000..09c84716e4 --- /dev/null +++ b/tangem-sdk/src/main/java/com/tangem/tangem_sdk_new/extensions/TangemSdkError.kt @@ -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 + } +} \ No newline at end of file diff --git a/tangem-sdk/src/main/res/values/strings_errors.xml b/tangem-sdk/src/main/res/values/strings_errors.xml new file mode 100644 index 0000000000..b41a0e5d1f --- /dev/null +++ b/tangem-sdk/src/main/res/values/strings_errors.xml @@ -0,0 +1,32 @@ + + + %s: %s + + An error occurred during the operation + Tag lost. + This card has already been personalized + This card cannot be depersonalized + A wallet has already been created + This card’s configuration does not allow you to erase the wallet + PIN1 Access Code cannot be changed + PIN2 Passcode cannot be changed + PIN1 Access Code cannot be changed to the default value. Please create a new PIN1 Access Code. + You cannot sign data with this wallet because the card has reached its signature limit + There is nothing to sign here + This data cannot be signed + Please create a wallet to sign data + This card has not been personalized + This card has not been activated + You cannot sign data with this wallet because the card has been purged + Data verification failed + Data size exceeds the max limit of 512 bytes + Data size exceeds the max limit of 32 Kbytes + The data cannot be written to the card because there is no counter + The data cannot be written to the card + The issuer public key is missing + The user cancelled the operation + The CardSession is running a command. Please wait and try again + You tapped a different card. Please match the in-app Card ID to the your physical Card ID to continue this process. + This card is configured for a different app. Please see the information on your card and download the related app. + Your card is missing essential data + \ No newline at end of file