Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-01 23:03:36 +07:00
parent aee6f2b131
commit fa6b5817bf
4 changed files with 41 additions and 19 deletions

View file

@ -1420,7 +1420,7 @@
<string name="warning_testnet_card_message">This is a Testnet card. It cannot process transactions and should only be used for testing and development purposes.</string>
<string name="warning_testnet_card_title">For testing purposes only</string>
<string name="warning_token_balance_not_updated">Balance may be outdated. Refresh the page.</string>
<string name="warning_token_required_min_coin_reserve">Not enough %1$s. Top up your XLM account to associate this token</string>
<string name="warning_token_required_min_coin_reserve">Not enough %1$s. Top up your %2$s account to associate this token</string>
<string name="warning_token_trustline_button_title">Enable Trustline</string>
<string name="warning_token_trustline_subtitle">A Trustline must be enabled to receive this token. The network requires a %1$s %2$s reserve.</string>
<string name="warning_token_trustline_title">Trustline Required</string>

View file

@ -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
}

View file

@ -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)) },
)
}
}

View file

@ -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() },
)