Updated on 2026-08-14
This commit is contained in:
parent
097e9c1bce
commit
2437fa39d8
9 changed files with 120 additions and 22 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.data.networks.fetcher
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.right
|
||||
import com.tangem.data.networks.store.NetworksStatusesStore
|
||||
import com.tangem.data.networks.store.setSourceAsOnlyCache
|
||||
import com.tangem.data.networks.store.storeStatus
|
||||
|
|
@ -44,6 +45,13 @@ internal class CommonNetworkStatusFetcher @Inject constructor(
|
|||
network: Network,
|
||||
networkCurrencies: Set<CryptoCurrency>,
|
||||
): Either<Throwable, Unit> {
|
||||
// Guard: empty networkCurrencies would result in NetworkStatus.Verified(amounts=emptyMap()),
|
||||
// which overwrites any valid cached status and leaves all currencies in this network as Loading.
|
||||
if (networkCurrencies.isEmpty()) {
|
||||
TangemLogger.w("Skipping fetch for $userWalletId [${network.rawId}]: networkCurrencies is empty")
|
||||
return Unit.right()
|
||||
}
|
||||
|
||||
return Either.catchOn(dispatchers.default) {
|
||||
val result = withContext(dispatchers.io) {
|
||||
walletManagersFacade.update(
|
||||
|
|
|
|||
|
|
@ -73,6 +73,32 @@ internal class CommonNetworkStatusFetcherTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fetch skips wallet manager update when networkCurrencies is empty`() = runTest {
|
||||
// Arrange
|
||||
val userWalletId = UserWalletId("011")
|
||||
val network = cryptoCurrencyFactory.ethereum.network
|
||||
|
||||
// Act
|
||||
val actual = fetcher.fetch(
|
||||
userWalletId = userWalletId,
|
||||
network = network,
|
||||
networkCurrencies = emptySet(),
|
||||
)
|
||||
|
||||
// Assert: returns success without touching the wallet manager facade — guard prevents storing
|
||||
// a NetworkStatus.Verified with empty `amounts` over an existing valid cached status.
|
||||
Truth.assertThat(actual).isEqualTo(Either.Right(Unit))
|
||||
|
||||
coVerify(inverse = true) {
|
||||
walletManagersFacade.update(
|
||||
userWalletId = any(),
|
||||
network = any(),
|
||||
extraTokens = any(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ProvideTestModels
|
||||
fun `fetch successfully for any result of walletManagersFacade`(model: SuccessTestModel) = runTest {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue