From d9bbb09aef69fce3650ea7c36e00291f4c2cc852 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 17 Nov 2025 12:55:48 +0200 Subject: [PATCH] Updated on 2026-08-14 --- .../main/java/com/tangem/tap/common/images/Coil.kt | 4 ++-- .../com/tangem/tap/common/ui/SimpleAlertDialog.kt | 4 ++-- .../repository/DefaultUserWalletsListRepository.kt | 7 ++++--- .../tap/features/welcome/model/WelcomeModel.kt | 10 +++++++--- .../network/exchangeServices/DefaultRampManager.kt | 5 +++-- .../java/com/tangem/utils/coroutines/CoroutineExt.kt | 10 ++++++++++ .../blockchainsdk/utils/ExcludedBlockchains.kt | 12 ++++++------ tangem-android-tools | 2 +- 8 files changed, 35 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/common/images/Coil.kt b/app/src/main/java/com/tangem/tap/common/images/Coil.kt index 328a1d431e..39b02987d6 100644 --- a/app/src/main/java/com/tangem/tap/common/images/Coil.kt +++ b/app/src/main/java/com/tangem/tap/common/images/Coil.kt @@ -54,8 +54,8 @@ private class CoilTimberLogger : Logger { override fun log(tag: String, priority: Int, message: String?, throwable: Throwable?) { with(Timber.tag(COIL_LOG_TAG)) { - throwable?.let { e -> e(e, message) } - message?.let { msg -> d(msg) } + if (throwable != null) e(throwable, message) + if (message != null) d(message) } } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt b/app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt index 3cd171d04a..078691ca7c 100644 --- a/app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt +++ b/app/src/main/java/com/tangem/tap/common/ui/SimpleAlertDialog.kt @@ -41,8 +41,8 @@ object SimpleCancelableAlertDialog { context: Context, ): AlertDialog { return MaterialAlertDialogBuilder(context, R.style.CustomMaterialDialog).apply { - setTitle(titleRes?.let { context.getString(it) } ?: title) - setMessage(messageRes?.let { context.getString(it) } ?: message) + setTitle(if (titleRes != null) context.getString(titleRes) else title) + setMessage(if (messageRes != null) context.getString(messageRes) else message) setPositiveButton(context.getText(primaryButtonRes)) { _, _ -> primaryButtonAction() } if (secondaryButtonRes != null) { setNegativeButton(context.getText(secondaryButtonRes)) { _, _ -> secondaryButtonAction() } diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DefaultUserWalletsListRepository.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DefaultUserWalletsListRepository.kt index c3a79f47fa..4f38f8e6ce 100644 --- a/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DefaultUserWalletsListRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/repository/DefaultUserWalletsListRepository.kt @@ -27,6 +27,7 @@ import com.tangem.tap.domain.userWalletList.utils.toUserWallets import com.tangem.tap.domain.userWalletList.utils.updateWith import com.tangem.utils.Provider import com.tangem.utils.ProviderSuspend +import com.tangem.utils.coroutines.runSuspendCatching import com.tangem.utils.extensions.indexOfFirstOrNull import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update @@ -149,7 +150,7 @@ internal class DefaultUserWalletsListRepository( val encryptionKey = userWallet.encryptionKey ?: raise(SetLockError.UserWalletLocked) - runCatching { + runSuspendCatching { userWalletEncryptionKeysRepository.save( encryptionKey = UserWalletEncryptionKey( walletId = userWalletId, @@ -232,7 +233,7 @@ internal class DefaultUserWalletsListRepository( val encryptionKey = requestPasswordRecursive( hotWalletId = userWallet.hotWalletId, block = { password -> - runCatching { + runSuspendCatching { userWalletEncryptionKeysRepository.getEncryptedWithPassword(userWalletId, password) }.onFailure { raise(UnlockWalletError.UnableToUnlock) @@ -288,7 +289,7 @@ internal class DefaultUserWalletsListRepository( override suspend fun unlockAllWallets(): Either = either { val userWallets = userWalletsSync() - val biometricKeys = runCatching { + val biometricKeys = runSuspendCatching { userWalletEncryptionKeysRepository.getAllBiometric() }.getOrElse { // TODO handle error properly [REDACTED_TASK_KEY] diff --git a/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt b/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt index f6e882e5fb..9ca6d43223 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt @@ -77,9 +77,13 @@ internal class WelcomeModel @Inject constructor( warning = warning, error = state.error ?.takeIf { !it.silent && warning == null } - ?.let { e -> - e.messageResId?.let { TextReference.Res(it) } - ?: TextReference.Str(e.customMessage) + ?.let { error -> + val messageResId = error.messageResId + if (messageResId != null) { + TextReference.Res(messageResId) + } else { + TextReference.Str(error.customMessage) + } }, ) } diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt index 9b9018f1ba..bd69d9835d 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt @@ -20,6 +20,7 @@ import com.tangem.domain.transaction.models.AssetRequirementsCondition import com.tangem.utils.Provider import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.runCatching +import com.tangem.utils.coroutines.runSuspendCatching import com.tangem.utils.isNullOrZero import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.firstOrNull @@ -35,7 +36,7 @@ internal class DefaultRampManager( userWallet: UserWallet, cryptoCurrency: CryptoCurrency, ): ScenarioUnavailabilityReason { - val availabilityState = runCatching { getOnrampAvailableState(userWallet.walletId, cryptoCurrency) } + val availabilityState = runSuspendCatching { getOnrampAvailableState(userWallet.walletId, cryptoCurrency) } .getOrNull() ?: ExpressAvailabilityState.Error @@ -84,7 +85,7 @@ internal class DefaultRampManager( userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency, ): ScenarioUnavailabilityReason { - val availabilityState = runCatching { + val availabilityState = runSuspendCatching { getExchangeableState(userWalletId, cryptoCurrency) }.getOrNull() ?: ExpressAvailabilityState.Error return availabilityState.toReason(cryptoCurrency.name) diff --git a/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt b/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt index b57c8e0015..8a2fd97b72 100644 --- a/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt +++ b/core/utils/src/main/java/com/tangem/utils/coroutines/CoroutineExt.kt @@ -19,6 +19,16 @@ suspend fun waitForDelay(delay: Long, block: suspend CoroutineScope.() -> R) actionInvoke.await() } +suspend inline fun T.runSuspendCatching(block: suspend T.() -> R): Result { + return try { + Result.success(block()) + } catch (e: CancellationException) { + throw e + } catch (e: Throwable) { + Result.failure(e) + } +} + class Debouncer { private var debounceJob: Job? = null diff --git a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/ExcludedBlockchains.kt b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/ExcludedBlockchains.kt index 18125a1152..4b509a9370 100644 --- a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/ExcludedBlockchains.kt +++ b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/ExcludedBlockchains.kt @@ -10,7 +10,7 @@ class ExcludedBlockchains @Inject internal constructor( private val excludedBlockchainsManager: ExcludedBlockchainsManager, ) : Set { - private val excludedBlockchains: Set by lazy(mode = LazyThreadSafetyMode.NONE) { + private val excludedBlockchainsSet: Set by lazy(mode = LazyThreadSafetyMode.NONE) { excludedBlockchainsManager.excludedBlockchainsIds.fold(mutableSetOf()) { acc, blockchainId -> val blockchain = Blockchain.fromId(blockchainId) acc.add(blockchain) @@ -22,7 +22,7 @@ class ExcludedBlockchains @Inject internal constructor( } override val size: Int - get() = excludedBlockchains.size + get() = excludedBlockchainsSet.size @TestOnly constructor() : this( @@ -32,11 +32,11 @@ class ExcludedBlockchains @Inject internal constructor( }, ) - override fun contains(element: Blockchain): Boolean = excludedBlockchains.contains(element) + override fun contains(element: Blockchain): Boolean = excludedBlockchainsSet.contains(element) - override fun containsAll(elements: Collection): Boolean = excludedBlockchains.containsAll(elements) + override fun containsAll(elements: Collection): Boolean = excludedBlockchainsSet.containsAll(elements) - override fun isEmpty(): Boolean = excludedBlockchains.isEmpty() + override fun isEmpty(): Boolean = excludedBlockchainsSet.isEmpty() - override fun iterator(): Iterator = excludedBlockchains.iterator() + override fun iterator(): Iterator = excludedBlockchainsSet.iterator() } \ No newline at end of file diff --git a/tangem-android-tools b/tangem-android-tools index 193db8a024..92c1bfd312 160000 --- a/tangem-android-tools +++ b/tangem-android-tools @@ -1 +1 @@ -Subproject commit 193db8a0247a1f33574dcdd5f9ec4dab2c28ea73 +Subproject commit 92c1bfd3123f0b2fd9e5a80b9d69bbc17a6e1160