Updated on 2026-08-14
This commit is contained in:
parent
3e65b44408
commit
6d91b2e30b
9 changed files with 338 additions and 31 deletions
|
|
@ -41,6 +41,10 @@ fun View.getString(@StringRes id: Int): String {
|
|||
return context.getString(id)
|
||||
}
|
||||
|
||||
fun View.getString(@StringRes id: Int, vararg formatArgs: String): String {
|
||||
return context.getString(id, *formatArgs)
|
||||
}
|
||||
|
||||
fun View.getResourceName(): String {
|
||||
return try {
|
||||
resources.getResourceEntryName(id)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.tangem.tap.domain.extensions.getCustomIconUrl
|
|||
import com.tangem.tap.domain.extensions.setCustomIconUrl
|
||||
import com.tangem.tap.features.demo.DemoHelper
|
||||
import com.tangem.tap.network.createMoshi
|
||||
import timber.log.Timber
|
||||
|
||||
class CurrenciesRepository(val context: Application) {
|
||||
|
||||
|
|
@ -122,16 +123,21 @@ class CurrenciesRepository(val context: Application) {
|
|||
getSupportedTokens()
|
||||
}
|
||||
|
||||
val blockchainTokens = supportedTokens.map {
|
||||
fromJsonToTokensDao(loadTokensJson(it), it)
|
||||
val blockchainTokens = supportedTokens.mapNotNull { blockchain ->
|
||||
loadTokensJson(blockchain)?.let { fromJsonToTokensDao(it, blockchain) }
|
||||
}
|
||||
val tokens = blockchainTokens.flatten().map { it.toToken() }
|
||||
return tokens
|
||||
}
|
||||
|
||||
private fun loadTokensJson(blockchain: Blockchain): String {
|
||||
private fun loadTokensJson(blockchain: Blockchain): String? {
|
||||
val fileName = getFileName(blockchain)
|
||||
return context.assets.readJsonFileToString(fileName)
|
||||
return try {
|
||||
context.assets.readJsonFileToString(fileName)
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Tokens with the file name %s not found", fileName)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getFileName(blockchain: Blockchain): String {
|
||||
|
|
@ -148,12 +154,12 @@ class CurrenciesRepository(val context: Application) {
|
|||
|
||||
private fun getSupportedTokens(): List<Blockchain> {
|
||||
return listOf(
|
||||
Blockchain.Avalanche,
|
||||
Blockchain.Binance,
|
||||
Blockchain.BSC,
|
||||
Blockchain.Ethereum,
|
||||
Blockchain.BSC,
|
||||
Blockchain.Binance,
|
||||
Blockchain.Polygon,
|
||||
Blockchain.Solana,
|
||||
Blockchain.Avalanche,
|
||||
Blockchain.Fantom,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -169,10 +175,11 @@ class CurrenciesRepository(val context: Application) {
|
|||
return excludeUnsupportedBlockchains(blockchains)
|
||||
}
|
||||
|
||||
// Use this list to temporarily exclude a blockchain from the list of tokens.
|
||||
private fun excludeUnsupportedBlockchains(blockchains: List<Blockchain>): List<Blockchain> {
|
||||
return blockchains.toMutableList().apply {
|
||||
removeAll(listOf(
|
||||
// Blockchain.Fantom, Blockchain.FantomTestnet
|
||||
// Any blockchain
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
@ -187,6 +194,13 @@ class CurrenciesRepository(val context: Application) {
|
|||
}
|
||||
}
|
||||
|
||||
fun Blockchain.getTokensName(): String {
|
||||
return when (this) {
|
||||
Blockchain.Fantom -> "Fantom Opera"
|
||||
else -> this.fullName
|
||||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class TokenDao(
|
||||
val name: String,
|
||||
|
|
|
|||
|
|
@ -23,12 +23,11 @@ sealed class CurrencyListItem {
|
|||
blockchains: List<Blockchain>,
|
||||
tokens: List<Token>,
|
||||
): List<CurrencyListItem> {
|
||||
return createBlockchainList(blockchains) +
|
||||
createTokensList(R.string.add_tokens_subtitle_ethereum_tokens, Blockchain.Ethereum, tokens) +
|
||||
createTokensList(R.string.add_tokens_subtitle_bsc_tokens, Blockchain.BSC, tokens) +
|
||||
createTokensList(R.string.add_tokens_subtitle_binance_tokens, Blockchain.Binance, tokens) +
|
||||
createTokensList(R.string.add_tokens_subtitle_polygon_tokens, Blockchain.Polygon, tokens) +
|
||||
createTokensList(R.string.add_tokens_subtitle_avalanche_tokens, Blockchain.Avalanche, tokens)
|
||||
val blockchainsItemList = createBlockchainList(blockchains)
|
||||
val tokenItemsLists = tokens.groupBy { it.blockchain }.map {
|
||||
createTokensList(R.string.add_tokens_subtitle_format, it.key, it.value)
|
||||
}
|
||||
return blockchainsItemList + tokenItemsLists.flatten()
|
||||
}
|
||||
|
||||
private fun createBlockchainList(blockchains: List<Blockchain>): List<CurrencyListItem> {
|
||||
|
|
|
|||
|
|
@ -49,8 +49,7 @@ class TokensMiddleware {
|
|||
cardFirmware = scanResponse.card.firmwareVersion,
|
||||
isTestNet = isTestcard
|
||||
).sortedBy { it.fullName }
|
||||
val currencies =
|
||||
CurrencyListItem.createListOfCurrencies(blockchains, tokens).toMutableList()
|
||||
val currencies = CurrencyListItem.createListOfCurrencies(blockchains, tokens)
|
||||
store.dispatch(TokensAction.LoadCurrencies.Success(currencies))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.tangem.tap.common.extensions.hide
|
|||
import com.tangem.tap.common.extensions.loadCurrenciesIcon
|
||||
import com.tangem.tap.common.extensions.show
|
||||
import com.tangem.tap.domain.tokens.CardCurrencies
|
||||
import com.tangem.tap.domain.tokens.getTokensName
|
||||
import com.tangem.tap.features.tokens.redux.CurrencyListItem
|
||||
import com.tangem.tap.features.tokens.redux.TokensAction
|
||||
import com.tangem.tap.store
|
||||
|
|
@ -211,12 +212,11 @@ class CurrenciesAdapter : ListAdapter<CurrencyListItem, RecyclerView.ViewHolder>
|
|||
}
|
||||
}
|
||||
|
||||
class TitleViewHolder(val view: View) :
|
||||
RecyclerView.ViewHolder(view) {
|
||||
class TitleViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
|
||||
fun bind(title: CurrencyListItem.TitleListItem) {
|
||||
view.tv_subtitle.text = view.getString(title.titleResId).uppercase()
|
||||
|
||||
if (title.blockchain != null) {
|
||||
val subtitle = view.getString(title.titleResId, title.blockchain.getTokensName())
|
||||
view.tv_subtitle.text = subtitle.uppercase()
|
||||
view.cl_subtitle_container.setOnClickListener {
|
||||
val rotation = if (title.isContentShown) -90f else 90f
|
||||
store.dispatch(TokensAction.ToggleShowTokensForBlockchain(
|
||||
|
|
@ -228,6 +228,7 @@ class CurrenciesAdapter : ListAdapter<CurrencyListItem, RecyclerView.ViewHolder>
|
|||
}
|
||||
showArrow(view, title.isContentShown)
|
||||
} else {
|
||||
view.tv_subtitle.text = view.getString(title.titleResId).uppercase()
|
||||
view.iv_toggle_sublist_visibility.hide()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue