Updated on 2026-08-14

This commit is contained in:
Tangem 2026-04-13 16:38:04 +05:00
parent 9ef791c432
commit 1afa4a5d0e
5 changed files with 31 additions and 7 deletions

View file

@ -24,6 +24,7 @@ import com.tangem.domain.common.wallets.getSyncStrict
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.wallets.models.UserWalletRemoteInfo 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.models.errors.ActivatePromoCodeError
import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.CoroutineDispatcherProvider
@ -118,8 +119,13 @@ internal class DefaultWalletsRepository(
} }
} }
override suspend fun createWallet(userWalletId: UserWalletId) { override suspend fun createWallet(userWalletId: UserWalletId): WalletSyncResult {
walletServerBinder.bind(userWalletId) 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<Boolean> = appPreferencesStore override fun nftEnabledStatus(userWalletId: UserWalletId): Flow<Boolean> = appPreferencesStore

View file

@ -0,0 +1,6 @@
package com.tangem.domain.wallets.models
enum class WalletSyncResult {
AlreadyExists,
Created,
}

View file

@ -4,6 +4,7 @@ import arrow.core.Either
import com.tangem.domain.models.wallet.UserWallet import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.wallets.models.UserWalletRemoteInfo 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.models.errors.ActivatePromoCodeError
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -22,7 +23,7 @@ interface WalletsRepository {
suspend fun setHasWalletsWithRing(userWalletId: UserWalletId) suspend fun setHasWalletsWithRing(userWalletId: UserWalletId)
suspend fun createWallet(userWalletId: UserWalletId) suspend fun createWallet(userWalletId: UserWalletId): WalletSyncResult
fun nftEnabledStatus(userWalletId: UserWalletId): Flow<Boolean> fun nftEnabledStatus(userWalletId: UserWalletId): Flow<Boolean>

View file

@ -1,6 +1,7 @@
package com.tangem.domain.wallets.usecase package com.tangem.domain.wallets.usecase
import com.tangem.domain.models.wallet.UserWalletId import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.wallets.models.WalletSyncResult
import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.utils.coroutines.runSuspendCatching import com.tangem.utils.coroutines.runSuspendCatching
import com.tangem.utils.logging.TangemLogger import com.tangem.utils.logging.TangemLogger
@ -14,8 +15,9 @@ class SyncWalletWithRemoteUseCase(
private val walletsRepository: WalletsRepository, private val walletsRepository: WalletsRepository,
) { ) {
suspend operator fun invoke(userWalletId: UserWalletId) { suspend operator fun invoke(userWalletId: UserWalletId): WalletSyncResult {
runSuspendCatching { walletsRepository.createWallet(userWalletId) } return runSuspendCatching { walletsRepository.createWallet(userWalletId) }
.onFailure { TangemLogger.e("Error", it) } .onFailure { TangemLogger.e("Error", it) }
.getOrDefault(WalletSyncResult.AlreadyExists)
} }
} }

View file

@ -19,7 +19,9 @@ import com.tangem.datasource.local.appsflyer.AppsFlyerStore
import com.tangem.domain.common.wallets.error.SaveWalletError import com.tangem.domain.common.wallets.error.SaveWalletError
import com.tangem.domain.assetsdiscovery.usecase.StartAssetsDiscoveryUseCase import com.tangem.domain.assetsdiscovery.usecase.StartAssetsDiscoveryUseCase
import com.tangem.domain.wallets.builder.HotUserWalletBuilder 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.SaveWalletUseCase
import com.tangem.domain.wallets.usecase.SyncWalletWithRemoteUseCase
import com.tangem.features.hotwallet.HotWalletFeatureToggles import com.tangem.features.hotwallet.HotWalletFeatureToggles
import com.tangem.features.hotwallet.MnemonicRepository import com.tangem.features.hotwallet.MnemonicRepository
import com.tangem.features.hotwallet.addexistingwallet.im.port.AddExistingWalletImportComponent 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.TangemHotSdk
import com.tangem.hot.sdk.model.HotAuth import com.tangem.hot.sdk.model.HotAuth
import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update import kotlinx.coroutines.flow.update
@ -42,6 +45,7 @@ internal class AddExistingWalletImportModel @Inject constructor(
private val tangemHotSdk: TangemHotSdk, private val tangemHotSdk: TangemHotSdk,
private val hotUserWalletBuilderFactory: HotUserWalletBuilder.Factory, private val hotUserWalletBuilderFactory: HotUserWalletBuilder.Factory,
private val saveUserWalletUseCase: SaveWalletUseCase, private val saveUserWalletUseCase: SaveWalletUseCase,
private val syncWalletWithRemoteUseCase: SyncWalletWithRemoteUseCase,
private val startAssetsDiscoveryUseCase: StartAssetsDiscoveryUseCase, private val startAssetsDiscoveryUseCase: StartAssetsDiscoveryUseCase,
private val hotWalletFeatureToggles: HotWalletFeatureToggles, private val hotWalletFeatureToggles: HotWalletFeatureToggles,
@GlobalUiMessageSender private val uiMessageSender: UiMessageSender, @GlobalUiMessageSender private val uiMessageSender: UiMessageSender,
@ -114,8 +118,13 @@ internal class AddExistingWalletImportModel @Inject constructor(
.onRight { .onRight {
setImportProgress(false) setImportProgress(false)
if (hotWalletFeatureToggles.isAssetsDiscoveryEnabled) { launch(dispatchers.main + NonCancellable) {
startAssetsDiscoveryUseCase(userWallet.walletId) val syncResult = syncWalletWithRemoteUseCase(userWallet.walletId)
if (hotWalletFeatureToggles.isAssetsDiscoveryEnabled &&
syncResult == WalletSyncResult.Created
) {
startAssetsDiscoveryUseCase(userWallet.walletId)
}
} }
analyticsEventHandler.send( analyticsEventHandler.send(