Skip to content

Commit

Permalink
Fixed pr notes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonijzelinskij committed Oct 4, 2024
1 parent 143af64 commit b1722e4
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 133 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import io.novafoundation.nova.common.data.network.NetworkApiCreator
import io.novafoundation.nova.common.di.scope.FeatureScope
import io.novafoundation.nova.core_db.dao.TinderGovDao
import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepository
import io.novafoundation.nova.feature_governance_api.domain.referendum.summary.ReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.domain.summary.ReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.data.GovernanceSharedState
import io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.RealReferendumSummaryDataSource
import io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.ReferendumSummaryApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepos
import io.novafoundation.nova.feature_governance_api.data.model.TinderGovBasketItem
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.ReferendumId
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.VoteType
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.data.GovernanceSharedState
import io.novafoundation.nova.feature_governance_impl.data.repository.tindergov.TinderGovBasketRepository
import io.novafoundation.nova.feature_governance_impl.data.repository.tindergov.TinderGovVotingPowerRepository
Expand All @@ -23,6 +21,27 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first

interface TinderGovBasketInteractor {

fun observeTinderGovBasket(): Flow<List<TinderGovBasketItem>>

suspend fun getTinderGovBasket(): List<TinderGovBasketItem>

suspend fun addItemToBasket(referendumId: ReferendumId, voteType: VoteType)

suspend fun removeReferendumFromBasket(item: TinderGovBasketItem)

suspend fun removeBasketItems(items: Collection<TinderGovBasketItem>)

suspend fun isBasketEmpty(): Boolean

suspend fun clearBasket()

suspend fun getBasketItemsToRemove(coroutineScope: CoroutineScope): List<TinderGovBasketItem>

suspend fun awaitAllItemsVoted(coroutineScope: CoroutineScope, basket: List<TinderGovBasketItem>)
}

class RealTinderGovBasketInteractor(
private val governanceSharedState: GovernanceSharedState,
private val referendaSharedComputation: ReferendaSharedComputation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import io.novafoundation.nova.feature_governance_api.domain.referendum.list.Refe
import io.novafoundation.nova.feature_governance_api.domain.referendum.list.Voter
import io.novafoundation.nova.feature_governance_api.domain.referendum.list.toCallOrNull
import io.novafoundation.nova.feature_governance_api.domain.referendum.list.user
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.VotingPowerState
import io.novafoundation.nova.feature_governance_impl.data.GovernanceSharedState
import io.novafoundation.nova.feature_governance_impl.data.repository.tindergov.TinderGovVotingPowerRepository
import io.novafoundation.nova.feature_governance_impl.domain.referendum.details.call.ReferendumPreImageParser
Expand All @@ -32,6 +30,32 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map

sealed interface VotingPowerState {

object Empty : VotingPowerState

class InsufficientAmount(val votingPower: VotingPower) : VotingPowerState

class SufficientAmount(val votingPower: VotingPower) : VotingPowerState
}

interface TinderGovInteractor {

fun observeReferendaState(coroutineScope: CoroutineScope): Flow<ReferendaState>

fun observeReferendaAvailableToVote(coroutineScope: CoroutineScope): Flow<List<ReferendumPreview>>

suspend fun getReferendumAmount(referendumPreview: ReferendumPreview): ReferendumCall.TreasuryRequest?

suspend fun setVotingPower(votingPower: VotingPower)

suspend fun getVotingPower(metaId: Long, chainId: ChainId): VotingPower?

suspend fun getVotingPowerState(): VotingPowerState

suspend fun awaitAllItemsVoted(coroutineScope: CoroutineScope, basket: List<TinderGovBasketItem>)
}

class RealTinderGovInteractor(
private val governanceSharedState: GovernanceSharedState,
private val referendaSharedComputation: ReferendaSharedComputation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.novafoundation.nova.feature_governance_impl.domain.summary

import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.ReferendumId
import io.novafoundation.nova.feature_governance_api.domain.referendum.summary.ReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_impl.data.GovernanceSharedState
import io.novafoundation.nova.runtime.state.selectedOption
import kotlinx.coroutines.CoroutineScope

interface ReferendaSummaryInteractor {

suspend fun getReferendaSummaries(ids: List<ReferendumId>, coroutineScope: CoroutineScope): Map<ReferendumId, String>
}

class RealReferendaSummaryInteractor(
private val governanceSharedState: GovernanceSharedState,
private val referendaSummarySharedComputation: ReferendaSummarySharedComputation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class ReferendaSummarySharedComputation(
scope: CoroutineScope
): Map<ReferendumId, String>? {
val chainId = governanceOption.assetWithChain.chain.id
val referendaSet = referendaIds.toSet()
val referendaHashCode = referendaIds.toSet().hashCode()
val selectedLanguage = accountRepository.selectedLanguage()
val key = "REFERENDA_SUMMARIES:$chainId:$referendaSet:${selectedLanguage.iso639Code}"
val key = "REFERENDA_SUMMARIES:$chainId:$referendaHashCode:${selectedLanguage.iso639Code}"

return computationalCache.useCache(key, scope) {
referendumDetailsRepository.loadSummaries(governanceOption.assetWithChain.chain, referendaIds, selectedLanguage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.novafoundation.nova.feature_governance_impl.presentation.referenda.li
import android.util.Log
import androidx.lifecycle.viewModelScope
import io.novafoundation.nova.common.base.BaseViewModel
import io.novafoundation.nova.common.domain.ExtendedLoadingState
import io.novafoundation.nova.common.domain.dataOrNull
import io.novafoundation.nova.common.list.toListWithHeaders
import io.novafoundation.nova.common.domain.mapLoading
Expand All @@ -28,7 +29,7 @@ import io.novafoundation.nova.feature_governance_impl.domain.filters.ReferendaFi
import io.novafoundation.nova.feature_governance_api.domain.referendum.filters.ReferendumType
import io.novafoundation.nova.feature_governance_api.domain.referendum.filters.ReferendumTypeFilter
import io.novafoundation.nova.feature_governance_api.domain.referendum.list.ReferendaListState
import io.novafoundation.nova.feature_governance_api.domain.referendum.summary.ReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_impl.domain.summary.ReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_impl.presentation.GovernanceRouter
import io.novafoundation.nova.feature_governance_impl.presentation.referenda.common.ReferendumFormatter
import io.novafoundation.nova.feature_governance_impl.presentation.referenda.common.list.ReferendaListStateModel
Expand Down Expand Up @@ -114,7 +115,7 @@ class ReferendaListViewModel(

val tinderGovBanner = referendaSummariesFlow.map { summaries ->
val chain = selectedAssetSharedState.chain()
mapTinderGovToUi(chain, summaries.dataOrNull)
mapTinderGovToUi(chain, summaries)
}
.inBackground()
.shareWhileSubscribed()
Expand Down Expand Up @@ -179,15 +180,16 @@ class ReferendaListViewModel(
}
}

private fun mapTinderGovToUi(chain: Chain, referendaSummaries: Map<ReferendumId, String>?): TinderGovBannerModel? {
private fun mapTinderGovToUi(chain: Chain, referendaSummariesLoadingState: ExtendedLoadingState<Map<ReferendumId, String>>): TinderGovBannerModel? {
if (!chain.supportTinderGov()) return null
if (referendaSummaries == null) return null

val referendumSummaries = referendaSummariesLoadingState.dataOrNull ?: return null

return TinderGovBannerModel(
if (referendaSummaries.isEmpty()) {
if (referendumSummaries.isEmpty()) {
null
} else {
resourceManager.getString(R.string.referenda_swipe_gov_banner_chip, referendaSummaries.size)
resourceManager.getString(R.string.referenda_swipe_gov_banner_chip, referendumSummaries.size)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.novafoundation.nova.common.resources.ResourceManager
import io.novafoundation.nova.core.updater.UpdateSystem
import io.novafoundation.nova.feature_account_api.domain.interfaces.SelectedAccountUseCase
import io.novafoundation.nova.feature_governance_api.domain.referendum.list.ReferendaListInteractor
import io.novafoundation.nova.feature_governance_api.domain.referendum.summary.ReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_impl.domain.summary.ReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_impl.data.GovernanceSharedState
import io.novafoundation.nova.feature_governance_impl.domain.dapp.GovernanceDAppsInteractor
import io.novafoundation.nova.feature_governance_impl.domain.filters.ReferendaFiltersInteractor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepos
import io.novafoundation.nova.feature_governance_api.data.model.VotingPower
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.VoteType
import io.novafoundation.nova.feature_governance_api.domain.referendum.vote.VoteReferendumInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.R
import io.novafoundation.nova.feature_governance_impl.domain.referendum.vote.validations.referendum.VoteReferendaValidationPayload
import io.novafoundation.nova.feature_governance_impl.domain.referendum.vote.validations.referendum.VoteReferendumValidationSystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.novafoundation.nova.common.resources.ResourceManager
import io.novafoundation.nova.common.validation.ValidationExecutor
import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepository
import io.novafoundation.nova.feature_governance_api.domain.referendum.vote.VoteReferendumInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.vote.validations.referendum.VoteReferendumValidationSystem
import io.novafoundation.nova.feature_governance_impl.presentation.GovernanceRouter
import io.novafoundation.nova.feature_governance_impl.presentation.common.conviction.ConvictionValuesProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import io.novafoundation.nova.common.utils.toggle
import io.novafoundation.nova.feature_governance_api.data.model.TinderGovBasketItem
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.VoteType
import io.novafoundation.nova.feature_governance_api.domain.referendum.list.ReferendumPreview
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.R
import io.novafoundation.nova.feature_governance_impl.data.GovernanceSharedState
import io.novafoundation.nova.feature_governance_impl.presentation.GovernanceRouter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import io.novafoundation.nova.common.di.viewmodel.ViewModelKey
import io.novafoundation.nova.common.di.viewmodel.ViewModelModule
import io.novafoundation.nova.common.mixin.actionAwaitable.ActionAwaitableMixin
import io.novafoundation.nova.common.resources.ResourceManager
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_api.domain.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.TinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.data.GovernanceSharedState
import io.novafoundation.nova.feature_governance_impl.presentation.GovernanceRouter
import io.novafoundation.nova.feature_governance_impl.presentation.common.voters.VotersFormatter
Expand Down
Loading

0 comments on commit b1722e4

Please sign in to comment.