Updated on 2026-08-14
This commit is contained in:
parent
07833b1814
commit
439fb00fb2
14 changed files with 89 additions and 39 deletions
|
|
@ -13,7 +13,7 @@ import com.tangem.features.onramp.impl.R
|
|||
* @property currencyName currency name
|
||||
* @property networkName network name
|
||||
* @property currencyIconState currency icon state
|
||||
* @property onAddClick lambda be invoked when add button is clicked
|
||||
* @property addButtonUM add button UM
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
|
|
@ -22,7 +22,7 @@ data class OnrampAddToPortfolioUM(
|
|||
val currencyName: String,
|
||||
val networkName: String,
|
||||
val currencyIconState: CurrencyIconState,
|
||||
val onAddClick: () -> Unit,
|
||||
val addButtonUM: AddButtonUM,
|
||||
) {
|
||||
|
||||
val bsTitle: TextReference = resourceReference(id = R.string.common_add_token)
|
||||
|
|
@ -37,5 +37,8 @@ data class OnrampAddToPortfolioUM(
|
|||
formatArgs = wrappedList(networkName),
|
||||
)
|
||||
|
||||
val addButtonText: TextReference = resourceReference(R.string.common_add_to_portfolio)
|
||||
data class AddButtonUM(val isProgress: Boolean, val onClick: () -> Unit) {
|
||||
|
||||
val text: TextReference = resourceReference(R.string.common_add_to_portfolio)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import com.tangem.features.onramp.hottokens.portfolio.entity.OnrampAddToPortfoli
|
|||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
|
@ -48,7 +49,7 @@ internal class OnrampAddToPortfolioModel @Inject constructor(
|
|||
currencyName = params.cryptoCurrency.name,
|
||||
networkName = params.cryptoCurrency.network.name,
|
||||
currencyIconState = params.currencyIconState,
|
||||
onAddClick = ::onAddClick,
|
||||
addButtonUM = OnrampAddToPortfolioUM.AddButtonUM(isProgress = false, onClick = ::onAddClick),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -60,8 +61,12 @@ internal class OnrampAddToPortfolioModel @Inject constructor(
|
|||
|
||||
private fun onAddClick() {
|
||||
modelScope.launch {
|
||||
changeAddButtonProgressStatus(isProgress = true)
|
||||
|
||||
derivePublicKeysUseCase(params.userWalletId, listOfNotNull(params.cryptoCurrency)).getOrElse {
|
||||
Timber.e("Failed to derive public keys: $it")
|
||||
|
||||
changeAddButtonProgressStatus(isProgress = false)
|
||||
}
|
||||
|
||||
addCryptoCurrenciesUseCase(
|
||||
|
|
@ -69,6 +74,13 @@ internal class OnrampAddToPortfolioModel @Inject constructor(
|
|||
currencies = listOfNotNull(params.cryptoCurrency),
|
||||
)
|
||||
.onRight { params.onSuccessAdding(params.cryptoCurrency.id) }
|
||||
.onLeft { changeAddButtonProgressStatus(isProgress = false) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun changeAddButtonProgressStatus(isProgress: Boolean) {
|
||||
_state.update {
|
||||
it.copy(addButtonUM = it.addButtonUM.copy(isProgress = isProgress))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,8 +66,7 @@ fun OnrampAddToPortfolioContent(state: OnrampAddToPortfolioUM) {
|
|||
SpacerH24()
|
||||
|
||||
AddToPortfolioButton(
|
||||
text = state.addButtonText,
|
||||
onClick = state.onAddClick,
|
||||
state = state.addButtonUM,
|
||||
modifier = Modifier.padding(horizontal = 16.dp),
|
||||
)
|
||||
|
||||
|
|
@ -109,13 +108,13 @@ private fun CurrencyNetworkName(text: TextReference, modifier: Modifier = Modifi
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun AddToPortfolioButton(text: TextReference, onClick: () -> Unit, modifier: Modifier = Modifier) {
|
||||
private fun AddToPortfolioButton(state: OnrampAddToPortfolioUM.AddButtonUM, modifier: Modifier = Modifier) {
|
||||
TangemButton(
|
||||
text = text.resolveReference(),
|
||||
text = state.text.resolveReference(),
|
||||
icon = TangemButtonIconPosition.End(iconResId = R.drawable.ic_tangem_24),
|
||||
onClick = onClick,
|
||||
onClick = state.onClick,
|
||||
colors = TangemButtonsDefaults.primaryButtonColors,
|
||||
showProgress = false,
|
||||
showProgress = state.isProgress,
|
||||
enabled = true,
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
size = TangemButtonSize.WideAction,
|
||||
|
|
@ -150,7 +149,7 @@ private fun PreviewOnrampAddToPortfolioContent() {
|
|||
isGrayscale = false,
|
||||
showCustomBadge = false,
|
||||
),
|
||||
onAddClick = {},
|
||||
addButtonUM = OnrampAddToPortfolioUM.AddButtonUM(isProgress = false, onClick = {}),
|
||||
),
|
||||
)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ internal class DefaultOnrampOperationComponent @AssistedInject constructor(
|
|||
context = child(key = "hot_crypto"),
|
||||
params = HotCryptoComponent.Params(
|
||||
userWalletId = params.userWalletId,
|
||||
onTokenClick = model::onTokenClick,
|
||||
onTokenClick = model::onHotTokenClick,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,18 @@ internal class OnrampOperationModel @Inject constructor(
|
|||
},
|
||||
)
|
||||
|
||||
selectTokenIfDemoModeOff(status)
|
||||
}
|
||||
|
||||
fun onHotTokenClick(status: CryptoCurrencyStatus) {
|
||||
analyticsEventHandler.send(
|
||||
event = MainScreenAnalyticsEvent.HotTokenClicked(currencySymbol = status.currency.symbol),
|
||||
)
|
||||
|
||||
selectTokenIfDemoModeOff(status)
|
||||
}
|
||||
|
||||
private fun selectTokenIfDemoModeOff(status: CryptoCurrencyStatus) {
|
||||
if (params is Params.Sell || !onrampFeatureToggles.isFeatureEnabled) {
|
||||
showErrorIfDemoModeOrElse { selectToken(status) }
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue