From 1afa4a5d0e84fd563135ace691e7acbabd839664 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 13 Apr 2026 16:38:04 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/data/wallets/DefaultWalletsRepository.kt | 10 ++++++++-- .../domain/wallets/models/WalletSyncResult.kt | 6 ++++++ .../domain/wallets/repository/WalletsRepository.kt | 3 ++- .../wallets/usecase/SyncWalletWithRemoteUseCase.kt | 6 ++++-- .../im/port/model/AddExistingWalletImportModel.kt | 13 +++++++++++-- 5 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/WalletSyncResult.kt diff --git a/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt b/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt index 5a5278632e..f748ce863f 100644 --- a/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt +++ b/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt @@ -24,6 +24,7 @@ import com.tangem.domain.common.wallets.getSyncStrict import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.wallets.models.UserWalletRemoteInfo +import com.tangem.domain.wallets.models.WalletSyncResult import com.tangem.domain.wallets.models.errors.ActivatePromoCodeError import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.utils.coroutines.CoroutineDispatcherProvider @@ -118,8 +119,13 @@ internal class DefaultWalletsRepository( } } - override suspend fun createWallet(userWalletId: UserWalletId) { - walletServerBinder.bind(userWalletId) + override suspend fun createWallet(userWalletId: UserWalletId): WalletSyncResult { + val response = walletServerBinder.bind(userWalletId) ?: return WalletSyncResult.AlreadyExists + return if (response is ApiResponse.Success && response.code == HttpException.Code.CREATED) { + WalletSyncResult.Created + } else { + WalletSyncResult.AlreadyExists + } } override fun nftEnabledStatus(userWalletId: UserWalletId): Flow = appPreferencesStore diff --git a/domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/WalletSyncResult.kt b/domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/WalletSyncResult.kt new file mode 100644 index 0000000000..48c7caae72 --- /dev/null +++ b/domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/WalletSyncResult.kt @@ -0,0 +1,6 @@ +package com.tangem.domain.wallets.models + +enum class WalletSyncResult { + AlreadyExists, + Created, +} \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/repository/WalletsRepository.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/repository/WalletsRepository.kt index 2b25388b1e..33686eea83 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/repository/WalletsRepository.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/repository/WalletsRepository.kt @@ -4,6 +4,7 @@ import arrow.core.Either import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.wallets.models.UserWalletRemoteInfo +import com.tangem.domain.wallets.models.WalletSyncResult import com.tangem.domain.wallets.models.errors.ActivatePromoCodeError import kotlinx.coroutines.flow.Flow @@ -22,7 +23,7 @@ interface WalletsRepository { suspend fun setHasWalletsWithRing(userWalletId: UserWalletId) - suspend fun createWallet(userWalletId: UserWalletId) + suspend fun createWallet(userWalletId: UserWalletId): WalletSyncResult fun nftEnabledStatus(userWalletId: UserWalletId): Flow diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SyncWalletWithRemoteUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SyncWalletWithRemoteUseCase.kt index 063dd3380d..82ebc8e397 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SyncWalletWithRemoteUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SyncWalletWithRemoteUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.wallets.usecase import com.tangem.domain.models.wallet.UserWalletId +import com.tangem.domain.wallets.models.WalletSyncResult import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.utils.coroutines.runSuspendCatching import com.tangem.utils.logging.TangemLogger @@ -14,8 +15,9 @@ class SyncWalletWithRemoteUseCase( private val walletsRepository: WalletsRepository, ) { - suspend operator fun invoke(userWalletId: UserWalletId) { - runSuspendCatching { walletsRepository.createWallet(userWalletId) } + suspend operator fun invoke(userWalletId: UserWalletId): WalletSyncResult { + return runSuspendCatching { walletsRepository.createWallet(userWalletId) } .onFailure { TangemLogger.e("Error", it) } + .getOrDefault(WalletSyncResult.AlreadyExists) } } \ No newline at end of file diff --git a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/im/port/model/AddExistingWalletImportModel.kt b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/im/port/model/AddExistingWalletImportModel.kt index ce2c9cb8f9..6c6efa8ece 100644 --- a/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/im/port/model/AddExistingWalletImportModel.kt +++ b/features/hot-wallet/impl/src/main/kotlin/com/tangem/features/hotwallet/addexistingwallet/im/port/model/AddExistingWalletImportModel.kt @@ -19,7 +19,9 @@ import com.tangem.datasource.local.appsflyer.AppsFlyerStore import com.tangem.domain.common.wallets.error.SaveWalletError import com.tangem.domain.assetsdiscovery.usecase.StartAssetsDiscoveryUseCase import com.tangem.domain.wallets.builder.HotUserWalletBuilder +import com.tangem.domain.wallets.models.WalletSyncResult import com.tangem.domain.wallets.usecase.SaveWalletUseCase +import com.tangem.domain.wallets.usecase.SyncWalletWithRemoteUseCase import com.tangem.features.hotwallet.HotWalletFeatureToggles import com.tangem.features.hotwallet.MnemonicRepository import com.tangem.features.hotwallet.addexistingwallet.im.port.AddExistingWalletImportComponent @@ -27,6 +29,7 @@ import com.tangem.features.hotwallet.addexistingwallet.im.port.entity.AddExistin import com.tangem.hot.sdk.TangemHotSdk import com.tangem.hot.sdk.model.HotAuth import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update @@ -42,6 +45,7 @@ internal class AddExistingWalletImportModel @Inject constructor( private val tangemHotSdk: TangemHotSdk, private val hotUserWalletBuilderFactory: HotUserWalletBuilder.Factory, private val saveUserWalletUseCase: SaveWalletUseCase, + private val syncWalletWithRemoteUseCase: SyncWalletWithRemoteUseCase, private val startAssetsDiscoveryUseCase: StartAssetsDiscoveryUseCase, private val hotWalletFeatureToggles: HotWalletFeatureToggles, @GlobalUiMessageSender private val uiMessageSender: UiMessageSender, @@ -114,8 +118,13 @@ internal class AddExistingWalletImportModel @Inject constructor( .onRight { setImportProgress(false) - if (hotWalletFeatureToggles.isAssetsDiscoveryEnabled) { - startAssetsDiscoveryUseCase(userWallet.walletId) + launch(dispatchers.main + NonCancellable) { + val syncResult = syncWalletWithRemoteUseCase(userWallet.walletId) + if (hotWalletFeatureToggles.isAssetsDiscoveryEnabled && + syncResult == WalletSyncResult.Created + ) { + startAssetsDiscoveryUseCase(userWallet.walletId) + } } analyticsEventHandler.send(