Updated on 2026-08-14
This commit is contained in:
parent
3560144914
commit
d8368a08f0
7 changed files with 69 additions and 15 deletions
|
|
@ -0,0 +1,6 @@
|
|||
package com.tangem.tap.features.customtoken.impl.presentation.models
|
||||
|
||||
internal enum class SupportBlockchainType {
|
||||
|
||||
SUPPORTED, UNSUPPORTED, UNABLE_TO_DETERMINE
|
||||
}
|
||||
|
|
@ -20,4 +20,6 @@ internal interface CustomTokenRouter {
|
|||
* @param blockchain blockchain to show alert
|
||||
*/
|
||||
fun openUnsupportedNetworkAlert(blockchain: Blockchain)
|
||||
|
||||
fun showGenericErrorAlertAndPopBack()
|
||||
}
|
||||
|
|
@ -27,4 +27,13 @@ internal class DefaultCustomTokenRouter : CustomTokenRouter {
|
|||
)
|
||||
store.dispatchDialogShow(alert)
|
||||
}
|
||||
|
||||
override fun showGenericErrorAlertAndPopBack() {
|
||||
val alert = AppDialog.SimpleOkDialogRes(
|
||||
headerId = R.string.common_error,
|
||||
messageId = R.string.common_unknown_error,
|
||||
onOk = { store.dispatch(NavigationAction.PopBackTo()) },
|
||||
)
|
||||
store.dispatchDialogShow(alert)
|
||||
}
|
||||
}
|
||||
|
|
@ -697,14 +697,19 @@ internal class AddCustomTokenViewModel @Inject constructor(
|
|||
return derivationNetwork.derivationPath(derivationStyle)
|
||||
}
|
||||
|
||||
private fun isUnsupportedBlockchain(blockchain: Blockchain): Boolean {
|
||||
private fun getSupportBlockchainType(blockchain: Blockchain): SupportBlockchainType {
|
||||
return getSelectedWalletSyncUseCase().fold(
|
||||
ifLeft = { false },
|
||||
ifLeft = { SupportBlockchainType.UNABLE_TO_DETERMINE },
|
||||
ifRight = {
|
||||
!it.scanResponse.card.canHandleBlockchain(
|
||||
val canHandleBlockchain = it.scanResponse.card.canHandleBlockchain(
|
||||
blockchain = blockchain,
|
||||
cardTypesResolver = it.scanResponse.cardTypesResolver,
|
||||
)
|
||||
if (canHandleBlockchain) {
|
||||
SupportBlockchainType.SUPPORTED
|
||||
} else {
|
||||
SupportBlockchainType.UNSUPPORTED
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -824,9 +829,18 @@ internal class AddCustomTokenViewModel @Inject constructor(
|
|||
fun onAddCustomTokenClick() {
|
||||
if (!isNetworkSelected()) return
|
||||
val blockchain = uiState.form.networkSelectorField.selectedItem.blockchain
|
||||
if (isUnsupportedBlockchain(blockchain)) {
|
||||
featureRouter.openUnsupportedNetworkAlert(blockchain)
|
||||
return
|
||||
when (getSupportBlockchainType(blockchain)) {
|
||||
SupportBlockchainType.SUPPORTED -> {
|
||||
/* no-op */
|
||||
}
|
||||
SupportBlockchainType.UNSUPPORTED -> {
|
||||
featureRouter.openUnsupportedNetworkAlert(blockchain)
|
||||
return
|
||||
}
|
||||
SupportBlockchainType.UNABLE_TO_DETERMINE -> {
|
||||
featureRouter.showGenericErrorAlertAndPopBack()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val currency = when (getCustomTokenType()) {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,15 @@ internal class DefaultTokensListRouter : TokensListRouter {
|
|||
store.dispatchDialogShow(alert)
|
||||
}
|
||||
|
||||
override fun showGenericErrorAlertAndPopBack() {
|
||||
val alert = AppDialog.SimpleOkDialogRes(
|
||||
headerId = R.string.common_error,
|
||||
messageId = R.string.common_unknown_error,
|
||||
onOk = { store.dispatch(NavigationAction.PopBackTo()) },
|
||||
)
|
||||
store.dispatchDialogShow(alert)
|
||||
}
|
||||
|
||||
override fun openNetworkTokensNotSupportAlert(networkName: String) {
|
||||
store.dispatchDialogShow(
|
||||
AppDialog.SimpleOkDialogRes(
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ internal interface TokensListRouter {
|
|||
*/
|
||||
fun openUnsupportedNetworkAlert(blockchain: Blockchain)
|
||||
|
||||
fun showGenericErrorAlertAndPopBack()
|
||||
|
||||
/**
|
||||
* Open alert with unsupported networks tokens error
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
|
|||
import com.tangem.tap.common.extensions.dispatchWithMain
|
||||
import com.tangem.tap.common.extensions.fullNameWithoutTestnet
|
||||
import com.tangem.tap.common.extensions.getNetworkName
|
||||
import com.tangem.tap.features.customtoken.impl.presentation.models.SupportBlockchainType
|
||||
import com.tangem.tap.features.tokens.impl.domain.TokensListInteractor
|
||||
import com.tangem.tap.features.tokens.impl.domain.models.Token
|
||||
import com.tangem.tap.features.tokens.impl.domain.models.Token.Network
|
||||
|
|
@ -380,12 +381,18 @@ internal class TokensListViewModel @Inject constructor(
|
|||
toggledNetwork.changeToggleState()
|
||||
}
|
||||
} else {
|
||||
if (isUnsupportedBlockchain(blockchain)) {
|
||||
router.openUnsupportedNetworkAlert(blockchain)
|
||||
} else {
|
||||
analyticsSender.sendWhenBlockchainAdded(blockchain)
|
||||
changedBlockchainList.add(blockchain)
|
||||
toggledNetwork.changeToggleState()
|
||||
when (getSupportBlockchainType(blockchain)) {
|
||||
SupportBlockchainType.SUPPORTED -> {
|
||||
analyticsSender.sendWhenBlockchainAdded(blockchain)
|
||||
changedBlockchainList.add(blockchain)
|
||||
toggledNetwork.changeToggleState()
|
||||
}
|
||||
SupportBlockchainType.UNSUPPORTED -> {
|
||||
router.openUnsupportedNetworkAlert(blockchain)
|
||||
}
|
||||
SupportBlockchainType.UNABLE_TO_DETERMINE -> {
|
||||
router.showGenericErrorAlertAndPopBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -469,14 +476,19 @@ internal class TokensListViewModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private fun isUnsupportedBlockchain(blockchain: Blockchain): Boolean {
|
||||
private fun getSupportBlockchainType(blockchain: Blockchain): SupportBlockchainType {
|
||||
return getSelectedWalletSyncUseCase().fold(
|
||||
ifLeft = { false },
|
||||
ifLeft = { SupportBlockchainType.UNABLE_TO_DETERMINE },
|
||||
ifRight = {
|
||||
!it.scanResponse.card.canHandleBlockchain(
|
||||
val canHandleBlockchain = it.scanResponse.card.canHandleBlockchain(
|
||||
blockchain = blockchain,
|
||||
cardTypesResolver = it.scanResponse.cardTypesResolver,
|
||||
)
|
||||
if (canHandleBlockchain) {
|
||||
SupportBlockchainType.SUPPORTED
|
||||
} else {
|
||||
SupportBlockchainType.UNSUPPORTED
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue