Updated on 2026-08-14

This commit is contained in:
Tangem 2023-07-13 09:44:52 +03:00
parent 546fd40ec2
commit 8e44c110bb
7 changed files with 297 additions and 18 deletions

View file

@ -1,8 +1,8 @@
package com.tangem.data.tokens.di
import com.tangem.data.tokens.repository.DefaultNetworksRepository
import com.tangem.data.tokens.repository.DefaultQuotesRepository
import com.tangem.data.tokens.repository.DefaultTokensRepository
import com.tangem.data.tokens.repository.MockNetworksRepository
import com.tangem.data.tokens.repository.MockQuotesRepository
import com.tangem.data.tokens.repository.MockTokensRepository
import com.tangem.domain.tokens.repository.NetworksRepository
import com.tangem.domain.tokens.repository.QuotesRepository
import com.tangem.domain.tokens.repository.TokensRepository
@ -18,13 +18,13 @@ internal object TokensDataModule {
@Provides
@Singleton
fun provideTokensRepository(): TokensRepository = DefaultTokensRepository()
fun provideTokensRepository(): TokensRepository = MockTokensRepository()
@Provides
@Singleton
fun provideQuotesRepository(): QuotesRepository = DefaultQuotesRepository()
fun provideQuotesRepository(): QuotesRepository = MockQuotesRepository()
@Provides
@Singleton
fun provideNetworksRepository(): NetworksRepository = DefaultNetworksRepository()
fun provideNetworksRepository(): NetworksRepository = MockNetworksRepository()
}

View file

@ -0,0 +1,56 @@
package com.tangem.data.tokens.mock
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.NetworkStatus
import java.math.BigDecimal
@Suppress("MemberVisibilityCanBePrivate")
internal object MockNetworks {
val network1 = Network(
id = Network.ID("network1"),
name = "Network One",
)
val network2 = Network(
id = Network.ID("network2"),
name = "Network Two",
)
val network3 = Network(
id = Network.ID("network3"),
name = "Network Three",
)
val networks = setOf(network1, network2, network3)
val networkStatus1 = NetworkStatus(
networkId = network1.id,
value = NetworkStatus.Verified(
amounts = mapOf(
MockTokens.token1.id to BigDecimal("123.1234556789"),
MockTokens.token2.id to BigDecimal("42.2"),
MockTokens.token3.id to BigDecimal("1000000000.5"),
),
),
)
val networkStatus2 = NetworkStatus(
networkId = network2.id,
value = NetworkStatus.MissedDerivation,
)
val networkStatus3 = NetworkStatus(
networkId = network3.id,
value = NetworkStatus.Verified(
amounts = mapOf(
MockTokens.token7.id to BigDecimal.ZERO,
MockTokens.token8.id to BigDecimal.TEN,
MockTokens.token9.id to BigDecimal.TEN,
MockTokens.token10.id to BigDecimal.TEN,
),
),
)
val networksStatuses = setOf(networkStatus1, networkStatus2, networkStatus3)
}

View file

@ -0,0 +1,70 @@
package com.tangem.data.tokens.mock
import com.tangem.domain.tokens.model.Quote
import java.math.BigDecimal
@Suppress("MemberVisibilityCanBePrivate")
internal object MockQuotes {
val quote1 = Quote(
tokenId = MockTokens.token1.id,
fiatRate = BigDecimal("1.23"),
priceChange = BigDecimal("0.01"),
)
val quote2 = Quote(
tokenId = MockTokens.token2.id,
fiatRate = BigDecimal("2.34"),
priceChange = BigDecimal("-0.02"),
)
val quote3 = Quote(
tokenId = MockTokens.token3.id,
fiatRate = BigDecimal("3.45"),
priceChange = BigDecimal("0.03"),
)
val quote4 = Quote(
tokenId = MockTokens.token4.id,
fiatRate = BigDecimal("4.56"),
priceChange = BigDecimal("-0.04"),
)
val quote5 = Quote(
tokenId = MockTokens.token5.id,
fiatRate = BigDecimal("5.67"),
priceChange = BigDecimal("0.05"),
)
val quote6 = Quote(
tokenId = MockTokens.token6.id,
fiatRate = BigDecimal("6.78"),
priceChange = BigDecimal("-0.06"),
)
val quote7 = Quote(
tokenId = MockTokens.token7.id,
fiatRate = BigDecimal("7.89"),
priceChange = BigDecimal("0.07"),
)
val quote8 = Quote(
tokenId = MockTokens.token8.id,
fiatRate = BigDecimal("8.90"),
priceChange = BigDecimal("-0.08"),
)
val quote9 = Quote(
tokenId = MockTokens.token9.id,
fiatRate = BigDecimal("9.01"),
priceChange = BigDecimal("0.09"),
)
val quote10 = Quote(
tokenId = MockTokens.token10.id,
fiatRate = BigDecimal("10.12"),
priceChange = BigDecimal("-0.10"),
)
val quotes = setOf(quote1, quote2, quote3, quote4, quote5, quote6, quote7, quote8, quote9, quote10)
}

View file

@ -0,0 +1,132 @@
package com.tangem.data.tokens.mock
import com.tangem.domain.tokens.model.Token
import com.tangem.domain.wallets.models.UserWalletId
internal object MockTokens {
val token1 get() = Token(
id = Token.ID("token1"),
networkId = MockNetworks.network1.id,
name = "Token 1",
symbol = "T1",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = true,
)
val token2 get() = Token(
id = Token.ID("token2"),
networkId = MockNetworks.network1.id,
name = "Token 2",
symbol = "T2",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = false,
)
val token3 get() = Token(
id = Token.ID("token3"),
networkId = MockNetworks.network1.id,
name = "Token 3",
symbol = "T3",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = false,
)
val token4 get() = Token(
id = Token.ID("token4"),
networkId = MockNetworks.network2.id,
name = "Token 4",
symbol = "T4",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = true,
)
val token5 get() = Token(
id = Token.ID("token5"),
networkId = MockNetworks.network2.id,
name = "Token 5",
symbol = "T5",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = false,
)
val token6 get() = Token(
id = Token.ID("token6"),
networkId = MockNetworks.network2.id,
name = "Token 6",
symbol = "T6",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = false,
)
val token7 get() = Token(
id = Token.ID("token7"),
networkId = MockNetworks.network3.id,
name = "Token 7",
symbol = "T7",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = true,
)
val token8 get() = Token(
id = Token.ID("token8"),
networkId = MockNetworks.network3.id,
name = "Token 8",
symbol = "T8",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = false,
)
val token9 get() = Token(
id = Token.ID("token9"),
networkId = MockNetworks.network3.id,
name = "Token 9",
symbol = "T9",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = false,
)
val token10 get() = Token(
id = Token.ID("token10"),
networkId = MockNetworks.network3.id,
name = "Token 10",
symbol = "T10",
isCustom = false,
decimals = 8,
iconUrl = null,
isCoin = false,
)
val tokens get() = mapOf(
UserWalletId(stringValue = "123") to setOf(
token1, token2, token3, token4, token5,
token6, token7, token8, token9, token10,
),
UserWalletId(stringValue = "321") to setOf(token1, token2, token3),
UserWalletId(stringValue = "42") to setOf(token7, token8, token9, token10),
UserWalletId(stringValue = "24") to setOf(token4, token5, token6),
)
val isGrouped get() = mapOf(
UserWalletId(stringValue = "123") to true,
UserWalletId(stringValue = "321") to false,
UserWalletId(stringValue = "42") to false,
UserWalletId(stringValue = "24") to true,
)
val isSortedByBalance get() = mapOf(
UserWalletId(stringValue = "123") to true,
UserWalletId(stringValue = "321") to false,
UserWalletId(stringValue = "42") to true,
UserWalletId(stringValue = "24") to false,
)
}

View file

@ -1,6 +1,8 @@
package com.tangem.data.tokens.repository
import arrow.core.Either
import arrow.core.right
import com.tangem.data.tokens.mock.MockNetworks
import com.tangem.domain.tokens.error.TokensError
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.NetworkStatus
@ -8,11 +10,15 @@ import com.tangem.domain.tokens.model.Token
import com.tangem.domain.tokens.repository.NetworksRepository
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
internal class DefaultNetworksRepository : NetworksRepository {
internal class MockNetworksRepository : NetworksRepository {
override fun getNetworks(networksIds: Set<Network.ID>): Either<TokensError, Set<Network>> {
TODO("Not yet implemented")
return MockNetworks.networks
.filter { it.id in networksIds }
.toSet()
.right()
}
override fun getNetworkStatuses(
@ -20,6 +26,11 @@ internal class DefaultNetworksRepository : NetworksRepository {
networks: Map<Network.ID, Set<Token.ID>>,
refresh: Boolean,
): Flow<Either<TokensError, Set<NetworkStatus>>> {
TODO("Not yet implemented")
return flowOf(
MockNetworks.networksStatuses
.filter { it.networkId in networks.keys }
.toSet()
.right(),
)
}
}

View file

@ -1,15 +1,23 @@
package com.tangem.data.tokens.repository
import arrow.core.Either
import arrow.core.right
import com.tangem.data.tokens.mock.MockQuotes
import com.tangem.domain.tokens.error.TokensError
import com.tangem.domain.tokens.model.Quote
import com.tangem.domain.tokens.model.Token
import com.tangem.domain.tokens.repository.QuotesRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
internal class DefaultQuotesRepository : QuotesRepository {
internal class MockQuotesRepository : QuotesRepository {
override fun getQuotes(tokensIds: Set<Token.ID>, refresh: Boolean): Flow<Either<TokensError, Set<Quote>>> {
TODO("Not yet implemented")
return flowOf(
MockQuotes.quotes
.filter { it.tokenId in tokensIds }
.toSet()
.right(),
)
}
}

View file

@ -1,32 +1,34 @@
package com.tangem.data.tokens.repository
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import com.tangem.data.tokens.mock.MockTokens
import com.tangem.domain.tokens.error.TokensError
import com.tangem.domain.tokens.model.Token
import com.tangem.domain.tokens.repository.TokensRepository
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
internal class DefaultTokensRepository : TokensRepository {
internal class MockTokensRepository : TokensRepository {
override suspend fun sortTokens(
userWalletId: UserWalletId,
sortedTokensIds: Set<Token.ID>,
isGrouped: Boolean,
isSortedByBalance: Boolean,
): Either<TokensError, Unit> {
TODO("Not yet implemented")
}
): Either<TokensError, Unit> = Unit.right()
override fun getTokens(userWalletId: UserWalletId, refresh: Boolean): Flow<Either<TokensError, Set<Token>>> {
TODO("Not yet implemented")
return flowOf(value = MockTokens.tokens[userWalletId]?.right() ?: TokensError.EmptyTokens.left())
}
override fun isTokensGrouped(userWalletId: UserWalletId): Flow<Either<TokensError, Boolean>> {
TODO("Not yet implemented")
return flowOf(MockTokens.isGrouped[userWalletId]?.right() ?: TokensError.EmptyTokens.left())
}
override fun isTokensSortedByBalance(userWalletId: UserWalletId): Flow<Either<TokensError, Boolean>> {
TODO("Not yet implemented")
return flowOf(MockTokens.isSortedByBalance[userWalletId]?.right() ?: TokensError.EmptyTokens.left())
}
}