Updated on 2026-08-14

This commit is contained in:
Tangem 2022-05-20 22:59:49 +03:00
parent 46995368e3
commit f64b387fe2
2 changed files with 25 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.DerivationStyle
import com.tangem.blockchain.common.Token
import com.tangem.domain.common.ScanResponse
import com.tangem.domain.common.extensions.canHandleToken
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.tap.domain.tokens.Currency
import com.tangem.tap.features.wallet.redux.WalletData
@ -19,7 +20,14 @@ data class TokensState(
val allowToAdd: Boolean = true,
val derivationStyle: DerivationStyle? = null,
val scanResponse: ScanResponse? = null
) : StateType
) : StateType {
fun canHandleToken(token: TokenWithBlockchain?): Boolean {
val token = token ?: return false
val card = scanResponse?.card ?: return false
return card.canHandleToken(token.blockchain)
}
}
typealias ContractAddress = String
@ -62,7 +70,7 @@ fun List<Currency>.filter(supportedBlockchains: Set<Blockchain>?): List<Currency
it.copy(contracts =
it.contracts.filter {
supportedBlockchains.contains(it.blockchain) &&
(it.blockchain.canHandleTokens() || it.address == null)
(it.blockchain.canHandleTokens() || it.address == null)
}
)
}.filterNot {

View file

@ -22,7 +22,9 @@ import com.tangem.domain.common.TapWorkarounds.useOldStyleDerivation
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.tap.common.compose.Keyboard
import com.tangem.tap.common.compose.keyboardAsState
import com.tangem.tap.common.extensions.dispatchDialogShow
import com.tangem.tap.common.extensions.pixelsToDp
import com.tangem.tap.common.redux.AppDialog
import com.tangem.tap.domain.tokens.Currency
import com.tangem.tap.features.tokens.redux.ContractAddress
import com.tangem.tap.features.tokens.redux.TokenWithBlockchain
@ -37,7 +39,7 @@ fun CurrenciesScreen(
onSaveChanges: (List<TokenWithBlockchain>, List<Blockchain>) -> Unit,
onNetworkItemClicked: (ContractAddress) -> Unit
) {
val context = LocalContext.current
val addedTokensState = remember { mutableStateOf(tokensState.value.addedTokens) }
val addedBlockchainsState = remember { mutableStateOf(tokensState.value.addedBlockchains) }
@ -103,7 +105,18 @@ fun CurrenciesScreen(
addedBlockchains = addedBlockchainsState.value,
searchInput = searchInput.value,
allowToAdd = tokensState.value.allowToAdd,
onAddCurrencyToggled = onAddCurrencyToggleClick,
onAddCurrencyToggled = { currency, token ->
onAddCurrencyToggleClick(currency, token)
if (!tokensState.value.canHandleToken(token)) {
val dialog = AppDialog.SimpleOkDialog(
header = context.getString(R.string.common_warning),
message = context.getString(R.string.alert_manage_tokens_unsupported_message)
) {
onAddCurrencyToggleClick(currency, token)
}
store.dispatchDialogShow(dialog)
}
},
onNetworkItemClicked = onNetworkItemClicked
)
}