Updated on 2026-08-14
This commit is contained in:
parent
9c524c8113
commit
11687f6368
34 changed files with 239 additions and 239 deletions
|
|
@ -9,6 +9,7 @@ import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
|
|||
import com.tangem.datasource.local.token.UserTokensStore
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.core.error.DataError
|
||||
import com.tangem.domain.common.util.derivationStyleProvider
|
||||
import com.tangem.domain.demo.DemoConfig
|
||||
import com.tangem.domain.tokens.models.CryptoCurrency
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
|
|
@ -154,7 +155,8 @@ internal class DefaultCurrenciesRepository(
|
|||
val response = userTokensStore.getSyncOrNull(userWallet.walletId)
|
||||
?: userTokensResponseFactory.createUserTokensResponse(
|
||||
currencies = cardCurrenciesFactory.createDefaultCoinsForMultiCurrencyCard(
|
||||
userWallet.scanResponse.card,
|
||||
card = userWallet.scanResponse.card,
|
||||
derivationStyleProvider = userWallet.scanResponse.derivationStyleProvider,
|
||||
),
|
||||
isGroupedByNetwork = false,
|
||||
isSortedByBalance = false,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.tangem.data.tokens.utils
|
||||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.domain.common.DerivationStyleProvider
|
||||
import com.tangem.domain.common.TapWorkarounds.isTestCard
|
||||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.common.util.derivationStyleProvider
|
||||
import com.tangem.domain.demo.DemoConfig
|
||||
import com.tangem.domain.models.scan.CardDTO
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
|
|
@ -12,7 +14,10 @@ import com.tangem.blockchain.common.Token as SdkToken
|
|||
|
||||
internal class CardCurrenciesFactory(private val demoConfig: DemoConfig) {
|
||||
|
||||
fun createDefaultCoinsForMultiCurrencyCard(card: CardDTO): List<CryptoCurrency.Coin> {
|
||||
fun createDefaultCoinsForMultiCurrencyCard(
|
||||
card: CardDTO,
|
||||
derivationStyleProvider: DerivationStyleProvider,
|
||||
): List<CryptoCurrency.Coin> {
|
||||
var blockchains = if (demoConfig.isDemoCardId(card.cardId)) {
|
||||
demoConfig.demoBlockchains
|
||||
} else {
|
||||
|
|
@ -23,25 +28,29 @@ internal class CardCurrenciesFactory(private val demoConfig: DemoConfig) {
|
|||
blockchains = blockchains.mapNotNull { it.getTestnetVersion() }
|
||||
}
|
||||
|
||||
return blockchains.mapNotNull { createCoin(it, card) }
|
||||
return blockchains.mapNotNull { createCoin(it, derivationStyleProvider) }
|
||||
}
|
||||
|
||||
fun createPrimaryCurrencyForSingleCurrencyCard(scanResponse: ScanResponse): CryptoCurrency {
|
||||
val card = scanResponse.card
|
||||
val derivationStyleProvider = scanResponse.derivationStyleProvider
|
||||
val resolver = scanResponse.cardTypesResolver
|
||||
val blockchain = resolver.getBlockchain()
|
||||
|
||||
val coin = requireNotNull(createCoin(blockchain, card)) {
|
||||
val coin = requireNotNull(createCoin(blockchain, derivationStyleProvider)) {
|
||||
"Coin for the single currency card cannot be null"
|
||||
}
|
||||
val primaryToken = resolver.getPrimaryToken()?.let { token ->
|
||||
createToken(token, blockchain, card)
|
||||
createToken(token, blockchain, derivationStyleProvider)
|
||||
}
|
||||
|
||||
return primaryToken ?: coin
|
||||
}
|
||||
|
||||
private fun createToken(sdkToken: SdkToken, blockchain: Blockchain, card: CardDTO): CryptoCurrency.Token? {
|
||||
private fun createToken(
|
||||
sdkToken: SdkToken,
|
||||
blockchain: Blockchain,
|
||||
derivationStyleProvider: DerivationStyleProvider,
|
||||
): CryptoCurrency.Token? {
|
||||
if (blockchain != Blockchain.Unknown) {
|
||||
Timber.e("Unable to map the SDK token to the domain token with Unknown blockchain")
|
||||
return null
|
||||
|
|
@ -56,11 +65,14 @@ internal class CardCurrenciesFactory(private val demoConfig: DemoConfig) {
|
|||
decimals = sdkToken.decimals,
|
||||
isCustom = false,
|
||||
contractAddress = sdkToken.contractAddress,
|
||||
derivationPath = getDerivationPath(blockchain, card),
|
||||
derivationPath = getDerivationPath(blockchain, derivationStyleProvider),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createCoin(blockchain: Blockchain, card: CardDTO): CryptoCurrency.Coin? {
|
||||
private fun createCoin(
|
||||
blockchain: Blockchain,
|
||||
derivationStyleProvider: DerivationStyleProvider,
|
||||
): CryptoCurrency.Coin? {
|
||||
if (blockchain == Blockchain.Unknown) {
|
||||
Timber.e("Unable to map the SDK token to the domain token with Unknown blockchain")
|
||||
return null
|
||||
|
|
@ -73,7 +85,7 @@ internal class CardCurrenciesFactory(private val demoConfig: DemoConfig) {
|
|||
symbol = blockchain.currency,
|
||||
iconUrl = getCoinIconUrl(blockchain),
|
||||
decimals = blockchain.decimals(),
|
||||
derivationPath = getDerivationPath(blockchain, card),
|
||||
derivationPath = getDerivationPath(blockchain, derivationStyleProvider),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,10 @@ package com.tangem.data.tokens.utils
|
|||
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.IconsUtil
|
||||
import com.tangem.domain.common.TapWorkarounds.derivationStyle
|
||||
import com.tangem.domain.common.DerivationStyleProvider
|
||||
import com.tangem.domain.common.extensions.derivationPath
|
||||
import com.tangem.domain.common.extensions.toCoinId
|
||||
import com.tangem.domain.common.extensions.toNetworkId
|
||||
import com.tangem.domain.models.scan.CardDTO
|
||||
import com.tangem.domain.tokens.models.CryptoCurrency.ID
|
||||
import com.tangem.domain.tokens.models.Network
|
||||
import com.tangem.blockchain.common.Token as SdkToken
|
||||
|
|
@ -23,12 +23,8 @@ internal fun isCustomToken(tokenId: ID): Boolean {
|
|||
return tokenId.rawCurrencyId == null
|
||||
}
|
||||
|
||||
internal fun getDerivationPath(blockchain: Blockchain, card: CardDTO): String? {
|
||||
return if (card.settings.isHDWalletAllowed) {
|
||||
blockchain.derivationPath(card.derivationStyle)?.rawPath
|
||||
} else {
|
||||
null
|
||||
}
|
||||
internal fun getDerivationPath(blockchain: Blockchain, derivationStyleProvider: DerivationStyleProvider): String? {
|
||||
return blockchain.derivationPath(derivationStyleProvider.getDerivationStyle())?.rawPath
|
||||
}
|
||||
|
||||
internal fun getBlockchain(networkId: Network.ID): Blockchain {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue