Updated on 2026-08-14

This commit is contained in:
Tangem 2023-12-25 09:19:37 +02:00
parent 950aafe4ed
commit e0bc66f30c
8 changed files with 42 additions and 6 deletions

View file

@ -11,8 +11,8 @@ data class TokensDataStateExpress(
companion object {
val EMPTY =
TokensDataStateExpress(
fromGroup = CurrenciesGroup(emptyList(), emptyList()),
toGroup = CurrenciesGroup(emptyList(), emptyList()),
fromGroup = CurrenciesGroup(emptyList(), emptyList(), false),
toGroup = CurrenciesGroup(emptyList(), emptyList(), false),
allProviders = emptyList(),
)
}
@ -21,4 +21,5 @@ data class TokensDataStateExpress(
data class CurrenciesGroup(
val available: List<CryptoCurrencySwapInfo>,
val unavailable: List<CryptoCurrencySwapInfo>,
val afterSearch: Boolean,
)

View file

@ -148,6 +148,7 @@ internal class SwapInteractorImpl @Inject constructor(
return CurrenciesGroup(
available = availableCryptoCurrencies,
unavailable = unavailableCryptoCurrencies.map { CryptoCurrencySwapInfo(it, emptyList()) },
afterSearch = false
)
}

View file

@ -49,6 +49,7 @@ class TokensDataConverter(
.toImmutableList(),
onSearchEntered = onSearchEntered,
onTokenSelected = onTokenSelected,
afterSearch = value.afterSearch,
)
}

View file

@ -7,6 +7,7 @@ import kotlinx.collections.immutable.ImmutableList
data class SwapSelectTokenStateHolder(
val availableTokens: ImmutableList<TokenToSelectState>,
val unavailableTokens: ImmutableList<TokenToSelectState>,
val afterSearch: Boolean,
val onSearchEntered: (String) -> Unit,
val onTokenSelected: (String) -> Unit,
)

View file

@ -42,10 +42,16 @@ fun SwapSelectTokenScreen(state: SwapSelectTokenStateHolder, onBack: () -> Unit)
.background(color = TangemTheme.colors.background.secondary),
content = { padding ->
val modifier = Modifier.padding(padding)
if (state.availableTokens.isEmpty() && state.unavailableTokens.isEmpty()) {
EmptyTokensList(modifier)
} else {
ListOfTokens(state = state, modifier = modifier)
when {
state.availableTokens.isEmpty() && state.unavailableTokens.isEmpty() && state.afterSearch -> {
TokensNotFound(modifier)
}
state.availableTokens.isEmpty() && state.unavailableTokens.isEmpty() && !state.afterSearch -> {
EmptyTokensList(modifier)
}
else -> {
ListOfTokens(state = state, modifier = modifier)
}
}
},
topBar = {
@ -91,6 +97,26 @@ private fun EmptyTokensList(modifier: Modifier = Modifier) {
}
}
@Composable
private fun TokensNotFound(modifier: Modifier = Modifier) {
Box(
modifier = modifier
.background(TangemTheme.colors.background.secondary)
.fillMaxSize(),
) {
Text(
modifier = Modifier
.padding(top = TangemTheme.dimens.spacing32)
.padding(horizontal = TangemTheme.dimens.spacing30)
.align(Alignment.TopCenter),
text = stringResource(id = R.string.express_token_list_empty_search),
style = TangemTheme.typography.subtitle1,
color = TangemTheme.colors.text.tertiary,
textAlign = TextAlign.Center,
)
}
}
@Composable
private fun ListOfTokens(state: SwapSelectTokenStateHolder, modifier: Modifier = Modifier) {
val screenBackgroundColor = TangemTheme.colors.background.secondary
@ -283,6 +309,7 @@ private fun TokenScreenPreview() {
state = SwapSelectTokenStateHolder(
availableTokens = listOf(title, token, token, token).toImmutableList(),
unavailableTokens = listOf(title, token, token, token).toImmutableList(),
afterSearch = false,
onSearchEntered = {},
onTokenSelected = {},
),

View file

@ -586,13 +586,16 @@ internal class SwapViewModel @Inject constructor(
fromGroup = tokenDataState.fromGroup.copy(
available = available,
unavailable = unavailable,
afterSearch = true,
),
)
} else {
tokenDataState.copy(
toGroup = tokenDataState.toGroup.copy(
available = available,
unavailable = unavailable,
afterSearch = true,
),
)
}