diff --git a/core/res/src/main/res/values/strings.xml b/core/res/src/main/res/values/strings.xml index 9499629f9e..886d47ca48 100644 --- a/core/res/src/main/res/values/strings.xml +++ b/core/res/src/main/res/values/strings.xml @@ -1420,7 +1420,7 @@ This is a Testnet card. It cannot process transactions and should only be used for testing and development purposes. For testing purposes only Balance may be outdated. Refresh the page. - Not enough %1$s. Top up your XLM account to associate this token + Not enough %1$s. Top up your %2$s account to associate this token Enable Trustline A Trustline must be enabled to receive this token. The network requires a %1$s %2$s reserve. Trustline Required diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/error/OpenTrustlineError.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/OpenTrustlineError.kt index a71270bf29..ab53c5ec62 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/error/OpenTrustlineError.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/OpenTrustlineError.kt @@ -3,8 +3,8 @@ package com.tangem.domain.transaction.error import java.math.BigDecimal sealed interface OpenTrustlineError { - val message: String? - data class SomeError(override val message: String?) : OpenTrustlineError - data class NotEnoughCoin(val amount: BigDecimal, override val message: String?) : OpenTrustlineError + data class UnknownError(val message: String?) : OpenTrustlineError + data class SendError(val error: SendTransactionError) : OpenTrustlineError + data class NotEnoughCoin(val amount: BigDecimal, val symbol: String, val message: String?) : OpenTrustlineError } \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/OpenTrustlineUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/OpenTrustlineUseCase.kt index 6f2fc407d4..847f9ced22 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/OpenTrustlineUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/OpenTrustlineUseCase.kt @@ -8,6 +8,7 @@ import com.tangem.blockchain.extensions.SimpleResult import com.tangem.domain.card.repository.CardSdkConfigRepository import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.transaction.error.OpenTrustlineError +import com.tangem.domain.transaction.error.parseWrappedError import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.models.UserWalletId @@ -31,15 +32,29 @@ class OpenTrustlineUseCase( when (val result = walletManagersFacade.fulfillRequirements(userWalletId, currency, signer)) { is SimpleResult.Failure -> when (val error = result.error) { is BlockchainSdkError.Stellar.MinReserveRequired -> - raise(OpenTrustlineError.NotEnoughCoin(error.amount, result.error.customMessage)) + raise( + OpenTrustlineError.NotEnoughCoin( + amount = error.amount, + symbol = error.symbol, + message = result.error.customMessage, + ), + ) is BlockchainSdkError.Xrp.MinReserveRequired -> - raise(OpenTrustlineError.NotEnoughCoin(error.amount, result.error.customMessage)) - else -> raise(OpenTrustlineError.SomeError(result.error.customMessage)) + raise( + OpenTrustlineError.NotEnoughCoin( + amount = error.amount, + symbol = error.symbol, + message = result.error.customMessage, + ), + ) + is BlockchainSdkError.WrappedTangemError -> + raise(OpenTrustlineError.SendError(parseWrappedError(error))) + else -> raise(OpenTrustlineError.UnknownError(result.error.customMessage)) } SimpleResult.Success -> Unit } }, - catch = { error -> raise(OpenTrustlineError.SomeError(error.message)) }, + catch = { error -> raise(OpenTrustlineError.UnknownError(error.message)) }, ) } } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt index d2d966d302..ae48c2de2d 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt @@ -909,18 +909,25 @@ internal class TokenDetailsModel @Inject constructor( currency = cryptoCurrency, ).fold( ifLeft = { e -> - Timber.e(e.message) - internalUiState.value = when (e) { - is OpenTrustlineError.SomeError -> - stateFactory.getStateWithErrorDialog(stringReference(e.message.orEmpty())) - is OpenTrustlineError.NotEnoughCoin -> { - val text = resourceReference( - id = R.string.warning_token_required_min_coin_reserve, - formatArgs = wrappedList(e.amount), - ) - stateFactory.getStateWithErrorDialog(text) - } + val message: TextReference? = when (e) { + is OpenTrustlineError.UnknownError -> e.message?.let { stringReference(it) } + is OpenTrustlineError.NotEnoughCoin -> resourceReference( + id = R.string.warning_token_required_min_coin_reserve, + formatArgs = wrappedList(e.amount, e.symbol), + ) + is OpenTrustlineError.SendError -> when (val error = e.error) { + is SendTransactionError.UserCancelledError, + is SendTransactionError.CreateAccountUnderfunded, + is SendTransactionError.TangemSdkError, + is SendTransactionError.DemoCardError, + -> null + is SendTransactionError.DataError -> error.message + is SendTransactionError.BlockchainSdkError -> error.message + is SendTransactionError.NetworkError -> error.message + is SendTransactionError.UnknownError -> error.ex?.localizedMessage + }?.let { stringReference(it) } } + message?.let { internalUiState.value = stateFactory.getStateWithErrorDialog(message) } }, ifRight = { internalUiState.value = stateFactory.getStateWithRemovedRequiredTrustlineNotification() }, )