Updated on 2026-08-14

This commit is contained in:
Tangem 2022-04-15 10:57:21 +04:00
parent 27f05207a3
commit 61eabc7864
6 changed files with 48 additions and 28 deletions

View file

@ -168,7 +168,8 @@ class CurrenciesRepository(val context: Application) {
fun getSupportedTokens(isTestNet: Boolean = false): List<Currency> {
val fileName = if (isTestNet) "testnet_tokens" else "tokens"
val json = context.assets.readJsonFileToString(fileName)
return currenciesAdapter.fromJson(json)!!.tokens.map { Currency.fromJsonObject(it) }
return currenciesAdapter.fromJson(json)!!.tokens
.map { Currency.fromJsonObject(it, isTestNet) }
}
private fun loadTokensJson(blockchain: Blockchain): String? {

View file

@ -21,13 +21,13 @@ data class ContractFromJson(
@JsonClass(generateAdapter = true)
data class CurrenciesFromJson(
val imageHost: String,
val imageHost: String?,
val tokens: List<CurrencyFromJson>
)
fun List<ContractFromJson>.toContracts(): List<Contract> {
return mapNotNull { Contract.fromJsonObject(it) }
fun List<ContractFromJson>.toContracts(isTestNet: Boolean): List<Contract> {
return mapNotNull { Contract.fromJsonObject(it, isTestNet) }
}
data class Currency(
@ -39,13 +39,13 @@ data class Currency(
) {
companion object {
fun fromJsonObject(currency: CurrencyFromJson): Currency {
fun fromJsonObject(currency: CurrencyFromJson, isTestNet: Boolean): Currency {
return Currency(
id = currency.id,
name = currency.name,
symbol = currency.symbol,
iconUrl = getIconUrl(currency.id),
contracts = currency.contracts?.toContracts()
contracts = currency.contracts?.toContracts(isTestNet)
)
}
}
@ -60,16 +60,19 @@ data class Contract(
) {
companion object {
fun fromJsonObject(contract: ContractFromJson): Contract? {
val blockchain = Blockchain.fromNetworkId(contract.networkId) ?: return null
fun fromJsonObject(contract: ContractFromJson, isTestNet: Boolean): Contract? {
val networkId = if (isTestNet) contract.networkId + TESTNET else contract.networkId
val blockchain = Blockchain.fromNetworkId(networkId) ?: return null
return Contract(
networkId = contract.networkId,
networkId = networkId,
blockchain = blockchain,
address = contract.address,
decimalCount = contract.decimalCount,
iconUrl = getIconUrl(contract.networkId)
)
}
const val TESTNET = "-testnet"
}
}

View file

@ -10,11 +10,13 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.SubcomposeAsyncImage
import coil.request.ImageRequest
import com.tangem.blockchain.common.Blockchain
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.tap.common.extensions.getGreyedOutIconRes
@ -36,10 +38,12 @@ fun CollapsedCurrencyItem(
.clickable(onClick = { onCurrencyClick(currency.id) })
) {
val blockchain = Blockchain.fromNetworkId(currency.id)
val iconRes = currency.iconUrl
SubcomposeAsyncImage(
model = iconRes,
model = ImageRequest.Builder(LocalContext.current)
.data(currency.iconUrl)
.crossfade(true)
.build(),
contentDescription = currency.id,
loading = { CurrencyPlaceholderIcon(currency.id) },
error = { CurrencyPlaceholderIcon(currency.id) },

View file

@ -11,12 +11,14 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.SubcomposeAsyncImage
import coil.request.ImageRequest
import com.tangem.blockchain.common.Blockchain
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.tap.domain.tokens.Currency
@ -36,9 +38,6 @@ fun ExpandedCurrencyItem(
onAddCurrencyToggled: (Currency, TokenWithBlockchain?) -> Unit,
onNetworkItemClicked: (ContractAddress) -> Unit
) {
val blockchain = Blockchain.fromNetworkId(currency.id)
val iconRes = currency.iconUrl
Column {
Row(
modifier = Modifier
@ -46,7 +45,10 @@ fun ExpandedCurrencyItem(
.clickable(onClick = { onCurrencyClick(currency.id) })
) {
SubcomposeAsyncImage(
model = iconRes,
model = ImageRequest.Builder(LocalContext.current)
.data(currency.iconUrl)
.crossfade(true)
.build(),
contentDescription = currency.id,
loading = { CurrencyPlaceholderIcon(currency.id) },
error = { CurrencyPlaceholderIcon(currency.id) },

View file

@ -19,11 +19,11 @@ class MultiWalletReducer {
fun reduce(action: WalletAction.MultiWallet, state: WalletState): WalletState {
return when (action) {
is WalletAction.MultiWallet.AddBlockchains -> {
val wallets: List<WalletStore> = action.blockchains.map { blockchain ->
val walletManager = action.walletManagers.first {
val wallets: List<WalletStore> = action.blockchains.mapNotNull { blockchain ->
val walletManager = action.walletManagers.firstOrNull {
it.wallet.blockchain == blockchain.blockchain &&
(it.wallet.publicKey.derivationPath?.rawPath == blockchain.derivationPath)
}
} ?: return@mapNotNull null
val wallet = walletManager.wallet
val cardToken = if (!state.isMultiwalletAllowed) {
wallet.getFirstToken()?.symbol?.let { TokenData("", tokenSymbol = it) }