Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-17 17:10:19 +08:00
parent 4d028cc8e4
commit f04fdd1406
5 changed files with 46 additions and 18 deletions

View file

@ -10,11 +10,9 @@ internal sealed class WalletEvent {
data class ShowError(val text: TextReference) : WalletEvent()
data class ShowToast(val text: TextReference) : WalletEvent()
data class ShowAlert(val state: WalletAlertState) : WalletEvent()
data class CopyAddress(val address: String, val toast: TextReference) : WalletEvent()
data class CopyAddress(val address: String) : WalletEvent()
data class RateApp(val onDismissClick: () -> Unit) : WalletEvent()

View file

@ -1,7 +1,7 @@
package com.tangem.feature.wallet.presentation.wallet.ui
import android.widget.Toast
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
@ -11,6 +11,7 @@ import androidx.compose.ui.text.AnnotatedString
import com.tangem.core.ui.event.EventEffect
import com.tangem.core.ui.event.StateEvent
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.feature.wallet.impl.R
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletAlertState
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent
import com.tangem.feature.wallet.presentation.wallet.ui.utils.ReviewManagerRequester
@ -42,12 +43,12 @@ internal fun WalletEventEffect(
is WalletEvent.ShowError -> {
snackbarHostState.showSnackbar(message = value.text.resolveReference(resources))
}
is WalletEvent.ShowToast -> {
Toast.makeText(context, value.text.resolveReference(resources), Toast.LENGTH_SHORT).show()
}
is WalletEvent.CopyAddress -> {
clipboardManager.setText(AnnotatedString(value.address))
Toast.makeText(context, value.toast.resolveReference(resources), Toast.LENGTH_SHORT).show()
snackbarHostState.showSnackbar(
message = resources.getString(R.string.wallet_notification_address_copied),
duration = SnackbarDuration.Short,
)
}
is WalletEvent.ShowAlert -> onAlertConfigSet(value.state)
is WalletEvent.RateApp -> {

View file

@ -38,7 +38,10 @@ import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBot
import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheet
import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheetConfig
import com.tangem.core.ui.components.keyboardAsState
import com.tangem.core.ui.components.snackbar.CopiedTextSnackbar
import com.tangem.core.ui.components.snackbar.TangemSnackbar
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.core.ui.event.StateEvent
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.test.TestTags
import com.tangem.feature.wallet.impl.R
@ -288,7 +291,11 @@ private fun BaseScaffoldManageTokenRedesign(
BottomSheetScaffold(
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
WalletSnackbarHost(
snackbarHostState = it,
event = state.event,
modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing16),
)
},
containerColor = TangemTheme.colors.background.secondary,
sheetContainerColor = TangemTheme.colors.background.primary,
@ -492,7 +499,13 @@ private fun BaseScaffold(
) {
Scaffold(
topBar = { WalletTopBar(config = state.topBarConfig) },
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
snackbarHost = {
WalletSnackbarHost(
snackbarHostState = snackbarHostState,
event = state.event,
modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing16),
)
},
floatingActionButton = {
val manageTokensButtonConfig by remember(state.selectedWalletIndex) {
mutableStateOf(
@ -529,6 +542,21 @@ private fun BaseScaffold(
)
}
@Composable
private fun WalletSnackbarHost(
snackbarHostState: SnackbarHostState,
event: StateEvent<WalletEvent>,
modifier: Modifier = Modifier,
) {
SnackbarHost(hostState = snackbarHostState, modifier = modifier) { data ->
if (event is StateEvent.Triggered && event.data is WalletEvent.CopyAddress) {
CopiedTextSnackbar(data)
} else {
TangemSnackbar(data)
}
}
}
@Composable
private fun ManageTokensButton(onClick: () -> Unit) {
PrimaryButton(

View file

@ -7,7 +7,10 @@ import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBot
import com.tangem.core.ui.components.bottomsheets.tokenreceive.AddressModel
import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheetConfig
import com.tangem.core.ui.components.bottomsheets.tokenreceive.mapToAddressModels
import com.tangem.core.ui.extensions.*
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.WrappedList
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
import com.tangem.domain.appcurrency.extenstions.unwrap
import com.tangem.domain.common.util.cardTypesResolver
@ -39,7 +42,6 @@ import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.launch
import java.lang.IllegalArgumentException
import javax.inject.Inject
interface WalletCurrencyActionsClickIntents {
@ -204,11 +206,10 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
.find { it.type == AddressType.Default }
?.value
?.let {
stateHolder.update(CloseBottomSheetTransformer(userWalletId = stateHolder.getSelectedWalletId()))
walletEventSender.send(
event = WalletEvent.CopyAddress(
address = it,
toast = resourceReference(R.string.wallet_notification_address_copied),
),
event = WalletEvent.CopyAddress(address = it),
)
}
}
@ -270,7 +271,7 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
.fold(
ifLeft = {
walletEventSender.send(
event = WalletEvent.ShowToast(text = resourceReference(R.string.common_error)),
event = WalletEvent.ShowError(text = resourceReference(R.string.common_error)),
)
},
ifRight = {

View file

@ -154,7 +154,7 @@ internal class WalletWarningsClickIntentsImplementor @Inject constructor(
val event = when (error) {
is UnlockWalletsError.DataError,
is UnlockWalletsError.UnableToUnlockWallets,
-> WalletEvent.ShowToast(resourceReference(R.string.user_wallet_list_error_unable_to_unlock))
-> WalletEvent.ShowError(resourceReference(R.string.user_wallet_list_error_unable_to_unlock))
is UnlockWalletsError.NoUserWalletSelected,
is UnlockWalletsError.NotAllUserWalletsUnlocked,
-> WalletEvent.ShowAlert(WalletAlertState.RescanWallets)