Skip to content

Commit

Permalink
Merge pull request #190 from sora-xor/sn-2891
Browse files Browse the repository at this point in the history
sn-2891 token search feature
  • Loading branch information
arvifox authored Sep 6, 2023
2 parents 96077ea + ff1a301 commit 5a0d4d0
Show file tree
Hide file tree
Showing 33 changed files with 128 additions and 42 deletions.
1 change: 1 addition & 0 deletions common/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@
<string name="route">مسار</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">البحث عن الأصول</string>
<string name="search_empty_state">لا توجد نتائج بحث</string>
<string name="select_account_address">البحث عن عنوان الحساب</string>
<string name="select_account_address_1">بحث أو إضافة عنوان جديد</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-az/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Axtarış nəticələri yoxdur</string>
<string name="select_account_address">Hesab ünvanını axtarın</string>
<string name="select_account_address_1">Yeni ünvan axtarın və ya əlavə edin</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Keine Suchergebnisse</string>
<string name="select_account_address">Kontoadresse suchen</string>
<string name="select_account_address_1">Suchen oder Hinzufügen einer neuen Adresse</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Ruta</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Buscar activos</string>
<string name="search_empty_state">No hay resultados de búsqueda</string>
<string name="select_account_address">Buscar dirección de la cuenta</string>
<string name="select_account_address_1">Search or add a new address</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">هیچ نتیجه ای برای جستجو یافت نشد</string>
<string name="select_account_address">جستجو آدرس حساب</string>
<string name="select_account_address_1">جستجو یا افزودن یک آدرس جدید</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Ei hakutuloksia</string>
<string name="select_account_address">Hae tilin osoite</string>
<string name="select_account_address_1">Hae tai lisää uusi osoite</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Afficher mon code QR</string>
<string name="search_assets">Rechercher des actifs</string>
<string name="search_empty_state">Aucun résultat trouvé</string>
<string name="select_account_address">Recherche de l\'adresse du compte</string>
<string name="select_account_address_1">Chercher ou ajouter une nouvelle adresse</string>
<string name="select_account_import">Sélectionnez un compte à importer</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-hi-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">मार्ग</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">संपत्ति खोजें</string>
<string name="search_empty_state">खोजने पर कोई परिणाम नहीं मिला</string>
<string name="select_account_address">खाता पता खोजें\n</string>
<string name="select_account_address_1">नया पता खोजें या जोड़ें</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Tidak ada hasil pencarian</string>
<string name="select_account_address">Cari alamat akun</string>
<string name="select_account_address_1">Search or add a new address</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@
<string name="route">מסלול</string>
<string name="scan_qr_show_my_qr">הצג את קוד ה-QR שלי</string>
<string name="search_assets">חפש נכסים</string>
<string name="search_empty_state">אין תוצאות חיפוש</string>
<string name="select_account_address">חפש כתובת חשבון</string>
<string name="select_account_address_1">חפש או הוסף כתובת חדשה</string>
<string name="select_account_import">בחר חשבון לייבוא</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
<string name="route">ルート</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">アセットの検索</string>
<string name="search_empty_state">検索結果が存在しません</string>
<string name="select_account_address">アカウントのアドレスを検索</string>
<string name="select_account_address_1">検索または新規アドレスを追加</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-ms-rMY/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
<string name="route">Laluan</string>
<string name="scan_qr_show_my_qr">Tunjukkan kod QR saya</string>
<string name="search_assets">Cari aset</string>
<string name="search_empty_state">Tiada hasil carian</string>
<string name="select_account_address">Cari alamat akaun</string>
<string name="select_account_address_1">Cari atau tambah alamat baharu</string>
<string name="select_account_import">Pilih akaun untuk diimport</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Ingen søkeresultater</string>
<string name="select_account_address">Søk etter kontoadresse</string>
<string name="select_account_address_1">Search or add a new address</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Assets zoeken</string>
<string name="search_empty_state">Geen resultaten gevonden</string>
<string name="select_account_address">Accountadres zoeken</string>
<string name="select_account_address_1">Zoek of voeg een nieuw adres toe</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Nenhum resultado de pesquisa</string>
<string name="select_account_address">Pesquisar endereço de conta</string>
<string name="select_account_address_1">Pesquisar ou adicionar um novo endereço</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
<string name="route">Путь</string>
<string name="scan_qr_show_my_qr">Показать мой QR-код</string>
<string name="search_assets">Поиск ассетов</string>
<string name="search_empty_state">Нет результатов</string>
<string name="select_account_address">Поиск адреса</string>
<string name="select_account_address_1">Поиск или добавление нового адреса</string>
<string name="select_account_import">Выберите аккаунт для импорта</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-sr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Нема резултата претраге</string>
<string name="select_account_address">Претражите адресу налога</string>
<string name="select_account_address_1">Претражите или додајте нову адресу</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">Arama sonucu bulunamadı</string>
<string name="select_account_address">Hesap adresini ara</string>
<string name="select_account_address_1">Yeni bir adres arayın veya ekleyin</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Hiển thị mã QR của tôi</string>
<string name="search_assets">Tìm kiếm tài sản</string>
<string name="search_empty_state">Không có kết quả tìm kiếm</string>
<string name="select_account_address">Tìm kiếm địa chỉ tài khoản</string>
<string name="select_account_address_1">Tìm kiếm hoặc thêm địa chỉ mới</string>
<string name="select_account_import">Chọn tài khoản để nhập</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
<string name="route">路径</string>
<string name="scan_qr_show_my_qr">显示我的二维码</string>
<string name="search_assets">搜索资产</string>
<string name="search_empty_state">无搜索结果</string>
<string name="select_account_address">搜索账户地址</string>
<string name="select_account_address_1">搜索或添加新地址</string>
<string name="select_account_import">选择要导入的账户</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">搜索資產</string>
<string name="search_empty_state">無搜尋結果</string>
<string name="select_account_address">搜索賬戶地址</string>
<string name="select_account_address_1">搜索或添加新地址</string>
<string name="select_account_import">Select account to import</string>
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
<string name="route">Route</string>
<string name="scan_qr_show_my_qr">Show my QR code</string>
<string name="search_assets">Search assets</string>
<string name="search_empty_state">No results</string>
<string name="select_account_address">Search account address</string>
<string name="select_account_address_1">Search or add a new address</string>
<string name="select_account_import">Select account to import</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,58 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package jp.co.soramitsu.feature_assets_api.presentation.selectsearchtoken

import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Divider
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import jp.co.soramitsu.common.R
import jp.co.soramitsu.common.presentation.compose.components.ContentCardEndless
import jp.co.soramitsu.common_wallet.presentation.compose.components.AssetItem
import jp.co.soramitsu.common_wallet.presentation.compose.states.AssetItemCardState
import jp.co.soramitsu.common_wallet.presentation.compose.states.previewAssetItemCardStateList
import jp.co.soramitsu.ui_core.resources.Dimens
import jp.co.soramitsu.ui_core.theme.customColors
import jp.co.soramitsu.ui_core.theme.customTypography

data class SelectSearchAssetState(
val list: List<AssetItemCardState>,
)

data class SearchTokenFilter(
val filter: String,
val tokenIds: List<String>,
)

val emptySearchTokenFilter = SearchTokenFilter("", emptyList())

@Composable
fun SelectSearchTokenScreen(
scrollState: ScrollState,
filter: String,
searchTokenFilter: SearchTokenFilter,
viewModel: SelectSearchTokenViewModel = hiltViewModel(),
onAssetSelect: (String) -> Unit,
) {
val state = viewModel.state.collectAsStateWithLifecycle().value
LaunchedEffect(filter) {
viewModel.onFilterChange(filter)
LaunchedEffect(searchTokenFilter) {
viewModel.onFilterChange(searchTokenFilter)
}
SelectSearchTokenCard(
scrollState = scrollState,
Expand All @@ -88,19 +105,31 @@ private fun SelectSearchTokenCard(
.fillMaxSize(),
innerPadding = PaddingValues(top = Dimens.x3),
) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
) {
state.list.forEachIndexed { index, assetState ->
AssetItem(
assetState = assetState,
testTag = "${assetState.tokenSymbol}Element",
onClick = onAssetSelect,
if (state.list.isEmpty()) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
modifier = Modifier.wrapContentSize(),
text = stringResource(id = R.string.search_empty_state),
textAlign = TextAlign.Center,
style = MaterialTheme.customTypography.paragraphM,
color = MaterialTheme.customColors.fgSecondary,
)
if (index < state.list.lastIndex) {
Divider(color = Color.Transparent, modifier = Modifier.height(Dimens.x1))
}
} else {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
) {
state.list.forEachIndexed { index, assetState ->
AssetItem(
assetState = assetState,
testTag = "${assetState.tokenSymbol}Element",
onClick = onAssetSelect,
)
if (index < state.list.lastIndex) {
Divider(color = Color.Transparent, modifier = Modifier.height(Dimens.x1))
}
}
}
}
Expand All @@ -109,7 +138,7 @@ private fun SelectSearchTokenCard(

@Composable
@Preview
private fun PreviewSelectSearchTokenCard() {
private fun PreviewSelectSearchTokenCard1() {
SelectSearchTokenCard(
scrollState = rememberScrollState(),
state = SelectSearchAssetState(
Expand All @@ -118,3 +147,15 @@ private fun PreviewSelectSearchTokenCard() {
onAssetSelect = {},
)
}

@Composable
@Preview
private fun PreviewSelectSearchTokenCard2() {
SelectSearchTokenCard(
scrollState = rememberScrollState(),
state = SelectSearchAssetState(
list = emptyList(),
),
onAssetSelect = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SelectSearchTokenViewModel @Inject constructor(
private val _state = MutableStateFlow(SelectSearchAssetState(emptyList()))
val state = _state.asStateFlow()

private var filter: String = ""
private var searchTokenFilter = emptySearchTokenFilter
private val assets = mutableListOf<Asset>()

init {
Expand All @@ -73,21 +73,28 @@ class SelectSearchTokenViewModel @Inject constructor(
}
}

fun onFilterChange(value: String) {
filter = value
fun onFilterChange(value: SearchTokenFilter) {
searchTokenFilter = value
reCalcFilter()
}

private val tokenFilterInclude: (Asset) -> Boolean = {
searchTokenFilter.tokenIds.contains(it.token.id)
}

private fun reCalcFilter() {
val curFilter = filter.lowercase()
val list = if (curFilter.isBlank()) {
mapAssetsToCardState(assets, numbersFormatter)
val tokensFiltered =
if (searchTokenFilter.tokenIds.isEmpty()) assets
else assets.filter(tokenFilterInclude)
val curFilterValue = searchTokenFilter.filter.lowercase()
val list = if (curFilterValue.isBlank()) {
mapAssetsToCardState(tokensFiltered, numbersFormatter)
} else {
buildList {
addAll(
mapAssetsToCardState(
assets.filter {
it.token.isMatchFilter(curFilter)
tokensFiltered.filter {
it.token.isMatchFilter(curFilterValue)
},
numbersFormatter
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class QRCodeFlowFragment : SoraBaseFragment<QRCodeFlowViewModel>() {
viewModel.onSelectToken(it)
navController.popBackStack()
},
filter = filter.value,
searchTokenFilter = filter.value,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import jp.co.soramitsu.common_wallet.domain.model.QrException
import jp.co.soramitsu.common_wallet.presentation.compose.util.AmountFormat.getAssetBalanceText
import jp.co.soramitsu.feature_assets_api.domain.AssetsInteractor
import jp.co.soramitsu.feature_assets_api.domain.QrCodeInteractor
import jp.co.soramitsu.feature_assets_api.presentation.selectsearchtoken.emptySearchTokenFilter
import jp.co.soramitsu.feature_assets_impl.presentation.components.compose.receiverequest.ReceiveTokenByQrScreenState
import jp.co.soramitsu.feature_assets_impl.presentation.components.compose.receiverequest.RequestTokenConfirmScreenState
import jp.co.soramitsu.feature_assets_impl.presentation.components.compose.receiverequest.RequestTokenScreenState
Expand Down Expand Up @@ -123,7 +124,7 @@ class QRCodeFlowViewModel @Inject constructor(
)
val requestTokenScreenState = _requestTokenScreenState.asStateFlow()

private val _selectTokenScreenState = MutableStateFlow("")
private val _selectTokenScreenState = MutableStateFlow(emptySearchTokenFilter)
val selectTokenScreenState = _selectTokenScreenState.asStateFlow()

private val _requestTokenConfirmScreenState = MutableStateFlow(
Expand Down Expand Up @@ -204,7 +205,9 @@ class QRCodeFlowViewModel @Inject constructor(
override fun startScreen(): String = QRCodeFlowRoute.MainScreen.route

override fun onToolbarSearch(value: String) {
_selectTokenScreenState.value = value
_selectTokenScreenState.value = _selectTokenScreenState.value.copy(
filter = value,
)
}

override fun onCurrentDestinationChanged(curDest: String) {
Expand All @@ -219,7 +222,7 @@ class QRCodeFlowViewModel @Inject constructor(
else -> ""
},
searchEnabled = curDest == QRCodeFlowRoute.SelectToken.route,
searchValue = if (curDest == QRCodeFlowRoute.SelectToken.route) _selectTokenScreenState.value else "",
searchValue = if (curDest == QRCodeFlowRoute.SelectToken.route) _selectTokenScreenState.value.filter else "",
)
)
}
Expand Down
Loading

0 comments on commit 5a0d4d0

Please sign in to comment.