Updated on 2026-08-14
This commit is contained in:
commit
de99ae0e61
6 changed files with 31 additions and 25 deletions
|
|
@ -61,15 +61,9 @@ internal class CustomTokenFormModel @Inject constructor(
|
|||
|
||||
if (params.network.canHandleTokens) {
|
||||
observeTokenFormUpdates()
|
||||
} else {
|
||||
modelScope.launch {
|
||||
customCurrencyValidator.createCoin(
|
||||
userWalletId = params.userWalletId,
|
||||
networkId = params.network.id,
|
||||
derivationPath = getDerivationPath(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
createCoin()
|
||||
}
|
||||
|
||||
private fun getInitialState(): CustomTokenFormUM {
|
||||
|
|
@ -112,6 +106,7 @@ internal class CustomTokenFormModel @Inject constructor(
|
|||
}
|
||||
.distinctUntilChanged()
|
||||
.sample(periodMillis = 1_000)
|
||||
.drop(count = 1) // Skip initial state
|
||||
.onEach { formValues ->
|
||||
customCurrencyValidator.validateForm(
|
||||
userWalletId = params.userWalletId,
|
||||
|
|
@ -151,6 +146,14 @@ internal class CustomTokenFormModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createCoin() = modelScope.launch {
|
||||
customCurrencyValidator.createCoin(
|
||||
userWalletId = params.userWalletId,
|
||||
networkId = params.network.id,
|
||||
derivationPath = getDerivationPath(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun updateStateWithCurrency(
|
||||
currency: CryptoCurrency,
|
||||
fillForm: Boolean,
|
||||
|
|
|
|||
|
|
@ -75,9 +75,12 @@ internal class CustomCurrencyValidator @Inject constructor(
|
|||
is AddCustomTokenForm.Validated.All -> {
|
||||
findOrCreateCurrency(userWalletId, networkId, derivationPath, validatedForm)
|
||||
}
|
||||
is AddCustomTokenForm.Validated.ContractAddress -> {
|
||||
is AddCustomTokenForm.Validated.ContractAddressOnly -> {
|
||||
findToken(userWalletId, networkId, derivationPath, validatedForm)
|
||||
}
|
||||
is AddCustomTokenForm.Validated.Empty -> {
|
||||
createCoin(userWalletId, networkId, derivationPath)
|
||||
}
|
||||
}
|
||||
}.saveInAndJoin(validateFormJobHolder)
|
||||
}
|
||||
|
|
@ -132,7 +135,7 @@ internal class CustomCurrencyValidator @Inject constructor(
|
|||
userWalletId: UserWalletId,
|
||||
networkId: Network.ID,
|
||||
derivationPath: Network.DerivationPath,
|
||||
validatedForm: AddCustomTokenForm.Validated.ContractAddress,
|
||||
validatedForm: AddCustomTokenForm.Validated.ContractAddressOnly,
|
||||
) {
|
||||
updateStatus(Status.SearchingToken)
|
||||
|
||||
|
|
|
|||
|
|
@ -94,9 +94,6 @@ internal fun CustomTokenFormUM.updateWithContractAddressException(
|
|||
val updatedFields = fields.mutate {
|
||||
it[Field.CONTRACT_ADDRESS] = it.getValue(Field.CONTRACT_ADDRESS).copy(
|
||||
error = when (exception) {
|
||||
CustomTokenFormValidationException.ContractAddress.Empty -> {
|
||||
null // Should not display this error
|
||||
}
|
||||
CustomTokenFormValidationException.ContractAddress.Invalid -> {
|
||||
resourceReference(R.string.custom_token_creation_error_invalid_contract_address)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue