Updated on 2026-08-14
This commit is contained in:
parent
5e42e64172
commit
55eb45a3a2
3 changed files with 7 additions and 5 deletions
|
|
@ -36,7 +36,7 @@ class UserTokensRepository(
|
|||
|
||||
return when (val networkResult = networkService.getUserTokens(userId)) {
|
||||
is Result.Success -> {
|
||||
val tokens = networkResult.data.tokens.map { Currency.fromTokenResponse(it) }
|
||||
val tokens = networkResult.data.tokens.mapNotNull { Currency.fromTokenResponse(it) }
|
||||
storageService.saveUserTokens(card.getUserId(), tokens.toUserTokensResponse())
|
||||
tokens
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class UserTokensStorageService(
|
|||
fun getUserTokens(userId: String): List<Currency>? {
|
||||
return try {
|
||||
val json = fileReader.readFile(getFileNameForUserTokens(userId))
|
||||
userTokensAdapter.fromJson(json)?.tokens?.map { Currency.fromTokenResponse(it) }
|
||||
userTokensAdapter.fromJson(json)?.tokens?.mapNotNull { Currency.fromTokenResponse(it) }
|
||||
} catch (exception: Exception) {
|
||||
Log.error { exception.stackTraceToString() }
|
||||
null
|
||||
|
|
|
|||
|
|
@ -110,7 +110,9 @@ sealed interface Currency {
|
|||
)
|
||||
}
|
||||
|
||||
fun fromTokenResponse(tokenResponse: TokenResponse): Currency {
|
||||
fun fromTokenResponse(tokenResponse: TokenResponse): Currency? {
|
||||
val blockchain = com.tangem.blockchain.common.Blockchain.fromNetworkId(tokenResponse.networkId)
|
||||
?: return null
|
||||
return when {
|
||||
tokenResponse.contractAddress != null -> Token(
|
||||
com.tangem.blockchain.common.Token(
|
||||
|
|
@ -120,11 +122,11 @@ sealed interface Currency {
|
|||
decimals = tokenResponse.decimals,
|
||||
id = tokenResponse.id,
|
||||
),
|
||||
blockchain = com.tangem.blockchain.common.Blockchain.fromNetworkId(tokenResponse.networkId)!!,
|
||||
blockchain = blockchain,
|
||||
derivationPath = tokenResponse.derivationPath,
|
||||
)
|
||||
else -> Blockchain(
|
||||
blockchain = com.tangem.blockchain.common.Blockchain.fromNetworkId(tokenResponse.networkId)!!,
|
||||
blockchain = blockchain,
|
||||
derivationPath = tokenResponse.derivationPath,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue