-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.ReferendumId | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
interface ReferendaSummaryInteractor { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?> { |
There was a problem hiding this comment.
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?
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 | ||
} |
There was a problem hiding this comment.
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
Feature/swipe gov backend
#86961b694