Updated on 2026-08-14

This commit is contained in:
Tangem 2023-08-28 10:51:17 +03:00
parent cd02ce7bc0
commit e421ca8d32
11 changed files with 160 additions and 31 deletions

View file

@ -1,5 +1,7 @@
package com.tangem.tap.features.customtoken.impl.presentation.routers
import com.tangem.blockchain.common.Blockchain
/**
* Custom token feature router
*
@ -12,4 +14,10 @@ internal interface CustomTokenRouter {
/** Open wallet (main) screen */
fun openWalletScreen()
/** Open alert if solana network is unsupported
*
* @param blockchain blockchain to show alert
*/
fun openUnsupportedNetworkAlert(blockchain: Blockchain)
}

View file

@ -1,8 +1,12 @@
package com.tangem.tap.features.customtoken.impl.presentation.routers
import com.tangem.blockchain.common.Blockchain
import com.tangem.core.navigation.AppScreen
import com.tangem.core.navigation.NavigationAction
import com.tangem.tap.common.extensions.dispatchDialogShow
import com.tangem.tap.common.redux.AppDialog
import com.tangem.tap.store
import com.tangem.wallet.R
/** Default implementation of custom token feature router */
internal class DefaultCustomTokenRouter : CustomTokenRouter {
@ -14,4 +18,13 @@ internal class DefaultCustomTokenRouter : CustomTokenRouter {
override fun openWalletScreen() {
store.dispatch(NavigationAction.PopBackTo(screen = AppScreen.Wallet))
}
override fun openUnsupportedNetworkAlert(blockchain: Blockchain) {
val alert = AppDialog.SimpleOkDialogRes(
headerId = R.string.common_warning,
messageId = R.string.alert_manage_tokens_unsupported_curve_message,
args = listOf(blockchain.fullName),
)
store.dispatchDialogShow(alert)
}
}

View file

@ -635,6 +635,15 @@ internal class AddCustomTokenViewModel @Inject constructor(
return derivationNetwork.derivationPath(derivationStyle)
}
private fun isUnsupportedBlockchain(blockchain: Blockchain): Boolean {
val scanResponse = reduxStateHolder.scanResponse
val canHandleToken = scanResponse?.card?.canHandleBlockchain(
blockchain = blockchain,
cardTypesResolver = scanResponse.cardTypesResolver,
) ?: false
return !canHandleToken
}
private inner class ActionsHandler(private val featureRouter: CustomTokenRouter) {
fun onBackButtonClick() {
@ -747,6 +756,11 @@ internal class AddCustomTokenViewModel @Inject constructor(
fun onAddCustomTokenClick() {
if (!isNetworkSelected()) return
val blockchain = uiState.form.networkSelectorField.selectedItem.blockchain
if (isUnsupportedBlockchain(blockchain)) {
featureRouter.openUnsupportedNetworkAlert(blockchain)
return
}
val currency = when (getCustomTokenType()) {
CustomTokenType.TOKEN -> {
@ -758,13 +772,13 @@ internal class AddCustomTokenViewModel @Inject constructor(
decimals = requireNotNull(uiState.form.decimalsInputField.value.toIntOrNull()),
id = foundToken?.id,
),
network = uiState.form.networkSelectorField.selectedItem.blockchain,
network = blockchain,
derivationPath = getDerivationPath(),
)
}
CustomTokenType.BLOCKCHAIN -> {
CustomCurrency.CustomBlockchain(
network = uiState.form.networkSelectorField.selectedItem.blockchain,
network = blockchain,
derivationPath = getDerivationPath(),
)
}