Skip to content

Commit 930b15e

Browse files
author
Tangem
committed
${LATEST_TAG}
1 parent 79ddc48 commit 930b15e

23 files changed

Lines changed: 403 additions & 301 deletions

File tree

app/src/main/java/com/tangem/tap/di/domain/ManageTokensDomainModule.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.tangem.domain.managetokens.repository.CustomTokensRepository
66
import com.tangem.domain.managetokens.repository.ManageTokensRepository
77
import com.tangem.domain.networks.multi.MultiNetworkStatusFetcher
88
import com.tangem.domain.quotes.multi.MultiQuoteStatusFetcher
9+
import com.tangem.domain.staking.StakingIdFactory
910
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
1011
import com.tangem.domain.tokens.repository.CurrenciesRepository
1112
import com.tangem.domain.walletmanager.WalletManagersFacade
@@ -72,6 +73,7 @@ internal object ManageTokensDomainModule {
7273
multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
7374
multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
7475
multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
76+
stakingIdFactory: StakingIdFactory,
7577
): SaveManagedTokensUseCase {
7678
return SaveManagedTokensUseCase(
7779
customTokensRepository = customTokensRepository,
@@ -81,6 +83,7 @@ internal object ManageTokensDomainModule {
8183
multiNetworkStatusFetcher = multiNetworkStatusFetcher,
8284
multiQuoteStatusFetcher = multiQuoteStatusFetcher,
8385
multiYieldBalanceFetcher = multiYieldBalanceFetcher,
86+
stakingIdFactory = stakingIdFactory,
8487
)
8588
}
8689

app/src/main/java/com/tangem/tap/di/domain/MarketsDomainModule.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.tangem.domain.promo.PromoRepository
99
import com.tangem.domain.quotes.multi.MultiQuoteStatusFetcher
1010
import com.tangem.domain.quotes.single.SingleQuoteStatusSupplier
1111
import com.tangem.domain.settings.repositories.SettingsRepository
12+
import com.tangem.domain.staking.StakingIdFactory
1213
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
1314
import com.tangem.domain.tokens.repository.CurrenciesRepository
1415
import com.tangem.domain.wallets.legacy.UserWalletsListManager
@@ -63,6 +64,7 @@ object MarketsDomainModule {
6364
multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
6465
multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
6566
multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
67+
stakingIdFactory: StakingIdFactory,
6668
): SaveMarketTokensUseCase {
6769
return SaveMarketTokensUseCase(
6870
derivationsRepository = derivationsRepository,
@@ -71,6 +73,7 @@ object MarketsDomainModule {
7173
multiNetworkStatusFetcher = multiNetworkStatusFetcher,
7274
multiQuoteStatusFetcher = multiQuoteStatusFetcher,
7375
multiYieldBalanceFetcher = multiYieldBalanceFetcher,
76+
stakingIdFactory = stakingIdFactory,
7477
)
7578
}
7679

app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ internal object StakingDomainModule {
9494
@Provides
9595
@Singleton
9696
fun provideFetchStakingYieldBalanceUseCase(
97-
stakingErrorResolver: StakingErrorResolver,
9897
singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
98+
stakingIdFactory: StakingIdFactory,
9999
): FetchStakingYieldBalanceUseCase {
100100
return FetchStakingYieldBalanceUseCase(
101-
stakingErrorResolver = stakingErrorResolver,
102101
singleYieldBalanceFetcher = singleYieldBalanceFetcher,
102+
stakingIdFactory = stakingIdFactory,
103103
)
104104
}
105105

app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ internal object TokensDomainModule {
4747
singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
4848
multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
4949
tokensFeatureToggles: TokensFeatureToggles,
50+
stakingIdFactory: StakingIdFactory,
5051
): AddCryptoCurrenciesUseCase {
5152
return AddCryptoCurrenciesUseCase(
5253
currenciesRepository = currenciesRepository,
@@ -55,6 +56,7 @@ internal object TokensDomainModule {
5556
singleYieldBalanceFetcher = singleYieldBalanceFetcher,
5657
multiWalletCryptoCurrenciesSupplier = multiWalletCryptoCurrenciesSupplier,
5758
tokensFeatureToggles = tokensFeatureToggles,
59+
stakingIdFactory = stakingIdFactory,
5860
)
5961
}
6062

@@ -65,12 +67,14 @@ internal object TokensDomainModule {
6567
multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
6668
multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
6769
multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
70+
stakingIdFactory: StakingIdFactory,
6871
): FetchTokenListUseCase {
6972
return FetchTokenListUseCase(
7073
currenciesRepository = currenciesRepository,
7174
multiNetworkStatusFetcher = multiNetworkStatusFetcher,
7275
multiQuoteStatusFetcher = multiQuoteStatusFetcher,
7376
multiYieldBalanceFetcher = multiYieldBalanceFetcher,
77+
stakingIdFactory = stakingIdFactory,
7478
)
7579
}
7680

@@ -173,6 +177,7 @@ internal object TokensDomainModule {
173177
singleYieldBalanceFetcher: SingleYieldBalanceFetcher,
174178
multiWalletCryptoCurrenciesSupplier: MultiWalletCryptoCurrenciesSupplier,
175179
tokensFeatureToggles: TokensFeatureToggles,
180+
stakingIdFactory: StakingIdFactory,
176181
): FetchCurrencyStatusUseCase {
177182
return FetchCurrencyStatusUseCase(
178183
currenciesRepository = currenciesRepository,
@@ -181,6 +186,7 @@ internal object TokensDomainModule {
181186
singleYieldBalanceFetcher = singleYieldBalanceFetcher,
182187
multiWalletCryptoCurrenciesSupplier = multiWalletCryptoCurrenciesSupplier,
183188
tokensFeatureToggles = tokensFeatureToggles,
189+
stakingIdFactory = stakingIdFactory,
184190
)
185191
}
186192

@@ -191,12 +197,14 @@ internal object TokensDomainModule {
191197
multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
192198
multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
193199
multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
200+
stakingIdFactory: StakingIdFactory,
194201
): FetchCardTokenListUseCase {
195202
return FetchCardTokenListUseCase(
196203
currenciesRepository = currenciesRepository,
197204
multiNetworkStatusFetcher = multiNetworkStatusFetcher,
198205
multiQuoteStatusFetcher = multiQuoteStatusFetcher,
199206
multiYieldBalanceFetcher = multiYieldBalanceFetcher,
207+
stakingIdFactory = stakingIdFactory,
200208
)
201209
}
202210

@@ -477,6 +485,7 @@ internal object TokensDomainModule {
477485
multiNetworkStatusFetcher: MultiNetworkStatusFetcher,
478486
multiQuoteStatusFetcher: MultiQuoteStatusFetcher,
479487
multiYieldBalanceFetcher: MultiYieldBalanceFetcher,
488+
stakingIdFactory: StakingIdFactory,
480489
dispatchers: CoroutineDispatcherProvider,
481490
): WalletBalanceFetcher {
482491
return WalletBalanceFetcher(
@@ -486,6 +495,7 @@ internal object TokensDomainModule {
486495
multiNetworkStatusFetcher = multiNetworkStatusFetcher,
487496
multiQuoteStatusFetcher = multiQuoteStatusFetcher,
488497
multiYieldBalanceFetcher = multiYieldBalanceFetcher,
498+
stakingIdFactory = stakingIdFactory,
489499
dispatchers = dispatchers,
490500
)
491501
}

common/test/src/main/java/com/tangem/common/test/domain/token/MockCryptoCurrencyFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class MockCryptoCurrencyFactory(private val userWallet: UserWallet.Cold = defaul
2525
val cardano by lazy { createCoin(blockchain = Blockchain.Cardano) }
2626
val chia by lazy { createCoin(Blockchain.Chia) }
2727
val ethereum by lazy { createCoin(Blockchain.Ethereum) }
28+
val stellar by lazy { createCoin(Blockchain.Stellar) }
2829

2930
val chiaAndEthereum by lazy {
3031
listOf(

common/test/src/main/java/com/tangem/common/test/utils/TruthExt.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,24 @@ fun <B> assertEither(actual: Either<Throwable, B>, expected: Either<Throwable, B
99
.onLeft {
1010
val expectedError = expected.leftOrNull() ?: error("Actual is Either.Left: $it")
1111

12-
Truth.assertThat(it::class.java).isEqualTo(expectedError::class.java)
12+
Truth.assertThat(it).isInstanceOf(expectedError::class.java)
1313
Truth.assertThat(it).hasMessageThat().isEqualTo(expectedError.message)
1414
}
1515
}
16+
17+
fun assertEitherRight(actual: Either<Throwable, Unit>) {
18+
actual
19+
.onRight { Truth.assertThat(actual).isEqualTo(Either.Right(Unit)) }
20+
.onLeft {
21+
error("Actual is Either.Left: $it")
22+
}
23+
}
24+
25+
fun <B> assertEitherLeft(actual: Either<Throwable, B>, expected: Throwable) {
26+
actual
27+
.onRight { error("Actual is Either.Right: $it") }
28+
.onLeft {
29+
Truth.assertThat(it::class.java).isEqualTo(expected::class.java)
30+
Truth.assertThat(it).hasMessageThat().isEqualTo(expected.message)
31+
}
32+
}

data/staking/src/main/java/com/tangem/data/staking/multi/DefaultMultiYieldBalanceFetcher.kt

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.tangem.data.staking.multi
22

33
import arrow.core.Either
4-
import arrow.core.getOrElse
54
import arrow.core.left
6-
import arrow.core.raise.catch
7-
import arrow.core.raise.either
8-
import arrow.core.raise.ensure
5+
import arrow.core.right
96
import arrow.core.toOption
107
import com.tangem.data.common.api.safeApiCall
118
import com.tangem.data.staking.store.YieldsBalancesStore
12-
import com.tangem.data.staking.utils.StakingIdFactory
139
import com.tangem.data.staking.utils.YieldBalanceRequestBodyFactory
1410
import com.tangem.datasource.api.stakekit.StakeKitApi
1511
import com.tangem.datasource.api.stakekit.models.request.YieldBalanceRequestBody
@@ -36,7 +32,6 @@ import javax.inject.Inject
3632
* @property userWalletsStore user wallets store
3733
* @property stakingYieldsStore staking yields store
3834
* @property yieldsBalancesStore yields balances store
39-
* @property stakingIdFactory factory for creating StakingID
4035
* @property stakeKitApi stake kit API
4136
* @property dispatchers dispatchers
4237
*
@@ -46,19 +41,19 @@ internal class DefaultMultiYieldBalanceFetcher @Inject constructor(
4641
private val userWalletsStore: UserWalletsStore,
4742
private val stakingYieldsStore: StakingYieldsStore,
4843
private val yieldsBalancesStore: YieldsBalancesStore,
49-
private val stakingIdFactory: StakingIdFactory,
5044
private val stakeKitApi: StakeKitApi,
5145
private val dispatchers: CoroutineDispatcherProvider,
5246
) : MultiYieldBalanceFetcher {
5347

5448
override suspend fun invoke(params: MultiYieldBalanceFetcher.Params): Either<Throwable, Unit> {
5549
Timber.i("Start fetching yield balances for params:\n$params")
5650

57-
checkIsSupportedByWalletOrElse(userWalletId = params.userWalletId) {
58-
return it.left()
51+
val stakingIds = params.stakingIds.ifEmpty {
52+
Timber.i("Nothing to fetch, empty stakingIds for ${params.userWalletId}")
53+
return Unit.right()
5954
}
6055

61-
val stakingIds = getStakingIds(params).getOrElse {
56+
checkIsSupportedByWalletOrElse(userWalletId = params.userWalletId) {
6257
return it.left()
6358
}
6459

@@ -94,30 +89,6 @@ internal class DefaultMultiYieldBalanceFetcher @Inject constructor(
9489
}
9590
}
9691

97-
private suspend fun getStakingIds(params: MultiYieldBalanceFetcher.Params) = either {
98-
val stakingIds = catch(
99-
block = {
100-
params.currencyIdWithNetworkMap.mapNotNullTo(hashSetOf()) { (currencyId, network) ->
101-
stakingIdFactory.create(
102-
userWalletId = params.userWalletId,
103-
currencyId = currencyId,
104-
network = network,
105-
)
106-
}
107-
},
108-
catch = ::raise,
109-
)
110-
111-
ensure(stakingIds.isNotEmpty()) {
112-
val exception = IllegalStateException("Unable to create staking ids for $params: list is empty")
113-
Timber.e(exception)
114-
115-
raise(exception)
116-
}
117-
118-
stakingIds
119-
}
120-
12192
private suspend fun getAvailableStakingIds(userWalletId: UserWalletId, stakingIds: Set<StakingID>): Set<StakingID> {
12293
val yieldIds = getYieldsIds(userWalletId = userWalletId)
12394

data/staking/src/main/java/com/tangem/data/staking/single/DefaultSingleYieldBalanceFetcher.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ internal class DefaultSingleYieldBalanceFetcher @Inject constructor(
2020
return multiYieldBalanceFetcher(
2121
params = MultiYieldBalanceFetcher.Params(
2222
userWalletId = params.userWalletId,
23-
currencyIdWithNetworkMap = mapOf(
24-
params.currencyId to params.network,
25-
),
23+
stakingIds = setOf(params.stakingId),
2624
),
2725
)
2826
}

0 commit comments

Comments
 (0)