Updated on 2026-08-14

This commit is contained in:
Tangem 2023-09-11 16:33:28 +03:00
parent cad4da6f19
commit 2c259cb036
9 changed files with 79 additions and 37 deletions

View file

@ -8,7 +8,6 @@ import com.tangem.datasource.utils.RequestHeader.*
import com.tangem.datasource.utils.addHeaders
import com.tangem.datasource.utils.allowLogging
import com.tangem.lib.auth.AuthProvider
import com.tangem.lib.auth.BuildConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@ -28,7 +27,7 @@ class NetworkModule {
fun provideTangemTechApi(@NetworkMoshi moshi: Moshi): TangemTechApi {
return Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create(moshi))
.baseUrl(if (BuildConfig.DEBUG) DEV_TANGEM_TECH_BASE_URL else PROD_TANGEM_TECH_BASE_URL)
.baseUrl(PROD_TANGEM_TECH_BASE_URL)
.client(
OkHttpClient.Builder()
.addHeaders(
@ -76,7 +75,7 @@ class NetworkModule {
private fun createBasePromotionRetrofit(okHttpClient: OkHttpClient, moshi: Moshi): PromotionApi {
return Retrofit.Builder()
.addConverterFactory(MoshiConverterFactory.create(moshi))
.baseUrl(if (BuildConfig.DEBUG) DEV_TANGEM_TECH_BASE_URL else PROD_TANGEM_TECH_BASE_URL)
.baseUrl(PROD_TANGEM_TECH_BASE_URL)
.client(okHttpClient)
.build()
.create(PromotionApi::class.java)

View file

@ -5,5 +5,5 @@
android:viewportHeight="24">
<path
android:pathData="M7,15H9C9,16.08 10.37,17 12,17C13.63,17 15,16.08 15,15C15,13.9 13.96,13.5 11.76,12.97C9.64,12.44 7,11.78 7,9C7,7.21 8.47,5.69 10.5,5.18V3H13.5V5.18C15.53,5.69 17,7.21 17,9H15C15,7.92 13.63,7 12,7C10.37,7 9,7.92 9,9C9,10.1 10.04,10.5 12.24,11.03C14.36,11.56 17,12.22 17,15C17,16.79 15.53,18.31 13.5,18.82V21H10.5V18.82C8.47,18.31 7,16.79 7,15Z"
android:fillColor="#1E1E1E" />
android:fillColor="#000000" />
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M21,8L17,4V7H9V9H17V12L21,8ZM7,12L3,16L7,20V17H15V15H7V12Z"
android:fillColor="#000000"/>
</vector>

View file

@ -304,7 +304,7 @@ internal object WalletPreviewData {
onDismissRequest = {},
actions = listOf(
TokenActionButtonConfig(
text = "Send",
text = TextReference.Str("Send"),
iconResId = R.drawable.ic_share_24,
onClick = {},
),

View file

@ -1,6 +1,7 @@
package com.tangem.feature.wallet.presentation.wallet.state
import androidx.annotation.DrawableRes
import com.tangem.core.ui.extensions.TextReference
/**
* Action button config
@ -11,7 +12,7 @@ import androidx.annotation.DrawableRes
* @property enabled enabled
*/
data class TokenActionButtonConfig(
val text: String,
val text: TextReference,
@DrawableRes val iconResId: Int,
val onClick: () -> Unit,
val enabled: Boolean = true,

View file

@ -1,6 +1,8 @@
package com.tangem.feature.wallet.presentation.wallet.state.factory
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.domain.tokens.model.TokenActionsState
import com.tangem.feature.wallet.impl.R
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
import com.tangem.feature.wallet.presentation.wallet.state.TokenActionButtonConfig
@ -14,35 +16,57 @@ import kotlinx.collections.immutable.toImmutableList
* @property clickIntents screen click intents
*
*/
@Suppress("UnusedPrivateMember") // will be used in next PRs
internal class TokenActionsProvider(private val clickIntents: WalletClickIntents) {
fun provideActions(cryptoCurrencyStatus: CryptoCurrencyStatus): ImmutableList<TokenActionButtonConfig> {
// TODO: [REDACTED_JIRA]
return mockTokenActionButtonConfig(cryptoCurrencyStatus).toImmutableList()
fun provideActions(tokenActions: TokenActionsState): ImmutableList<TokenActionButtonConfig> {
return convertTokenActionsState(tokenActions)
}
private fun mockTokenActionButtonConfig(cryptoCurrencyStatus: CryptoCurrencyStatus): List<TokenActionButtonConfig> {
return listOf(
TokenActionButtonConfig(
text = "Send",
iconResId = R.drawable.ic_plus_24,
onClick = { clickIntents.onMultiCurrencySendClick(cryptoCurrencyStatus) },
),
TokenActionButtonConfig(
text = "Buy",
iconResId = R.drawable.ic_plus_24,
onClick = {},
),
TokenActionButtonConfig(
text = "Sell",
iconResId = R.drawable.ic_plus_24,
onClick = {},
),
TokenActionButtonConfig(
text = "Swap",
iconResId = R.drawable.ic_plus_24,
onClick = {},
),
private fun convertTokenActionsState(
tokenActionsState: TokenActionsState,
): ImmutableList<TokenActionButtonConfig> {
return tokenActionsState.states
.map(::tokenActionStateMapper)
.toImmutableList()
}
private fun tokenActionStateMapper(actionsState: TokenActionsState.ActionState): TokenActionButtonConfig {
val title: TextReference
val icon: Int
val action: () -> Unit
when (actionsState) {
is TokenActionsState.ActionState.Buy -> {
title = resourceReference(R.string.common_buy)
icon = R.drawable.ic_plus_24
action = { }
}
is TokenActionsState.ActionState.Receive -> {
title = resourceReference(R.string.common_receive)
icon = R.drawable.ic_arrow_down_24
action = { }
}
is TokenActionsState.ActionState.Sell -> {
title = resourceReference(R.string.common_sell)
icon = R.drawable.ic_currency_24
action = { }
}
is TokenActionsState.ActionState.Send -> {
title = resourceReference(R.string.common_send)
icon = R.drawable.ic_arrow_up_24
action = { }
}
is TokenActionsState.ActionState.Swap -> {
title = resourceReference(R.string.common_swap)
icon = R.drawable.ic_exchange_horizontal_24
action = { }
}
}
return TokenActionButtonConfig(
text = title,
iconResId = icon,
onClick = action,
enabled = actionsState.enabled,
)
}
}

View file

@ -199,16 +199,15 @@ internal class WalletStateFactory(
bottomSheetConfig = state.bottomSheetConfig?.copy(isShow = false),
)
is WalletSingleCurrencyState.Locked -> state.copy(isBottomSheetShow = false)
else -> state
}
}
fun getStateWithTokenActionBottomSheet(currencyStatus: CryptoCurrencyStatus): WalletState {
fun getStateWithTokenActionBottomSheet(tokenActions: TokenActionsState): WalletState {
return when (val state = currentStateProvider() as WalletState.ContentState) {
is WalletMultiCurrencyState.Content -> state.copy(
tokenActionsBottomSheet = ActionsBottomSheetConfig(
isShow = true,
actions = tokenActionsProvider.provideActions(currencyStatus),
actions = tokenActionsProvider.provideActions(tokenActions),
onDismissRequest = clickIntents::onDismissActionsBottomSheet,
),
)

View file

@ -12,6 +12,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
import com.tangem.core.ui.components.SimpleSettingsRow
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
import com.tangem.feature.wallet.presentation.wallet.state.ActionsBottomSheetConfig
@ -38,7 +39,7 @@ private fun ActionsBottomSheetContent(actions: ImmutableList<TokenActionButtonCo
) {
actions.forEach { action ->
SimpleSettingsRow(
title = action.text,
title = action.text.resolveReference(),
icon = action.iconResId,
enabled = action.enabled,
onItemsClick = action.onClick,

View file

@ -496,7 +496,16 @@ internal class WalletViewModel @Inject constructor(
}
override fun onTokenItemLongClick(cryptoCurrencyStatus: CryptoCurrencyStatus) {
uiState = stateFactory.getStateWithTokenActionBottomSheet(cryptoCurrencyStatus)
val state = uiState as? WalletState.ContentState ?: return
val userWallet = getWallet(state.walletsListConfig.selectedWalletIndex)
viewModelScope.launch(dispatchers.io) {
getCryptoCurrencyActionsUseCase
.invoke(userWallet.walletId, cryptoCurrencyStatus.currency)
.take(count = 1)
.collectLatest {
uiState = stateFactory.getStateWithTokenActionBottomSheet(it)
}
}
}
override fun onRenameClick(userWalletId: UserWalletId, name: String) {