Skip to content

Commit

Permalink
Fix assets screen
Browse files Browse the repository at this point in the history
  • Loading branch information
furenster committed Nov 27, 2024
1 parent 79dcd6a commit ecf25ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.gemwallet.android.model.format
import com.gemwallet.android.ui.models.AssetInfoUIModel
import com.gemwallet.android.ui.models.AssetItemUIModel
import com.wallet.core.primitives.AssetId
import com.wallet.core.primitives.Currency
import com.wallet.core.primitives.Wallet
import com.wallet.core.primitives.WalletType
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -82,7 +83,8 @@ class AssetsViewModel @Inject constructor(

val walletInfo: StateFlow<WalletInfoUIState> = sessionRepository.session().combine(assetsState) {session, assets ->
val wallet = session?.wallet ?: return@combine null
calcWalletInfo(wallet, assets)
val currency = session.currency
calcWalletInfo(wallet, currency, assets)
}
.flowOn(Dispatchers.IO)
.filterNotNull()
Expand Down Expand Up @@ -115,7 +117,7 @@ class AssetsViewModel @Inject constructor(
}
}

private fun calcWalletInfo(wallet: Wallet, assets: List<AssetInfo>): WalletInfoUIState? {
private fun calcWalletInfo(wallet: Wallet, currency: Currency, assets: List<AssetInfo>): WalletInfoUIState? {
val (totalValue, changedValue) = assets.map {
val current = it.balance.fiatTotalAmount
val changed = current * ((it.price?.price?.priceChangePercentage24h ?: 0.0) / 100)
Expand All @@ -131,7 +133,6 @@ class AssetsViewModel @Inject constructor(
} else {
wallet.accounts.firstOrNull()?.chain?.getIconUrl() ?: ""
}
val currency = assets.firstOrNull()?.price?.currency ?: return null
return WalletInfoUIState(
name = wallet.name,
icon = icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ class AssetsRepository @Inject constructor(
fun invalidateDefault(wallet: Wallet, currency: Currency) = scope.launch(Dispatchers.IO) {
val assets = assetsDao.getAssetsInfoByAccountsInWallet(wallet.accounts.map { it.address }, wallet.id)
.map { AssetInfoMapper().asDomain(it) }
.map { it.filter { it.asset.type == AssetType.NATIVE } }
.firstOrNull()
?.associateBy( { it.asset.id.toIdentifier() }, { it } )?: emptyMap()

Expand All @@ -320,11 +321,11 @@ class AssetsRepository @Inject constructor(
Pair(account, account.chain.asset())
}.map {
val isNew = assets[it.first.chain.string] == null
val isVisible = assets[it.second.id.toIdentifier()]?.metadata?.isEnabled
?: visibleByDefault.contains(it.first.chain) || wallet.type != WalletType.multicoin
add(wallet.id, it.first.address, it.second, isVisible)
async {
if (isNew) {
val isVisible = assets[it.second.id.toIdentifier()]?.metadata?.isEnabled
?: visibleByDefault.contains(it.first.chain) || wallet.type != WalletType.multicoin
add(wallet.id, it.first.address, it.second, isVisible)
val balances = updateBalances(it.first, emptyList()).firstOrNull()
if ((balances?.totalAmount ?: 0.0) > 0.0) {
setVisibility(wallet.id, it.second.id, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AssetInfoMapper(private val gson: Gson = Gson()) : Mapper<List<DbAssetInfo
)
} else null,
metadata = AssetMetaData(
isEnabled = entity.visible != false,
isEnabled = entity.visible == true,
isBuyEnabled = entity.isBuyEnabled,
isSwapEnabled = entity.isSwapEnabled,
isStakeEnabled = entity.isStakeEnabled,
Expand Down

0 comments on commit ecf25ad

Please sign in to comment.