Updated on 2026-08-14

This commit is contained in:
Tangem 2026-01-27 16:53:30 +04:00
parent f21da4c520
commit bc24aeb9f3

View file

@ -30,9 +30,9 @@ import javax.inject.Inject
@ModelScoped
internal class PortfolioSelectorModel @Inject constructor(
paramsContainer: ParamsContainer,
walletImageFetcher: UserWalletImageFetcher,
isAccountsModeEnabledUseCase: IsAccountsModeEnabledUseCase,
override val dispatchers: CoroutineDispatcherProvider,
private val walletImageFetcher: UserWalletImageFetcher,
private val isAccountsModeEnabledUseCase: IsAccountsModeEnabledUseCase,
) : Model() {
private val params = paramsContainer.require<PortfolioSelectorComponent.Params>()
@ -128,13 +128,9 @@ internal class PortfolioSelectorModel @Inject constructor(
lockedWallets.add(PortfolioSelectorItemUM.Portfolio(walletItemUM, isSelected = false))
}
}
if (lockedWallets.isNotEmpty()) {
val lockedWalletsTitle = PortfolioSelectorItemUM.GroupTitle(
id = "lockedWalletsTitleId",
name = resourceReference(R.string.common_locked_wallets),
)
add(lockedWalletsTitle)
addAll(lockedWallets)
addAll(createLockedWallets(wallets = lockedWallets))
}
}
@ -147,7 +143,7 @@ internal class PortfolioSelectorModel @Inject constructor(
val appCurrency = portfolioData.appCurrency
val isBalanceHidden = portfolioData.isBalanceHidden
val lockedWallets = mutableListOf<PortfolioSelectorItemUM>()
portfolioData.balances.forEach { walletId, portfolio ->
portfolioData.balances.forEach { (_, portfolio) ->
val balance = portfolio.walletBalance
val wallet = portfolio.userWallet
val walletItemUM = UserWalletItemUMConverter(
@ -169,13 +165,16 @@ internal class PortfolioSelectorModel @Inject constructor(
// for Wallet mode expected single portfolioData.balances
is PortfolioFetcher.Mode.Wallet -> Unit
is PortfolioFetcher.Mode.All -> {
if (portfolioData.balances.size > 1) {
val walletTitle = PortfolioSelectorItemUM.GroupTitle(
id = "GroupTitle ${wallet.walletId.stringValue}",
name = stringReference(wallet.name),
)
add(walletTitle)
}
}
}
portfolio.accountsBalance.accountStatuses.forEach { accountStatus ->
val isEnabledByFeature = isEnabled(wallet, accountStatus)
@ -195,13 +194,17 @@ internal class PortfolioSelectorModel @Inject constructor(
}
}
if (lockedWallets.isNotEmpty()) {
addAll(createLockedWallets(wallets = lockedWallets))
}
}
private fun createLockedWallets(wallets: List<PortfolioSelectorItemUM>): List<PortfolioSelectorItemUM> {
val lockedWalletsTitle = PortfolioSelectorItemUM.GroupTitle(
id = "lockedWalletsTitleId",
name = resourceReference(R.string.common_locked_wallets),
)
add(lockedWalletsTitle)
addAll(lockedWallets)
}
return listOf(lockedWalletsTitle) + wallets
}
private fun AccountStatus.isSelected(selectedId: AccountId?) = this.account.accountId == selectedId