diff --git a/common/src/main/java/io/novafoundation/nova/common/utils/FlowExt.kt b/common/src/main/java/io/novafoundation/nova/common/utils/FlowExt.kt index e5a94291af..06686e8ced 100644 --- a/common/src/main/java/io/novafoundation/nova/common/utils/FlowExt.kt +++ b/common/src/main/java/io/novafoundation/nova/common/utils/FlowExt.kt @@ -145,6 +145,8 @@ inline fun withFlowScope(crossinline block: suspend (scope: CoroutineScope) fun combineToPair(flow1: Flow, flow2: Flow): Flow> = combine(flow1, flow2, ::Pair) +fun combineToTriple(flow1: Flow, flow2: Flow, flow3: Flow): Flow> = combine(flow1, flow2, flow3, ::Triple) + /** * Modifies flow so that it firstly emits [LoadingState.Loading] state for each element from upstream. * Then, it constructs new source via [sourceSupplier] and emits all of its items wrapped into [LoadingState.Loaded] state diff --git a/common/src/main/java/io/novafoundation/nova/common/utils/formatting/DynamicPrecisionFormatter.kt b/common/src/main/java/io/novafoundation/nova/common/utils/formatting/DynamicPrecisionFormatter.kt index b5f2554719..5cfb1a8c47 100644 --- a/common/src/main/java/io/novafoundation/nova/common/utils/formatting/DynamicPrecisionFormatter.kt +++ b/common/src/main/java/io/novafoundation/nova/common/utils/formatting/DynamicPrecisionFormatter.kt @@ -3,6 +3,7 @@ package io.novafoundation.nova.common.utils.formatting import java.lang.Integer.max import java.math.BigDecimal import java.math.RoundingMode +import java.text.DecimalFormat import kotlin.math.min class DynamicPrecisionFormatter( @@ -10,6 +11,8 @@ class DynamicPrecisionFormatter( private val minPrecision: Int, ) : NumberFormatter { + private val patternCache = mutableMapOf() + override fun format(number: BigDecimal, roundingMode: RoundingMode): String { // scale() - total amount of digits after 0., // precision() - amount of non-zero digits in decimal part @@ -18,6 +21,11 @@ class DynamicPrecisionFormatter( val formattingPrecision = max(minScale, requiredPrecision) - return decimalFormatterFor(patternWith(formattingPrecision), roundingMode).format(number) + val formatter = patternCache.getOrPut(formattingPrecision) { decimalFormatterFor(patternWith(formattingPrecision)) } + if (formatter.roundingMode != roundingMode) { + formatter.roundingMode = roundingMode + } + + return formatter.format(number) } } diff --git a/common/src/main/java/io/novafoundation/nova/common/utils/formatting/FixedPrecisionFormatter.kt b/common/src/main/java/io/novafoundation/nova/common/utils/formatting/FixedPrecisionFormatter.kt index 361e7e2afc..c03638b908 100644 --- a/common/src/main/java/io/novafoundation/nova/common/utils/formatting/FixedPrecisionFormatter.kt +++ b/common/src/main/java/io/novafoundation/nova/common/utils/formatting/FixedPrecisionFormatter.kt @@ -5,8 +5,12 @@ import java.math.RoundingMode class FixedPrecisionFormatter(private val precision: Int) : NumberFormatter { + private val delegate = decimalFormatterFor(patternWith(precision)) + override fun format(number: BigDecimal, roundingMode: RoundingMode): String { - val delegate = decimalFormatterFor(patternWith(precision), roundingMode) + if (delegate.roundingMode != roundingMode) { + delegate.roundingMode = roundingMode + } return delegate.format(number) } diff --git a/common/src/main/java/io/novafoundation/nova/common/utils/formatting/NumberFormatters.kt b/common/src/main/java/io/novafoundation/nova/common/utils/formatting/NumberFormatters.kt index 47970dedea..1c58aa033f 100644 --- a/common/src/main/java/io/novafoundation/nova/common/utils/formatting/NumberFormatters.kt +++ b/common/src/main/java/io/novafoundation/nova/common/utils/formatting/NumberFormatters.kt @@ -169,7 +169,7 @@ fun formatDateISO_8601_NoMs(date: Date): String { return dateTimeFormatISO_8601_NoMs.format(date) } -fun decimalFormatterFor(pattern: String, roundingMode: RoundingMode): DecimalFormat { +fun decimalFormatterFor(pattern: String): DecimalFormat { return DecimalFormat(pattern).apply { val symbols = decimalFormatSymbols @@ -178,7 +178,6 @@ fun decimalFormatterFor(pattern: String, roundingMode: RoundingMode): DecimalFor decimalFormatSymbols = symbols - this.roundingMode = roundingMode decimalFormatSymbols = decimalFormatSymbols } } diff --git a/common/src/main/java/io/novafoundation/nova/common/view/QrCodeView.kt b/common/src/main/java/io/novafoundation/nova/common/view/QrCodeView.kt index 5606c53e80..af48b0b7a5 100644 --- a/common/src/main/java/io/novafoundation/nova/common/view/QrCodeView.kt +++ b/common/src/main/java/io/novafoundation/nova/common/view/QrCodeView.kt @@ -42,7 +42,7 @@ class QrCodeView @JvmOverloads constructor( private var overlayBackground: Drawable? = null private val overlaySize = 64.dp - private val overlayQuiteZone = 4.dp + private val overlayQuiteZone = 0 private val qrPadding = 16.dpF private val centerRect: RectF = RectF() diff --git a/common/src/main/res/values-es/strings.xml b/common/src/main/res/values-es/strings.xml index 2d5c85e18f..92e21215cb 100644 --- a/common/src/main/res/values-es/strings.xml +++ b/common/src/main/res/values-es/strings.xml @@ -1132,6 +1132,7 @@ Pistas no disponibles Nova necesita que la ubicación esté habilitada para poder realizar el escaneo bluetooth y encontrar tu dispositivo Ledger Por favor, habilita la geolocalización en las configuraciones del dispositivo + Seleccionar red Seleccione pistas para %d de %d Dirección o w3n diff --git a/common/src/main/res/values-fr-rFR/strings.xml b/common/src/main/res/values-fr-rFR/strings.xml index 1093eadfca..1a2d369044 100644 --- a/common/src/main/res/values-fr-rFR/strings.xml +++ b/common/src/main/res/values-fr-rFR/strings.xml @@ -1132,6 +1132,7 @@ Chemins non disponibles Nova a besoin que la localisation soit activée pour pouvoir effectuer un balayage Bluetooth afin de trouver votre appareil Ledger Veuillez activer la géolocalisation dans les paramètres de l\'appareil + Sélectionner un réseau Sélectionner des pistes pour %d sur %d Adresse ou w3n diff --git a/common/src/main/res/values-in/strings.xml b/common/src/main/res/values-in/strings.xml index e66f9d5448..d6b692fefb 100644 --- a/common/src/main/res/values-in/strings.xml +++ b/common/src/main/res/values-in/strings.xml @@ -1124,6 +1124,7 @@ Unavailable tracks Nova needs location to be enabled to be able to perform bluetooth scanning to find your Ledger device Please enable geo-location in device settings + Pilih jaringan Select tracks for %d of %d Address or w3n diff --git a/common/src/main/res/values-it/strings.xml b/common/src/main/res/values-it/strings.xml index eda74cbb6b..7ccfbe525a 100644 --- a/common/src/main/res/values-it/strings.xml +++ b/common/src/main/res/values-it/strings.xml @@ -1132,6 +1132,7 @@ Tracce non disponibili Nova ha bisogno che la posizione sia attivata per poter effettuare la scansione Bluetooth per trovare il tuo dispositivo Ledger Si prega di abilitare la geolocalizzazione nelle impostazioni del dispositivo + Seleziona rete Seleziona brani per %d di %d Indirizzo o w3n diff --git a/common/src/main/res/values-ja/strings.xml b/common/src/main/res/values-ja/strings.xml index cf8ebfb504..2b31a4ecfd 100644 --- a/common/src/main/res/values-ja/strings.xml +++ b/common/src/main/res/values-ja/strings.xml @@ -1124,6 +1124,7 @@ 利用不可のトラック Novaは、Ledgerデバイスを見つけるためにBluetoothスキャンを実行するために位置情報の有効化が必要です デバイス設定で位置情報を有効にしてください + ネットワークを選択 トラックを選択 %d / %d アドレスまたはw3n diff --git a/common/src/main/res/values-ko/strings.xml b/common/src/main/res/values-ko/strings.xml index 7334561d41..17b029a572 100644 --- a/common/src/main/res/values-ko/strings.xml +++ b/common/src/main/res/values-ko/strings.xml @@ -1124,6 +1124,7 @@ 사용할 수 없는 트랙 Ledger 장치를 찾기 위해 블루투스 스캔을 수행하려면 Nova는 위치 기능을 활성화해야 합니다. 기기 설정에서 지리적 위치를 활성화해주세요. + 네트워크 선택 트랙 선택 %d 중 %d 주소 또는 w3n diff --git a/common/src/main/res/values-pl/strings.xml b/common/src/main/res/values-pl/strings.xml index 4d9c03490d..0721f8cab6 100644 --- a/common/src/main/res/values-pl/strings.xml +++ b/common/src/main/res/values-pl/strings.xml @@ -1148,6 +1148,7 @@ Niedostępne trasy Nova wymaga włączenia lokalizacji, aby móc przeprowadzać skanowanie Bluetooth w celu znalezienia urządzenia Ledger Proszę włączyć geolokalizację w ustawieniach urządzenia + Wybierz sieć Wybierz trasy dla %d z %d Adres lub w3n diff --git a/common/src/main/res/values-pt/strings.xml b/common/src/main/res/values-pt/strings.xml index e86459e34e..a6aab8484e 100644 --- a/common/src/main/res/values-pt/strings.xml +++ b/common/src/main/res/values-pt/strings.xml @@ -1132,6 +1132,7 @@ Faixas indisponíveis Nova precisa que a localização seja ativada para poder realizar a varredura Bluetooth para encontrar seu dispositivo Ledger Por favor, ative a localização geográfica nas configurações do dispositivo + Selecionar rede Selecione faixas para %d de %d Endereço ou w3n diff --git a/common/src/main/res/values-ru/strings.xml b/common/src/main/res/values-ru/strings.xml index b1f4666312..33dc180a91 100644 --- a/common/src/main/res/values-ru/strings.xml +++ b/common/src/main/res/values-ru/strings.xml @@ -1148,6 +1148,7 @@ Недоступные треки Nova нуждается в включении местоположения, чтобы иметь возможность выполнять сканирование Bluetooth для поиска вашего устройства Ledger Пожалуйста, включите геолокацию в настройках устройства + Выберите сеть Выберите треки для %d из %d Адрес или w3n diff --git a/common/src/main/res/values-tr/strings.xml b/common/src/main/res/values-tr/strings.xml index 919eab0a59..1775904096 100644 --- a/common/src/main/res/values-tr/strings.xml +++ b/common/src/main/res/values-tr/strings.xml @@ -1132,6 +1132,7 @@ Ulaşılamayan yollar Nova\'nın Bluetooth taraması yaparak Ledger cihazınızı bulabilmesi için konumun etkinleştirilmesi gerekiyor Lütfen cihaz ayarlarında coğrafi konumu etkinleştirin + Ağ seç İçin şarkıları seçin %d / %d Adres veya w3n diff --git a/common/src/main/res/values-vi/strings.xml b/common/src/main/res/values-vi/strings.xml index 50cb3a328b..7379a43bef 100644 --- a/common/src/main/res/values-vi/strings.xml +++ b/common/src/main/res/values-vi/strings.xml @@ -1124,6 +1124,7 @@ Track không có sẵn Nova cần bật định vị để có thể thực hiện quét Bluetooth để tìm thiết bị Ledger của bạn Vui lòng bật định vị địa lý trong cài đặt thiết bị + Chọn mạng Chọn track cho %d trong %d Địa chỉ hoặc w3n diff --git a/common/src/main/res/values-zh-rCN/strings.xml b/common/src/main/res/values-zh-rCN/strings.xml index dc2ebea500..8e720b42a4 100644 --- a/common/src/main/res/values-zh-rCN/strings.xml +++ b/common/src/main/res/values-zh-rCN/strings.xml @@ -1124,6 +1124,7 @@ 不可用的轨道 Nova需要启用地理位置,以便能够进行蓝牙扫描查找您的Ledger设备 请在设备设置中启用地理位置 + 选择网络 选择曲目 %d / %d 地址或w3n diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index 5edea2541d..b157bffc3d 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1,6 +1,8 @@ + Select network + Search by token Copy Address diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/assets/search/ByTokensAssetSearchInteractor.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/assets/search/ByTokensAssetSearchInteractor.kt index 2410f2e2df..5755da513a 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/assets/search/ByTokensAssetSearchInteractor.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/assets/search/ByTokensAssetSearchInteractor.kt @@ -55,15 +55,16 @@ class ByTokensAssetSearchInteractor( externalBalancesFlow: Flow>, coroutineScope: CoroutineScope ): Flow { - val filterFlow = assetSearchUseCase.getAvailableSwapAssets(forAsset, coroutineScope).map { availableAssetsForSwap -> - val filter: AssetSearchFilter = { asset -> - val chainAsset = asset.token.configuration + val filterFlow = assetSearchUseCase.getAvailableSwapAssets(forAsset, coroutineScope) + .map { availableAssetsForSwap -> + val filter: AssetSearchFilter = { asset -> + val chainAsset = asset.token.configuration - chainAsset.fullId in availableAssetsForSwap - } + chainAsset.fullId in availableAssetsForSwap + } - filter - } + filter + } return searchAssetsByTokensInternalFlow(queryFlow, externalBalancesFlow, filterFlow = filterFlow) } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/common/TokenAssetSorting.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/common/TokenAssetSorting.kt index 53e97054f8..0a976a3580 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/common/TokenAssetSorting.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/domain/common/TokenAssetSorting.kt @@ -46,9 +46,9 @@ fun groupAndSortAssetsByToken( .map { asset -> AssetWithNetwork(chainsById.getValue(asset.token.configuration.chainId), asset, asset.totalWithOffChain(externalBalances)) } .groupBy { mapToTokenGroup(it) } .mapValues { (_, assets) -> assets.sortedWith(assetComparator) } - .mapKeys { (token, assets) -> + .mapKeys { (tokenWrapper, assets) -> TokenAssetGroup( - token = token, + token = tokenWrapper.token, groupBalance = assets.fold(AssetBalance.ZERO) { acc, element -> acc + element.balanceWithOffChain }, itemsCount = assets.size ) @@ -61,6 +61,7 @@ fun getTokenAssetBaseComparator( return compareByDescending(comparing) .thenByDescending { it.asset.token.configuration.isUtilityAsset } // utility assets first .thenBy { it.asset.token.configuration.symbol.value } + .then(Chain.defaultComparatorFrom(AssetWithNetwork::chain)) } fun getTokenAssetGroupBaseComparator( @@ -71,9 +72,23 @@ fun getTokenAssetGroupBaseComparator( .then(TokenSymbol.defaultComparatorFrom { it.token.symbol }) } -private fun mapToTokenGroup(it: AssetWithNetwork) = TokenAssetGroup.Token( - it.asset.token.configuration.icon, - it.asset.token.configuration.symbol.normalize(), - it.asset.token.currency, - it.asset.token.coinRate +private fun mapToTokenGroup(it: AssetWithNetwork) = TokenGroupWrapper( + TokenAssetGroup.Token( + it.asset.token.configuration.icon, + it.asset.token.configuration.symbol.normalize(), + it.asset.token.currency, + it.asset.token.coinRate + ) ) + +// Helper class to group items by symbol only +private class TokenGroupWrapper(val token: TokenAssetGroup.Token) { + + override fun equals(other: Any?): Boolean { + return other is TokenGroupWrapper && token.symbol == other.token.symbol + } + + override fun hashCode(): Int { + return token.symbol.hashCode() + } +} diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/AssetListMixin.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/AssetListMixin.kt index 4f247cc3d1..a7f40bbcb1 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/AssetListMixin.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/AssetListMixin.kt @@ -1,7 +1,9 @@ package io.novafoundation.nova.feature_assets.presentation.balance.common import io.novafoundation.nova.common.data.model.AssetViewMode +import io.novafoundation.nova.common.utils.combineToPair import io.novafoundation.nova.common.utils.shareInBackground +import io.novafoundation.nova.common.utils.throttleLast import io.novafoundation.nova.feature_assets.domain.WalletInteractor import io.novafoundation.nova.feature_assets.domain.assets.ExternalBalancesInteractor import io.novafoundation.nova.feature_assets.domain.assets.list.AssetsListInteractor @@ -15,6 +17,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.combine +import kotlin.time.Duration.Companion.milliseconds class AssetListMixinFactory( private val walletInteractor: WalletInteractor, @@ -67,11 +70,13 @@ class RealAssetListMixin( override val assetsViewModeFlow = assetsListInteractor.assetsViewModeFlow() .shareInBackground() + private val throttledBalance = combineToPair(filteredAssetsFlow, externalBalancesFlow) + .throttleLast(300.milliseconds) + private val assetsByViewMode = combine( - filteredAssetsFlow, - externalBalancesFlow, + throttledBalance, assetsViewModeFlow - ) { assets, externalBalances, viewMode -> + ) { (assets, externalBalances), viewMode -> when (viewMode) { AssetViewMode.NETWORKS -> walletInteractor.groupAssetsByNetwork(assets, externalBalances).byNetworks() AssetViewMode.TOKENS -> walletInteractor.groupAssetsByToken(assets, externalBalances).byTokens() diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/BalanceListAdapter.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/BalanceListAdapter.kt index 6ceb773c88..c6ab404aa6 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/BalanceListAdapter.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/BalanceListAdapter.kt @@ -22,6 +22,8 @@ import io.novafoundation.nova.feature_assets.presentation.balance.list.model.ite import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenAssetUi import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi import io.novafoundation.nova.feature_assets.presentation.model.AssetModel +import io.novafoundation.nova.feature_wallet_api.domain.model.Asset +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain private val priceRateExtractor = { asset: AssetModel -> asset.token.rate } private val recentChangeExtractor = { asset: AssetModel -> asset.token.recentRateChange } @@ -30,6 +32,7 @@ private val amountExtractor = { asset: AssetModel -> asset.amount } private val tokenGroupPriceRateExtractor = { group: TokenGroupUi -> group.rate } private val tokenGroupRecentChangeExtractor = { group: TokenGroupUi -> group.recentRateChange } private val tokenGroupAmountExtractor = { group: TokenGroupUi -> group.balance } +private val tokenGroupTypeExtractor = { group: TokenGroupUi -> group.groupType } const val TYPE_NETWORK_GROUP = 0 const val TYPE_NETWORK_ASSET = 1 @@ -42,7 +45,7 @@ class BalanceListAdapter( ) : ListAdapter(DiffCallback), ExpandableAdapter { interface ItemAssetHandler { - fun assetClicked(asset: AssetModel) + fun assetClicked(asset: Chain.Asset) fun tokenGroupClicked(tokenGroup: TokenGroupUi) } @@ -51,7 +54,7 @@ class BalanceListAdapter( return when (viewType) { TYPE_NETWORK_GROUP -> NetworkAssetGroupViewHolder(parent.inflateChild(R.layout.item_network_asset_group)) TYPE_NETWORK_ASSET -> NetworkAssetViewHolder(parent.inflateChild(R.layout.item_network_asset), imageLoader) - TYPE_TOKEN_GROUP -> TokenAssetGroupViewHolder(parent.inflateChild(R.layout.item_token_asset_group), imageLoader) + TYPE_TOKEN_GROUP -> TokenAssetGroupViewHolder(parent.inflateChild(R.layout.item_token_asset_group), imageLoader, itemHandler) TYPE_TOKEN_ASSET -> TokenAssetViewHolder(parent.inflateChild(R.layout.item_token_asset), imageLoader) else -> error("Unknown view type") } @@ -61,7 +64,7 @@ class BalanceListAdapter( return when (holder) { is NetworkAssetGroupViewHolder -> holder.bind(getItem(position) as NetworkGroupUi) is NetworkAssetViewHolder -> holder.bind(getItem(position) as NetworkAssetUi, itemHandler) - is TokenAssetGroupViewHolder -> holder.bind(getItem(position) as TokenGroupUi, itemHandler) + is TokenAssetGroupViewHolder -> holder.bind(getItem(position) as TokenGroupUi) is TokenAssetViewHolder -> holder.bind(getItem(position) as TokenAssetUi, itemHandler) else -> error("Unknown holder") } @@ -96,6 +99,7 @@ class BalanceListAdapter( tokenGroupPriceRateExtractor -> holder.bindPriceRate(item) tokenGroupRecentChangeExtractor -> holder.bindRecentChange(item) tokenGroupAmountExtractor -> holder.bindTotal(item) + tokenGroupTypeExtractor -> holder.bindGroupType(item) } } } @@ -156,5 +160,6 @@ private object TokenAssetPayloadGenerator : PayloadGenerator( private object TokenGroupAssetPayloadGenerator : PayloadGenerator( tokenGroupPriceRateExtractor, tokenGroupRecentChangeExtractor, - tokenGroupAmountExtractor + tokenGroupAmountExtractor, + tokenGroupTypeExtractor ) diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/ExpandableAssetsMixin.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/ExpandableAssetsMixin.kt index 074d29bd6b..71f74fc753 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/ExpandableAssetsMixin.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/ExpandableAssetsMixin.kt @@ -3,6 +3,7 @@ package io.novafoundation.nova.feature_assets.presentation.balance.common import io.novafoundation.nova.common.data.model.switch import io.novafoundation.nova.common.data.repository.AssetsViewModeRepository import io.novafoundation.nova.common.presentation.AssetIconProvider +import io.novafoundation.nova.common.utils.combineToTriple import io.novafoundation.nova.common.utils.toggle import io.novafoundation.nova.common.utils.updateValue import io.novafoundation.nova.feature_assets.domain.assets.models.AssetsByViewModeResult @@ -14,8 +15,8 @@ import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountFormatter import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.mapLatest class ExpandableAssetsMixinFactory( private val assetIconProvider: AssetIconProvider, @@ -50,20 +51,21 @@ class RealExpandableAssetsMixin( private val expandedTokenIdsFlow = MutableStateFlow(setOf()) - override val assetModelsFlow: Flow> = combine( + override val assetModelsFlow: Flow> = combineToTriple( assetsFlow, expandedTokenIdsFlow, selectedCurrency - ) { assetesByViewMode, expandedTokens, currency -> - when (assetesByViewMode) { - is AssetsByViewModeResult.ByNetworks -> assetesByViewMode.assets.mapGroupedAssetsToUi(amountFormatter, assetIconProvider, currency) - is AssetsByViewModeResult.ByTokens -> assetesByViewMode.tokens.mapGroupedAssetsToUi( + ).mapLatest { (assetsByViewMode, expandedTokens, currency) -> + when (assetsByViewMode) { + is AssetsByViewModeResult.ByNetworks -> assetsByViewMode.assets.mapGroupedAssetsToUi(amountFormatter, assetIconProvider, currency) + is AssetsByViewModeResult.ByTokens -> assetsByViewMode.tokens.mapGroupedAssetsToUi( amountFormatter = amountFormatter, assetIconProvider = assetIconProvider, assetFilter = { groupId, assetsInGroup -> filterTokens(groupId, assetsInGroup, expandedTokens) } ) } - }.distinctUntilChanged() + } + .distinctUntilChanged() override fun expandToken(tokenGroupUi: TokenGroupUi) { expandedTokenIdsFlow.updateValue { it.toggle(tokenGroupUi.itemId) } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/NetworkAssetViewHolder.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/NetworkAssetViewHolder.kt index 4a9b2344bf..c743f884f2 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/NetworkAssetViewHolder.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/NetworkAssetViewHolder.kt @@ -32,7 +32,7 @@ class NetworkAssetViewHolder( itemAssetToken.text = asset.token.configuration.symbol.value - setOnClickListener { itemHandler.assetClicked(asset) } + setOnClickListener { itemHandler.assetClicked(asset.token.configuration) } } fun bindTotal(asset: AssetModel) { diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetGroupViewHolder.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetGroupViewHolder.kt index 02e6a972e6..06a6872b1c 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetGroupViewHolder.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetGroupViewHolder.kt @@ -19,38 +19,66 @@ import kotlinx.android.synthetic.main.item_token_asset_group.view.itemTokenGroup class TokenAssetGroupViewHolder( containerView: View, private val imageLoader: ImageLoader, + private val itemHandler: BalanceListAdapter.ItemAssetHandler, ) : GroupedListHolder(containerView), ExpandableParentViewHolder { override var expandableItem: ExpandableParentItem? = null - fun bind(tokenGroup: TokenGroupUi, itemHandler: BalanceListAdapter.ItemAssetHandler) = with(containerView) { + fun bind(tokenGroup: TokenGroupUi) = with(containerView) { expandableItem = tokenGroup itemTokenGroupAssetImage.setTokenIcon(tokenGroup.tokenIcon, imageLoader) - bindPriceRate(tokenGroup) + bindPriceRateInternal(tokenGroup) - bindRecentChange(tokenGroup) + bindRecentChangeInternal(tokenGroup) - bindTotal(tokenGroup) + bindTotalInternal(tokenGroup) - itemAssetTokenGroupToken.text = tokenGroup.tokenSymbol + updateListener(tokenGroup) - setOnClickListener { itemHandler.tokenGroupClicked(tokenGroup) } + itemAssetTokenGroupToken.text = tokenGroup.tokenSymbol } fun bindTotal(networkAsset: TokenGroupUi) { + updateListener(networkAsset) + bindTotalInternal(networkAsset) + } + + fun bindRecentChange(networkAsset: TokenGroupUi) { + updateListener(networkAsset) + bindRecentChangeInternal(networkAsset) + } + + fun bindPriceRate(networkAsset: TokenGroupUi) { + updateListener(networkAsset) + bindPriceRateInternal(networkAsset) + } + + fun bindGroupType(networkAsset: TokenGroupUi) { + updateListener(networkAsset) + } + + private fun bindTotalInternal(networkAsset: TokenGroupUi) { val balance = networkAsset.balance containerView.itemAssetTokenGroupBalance.text = balance.token containerView.itemAssetTokenGroupPriceAmount.text = balance.fiat } - fun bindRecentChange(networkAsset: TokenGroupUi) = with(containerView) { - itemAssetTokenGroupRateChange.setTextColorRes(networkAsset.rateChangeColorRes) - itemAssetTokenGroupRateChange.text = networkAsset.recentRateChange + private fun bindRecentChangeInternal(networkAsset: TokenGroupUi) { + with(containerView) { + itemAssetTokenGroupRateChange.setTextColorRes(networkAsset.rateChangeColorRes) + itemAssetTokenGroupRateChange.text = networkAsset.recentRateChange + } + } + + private fun bindPriceRateInternal(networkAsset: TokenGroupUi) { + with(containerView) { + itemAssetTokenGroupRate.text = networkAsset.rate + } } - fun bindPriceRate(networkAsset: TokenGroupUi) = with(containerView) { - itemAssetTokenGroupRate.text = networkAsset.rate + private fun updateListener(tokenGroupUi: TokenGroupUi) { + containerView.setOnClickListener { itemHandler.tokenGroupClicked(tokenGroupUi) } } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetViewHolder.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetViewHolder.kt index 0596f3a41e..5045e2854d 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetViewHolder.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/holders/TokenAssetViewHolder.kt @@ -36,7 +36,7 @@ class TokenAssetViewHolder( itemTokenAssetToken.text = asset.token.configuration.symbol.value - setOnClickListener { itemHandler.assetClicked(asset) } + setOnClickListener { itemHandler.assetClicked(asset.token.configuration) } } fun bindTotal(asset: AssetModel) { diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/mappers/TokenAssetMappers.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/mappers/TokenAssetMappers.kt index 7e13ddad55..49ba3823a1 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/mappers/TokenAssetMappers.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/common/mappers/TokenAssetMappers.kt @@ -58,7 +58,7 @@ fun mapTokenAssetGroupToUi( token = balance.amount.formatTokenAmount(), fiat = balance.fiat.formatAsCurrency(assetGroup.token.currency) ).formatBalanceWithFraction(amountFormatter, R.dimen.asset_balance_fraction_size), - groupType = mapType(amountFormatter, assetGroup, assets, groupBalance) + groupType = mapType(assets) ) } @@ -80,14 +80,10 @@ private fun mapAssetsToAssetModels( } private fun mapType( - amountFormatter: AmountFormatter, - assetGroup: TokenAssetGroup, assets: List, - groupBalance: (TokenAssetGroup) -> PricedAmount ): TokenGroupUi.GroupType { return if (assets.size == 1) { - val balance = groupBalance(assetGroup) - TokenGroupUi.GroupType.SingleItem(mapAssetToAssetModel(amountFormatter, assets.first().asset, balance)) + TokenGroupUi.GroupType.SingleItem(assets.first().asset.token.configuration) } else { TokenGroupUi.GroupType.Group } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListFragment.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListFragment.kt index 7601973c77..90c9211b52 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListFragment.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListFragment.kt @@ -24,7 +24,8 @@ import io.novafoundation.nova.feature_assets.presentation.balance.common.baseDec import io.novafoundation.nova.feature_assets.presentation.balance.common.createForAssets import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi import io.novafoundation.nova.feature_assets.presentation.balance.list.view.AssetsHeaderAdapter -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel +import io.novafoundation.nova.feature_wallet_api.domain.model.Asset +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.android.synthetic.main.fragment_balance_list.balanceListAssets import kotlinx.android.synthetic.main.fragment_balance_list.walletContainer import javax.inject.Inject @@ -142,7 +143,7 @@ class BalanceListFragment : viewModel.assetViewModeModelFlow.observe { headerAdapter.setAssetViewModeModel(it) } } - override fun assetClicked(asset: AssetModel) { + override fun assetClicked(asset: Chain.Asset) { viewModel.assetClicked(asset) } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListViewModel.kt index c6d8d940ff..59265f0fdb 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/BalanceListViewModel.kt @@ -28,19 +28,20 @@ import io.novafoundation.nova.feature_wallet_api.presentation.model.formatBalanc import io.novafoundation.nova.feature_assets.presentation.balance.list.model.NftPreviewUi import io.novafoundation.nova.feature_assets.presentation.balance.list.model.TotalBalanceModel import io.novafoundation.nova.feature_assets.presentation.balance.list.view.AssetViewModeModel -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor import io.novafoundation.nova.feature_currency_api.domain.model.Currency import io.novafoundation.nova.feature_currency_api.presentation.formatters.formatAsCurrency import io.novafoundation.nova.feature_currency_api.presentation.formatters.simpleFormatAsCurrency import io.novafoundation.nova.feature_nft_api.data.model.Nft import io.novafoundation.nova.feature_swap_api.domain.interactor.SwapAvailabilityInteractor +import io.novafoundation.nova.feature_wallet_api.domain.model.Asset import io.novafoundation.nova.feature_wallet_api.presentation.formatters.mapBalanceIdToUi import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountFormatter import io.novafoundation.nova.feature_wallet_api.presentation.model.AssetPayload import io.novafoundation.nova.feature_wallet_api.presentation.model.mapAmountToAmountModel import io.novafoundation.nova.feature_wallet_connect_api.domain.sessions.WalletConnectSessionsUseCase import io.novafoundation.nova.feature_wallet_connect_api.presentation.mapNumberOfActiveSessionsToUi +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.coroutines.async import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.debounce @@ -200,10 +201,10 @@ class BalanceListViewModel( } } - fun assetClicked(asset: AssetModel) { + fun assetClicked(asset: Chain.Asset) { val payload = AssetPayload( - chainId = asset.token.configuration.chainId, - chainAssetId = asset.token.configuration.id + chainId = asset.chainId, + chainAssetId = asset.id ) router.openAssetDetails(payload) diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/model/items/TokenGroupUi.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/model/items/TokenGroupUi.kt index b30d917195..45bd2da6f8 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/model/items/TokenGroupUi.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/list/model/items/TokenGroupUi.kt @@ -3,8 +3,9 @@ package io.novafoundation.nova.feature_assets.presentation.balance.list.model.it import androidx.annotation.ColorRes import io.novafoundation.nova.common.utils.images.Icon import io.novafoundation.nova.common.utils.recyclerView.expandable.items.ExpandableParentItem -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel +import io.novafoundation.nova.feature_wallet_api.domain.model.Asset import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountModel +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain data class TokenGroupUi( override val itemId: String, @@ -21,6 +22,6 @@ data class TokenGroupUi( sealed interface GroupType { object Group : GroupType - data class SingleItem(val asset: AssetModel) : GroupType + data class SingleItem(val asset: Chain.Asset) : GroupType } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchFragment.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchFragment.kt index 40300d348d..fd29d8aa92 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchFragment.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchFragment.kt @@ -26,7 +26,7 @@ import io.novafoundation.nova.feature_assets.presentation.balance.common.Balance import io.novafoundation.nova.feature_assets.presentation.balance.common.baseDecoration.applyDefaultTo import io.novafoundation.nova.feature_assets.presentation.balance.common.createForAssets import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.android.synthetic.main.fragment_asset_search.searchAssetContainer import kotlinx.android.synthetic.main.fragment_asset_search.searchAssetList import kotlinx.android.synthetic.main.fragment_asset_search.searchAssetSearch @@ -110,7 +110,7 @@ class AssetSearchFragment : searchAssetSearch.searchInput.hideSoftKeyboard() } - override fun assetClicked(asset: AssetModel) { + override fun assetClicked(asset: Chain.Asset) { viewModel.assetClicked(asset) } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchViewModel.kt index 1ceb18ebe1..1fcac9279e 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/balance/search/AssetSearchViewModel.kt @@ -6,7 +6,7 @@ import io.novafoundation.nova.feature_assets.domain.assets.search.AssetSearchInt import io.novafoundation.nova.feature_wallet_api.presentation.model.AssetPayload import io.novafoundation.nova.feature_assets.presentation.AssetsRouter import io.novafoundation.nova.feature_assets.presentation.balance.common.ExpandableAssetsMixinFactory -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.coroutines.flow.MutableStateFlow class AssetSearchViewModel( @@ -32,10 +32,10 @@ class AssetSearchViewModel( router.back() } - fun assetClicked(assetModel: AssetModel) { + fun assetClicked(asset: Chain.Asset) { val payload = AssetPayload( - chainId = assetModel.token.configuration.chainId, - chainAssetId = assetModel.token.configuration.id + chainId = asset.chainId, + chainAssetId = asset.id ) router.openAssetDetails(payload) diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/buy/flow/asset/AssetBuyFlowViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/buy/flow/asset/AssetBuyFlowViewModel.kt index daf1d74dff..42ee15147f 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/buy/flow/asset/AssetBuyFlowViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/buy/flow/asset/AssetBuyFlowViewModel.kt @@ -12,10 +12,10 @@ import io.novafoundation.nova.feature_assets.presentation.balance.common.Control import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi import io.novafoundation.nova.feature_assets.presentation.flow.asset.AssetFlowViewModel import io.novafoundation.nova.feature_assets.presentation.flow.network.NetworkFlowPayload -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel import io.novafoundation.nova.feature_buy_api.presentation.mixin.BuyMixin import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountFormatter +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.coroutines.flow.Flow class AssetBuyFlowViewModel( @@ -49,10 +49,9 @@ class AssetBuyFlowViewModel( return interactor.buyAssetSearch(query, externalBalancesFlow) } - override fun assetClicked(assetModel: AssetModel) { - validate(assetModel) { - val chainAsset = assetModel.token.configuration - buyMixin.buyClicked(chainAsset) + override fun assetClicked(asset: Chain.Asset) { + validate(asset) { + buyMixin.buyClicked(asset) } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowFragment.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowFragment.kt index 61c5ce5b32..42d1891ca4 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowFragment.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowFragment.kt @@ -24,8 +24,8 @@ import io.novafoundation.nova.feature_assets.presentation.balance.common.baseDec import io.novafoundation.nova.feature_assets.presentation.balance.common.baseDecoration.TokenAssetGroupDecorationPreferences import io.novafoundation.nova.feature_assets.presentation.balance.common.baseDecoration.applyDefaultTo import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel import io.novafoundation.nova.feature_assets.presentation.receive.view.LedgerNotSupportedWarningBottomSheet +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import javax.inject.Inject import kotlinx.android.synthetic.main.fragment_asset_flow_search.assetFlowList import kotlinx.android.synthetic.main.fragment_asset_flow_search.assetFlowPlaceholder @@ -113,7 +113,7 @@ abstract class AssetFlowFragment : } } - override fun assetClicked(asset: AssetModel) { + override fun assetClicked(asset: Chain.Asset) { viewModel.assetClicked(asset) assetFlowToolbar.searchField.hideSoftKeyboard() diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowViewModel.kt index d00936a90d..e651ae3206 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/flow/asset/AssetFlowViewModel.kt @@ -24,10 +24,10 @@ import io.novafoundation.nova.feature_assets.presentation.balance.common.mappers import io.novafoundation.nova.feature_assets.presentation.balance.common.mappers.mapGroupedAssetsToUi import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.BalanceListRvItem import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor import io.novafoundation.nova.feature_currency_api.domain.model.Currency import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountFormatter +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted @@ -87,7 +87,7 @@ abstract class AssetFlowViewModel( abstract fun searchAssetsFlow(): Flow - abstract fun assetClicked(assetModel: AssetModel) + abstract fun assetClicked(asset: Chain.Asset) abstract fun tokenClicked(tokenGroup: TokenGroupUi) @@ -106,12 +106,11 @@ abstract class AssetFlowViewModel( return assets.map { mapTokenAssetGroupToUi(amountFormatter, assetIconProvider, it.key, assets = it.value) } } - internal fun validate(assetModel: AssetModel, onAccept: (AssetModel) -> Unit) { + internal fun validate(asset: Chain.Asset, onAccept: (Chain.Asset) -> Unit) { launch { val metaAccount = accountUseCase.getSelectedMetaAccount() - val chainAsset = assetModel.token.configuration - controllableAssetCheck.check(metaAccount, chainAsset) { - onAccept(assetModel) + controllableAssetCheck.check(metaAccount, asset) { + onAccept(asset) } } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/receive/flow/asset/AssetReceiveFlowViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/receive/flow/asset/AssetReceiveFlowViewModel.kt index c33bee7613..761aa0d94d 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/receive/flow/asset/AssetReceiveFlowViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/receive/flow/asset/AssetReceiveFlowViewModel.kt @@ -13,9 +13,9 @@ import io.novafoundation.nova.feature_assets.presentation.balance.common.Control import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi import io.novafoundation.nova.feature_assets.presentation.flow.asset.AssetFlowViewModel import io.novafoundation.nova.feature_assets.presentation.flow.network.NetworkFlowPayload -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountFormatter +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.coroutines.flow.Flow class AssetReceiveFlowViewModel( @@ -45,9 +45,9 @@ class AssetReceiveFlowViewModel( return interactor.searchReceiveAssetsFlow(query, externalBalancesFlow) } - override fun assetClicked(assetModel: AssetModel) { - validate(assetModel) { - openNextScreen(assetModel) + override fun assetClicked(asset: Chain.Asset) { + validate(asset) { + openNextScreen(asset) } } @@ -59,9 +59,8 @@ class AssetReceiveFlowViewModel( } } - private fun openNextScreen(assetModel: AssetModel) { - val chainAsset = assetModel.token.configuration - val assetPayload = AssetPayload(chainAsset.chainId, chainAsset.id) + private fun openNextScreen(asset: Chain.Asset) { + val assetPayload = AssetPayload(asset.chainId, asset.id) router.openReceive(assetPayload) } } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/send/flow/asset/AssetSendFlowViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/send/flow/asset/AssetSendFlowViewModel.kt index 03f77014a9..135a2126af 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/send/flow/asset/AssetSendFlowViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/send/flow/asset/AssetSendFlowViewModel.kt @@ -22,12 +22,12 @@ import io.novafoundation.nova.feature_assets.presentation.balance.list.model.ite import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi import io.novafoundation.nova.feature_assets.presentation.flow.asset.AssetFlowViewModel import io.novafoundation.nova.feature_assets.presentation.flow.network.NetworkFlowPayload -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel import io.novafoundation.nova.feature_assets.presentation.send.amount.SendPayload import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor import io.novafoundation.nova.feature_currency_api.domain.model.Currency import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountFormatter import io.novafoundation.nova.feature_wallet_api.presentation.model.AssetPayload +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.coroutines.flow.Flow class AssetSendFlowViewModel( @@ -58,9 +58,8 @@ class AssetSendFlowViewModel( return interactor.sendAssetSearch(query, externalBalancesFlow) } - override fun assetClicked(assetModel: AssetModel) { - val chainAsset = assetModel.token.configuration - val assetPayload = AssetPayload(chainAsset.chainId, chainAsset.id) + override fun assetClicked(asset: Chain.Asset) { + val assetPayload = AssetPayload(asset.chainId, asset.id) router.openSend(SendPayload.SpecifiedOrigin(assetPayload)) } diff --git a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/swap/asset/AssetSwapFlowViewModel.kt b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/swap/asset/AssetSwapFlowViewModel.kt index 022222f7cd..820d286688 100644 --- a/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/swap/asset/AssetSwapFlowViewModel.kt +++ b/feature-assets/src/main/java/io/novafoundation/nova/feature_assets/presentation/swap/asset/AssetSwapFlowViewModel.kt @@ -24,7 +24,6 @@ import io.novafoundation.nova.feature_assets.presentation.balance.list.model.ite import io.novafoundation.nova.feature_assets.presentation.balance.list.model.items.TokenGroupUi import io.novafoundation.nova.feature_assets.presentation.flow.asset.AssetFlowViewModel import io.novafoundation.nova.feature_assets.presentation.flow.network.NetworkFlowPayload -import io.novafoundation.nova.feature_assets.presentation.model.AssetModel import io.novafoundation.nova.feature_assets.presentation.swap.executor.SwapFlowExecutor import io.novafoundation.nova.feature_assets.presentation.swap.network.NetworkSwapFlowPayload import io.novafoundation.nova.feature_currency_api.domain.CurrencyInteractor @@ -32,6 +31,7 @@ import io.novafoundation.nova.feature_currency_api.domain.model.Currency import io.novafoundation.nova.feature_swap_api.domain.interactor.SwapAvailabilityInteractor import io.novafoundation.nova.feature_wallet_api.presentation.model.AmountFormatter import io.novafoundation.nova.feature_wallet_api.presentation.model.fullChainAssetId +import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch @@ -85,10 +85,9 @@ class AssetSwapFlowViewModel( ) } - override fun assetClicked(assetModel: AssetModel) { + override fun assetClicked(asset: Chain.Asset) { launch { - val chainAsset = assetModel.token.configuration - swapFlowExecutor.openNextScreen(viewModelScope, chainAsset) + swapFlowExecutor.openNextScreen(viewModelScope, asset) } } diff --git a/feature-governance-impl/src/main/java/io/novafoundation/nova/feature_governance_impl/presentation/track/TrackFormatter.kt b/feature-governance-impl/src/main/java/io/novafoundation/nova/feature_governance_impl/presentation/track/TrackFormatter.kt index e0897e4fcf..36a475bdb9 100644 --- a/feature-governance-impl/src/main/java/io/novafoundation/nova/feature_governance_impl/presentation/track/TrackFormatter.kt +++ b/feature-governance-impl/src/main/java/io/novafoundation/nova/feature_governance_impl/presentation/track/TrackFormatter.kt @@ -1,5 +1,6 @@ package io.novafoundation.nova.feature_governance_impl.presentation.track +import io.novafoundation.nova.common.data.model.AssetIconMode import io.novafoundation.nova.common.presentation.AssetIconProvider import io.novafoundation.nova.common.resources.ResourceManager import io.novafoundation.nova.common.resources.formatListPreview @@ -37,7 +38,7 @@ class RealTrackFormatter( return when (trackCategorizer.typeOf(track.name)) { TrackType.ROOT -> TrackModel( name = resourceManager.getString(R.string.referendum_track_root), - icon = assetIconProvider.getAssetIconOrFallback(asset, fallbackIcon = R.drawable.ic_block.asIcon()), + icon = assetIconProvider.getAssetIconOrFallback(asset, iconMode = AssetIconMode.WHITE, fallbackIcon = R.drawable.ic_block.asIcon()), ) TrackType.WHITELISTED_CALLER -> TrackModel( diff --git a/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountFormatters.kt b/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountFormatters.kt index 0999e2b8a4..ce9a752716 100644 --- a/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountFormatters.kt +++ b/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountFormatters.kt @@ -11,15 +11,15 @@ import io.novafoundation.nova.feature_wallet_api.R interface AmountFormatter { - fun formatBalanceWithFraction(amount: CharSequence, @DimenRes floatAmountSize: Int): CharSequence + fun formatBalanceWithFraction(unformattedAmount: CharSequence, @DimenRes floatAmountSize: Int): CharSequence } class RealAmountFormatter( private val resourceManager: ResourceManager ) : AmountFormatter { - override fun formatBalanceWithFraction(amount: CharSequence, @DimenRes floatAmountSize: Int): CharSequence { - val amountWithFraction = amount.toAmountWithFraction() + override fun formatBalanceWithFraction(unformattedAmount: CharSequence, @DimenRes floatAmountSize: Int): CharSequence { + val amountWithFraction = unformattedAmount.toAmountWithFraction() val textColor = resourceManager.getColor(R.color.text_secondary) val colorSpan = ForegroundColorSpan(textColor) diff --git a/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountModel.kt b/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountModel.kt index 38140a1b6f..3bfadfdbc9 100644 --- a/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountModel.kt +++ b/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/model/AmountModel.kt @@ -14,7 +14,15 @@ import java.math.RoundingMode data class AmountModel( val token: CharSequence, val fiat: CharSequence? -) +) { + + // Override it since SpannableString is not equals by content + override fun equals(other: Any?): Boolean { + return other is AmountModel && + other.token.toString() == token.toString() && + other.fiat?.toString() == fiat?.toString() + } +} enum class AmountSign(val signSymbol: String) { NONE(""), NEGATIVE("-"), POSITIVE("+") diff --git a/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/view/AssetSelectorBottomSheet.kt b/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/view/AssetSelectorBottomSheet.kt index 7e382e1267..13fa413f1f 100644 --- a/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/view/AssetSelectorBottomSheet.kt +++ b/feature-wallet-api/src/main/java/io/novafoundation/nova/feature_wallet_api/presentation/view/AssetSelectorBottomSheet.kt @@ -33,7 +33,7 @@ class AssetSelectorBottomSheet( override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setTitle(R.string.wallet_assets) + setTitle(R.string.select_network_title) setSubtitle(null) }