Updated on 2026-08-14

This commit is contained in:
Tangem 2025-02-07 19:22:14 +04:00
parent 69754e4159
commit 9ad06df95c
6 changed files with 52 additions and 7 deletions

View file

@ -48,9 +48,20 @@ internal class DefaultNetworksRepository(
private val responseCurrenciesFactory = ResponseCryptoCurrenciesFactory(excludedBlockchains)
private val networkStatusFactory = NetworkStatusFactory()
override suspend fun fetchNetworkStatuses(userWalletId: UserWalletId, networks: Set<Network>, refresh: Boolean) {
TODO("Will be implemented in [REDACTED_TASK_KEY]")
}
override fun getNetworkStatusesUpdates(
userWalletId: UserWalletId,
networks: Set<Network>,
): Flow<Set<NetworkStatus>> {
TODO("Will be implemented in [REDACTED_TASK_KEY]")
}
override fun getNetworkStatusesUpdatesLegacy(
userWalletId: UserWalletId,
networks: Set<Network>,
): Flow<Set<NetworkStatus>> = channelFlow {
networksStatusesStore.get(userWalletId)
.onEach(::send)

View file

@ -4,7 +4,7 @@ import java.math.BigDecimal
sealed class UpdateWalletManagerResult {
object MissedDerivation : UpdateWalletManagerResult()
data object MissedDerivation : UpdateWalletManagerResult()
data class Unreachable(
val selectedAddress: String? = null,

View file

@ -9,5 +9,5 @@ sealed class CryptoCurrencyAmountStatus {
data class Loaded(val value: BigDecimal) : CryptoCurrencyAmountStatus()
object NotFound : CryptoCurrencyAmountStatus()
data object NotFound : CryptoCurrencyAmountStatus()
}

View file

@ -17,7 +17,6 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.tokens.repository.NetworksRepository
import com.tangem.domain.tokens.repository.QuotesRepository
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
@ -35,7 +34,6 @@ internal class CurrenciesStatusesLceOperations(
)
}
@OptIn(ExperimentalCoroutinesApi::class)
private fun transformToCurrenciesStatuses(
userWalletId: UserWalletId,
currenciesFlow: EitherFlow<TokenListError, List<CryptoCurrency>>,
@ -181,7 +179,7 @@ internal class CurrenciesStatusesLceOperations(
userWalletId: UserWalletId,
networks: NonEmptySet<Network>,
): EitherFlow<TokenListError, Set<NetworkStatus>> {
return networksRepository.getNetworkStatusesUpdates(userWalletId, networks)
return networksRepository.getNetworkStatusesUpdatesLegacy(userWalletId, networks)
.map<Set<NetworkStatus>, Either<TokenListError, Set<NetworkStatus>>> { it.right() }
.catch { emit(TokenListError.DataError(it).left()) }
.distinctUntilChanged()

View file

@ -10,6 +10,31 @@ import kotlinx.coroutines.flow.Flow
* Repository for everything related to the blockchain networks
* */
interface NetworksRepository {
/**
* Retrieves updates of network statuses of specified blockchain networks for a specific user wallet.
*
* To fetch and populate the cache with network statuses, use [fetchNetworkStatuses].
*
* @param userWalletId The unique identifier of the user wallet.
* @param networks A set of network which statuses are to be retrieved.
*
* @return A [Flow] emitting a set of [NetworkStatus] objects corresponding to the specified networks.
* */
fun getNetworkStatusesUpdates(userWalletId: UserWalletId, networks: Set<Network>): Flow<Set<NetworkStatus>>
/**
* Fetches network statuses of specified blockchain networks for a specific user wallet.
*
* Fetched network statuses are stored in the local cache and can be retrieved by calling
* [getNetworkStatusesUpdates].
*
* @param userWalletId The unique identifier of the user wallet.
* @param networks A set of network which statuses are to be retrieved.
* @param refresh A boolean flag indicating whether the data should be refreshed. Default is `false`.
* */
suspend fun fetchNetworkStatuses(userWalletId: UserWalletId, networks: Set<Network>, refresh: Boolean = false)
/**
* Retrieves updates of network statuses of specified blockchain networks for a specific user wallet.
*
@ -19,7 +44,7 @@ interface NetworksRepository {
* @param networks A set of network which statuses are to be retrieved.
* @return A [Flow] emitting a set of [NetworkStatus] objects corresponding to the specified networks.
*/
fun getNetworkStatusesUpdates(userWalletId: UserWalletId, networks: Set<Network>): Flow<Set<NetworkStatus>>
fun getNetworkStatusesUpdatesLegacy(userWalletId: UserWalletId, networks: Set<Network>): Flow<Set<NetworkStatus>>
/**
* Fetches pending transactions for given network

View file

@ -22,6 +22,17 @@ internal class MockNetworksRepository(
return statuses.map { it.getOrElse { e -> throw e } }
}
override suspend fun fetchNetworkStatuses(userWalletId: UserWalletId, networks: Set<Network>, refresh: Boolean) {
/* no-op */
}
override fun getNetworkStatusesUpdatesLegacy(
userWalletId: UserWalletId,
networks: Set<Network>,
): Flow<Set<NetworkStatus>> {
return statuses.map { it.getOrElse { e -> throw e } }
}
override suspend fun fetchNetworkPendingTransactions(userWalletId: UserWalletId, networks: Set<Network>) {
// no-op
}
@ -31,7 +42,7 @@ internal class MockNetworksRepository(
networks: Set<Network>,
refresh: Boolean,
): Set<NetworkStatus> {
return getNetworkStatusesUpdates(userWalletId, networks).first()
return getNetworkStatusesUpdatesLegacy(userWalletId, networks).first()
}
override fun isNeedToCreateAccountWithoutReserve(network: Network) = false