Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-10 13:29:55 +04:00
parent 208e63c414
commit 8adc179449
22 changed files with 175 additions and 212 deletions

View file

@ -21,6 +21,7 @@ dependencies {
implementation(projects.data.common)
/** Domain */
implementation(projects.domain.common)
implementation(projects.domain.express.models)
implementation(projects.domain.express)
implementation(projects.domain.wallets.models)

View file

@ -10,7 +10,7 @@ import com.tangem.datasource.api.express.models.request.LeastTokenInfo
import com.tangem.datasource.exchangeservice.swap.ExpressUtils.getRefCode
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.token.ExpressAssetsStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.lce.Lce
import com.tangem.domain.core.utils.catchOn
import com.tangem.domain.core.utils.lceContent
@ -42,7 +42,7 @@ internal class DefaultExpressServiceFetcher @Inject constructor(
private val tangemExpressApi: TangemExpressApi,
private val expressAssetsStore: ExpressAssetsStore,
private val appPreferencesStore: AppPreferencesStore,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val dispatchers: CoroutineDispatcherProvider,
) : ExpressServiceFetcher {
@ -52,7 +52,7 @@ internal class DefaultExpressServiceFetcher @Inject constructor(
override suspend fun fetch(userWalletId: UserWalletId, assetIds: Set<ExpressAsset.ID>): Either<Throwable, Unit> =
either {
val userWallet = arrow.core.raise.catch(
block = { userWalletsStore.getSyncStrict(userWalletId) },
block = { userWalletsListRepository.getSyncStrict(userWalletId) },
catch = ::raise,
)

View file

@ -23,13 +23,14 @@ dependencies {
implementation(projects.data.common)
/** Project - Domain */
implementation(projects.domain.models)
implementation(projects.domain.wallets.models)
implementation(projects.domain.tokens.models)
implementation(projects.domain.nft)
implementation(projects.domain.walletManager)
implementation(projects.domain.card)
implementation(projects.domain.common)
implementation(projects.domain.models)
implementation(projects.domain.nft)
implementation(projects.domain.nft.models)
implementation(projects.domain.tokens.models)
implementation(projects.domain.walletManager)
implementation(projects.domain.wallets.models)
/** Project - Utils */
implementation(projects.core.utils)

View file

@ -1,25 +0,0 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ NFTCollections( network = network, content = NFTCollections.Content.Collections( collections = it ?.map { collection -&gt; nftSdkCollectionConverter.convert(network to collection) } ?.filter { it.id !is NFTCollection.Identifier.Unknown }, source = StatusSource.CACHE, ), ) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ if (it !is UnsupportedOperationException) { saveFailedStateInRuntime( userWalletId = userWalletId, network = network, error = it, ) } }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ if (it.id == collectionId) { it.changeAssetsStatusSource(source) } else { it } }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ if (it.identifier == sdkCollectionId) { it.copy(assets = assets) } else { it } }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ networkFactory.create( blockchain = it, extraDerivationPath = null, userWallet = userWallet, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ nftRuntimeStores[storeId] = it val storedCollections = getStoredCollections(userWalletId, network) val storedPrices = getStoredPrices(userWalletId, network) it.initialize( collections = storedCollections, prices = storedPrices, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ saveCollectionsInRuntime( userWalletId = userWalletId, network = network, collections = it, ) saveCollectionsInPersistence( userWalletId = userWalletId, network = network, collections = it, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ saveFailedStateInRuntime( userWalletId = userWalletId, network = network, error = it, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ storedCollections.copy( content = it, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ val (assetId, _) = it assetIdConverter.convert(assetId) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ val (assetId, price) = it val nftCurrency = getNFTCurrency(network) NFTSalePrice.Value( assetId = assetId, value = price.value, fiatValue = null, symbol = nftCurrency.symbol, decimals = nftCurrency.decimals, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ val assetId = assetIdConverter.convert(it.identifier) val price = getNFTRuntimeStore(userWalletId, network).getSalePriceSync(assetId) if (price is NFTSalePrice.Empty || price is NFTSalePrice.Error) { refreshSalePrice(userWalletId, network, sdkCollectionId, it.identifier) } }</ID>
<ID>MultilineLambdaItParameter:DefaultNFTRepository.kt$DefaultNFTRepository${ val sdkAssetId = assetIdConverter.convertBack(assetId) saveSalePriceInPersistence(userWalletId, network, sdkAssetId, it) }</ID>
<ID>NamedArguments:DefaultNFTRepository.kt$DefaultNFTRepository$refreshSalePrice(userWalletId, network, sdkCollectionId, it.identifier)</ID>
<ID>NamedArguments:DefaultNFTRepository.kt$DefaultNFTRepository$saveSalePriceInPersistence(userWalletId, network, sdkAssetId, it)</ID>
<ID>NoNameShadowing:DefaultNFTRepository.kt$DefaultNFTRepository${ it.id !is NFTCollection.Identifier.Unknown }</ID>
<ID>SuspendFunSwallowedCancellation:DefaultNFTRepository.kt$DefaultNFTRepository$runCatching</ID>
<ID>SuspendFunWithFlowReturnType:DefaultNFTRepository.kt$DefaultNFTRepository$suspend</ID>
<ID>UnnecessaryLet:DefaultNFTRepository.kt$DefaultNFTRepository$let { prices -&gt; prices .mapKeys { val (assetId, _) = it assetIdConverter.convert(assetId) } .mapValues { val (assetId, price) = it val nftCurrency = getNFTCurrency(network) NFTSalePrice.Value( assetId = assetId, value = price.value, fiatValue = null, symbol = nftCurrency.symbol, decimals = nftCurrency.decimals, ) } }</ID>
</CurrentIssues>
</SmellBaseline>

View file

@ -16,8 +16,8 @@ import com.tangem.datasource.local.nft.converter.NFTSdkAssetIdentifierConverter
import com.tangem.datasource.local.nft.converter.NFTSdkAssetSalePriceConverter
import com.tangem.datasource.local.nft.converter.NFTSdkCollectionConverter
import com.tangem.datasource.local.nft.converter.NFTSdkCollectionIdentifierConverter
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.card.common.extensions.canHandleToken
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.StatusSource
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network
@ -47,13 +47,13 @@ import javax.inject.Inject
import com.tangem.blockchain.nft.models.NFTAsset as SdkNFTAsset
import com.tangem.blockchain.nft.models.NFTCollection as SdkNFTCollection
@Suppress("LargeClass", "LongParameterList")
@Suppress("LargeClass", "LongParameterList", "SuspendFunWithFlowReturnType")
internal class DefaultNFTRepository @Inject constructor(
private val nftPersistenceStoreFactory: NFTPersistenceStoreFactory,
private val nftRuntimeStoreFactory: NFTRuntimeStoreFactory,
private val walletManagersFacade: WalletManagersFacade,
private val dispatchers: CoroutineDispatcherProvider,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val networkFactory: NetworkFactory,
private val excludedBlockchains: ExcludedBlockchains,
@ApplicationContext private val context: Context,
@ -87,7 +87,7 @@ internal class DefaultNFTRepository @Inject constructor(
): NFTSalePrice = withContext(dispatchers.io) {
val salePriceConverter = NFTSdkAssetSalePriceConverter(assetId)
runCatching {
runSuspendCatching {
saveSalePriceInRuntime(userWalletId, network, NFTSalePrice.Loading(assetId))
val sdkPrice = walletManagersFacade.getNFTSalePrice(
@ -108,9 +108,14 @@ internal class DefaultNFTRepository @Inject constructor(
saveSalePriceInRuntime(userWalletId, network, salePrice)
sdkPrice?.let {
sdkPrice?.let { price ->
val sdkAssetId = assetIdConverter.convertBack(assetId)
saveSalePriceInPersistence(userWalletId, network, sdkAssetId, it)
saveSalePriceInPersistence(
userWalletId = userWalletId,
network = network,
assetId = sdkAssetId,
salePrice = price,
)
}
salePrice
@ -162,41 +167,46 @@ internal class DefaultNFTRepository @Inject constructor(
expireAssets(userWalletId, network, collectionId)
assets.forEach {
val assetId = assetIdConverter.convert(it.identifier)
assets.forEach { asset ->
val assetId = assetIdConverter.convert(asset.identifier)
val price = getNFTRuntimeStore(userWalletId, network).getSalePriceSync(assetId)
if (price is NFTSalePrice.Empty || price is NFTSalePrice.Error) {
refreshSalePrice(userWalletId, network, sdkCollectionId, it.identifier)
refreshSalePrice(
userWalletId = userWalletId,
network = network,
sdkCollectionId = sdkCollectionId,
sdkAssetId = asset.identifier,
)
}
}
getNFTPersistenceStore(userWalletId, network)
.getCollectionsSync()
?.map {
if (it.identifier == sdkCollectionId) {
it.copy(assets = assets)
?.map { collection ->
if (collection.identifier == sdkCollectionId) {
collection.copy(assets = assets)
} else {
it
collection
}
}
?.let {
?.let { collections ->
saveCollectionsInRuntime(
userWalletId = userWalletId,
network = network,
collections = it,
collections = collections,
)
saveCollectionsInPersistence(
userWalletId = userWalletId,
network = network,
collections = it,
collections = collections,
)
}
}.onLeft {
if (it !is UnsupportedOperationException) {
}.onLeft { throwable ->
if (throwable !is UnsupportedOperationException) {
saveFailedStateInRuntime(
userWalletId = userWalletId,
network = network,
error = it,
error = throwable,
)
}
}
@ -207,13 +217,13 @@ internal class DefaultNFTRepository @Inject constructor(
network.canHandleNFTs(userWalletId)
override suspend fun getNFTSupportedNetworks(userWalletId: UserWalletId): List<Network> {
val userWallet = userWalletsStore.getSyncStrict(userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
return Blockchain
.entries
.filter { !it.isTestnet() }
.mapNotNull {
.mapNotNull { blockchain ->
networkFactory.create(
blockchain = it,
blockchain = blockchain,
extraDerivationPath = null,
userWallet = userWallet,
)
@ -280,11 +290,11 @@ internal class DefaultNFTRepository @Inject constructor(
)
}
}
}.onLeft {
}.onLeft { throwable ->
saveFailedStateInRuntime(
userWalletId = userWalletId,
network = network,
error = it,
error = throwable,
)
}
}.saveIn(getNetworkJobHolder(network))
@ -334,11 +344,7 @@ internal class DefaultNFTRepository @Inject constructor(
val storedCollections = runtimeStore.getCollectionsSync()
val expiredCollections = storedCollections
.changeCollectionAssetsStatusSource(collectionId, StatusSource.CACHE)
.let {
storedCollections.copy(
content = it,
)
}
.let { storedCollections.copy(content = it) }
runtimeStore.saveCollections(expiredCollections)
}
@ -427,6 +433,7 @@ internal class DefaultNFTRepository @Inject constructor(
}
}
// TODO: remove suspend
private suspend fun getNFTRuntimeStore(userWalletId: UserWalletId, network: Network): NFTRuntimeStore {
val storeId = (userWalletId to network).formatted()
return nftRuntimeStoresMutex.withLock {
@ -446,44 +453,41 @@ internal class DefaultNFTRepository @Inject constructor(
private suspend fun getStoredCollections(userWalletId: UserWalletId, network: Network) =
getNFTPersistenceStore(userWalletId, network)
.getCollectionsSync()
.let {
.let { collections ->
NFTCollections(
network = network,
content = NFTCollections.Content.Collections(
collections = it
collections = collections
?.map { collection ->
nftSdkCollectionConverter.convert(network to collection)
}
?.filter {
it.id !is NFTCollection.Identifier.Unknown
},
?.filter { it.id !is NFTCollection.Identifier.Unknown },
source = StatusSource.CACHE,
),
)
}
private suspend fun getStoredPrices(userWalletId: UserWalletId, network: Network) =
getNFTPersistenceStore(userWalletId, network)
private suspend fun getStoredPrices(
userWalletId: UserWalletId,
network: Network,
): Map<NFTAsset.Identifier, NFTSalePrice.Value> {
val prices = getNFTPersistenceStore(userWalletId, network)
.getSalePricesSync()
.orEmpty()
.let { prices ->
prices
.mapKeys {
val (assetId, _) = it
assetIdConverter.convert(assetId)
}
.mapValues {
val (assetId, price) = it
val nftCurrency = getNFTCurrency(network)
NFTSalePrice.Value(
assetId = assetId,
value = price.value,
fiatValue = null,
symbol = nftCurrency.symbol,
decimals = nftCurrency.decimals,
)
}
return prices
.mapKeys { (assetId, _) -> assetIdConverter.convert(assetId) }
.mapValues { (assetId, price) ->
val nftCurrency = getNFTCurrency(network)
NFTSalePrice.Value(
assetId = assetId,
value = price.value,
fiatValue = null,
symbol = nftCurrency.symbol,
decimals = nftCurrency.decimals,
)
}
}
private fun NFTCollections.changeStatusSource(source: StatusSource) = copy(
content = when (val content = content) {
@ -503,11 +507,11 @@ internal class DefaultNFTRepository @Inject constructor(
.copy(
collections = content
.collections
?.map {
if (it.id == collectionId) {
it.changeAssetsStatusSource(source)
?.map { collection ->
if (collection.id == collectionId) {
collection.changeAssetsStatusSource(source)
} else {
it
collection
}
},
)
@ -562,7 +566,7 @@ internal class DefaultNFTRepository @Inject constructor(
}
private fun Network.canHandleNFTs(userWalletId: UserWalletId): Boolean {
val userWallet = userWalletsStore.getSyncStrict(userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
val blockchain = Blockchain.fromNetworkId(backendId) ?: return false
return blockchain.canHandleNFTs() &&

View file

@ -24,7 +24,7 @@ class NFTCleanerTest {
nftRuntimeStoreFactory = nftRuntimeStoreFactory,
walletManagersFacade = mockk(),
dispatchers = mockk(),
userWalletsStore = mockk(),
userWalletsListRepository = mockk(),
networkFactory = mockk(),
excludedBlockchains = mockk(),
context = mockk(),

View file

@ -17,7 +17,7 @@ import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrap
import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO
import com.tangem.datasource.local.token.P2PEthPoolVaultsStore
import com.tangem.datasource.local.token.StakingYieldsStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.core.utils.catchOn
import com.tangem.domain.models.staking.StakingID
import com.tangem.domain.models.wallet.UserWallet
@ -41,20 +41,20 @@ import javax.inject.Inject
*
* Supports both StakeKit and P2PEthPool staking providers.
*
* @property userWalletsStore user wallets store
* @property stakingYieldsStore staking yields store
* @property stakeKitBalancesStore staking balances store (StakeKit)
* @property p2PEthPoolBalancesStore P2PEthPool balances store
* @property stakeKitApi stake kit API
* @property p2pEthPoolApi P2PEthPool API
* @property p2pEthPoolVaultsStore P2PEthPool vaults store
* @property dispatchers dispatchers
* @property userWalletsListRepository repository of user wallets
* @property stakingYieldsStore staking yields store
* @property stakeKitBalancesStore staking balances store (StakeKit)
* @property p2PEthPoolBalancesStore P2PEthPool balances store
* @property stakeKitApi stake kit API
* @property p2pEthPoolApi P2PEthPool API
* @property p2pEthPoolVaultsStore P2PEthPool vaults store
* @property dispatchers dispatchers
*
[REDACTED_AUTHOR]
*/
@Suppress("LongParameterList")
internal class DefaultMultiStakingBalanceFetcher @Inject constructor(
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val stakingYieldsStore: StakingYieldsStore,
private val stakeKitBalancesStore: StakeKitBalancesStore,
private val p2PEthPoolBalancesStore: P2PEthPoolBalancesStore,
@ -238,7 +238,7 @@ internal class DefaultMultiStakingBalanceFetcher @Inject constructor(
}
private inline fun checkIsSupportedByWalletOrElse(userWalletId: UserWalletId, ifNotSupported: (Throwable) -> Unit) {
val maybeUserWallet = userWalletsStore.getSyncOrNull(key = userWalletId).toOption()
val maybeUserWallet = userWalletsListRepository.getSyncOrNull(id = userWalletId).toOption()
val isSupportedByWallet = maybeUserWallet.isSome(UserWallet::isMultiCurrency)

View file

@ -14,7 +14,7 @@ import com.tangem.datasource.api.stakekit.StakeKitApi
import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO
import com.tangem.datasource.local.token.P2PEthPoolVaultsStore
import com.tangem.datasource.local.token.StakingYieldsStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.staking.StakingID
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.staking.multi.MultiStakingBalanceFetcher
@ -33,7 +33,7 @@ import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class DefaultMultiStakingBalanceFetcherTest {
private val userWalletsStore: UserWalletsStore = mockk()
private val userWalletsListRepository: UserWalletsListRepository = mockk()
private val stakingYieldsStore: StakingYieldsStore = mockk()
private val stakeKitBalancesStore: StakeKitBalancesStore = mockk(relaxUnitFun = true)
private val p2PEthPoolBalancesStore: P2PEthPoolBalancesStore = mockk(relaxUnitFun = true)
@ -42,7 +42,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
private val p2pEthPoolVaultsStore: P2PEthPoolVaultsStore = mockk()
private val fetcher = DefaultMultiStakingBalanceFetcher(
userWalletsStore = userWalletsStore,
userWalletsListRepository = userWalletsListRepository,
stakingYieldsStore = stakingYieldsStore,
stakeKitBalancesStore = stakeKitBalancesStore,
p2PEthPoolBalancesStore = p2PEthPoolBalancesStore,
@ -54,7 +54,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
@BeforeEach
fun resetMocks() {
clearMocks(userWalletsStore, stakingYieldsStore, stakeKitBalancesStore, stakeKitApi)
clearMocks(userWalletsListRepository, stakingYieldsStore, stakeKitBalancesStore, stakeKitApi)
}
@Test
@ -62,7 +62,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val yields = listOf(MockYieldDTOFactory.create(tonId), MockYieldDTOFactory.create(solanaId))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -80,7 +80,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsStore.getSyncOrNull(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitApi.getMultipleYieldBalances(requests)
@ -97,7 +97,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val yields = listOf(MockYieldDTOFactory.create(tonId))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -112,7 +112,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsStore.getSyncOrNull(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId = userWalletId, stakingIds = setOf(solanaId))
@ -129,13 +129,13 @@ internal class DefaultMultiStakingBalanceFetcherTest {
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
val userWallet = MockUserWalletFactory.create().copy(isMultiCurrency = false)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
// Actual
val actual = fetcher.invoke(params)
// Assert
coVerifyOrder { userWalletsStore.getSyncOrNull(params.userWalletId) }
coVerifyOrder { userWalletsListRepository.getSyncOrNull(params.userWalletId) }
coVerify(inverse = true) {
stakeKitBalancesStore.refresh(userWalletId = any(), stakingIds = any())
@ -155,13 +155,13 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns null
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns null
// Actual
val actual = fetcher.invoke(params)
// Assert
coVerifyOrder { userWalletsStore.getSyncOrNull(params.userWalletId) }
coVerifyOrder { userWalletsListRepository.getSyncOrNull(params.userWalletId) }
coVerify(inverse = true) {
stakeKitBalancesStore.refresh(userWalletId = any(), stakingIds = any())
@ -181,7 +181,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns null
// Actual
@ -189,7 +189,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsStore.getSyncOrNull(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
stakeKitBalancesStore.refresh(params.userWalletId, tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -210,7 +210,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns emptyList()
// Actual
@ -218,7 +218,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsStore.getSyncOrNull(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -239,7 +239,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val yields = listOf(
MockYieldDTOFactory.create(tonId).copy(id = null),
@ -252,7 +252,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsStore.getSyncOrNull(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -273,7 +273,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val yields = listOf(MockYieldDTOFactory.create(StakingID(integrationId = "polygon", address = "0x1")))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -283,7 +283,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsStore.getSyncOrNull(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitBalancesStore.storeError(userWalletId, tonAndSolanaIds)
@ -310,7 +310,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Arrange
val params = MultiStakingBalanceFetcher.Params(userWalletId = userWalletId, stakingIds = tonAndSolanaIds)
coEvery { userWalletsStore.getSyncOrNull(params.userWalletId) } returns userWallet
coEvery { userWalletsListRepository.getSyncOrNull(params.userWalletId) } returns userWallet
val yields = listOf(MockYieldDTOFactory.create(tonId), MockYieldDTOFactory.create(solanaId))
coEvery { stakingYieldsStore.getSyncWithTimeout() } returns yields
@ -328,7 +328,7 @@ internal class DefaultMultiStakingBalanceFetcherTest {
// Assert
coVerifyOrder {
userWalletsStore.getSyncOrNull(params.userWalletId)
userWalletsListRepository.getSyncOrNull(params.userWalletId)
stakeKitBalancesStore.refresh(userWalletId = params.userWalletId, stakingIds = tonAndSolanaIds)
stakingYieldsStore.getSyncWithTimeout()
stakeKitApi.getMultipleYieldBalances(requests)

View file

@ -15,15 +15,18 @@ dependencies {
implementation(projects.core.utils)
implementation(projects.core.datasource)
implementation(projects.core.pagination)
implementation(projects.domain.legacy)
implementation(projects.domain.common)
implementation(projects.domain.walletManager)
implementation(projects.libs.blockchainSdk)
implementation(projects.domain.models)
implementation(projects.domain.tokens.models)
implementation(projects.domain.txhistory)
implementation(projects.domain.txhistory.models)
implementation(projects.domain.wallets.models)
implementation(projects.libs.blockchainSdk)
implementation(deps.kotlin.coroutines)
implementation(deps.androidx.paging.runtime)
implementation(deps.timber)

View file

@ -3,11 +3,7 @@
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>BooleanPropertyNaming:TxHistoryPagingSource.kt$TxHistoryPagingSource.Params$val refresh: Boolean</ID>
<ID>MaxChainedCallsOnSameLine:DefaultTxHistoryRepository.kt$DefaultTxHistoryRepository$walletManager?.wallet?.recentTransactions?.last()?.hash.orEmpty()</ID>
<ID>MultilineLambdaItParameter:TxHistoryPageBatchFetcher.kt$TxHistoryPageBatchFetcher${ currentCoroutineContext().ensureActive() BatchFetchResult.Error(it) }</ID>
<ID>NamedArguments:DefaultTxHistoryRepository.kt$DefaultTxHistoryRepository$Params(userWalletId, currency, pageSize, refresh)</ID>
<ID>NamedArguments:TxHistoryDataModule.kt$TxHistoryDataModule$DefaultTxHistoryRepository( cacheRegistry, walletManagersFacade, userWalletsStore, txHistoryItemsStore, dispatchers, )</ID>
<ID>SuspendFunSwallowedCancellation:TxHistoryPageBatchFetcher.kt$TxHistoryPageBatchFetcher$runCatching</ID>
<ID>UseOrEmpty:DefaultTxHistoryRepository.kt$DefaultTxHistoryRepository$txs ?: emptyList()</ID>
</CurrentIssues>
</SmellBaseline>

View file

@ -4,7 +4,7 @@ import com.tangem.data.common.cache.CacheRegistry
import com.tangem.data.txhistory.repository.DefaultTxHistoryRepository
import com.tangem.data.txhistory.repository.RefactoredTxHistoryRepository
import com.tangem.datasource.local.txhistory.TxHistoryItemsStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.txhistory.repository.TxHistoryRepository
import com.tangem.domain.txhistory.repository.TxHistoryRepositoryV2
import com.tangem.domain.walletmanager.WalletManagersFacade
@ -24,15 +24,15 @@ internal object TxHistoryDataModule {
fun provideTxHistoryRepository(
cacheRegistry: CacheRegistry,
walletManagersFacade: WalletManagersFacade,
userWalletsStore: UserWalletsStore,
userWalletsListRepository: UserWalletsListRepository,
txHistoryItemsStore: TxHistoryItemsStore,
dispatchers: CoroutineDispatcherProvider,
): TxHistoryRepository = DefaultTxHistoryRepository(
cacheRegistry,
walletManagersFacade,
userWalletsStore,
txHistoryItemsStore,
dispatchers,
cacheRegistry = cacheRegistry,
walletManagersFacade = walletManagersFacade,
userWalletsListRepository = userWalletsListRepository,
txHistoryItemsStore = txHistoryItemsStore,
dispatchers = dispatchers,
)
@Provides

View file

@ -8,10 +8,9 @@ import com.tangem.blockchainsdk.utils.toBlockchain
import com.tangem.data.common.cache.CacheRegistry
import com.tangem.data.txhistory.repository.paging.TxHistoryPagingSource
import com.tangem.datasource.local.txhistory.TxHistoryItemsStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.txhistory.models.Page
import com.tangem.domain.txhistory.models.TxHistoryState
@ -27,7 +26,7 @@ import timber.log.Timber
class DefaultTxHistoryRepository(
private val cacheRegistry: CacheRegistry,
private val walletManagersFacade: WalletManagersFacade,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val txHistoryItemsStore: TxHistoryItemsStore,
private val dispatchers: CoroutineDispatcherProvider,
) : TxHistoryRepository {
@ -35,7 +34,7 @@ class DefaultTxHistoryRepository(
override suspend fun getTxHistoryItemsCount(userWalletId: UserWalletId, currency: CryptoCurrency): Int {
return withContext(dispatchers.io) {
val userWallet = getUserWallet(userWalletId)
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
val state = walletManagersFacade.getTxHistoryState(
userWalletId = userWallet.walletId,
currency = currency,
@ -63,7 +62,12 @@ class DefaultTxHistoryRepository(
),
pagingSourceFactory = {
TxHistoryPagingSource(
sourceParams = TxHistoryPagingSource.Params(userWalletId, currency, pageSize, refresh),
sourceParams = TxHistoryPagingSource.Params(
userWalletId = userWalletId,
currency = currency,
pageSize = pageSize,
refresh = refresh,
),
txHistoryItemsStore = txHistoryItemsStore,
walletManagersFacade = walletManagersFacade,
cacheRegistry = cacheRegistry,
@ -98,11 +102,12 @@ class DefaultTxHistoryRepository(
skipCache = shouldRefresh,
block = { fetchFixedSizeTxHistoryItems(userWalletId, currency, pageSize) },
)
val txs = txHistoryItemsStore.getSyncOrNull(
txHistoryItemsStore.getSyncOrNull(
key = TxHistoryItemsStore.Key(userWalletId, currency),
page = Page.Initial,
)?.items
txs ?: emptyList()
)
?.items.orEmpty()
} catch (e: Throwable) {
Timber.e(e, "Unable to load the transaction history for the requested page: ${Page.Initial}")
emptyList()
@ -127,10 +132,4 @@ class DefaultTxHistoryRepository(
txHistoryItemsStore.store(TxHistoryItemsStore.Key(userWalletId, currency), wrappedItems)
}
private fun getUserWallet(userWalletId: UserWalletId): UserWallet {
return requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
"Unable to find user wallet with provided ID: $userWalletId"
}
}
}

View file

@ -1,22 +1,15 @@
package com.tangem.data.walletconnect
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.models.wallet.isMultiCurrency
import com.tangem.domain.walletconnect.repository.WalletConnectRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.withContext
internal class DefaultWalletConnectRepository(
private val userWalletsStore: UserWalletsStore,
private val dispatchers: CoroutineDispatcherProvider,
private val userWalletsListRepository: UserWalletsListRepository,
) : WalletConnectRepository {
override suspend fun checkIsAvailable(userWalletId: UserWalletId): Boolean = withContext(dispatchers.io) {
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
"User wallet with id $userWalletId not found"
}
userWallet.isMultiCurrency
override suspend fun checkIsAvailable(userWalletId: UserWalletId): Boolean {
return userWalletsListRepository.getSyncStrict(userWalletId).isMultiCurrency
}
}

View file

@ -19,12 +19,12 @@ import com.tangem.data.walletconnect.utils.WcNamespaceConverter
import com.tangem.data.walletconnect.utils.WcNetworksConverter
import com.tangem.data.walletconnect.utils.WcScope
import com.tangem.datasource.di.SdkMoshi
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.datasource.local.walletconnect.WalletConnectStore
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.account.status.supplier.SingleAccountStatusListSupplier
import com.tangem.domain.account.supplier.MultiAccountListSupplier
import com.tangem.domain.account.supplier.SingleAccountSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
import com.tangem.domain.walletconnect.WcPairService
import com.tangem.domain.walletconnect.WcRequestService
@ -51,10 +51,9 @@ internal object WalletConnectDataModule {
@Provides
@Singleton
fun providesWalletConnectRepository(
userWalletsStore: UserWalletsStore,
dispatchers: CoroutineDispatcherProvider,
userWalletsListRepository: UserWalletsListRepository,
): WalletConnectRepository {
return DefaultWalletConnectRepository(userWalletsStore, dispatchers)
return DefaultWalletConnectRepository(userWalletsListRepository)
}
@Provides

View file

@ -28,8 +28,8 @@ import com.tangem.blockchainsdk.utils.toNetworkId
import com.tangem.crypto.hdWallet.DerivationPath
import com.tangem.data.walletmanager.utils.*
import com.tangem.datasource.asset.loader.AssetLoader
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.datasource.local.walletmanager.WalletManagersStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.demo.models.DemoConfig
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network
@ -60,7 +60,7 @@ import javax.inject.Inject
@Suppress("LargeClass", "TooManyFunctions")
internal class DefaultWalletManagersFacade @Inject constructor(
private val walletManagersStore: WalletManagersStore,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val assetLoader: AssetLoader,
private val dispatchers: CoroutineDispatcherProvider,
private val gaslessTransactionRepository: GaslessTransactionRepository,
@ -300,7 +300,7 @@ internal class DefaultWalletManagersFacade @Inject constructor(
}
}
private fun getUserWallet(userWalletId: UserWalletId) = userWalletsStore.getSyncStrict(userWalletId)
private fun getUserWallet(userWalletId: UserWalletId) = userWalletsListRepository.getSyncStrict(userWalletId)
private suspend fun getAndUpdateWalletManager(
userWallet: UserWallet,

View file

@ -8,7 +8,7 @@ import com.tangem.data.common.currency.CryptoCurrencyFactory
import com.tangem.datasource.api.common.response.getOrThrow
import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.api.tangemTech.models.StartReferralBody
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWalletId
@ -27,8 +27,8 @@ typealias ExternalReferralRepository = com.tangem.domain.referral.ReferralReposi
internal class ReferralRepositoryImpl @Inject constructor(
private val referralApi: TangemTechApi,
private val referralConverter: ReferralConverter,
private val coroutineDispatcher: CoroutineDispatcherProvider,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val dispatchers: CoroutineDispatcherProvider,
excludedBlockchains: ExcludedBlockchains,
) : ReferralRepository, ExternalReferralRepository {
@ -38,7 +38,7 @@ internal class ReferralRepositoryImpl @Inject constructor(
private val referralStatus: ConcurrentHashMap<String, ReferralData> = ConcurrentHashMap()
override suspend fun getReferralData(walletId: String): ReferralData {
return withContext(coroutineDispatcher.io) {
return withContext(dispatchers.io) {
val referralData = referralConverter.convert(
referralApi.getReferralStatus(
walletId = walletId,
@ -76,7 +76,7 @@ internal class ReferralRepositoryImpl @Inject constructor(
tokenId: String,
address: String,
): ReferralData {
return withContext(coroutineDispatcher.io) {
return withContext(dispatchers.io) {
val referralData = referralConverter.convert(
referralApi.startReferral(
startReferralBody = StartReferralBody(
@ -97,9 +97,7 @@ internal class ReferralRepositoryImpl @Inject constructor(
tokenData: TokenData,
accountIndex: DerivationIndex?,
): CryptoCurrency? {
val userWallet = withContext(coroutineDispatcher.io) {
userWalletsStore.getSyncOrNull(userWalletId) ?: error("Wallet $userWalletId not found")
}
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
val blockchain = Blockchain.fromNetworkId(tokenData.networkId)
?: error("Blockchain ${tokenData.networkId} not found")

View file

@ -3,7 +3,7 @@ package com.tangem.feature.referral.di
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.feature.referral.converters.ReferralConverter
import com.tangem.feature.referral.data.DefaultMobileWalletPromoRepository
import com.tangem.feature.referral.data.ExternalReferralRepository
@ -26,15 +26,15 @@ class ReferralRepositoryModule {
fun provideReferralRepository(
tangemTechApi: TangemTechApi,
referralConverter: ReferralConverter,
coroutineDispatcherProvider: CoroutineDispatcherProvider,
userWalletsStore: UserWalletsStore,
userWalletsListRepository: UserWalletsListRepository,
dispatchers: CoroutineDispatcherProvider,
excludedBlockchains: ExcludedBlockchains,
): ReferralRepository {
return ReferralRepositoryImpl(
referralApi = tangemTechApi,
referralConverter = referralConverter,
coroutineDispatcher = coroutineDispatcherProvider,
userWalletsStore = userWalletsStore,
userWalletsListRepository = userWalletsListRepository,
dispatchers = dispatchers,
excludedBlockchains = excludedBlockchains,
)
}
@ -44,15 +44,15 @@ class ReferralRepositoryModule {
fun provideExternalReferralRepository(
tangemTechApi: TangemTechApi,
referralConverter: ReferralConverter,
coroutineDispatcherProvider: CoroutineDispatcherProvider,
userWalletsStore: UserWalletsStore,
userWalletsListRepository: UserWalletsListRepository,
dispatchers: CoroutineDispatcherProvider,
excludedBlockchains: ExcludedBlockchains,
): ExternalReferralRepository {
return ReferralRepositoryImpl(
referralApi = tangemTechApi,
referralConverter = referralConverter,
coroutineDispatcher = coroutineDispatcherProvider,
userWalletsStore = userWalletsStore,
userWalletsListRepository = userWalletsListRepository,
dispatchers = dispatchers,
excludedBlockchains = excludedBlockchains,
)
}

View file

@ -25,7 +25,7 @@ import com.tangem.datasource.api.express.models.response.TxDetails
import com.tangem.datasource.crypto.DataSignatureVerifier
import com.tangem.datasource.exchangeservice.swap.ExpressUtils
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.exchange.RampStateManager
import com.tangem.domain.express.models.ExpressOperationType
import com.tangem.domain.models.currency.CryptoCurrency
@ -52,7 +52,7 @@ internal class DefaultSwapRepository(
private val tangemExpressApi: TangemExpressApi,
private val coroutineDispatcher: CoroutineDispatcherProvider,
private val walletManagersFacade: WalletManagersFacade,
private val userWalletsStore: UserWalletsStore,
private val userWalletsListRepository: UserWalletsListRepository,
private val errorsDataConverter: ErrorsDataConverter,
private val dataSignatureVerifier: DataSignatureVerifier,
private val appPreferencesStore: AppPreferencesStore,
@ -406,14 +406,14 @@ internal class DefaultSwapRepository(
)
}
override fun getNativeTokenForNetwork(networkId: String): CryptoCurrency {
override suspend fun getNativeTokenForNetwork(networkId: String): CryptoCurrency {
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
return requireNotNull(
cryptoCurrencyFactory.createCoin(
blockchain = blockchain,
extraDerivationPath = null,
userWallet = requireNotNull(userWalletsStore.selectedUserWalletOrNull),
userWallet = requireNotNull(userWalletsListRepository.selectedUserWalletSync()),
),
)
}

View file

@ -9,9 +9,9 @@ import com.tangem.datasource.api.express.models.response.ExpressErrorResponse
import com.tangem.datasource.crypto.DataSignatureVerifier
import com.tangem.datasource.di.NetworkMoshi
import com.tangem.datasource.local.preferences.AppPreferencesStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
import com.tangem.domain.account.supplier.SingleAccountListSupplier
import com.tangem.domain.common.wallets.UserWalletsListRepository
import com.tangem.domain.exchange.RampStateManager
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.feature.swap.DefaultSwapRepository
@ -37,7 +37,7 @@ internal class SwapDataModule {
coroutineDispatcher: CoroutineDispatcherProvider,
dataSignature: DataSignatureVerifier,
walletManagerFacade: WalletManagersFacade,
userWalletsStore: UserWalletsStore,
userWalletsListRepository: UserWalletsListRepository,
errorsDataConverter: ErrorsDataConverter,
@NetworkMoshi moshi: Moshi,
excludedBlockchains: ExcludedBlockchains,
@ -48,7 +48,7 @@ internal class SwapDataModule {
tangemExpressApi = tangemExpressApi,
coroutineDispatcher = coroutineDispatcher,
walletManagersFacade = walletManagerFacade,
userWalletsStore = userWalletsStore,
userWalletsListRepository = userWalletsListRepository,
errorsDataConverter = errorsDataConverter,
dataSignatureVerifier = dataSignature,
moshi = moshi,

View file

@ -60,12 +60,16 @@ interface SwapInteractor {
/**
* Starts swap transaction, perform sign transaction
*
* @param networkId network for tokens
* @param swapStateData tx data to swap, contains data to sign
* @param currencyToSend [Currency]
* @param currencyToGet [Currency]
* @param swapProvider swap provider to use
* @param swapData tx data to swap, contains data to sign
* @param currencyToSend crypto currency to send
* @param currencyToGet crypto currency to get
* @param fromAccount account from which swap will be made
* @param toAccount account to which receive token
* @param amountToSwap amount to swap
* @param includeFeeInAmount flag to include fee in amount
* @param fee for tx (can be null only for tangem pay withdrawal)
* @param expressOperationType type of express operation
* @return [SwapTransactionState]
*/
@ -119,7 +123,7 @@ interface SwapInteractor {
isReverseFromTo: Boolean,
): AccountSwapCurrency?
fun getNativeToken(networkId: String): CryptoCurrency
suspend fun getNativeToken(networkId: String): CryptoCurrency
@Suppress("LongParameterList")
suspend fun storeSwapTransaction(

View file

@ -1338,7 +1338,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
}
}
override fun getNativeToken(networkId: String): CryptoCurrency {
override suspend fun getNativeToken(networkId: String): CryptoCurrency {
return repository.getNativeTokenForNetwork(networkId)
}
@ -2553,7 +2553,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
val areAllQuotesFound = cachedQuotes?.all { quote -> quote.value !is QuoteStatus.Empty } == true
if (areAllQuotesFound) return@runSuspendCatching cachedQuotes.orEmpty()
if (areAllQuotesFound) return@runSuspendCatching cachedQuotes
val currenciesIds = if (cachedQuotes.isNullOrEmpty()) {
this@getQuotesOrEmpty
@ -2612,11 +2612,6 @@ internal class SwapInteractorImpl @AssistedInject constructor(
sealed class TxFeeSealedState {
class Legacy(val txFeeState: TxFeeState, val selectedFee: FeeType) : TxFeeSealedState()
class Component(val txFee: TxFee.FeeComponent) : TxFeeSealedState()
fun getTxFeeStateOrNull() = when (this) {
is Component -> null
is Legacy -> txFeeState
}
}
sealed class TransactionFeeResult {

View file

@ -6,12 +6,7 @@ import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.feature.swap.domain.models.ExpressDataError
import com.tangem.feature.swap.domain.models.domain.ExchangeStatusModel
import com.tangem.feature.swap.domain.models.domain.LeastTokenInfo
import com.tangem.feature.swap.domain.models.domain.PairsWithProviders
import com.tangem.feature.swap.domain.models.domain.QuoteModel
import com.tangem.feature.swap.domain.models.domain.RateType
import com.tangem.feature.swap.domain.models.domain.SwapDataModel
import com.tangem.feature.swap.domain.models.domain.*
import java.math.BigDecimal
interface SwapRepository {
@ -87,5 +82,5 @@ interface SwapRepository {
payInExtraId: String?,
): Either<ExpressDataError, Unit>
fun getNativeTokenForNetwork(networkId: String): CryptoCurrency
suspend fun getNativeTokenForNetwork(networkId: String): CryptoCurrency
}