Updated on 2026-08-14

This commit is contained in:
Tangem 2022-10-18 03:05:37 +05:00
commit 49798fd8cd
9 changed files with 43 additions and 38 deletions

View file

@ -278,7 +278,7 @@ class TokensMiddleware {
val factory = store.state.globalState.tapWalletManager.walletManagerFactory
val derivationStyle = scanResponse.card.derivationStyle
val addActions = currencyList.mapNotNull { currency ->
val addActions = currencyList.mapIndexedNotNull { index, currency ->
when (currency) {
is Currency.Blockchain -> {
val derivationPath = currency.derivationPath?.let { DerivationPath(it) }
@ -293,12 +293,12 @@ class TokensMiddleware {
scanResponse = scanResponse,
blockchain = currency.blockchain,
derivationParams = derivationParams,
) ?: return@mapNotNull null
) ?: return@mapIndexedNotNull null
val blockchainNetwork = BlockchainNetwork.fromWalletManager(walletManager)
WalletAction.MultiWallet.AddBlockchain(
blockchain = blockchainNetwork,
walletManager = walletManager,
save = true,
save = index == currencyList.lastIndex,
)
}
is Currency.Token -> {
@ -309,7 +309,7 @@ class TokensMiddleware {
WalletAction.MultiWallet.AddToken(
token = currency.token,
blockchain = blockchainNetwork,
save = true,
save = index == currencyList.lastIndex,
)
}
}

View file

@ -59,9 +59,9 @@ sealed interface Currency {
fun isToken(): Boolean = this is Token
fun toTokenResponse(): TokenResponse {
return TokenResponse(
id = coinId ?: "",
id = coinId,
networkId = blockchain.toNetworkId(),
derivationPath = derivationPath ?: DERIVATION_PATH_RAW_VALUE,
derivationPath = derivationPath,
name = currencyName,
symbol = currencySymbol,
decimals = decimals,
@ -70,7 +70,6 @@ sealed interface Currency {
}
companion object {
private const val DERIVATION_PATH_RAW_VALUE = "m/44/0'/0/0"
fun fromBlockchainNetwork(
blockchainNetwork: BlockchainNetwork,
token: com.tangem.blockchain.common.Token? = null,
@ -112,11 +111,6 @@ sealed interface Currency {
}
fun fromTokenResponse(tokenResponse: TokenResponse): Currency {
val derivationPath = if (tokenResponse.derivationPath == DERIVATION_PATH_RAW_VALUE) {
null
} else {
tokenResponse.derivationPath
}
return when {
tokenResponse.contractAddress != null -> Token(
com.tangem.blockchain.common.Token(
@ -127,11 +121,11 @@ sealed interface Currency {
id = tokenResponse.id,
),
blockchain = com.tangem.blockchain.common.Blockchain.fromNetworkId(tokenResponse.networkId)!!,
derivationPath = derivationPath,
derivationPath = tokenResponse.derivationPath,
)
else -> Blockchain(
blockchain = com.tangem.blockchain.common.Blockchain.fromNetworkId(tokenResponse.networkId)!!,
derivationPath = derivationPath,
derivationPath = tokenResponse.derivationPath,
)
}
}