Updated on 2026-08-14

This commit is contained in:
Tangem 2022-10-24 21:33:35 +05:00
commit 69cfd56c13
3 changed files with 26 additions and 9 deletions

View file

@ -26,10 +26,11 @@ class UserTokensRepository(
private val networkService: UserTokensNetworkService,
) {
suspend fun getUserTokens(card: Card): List<Currency> {
if (DemoHelper.isDemoCardId(card.cardId)) {
return loadDemoCurrencies()
}
val userId = card.getUserId()
if (DemoHelper.isDemoCardId(card.cardId)) {
return loadTokensOffline(card, userId).ifEmpty { loadDemoCurrencies() }
}
if (!NetworkConnectivity.getInstance().isOnlineOrConnecting()) {
return loadTokensOffline(card, userId)
}
@ -68,9 +69,15 @@ class UserTokensRepository(
}
suspend fun loadBlockchainsToDerive(card: Card): List<BlockchainNetwork> {
return storageService.getUserTokens(card.getUserId())?.toBlockchainNetworks() ?: storageService.getUserTokens(
card,
).toBlockchainNetworks()
val userId = card.getUserId()
val blockchainNetworks = loadTokensOffline(card, userId).toBlockchainNetworks()
if (DemoHelper.isDemoCardId(card.cardId)) {
return blockchainNetworks
.ifEmpty { loadDemoCurrencies().toBlockchainNetworks() }
}
return blockchainNetworks
}
private fun loadDemoCurrencies(): List<Currency> {

View file

@ -137,4 +137,13 @@ fun Blockchain.toCoinId(): String {
Blockchain.SaltPay, Blockchain.SaltPayTestnet -> "xdai"
Blockchain.Unknown -> "unknown"
}
}
}
fun Blockchain.isSupportedInApp(): Boolean {
return !excludedBlockchains.contains(this)
}
private val excludedBlockchains = listOf(
Blockchain.Optimism, // TODO: remove when fee calculation is fixed
Blockchain.SaltPay,
)

View file

@ -21,8 +21,9 @@ fun Card.supportedBlockchains(): List<Blockchain> {
(Blockchain.fromCurve(EllipticCurve.Secp256k1) + Blockchain.fromCurve(EllipticCurve.Ed25519)).distinct()
}
}
val filtered = supportedBlockchains.filter { isTestCard == it.isTestnet() }
return filtered
return supportedBlockchains
.filter { isTestCard == it.isTestnet() }
.filter { it.isSupportedInApp() }
}
fun Card.supportedTokens(): List<Blockchain> {