Updated on 2026-08-14
This commit is contained in:
parent
b6a69d7e69
commit
90486a54fc
5 changed files with 41 additions and 36 deletions
|
|
@ -17,5 +17,5 @@ interface CustomTokenInteractor {
|
|||
|
||||
/** Save token [customCurrency] */
|
||||
@Throws(TangemError::class)
|
||||
suspend fun saveToken(customCurrency: CustomCurrency)
|
||||
suspend fun saveToken(customCurrency: CustomCurrency): Result<Unit>
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.tangem.tap.features.customtoken.impl.domain
|
||||
|
||||
import arrow.core.getOrElse
|
||||
import arrow.core.raise.result
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchainsdk.utils.toNetworkId
|
||||
import com.tangem.data.tokens.utils.CryptoCurrencyFactory
|
||||
|
|
@ -15,7 +17,6 @@ import com.tangem.tap.domain.model.Currency
|
|||
import com.tangem.tap.features.customtoken.impl.domain.models.FoundToken
|
||||
import com.tangem.tap.proxy.redux.DaggerGraphState
|
||||
import com.tangem.tap.store
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Default implementation of custom token interactor
|
||||
|
|
@ -45,16 +46,18 @@ class DefaultCustomTokenInteractor(
|
|||
)
|
||||
}
|
||||
|
||||
override suspend fun saveToken(customCurrency: CustomCurrency) {
|
||||
val userWallet = getSelectedWalletSyncUseCase().fold(ifLeft = { return }, ifRight = { it })
|
||||
val currency = Currency.fromCustomCurrency(customCurrency)
|
||||
|
||||
val currencies = listOfNotNull(element = currency.toCryptoCurrency(userWallet.scanResponse))
|
||||
derivePublicKeysUseCase(userWalletId = userWallet.walletId, currencies = currencies)
|
||||
.onRight {
|
||||
addCryptoCurrenciesUseCase(userWalletId = userWallet.walletId, currencies = currencies)
|
||||
override suspend fun saveToken(customCurrency: CustomCurrency): Result<Unit> {
|
||||
return result {
|
||||
val userWallet = getSelectedWalletSyncUseCase().getOrElse {
|
||||
error("Failed to get selected wallet: $it")
|
||||
}
|
||||
.onLeft { Timber.e("Failed to derive public keys: $it") }
|
||||
|
||||
val currency = Currency.fromCustomCurrency(customCurrency)
|
||||
val currencies = listOfNotNull(element = currency.toCryptoCurrency(userWallet.scanResponse))
|
||||
|
||||
derivePublicKeysUseCase(userWalletId = userWallet.walletId, currencies = currencies).bind()
|
||||
addCryptoCurrenciesUseCase(userWalletId = userWallet.walletId, currencies = currencies).bind()
|
||||
}
|
||||
}
|
||||
|
||||
private fun Currency.toCryptoCurrency(scanResponse: ScanResponse): CryptoCurrency? {
|
||||
|
|
|
|||
|
|
@ -886,17 +886,26 @@ internal class AddCustomTokenViewModel @Inject constructor(
|
|||
|
||||
analyticsSender.sendWhenAddTokenButtonClicked(currency)
|
||||
|
||||
viewModelScope.launch(dispatchers.io) {
|
||||
val oldButtonState = uiState.floatingButton
|
||||
viewModelScope.launch {
|
||||
uiState = uiState.copySealed(
|
||||
floatingButton = uiState.floatingButton.copy(isEnabled = false, showProgress = true),
|
||||
floatingButton = uiState.floatingButton.copy(
|
||||
isEnabled = false,
|
||||
showProgress = true,
|
||||
),
|
||||
)
|
||||
runCatching { featureInteractor.saveToken(currency) }
|
||||
|
||||
val result = featureInteractor.saveToken(currency)
|
||||
|
||||
uiState = uiState.copySealed(
|
||||
floatingButton = uiState.floatingButton.copy(
|
||||
isEnabled = true,
|
||||
showProgress = false,
|
||||
),
|
||||
)
|
||||
|
||||
result
|
||||
.onSuccess { featureRouter.openWalletScreen() }
|
||||
.onFailure {
|
||||
uiState = uiState.copySealed(floatingButton = oldButtonState)
|
||||
Timber.e(it)
|
||||
}
|
||||
.onFailure { Timber.e(it, "Unable to save custom token") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue