Updated on 2026-08-14
This commit is contained in:
parent
2e3d8506ad
commit
4e49562a24
2 changed files with 42 additions and 50 deletions
|
|
@ -59,48 +59,23 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
}
|
||||
is OnDestroy -> cancelAll()
|
||||
is OnTokenContractAddressChanged -> {
|
||||
val address = action.contractAddress.value
|
||||
val contractAddress = action.contractAddress.value
|
||||
|
||||
when (val error = ContractAddress.validateValue(address)) {
|
||||
null -> {
|
||||
// valid contract address
|
||||
ContractAddress.removeError()
|
||||
updateTokenDetailFields(false)
|
||||
changeBlockchainNetworkList()
|
||||
checkAndUpdateAddButton()
|
||||
manageFoundTokenChanges(requestInfoAboutToken(address))
|
||||
}
|
||||
AddCustomTokenError.FieldIsEmpty -> {
|
||||
// empty contract address
|
||||
ContractAddress.removeError()
|
||||
clearTokenDetailsFields()
|
||||
updateTokenDetailFields(false)
|
||||
changeBlockchainNetworkList()
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
AddCustomTokenError.InvalidContractAddress -> {
|
||||
ContractAddress.addError(error)
|
||||
updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled())
|
||||
changeBlockchainNetworkList()
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
}
|
||||
validateContractAddressAndNotify(contractAddress)
|
||||
}
|
||||
is OnTokenNetworkChanged -> {
|
||||
if (!action.blockchainNetwork.isUserInput) return
|
||||
|
||||
val contractAddress = ContractAddress.getFieldValue<String>()
|
||||
val error = ContractAddress.validateValue(contractAddress)
|
||||
if (error == null && contractAddress.isNotEmpty()) {
|
||||
// token branch
|
||||
manageFoundTokenChanges(requestInfoAboutToken(contractAddress))
|
||||
} else {
|
||||
// blockchain branch
|
||||
val isAlreadyAdded = isBlockchainPersistIntoAppSavedTokensList(
|
||||
selectedNetwork = action.blockchainNetwork.value
|
||||
)
|
||||
updateWarningAlreadyAdded(isAlreadyAdded)
|
||||
checkAndUpdateAddButton()
|
||||
when (validateContractAddressAndNotify(contractAddress)) {
|
||||
is AddCustomTokenError.InvalidContractAddress -> {
|
||||
val isAlreadyAdded = isBlockchainPersistIntoAppSavedTokensList(
|
||||
selectedNetwork = action.blockchainNetwork.value
|
||||
)
|
||||
updateWarningAlreadyAdded(isAlreadyAdded)
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
is OnTokenDerivationPathChanged -> {
|
||||
|
|
@ -118,19 +93,7 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
updateWarningAlreadyAdded(isAlreadyAdded)
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
is OnTokenNameChanged -> {
|
||||
// changeBlockchainNetworkList()
|
||||
// updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled())
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
is OnTokenSymbolChanged -> {
|
||||
// changeBlockchainNetworkList()
|
||||
// updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled())
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
is OnTokenDecimalsChanged -> {
|
||||
// changeBlockchainNetworkList()
|
||||
// updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled())
|
||||
is OnTokenNameChanged, is OnTokenSymbolChanged, is OnTokenDecimalsChanged -> {
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
is OnAddCustomTokenClicked -> {
|
||||
|
|
@ -157,6 +120,35 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun validateContractAddressAndNotify(contractAddress: String): AddCustomTokenError? {
|
||||
val error = ContractAddress.validateValue(contractAddress)
|
||||
when (error) {
|
||||
null -> {
|
||||
// valid contract address
|
||||
ContractAddress.removeError()
|
||||
updateTokenDetailFields(false)
|
||||
changeBlockchainNetworkList()
|
||||
checkAndUpdateAddButton()
|
||||
manageFoundTokenChanges(requestInfoAboutToken(contractAddress))
|
||||
}
|
||||
AddCustomTokenError.FieldIsEmpty -> {
|
||||
// empty contract address
|
||||
ContractAddress.removeError()
|
||||
clearTokenDetailsFields()
|
||||
updateTokenDetailFields(false)
|
||||
changeBlockchainNetworkList()
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
AddCustomTokenError.InvalidContractAddress -> {
|
||||
ContractAddress.addError(error)
|
||||
updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled())
|
||||
changeBlockchainNetworkList()
|
||||
checkAndUpdateAddButton()
|
||||
}
|
||||
}
|
||||
return error
|
||||
}
|
||||
|
||||
/**
|
||||
* This feature is only needed until Solana coins are added.
|
||||
* While they are not there - this function excludes the Solana blockchain if the user has
|
||||
|
|
|
|||
|
|
@ -172,10 +172,10 @@ data class AddCustomTokenState(
|
|||
Blockchain.Unknown,
|
||||
Blockchain.Ethereum,
|
||||
Blockchain.BSC,
|
||||
Blockchain.Binance, // not evm
|
||||
Blockchain.Polygon,
|
||||
Blockchain.Avalanche,
|
||||
Blockchain.Fantom,
|
||||
Blockchain.Binance, // not evm
|
||||
Blockchain.Solana, // not evm. Should be unsupported for coins until they are added to the Blockchain SDK
|
||||
)
|
||||
if (type == CustomTokenType.Token) networks.remove(Blockchain.Solana)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue