From 2c259cb036fa17c27a01f0eec069fbc1b850876c Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 11 Sep 2023 16:33:28 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../com/tangem/datasource/di/NetworkModule.kt | 5 +- .../src/main/res/drawable/ic_currency_24.xml | 2 +- .../drawable/ic_exchange_horizontal_24.xml | 9 +++ .../presentation/common/WalletPreviewData.kt | 2 +- .../wallet/state/TokenActionButtonConfig.kt | 3 +- .../state/factory/TokenActionsProvider.kt | 76 ++++++++++++------- .../state/factory/WalletStateFactory.kt | 5 +- .../ui/components/TokenActionsBottomSheet.kt | 3 +- .../wallet/viewmodels/WalletViewModel.kt | 11 ++- 9 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 core/ui/src/main/res/drawable/ic_exchange_horizontal_24.xml diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt b/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt index 10abba599f..e68a69e06e 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt @@ -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) diff --git a/core/ui/src/main/res/drawable/ic_currency_24.xml b/core/ui/src/main/res/drawable/ic_currency_24.xml index bee87c2b68..1b8eb1b684 100644 --- a/core/ui/src/main/res/drawable/ic_currency_24.xml +++ b/core/ui/src/main/res/drawable/ic_currency_24.xml @@ -5,5 +5,5 @@ android:viewportHeight="24"> + android:fillColor="#000000" /> diff --git a/core/ui/src/main/res/drawable/ic_exchange_horizontal_24.xml b/core/ui/src/main/res/drawable/ic_exchange_horizontal_24.xml new file mode 100644 index 0000000000..ab4c32c060 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_exchange_horizontal_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt index 8fd27445cb..307db0c04c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt @@ -304,7 +304,7 @@ internal object WalletPreviewData { onDismissRequest = {}, actions = listOf( TokenActionButtonConfig( - text = "Send", + text = TextReference.Str("Send"), iconResId = R.drawable.ic_share_24, onClick = {}, ), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/TokenActionButtonConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/TokenActionButtonConfig.kt index 934bfd6230..2c95c35f55 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/TokenActionButtonConfig.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/TokenActionButtonConfig.kt @@ -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, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt index 37c3309f8b..8b8c5f5086 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt @@ -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 { - // TODO: [REDACTED_JIRA] - return mockTokenActionButtonConfig(cryptoCurrencyStatus).toImmutableList() + fun provideActions(tokenActions: TokenActionsState): ImmutableList { + return convertTokenActionsState(tokenActions) } - private fun mockTokenActionButtonConfig(cryptoCurrencyStatus: CryptoCurrencyStatus): List { - 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 { + 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, ) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt index 4a282a682c..00e8cbc09a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt @@ -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, ), ) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt index 31ea416730..7037bcdd39 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/TokenActionsBottomSheet.kt @@ -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 SimpleSettingsRow( - title = action.text, + title = action.text.resolveReference(), icon = action.iconResId, enabled = action.enabled, onItemsClick = action.onClick, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 537366f56b..6efc2b0461 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -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) {