Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/swipe gov backend #1682

Merged
merged 6 commits into from
Oct 4, 2024
Merged

Conversation

antonijzelinskij
Copy link
Contributor

#86961b694

import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.ReferendumId
import kotlinx.coroutines.CoroutineScope

interface ReferendaSummaryInteractor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this interface in api module? We should try to keep api module as small as possible

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow

interface TinderGovBasketInteractor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

scope: CoroutineScope
): Map<ReferendumId, String>? {
val chainId = governanceOption.assetWithChain.chain.id
val referendaSet = referendaIds.toSet()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think it is good idea tu use an unbounded collection as a cache key
We can use hashCode of a sorted referneudm list. Converting list to a set is O(NlogN) anyways

Comment on lines 182 to 184
private fun mapTinderGovToUi(chain: Chain, referendaSummaries: Map<ReferendumId, String>?): TinderGovBannerModel? {
if (!chain.supportTinderGov()) return null
if (referendaListState == null) return null

val availableToVote = referendaListState.availableToVoteReferenda
if (referendaSummaries == null) return null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an excessive abuse of nullable types - they have no semantics attached why they are null. Are they null because they dont exist or they are loading, or they failed to load?
For loading values we have LoadingState, lets use it when possible

val cardAmount = cardsAmount.getOrDefault(referendum.id, ExtendedLoadingState.Loading)

CardWithDetails(referendum, cardSummary, cardAmount)
private val topReferendumWithDetails = combine(topCardIndex, sortedReferendaFlow) { topCardIndex, referenda ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a referendum now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a top card of referendum. I renamed it to topCardFlow to make it more clear

private fun List<ReferendumPreview>.mapToCardWithDetails(
summaries: Map<ReferendumId, String>,
amounts: Map<ReferendumId, AmountModel?>
): List<CardWithDetails?> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this abuses nullable values too much. This whole ViewModel is extremely hard to read because you cant quickly understand why certain values can be null and when they can be null

For example this method is called only once with later "filterNotNull" called afterwards. Why does it even return nullable values at the first place?

Comment on lines 12 to 24
override fun equals(other: Any?): Boolean {
return other is CardWithDetails &&
id == other.id &&
summary == other.summary &&
amount == other.amount
}

override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + summary.hashCode()
result = 31 * result + amount.hashCode()
return result
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really looks like a data class

@antonijzelinskij antonijzelinskij merged commit 2d235ba into develop Oct 4, 2024
3 checks passed
@antonijzelinskij antonijzelinskij deleted the feature/swipe-gov-backend branch October 4, 2024 15:08
antonijzelinskij added a commit that referenced this pull request Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants