Skip to content

Commit

Permalink
Merge pull request #1477 from novasamatech/rc/7.11.2
Browse files Browse the repository at this point in the history
Rc/7.11.2
  • Loading branch information
valentunn authored Apr 17, 2024
2 parents 6e9e668 + 6eaba16 commit d8bee70
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
buildscript {
ext {
// App version
versionName = '7.11.1'
versionCode = 130
versionName = '7.11.2'
versionCode = 131

applicationId = "io.novafoundation.nova"
releaseApplicationSuffix = "market"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface SubSquareV2Api {
@GET
suspend fun getReferendumPreviews(
@Url url: String,
@Query("page_size") pageSize: Int = 1000
@Query("page_size") pageSize: Int = 100
): ReferendaPreviewV2Response

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.novafoundation.nova.common.domain.ExtendedLoadingState
import io.novafoundation.nova.common.utils.castOrNull
import io.novafoundation.nova.common.utils.withSafeLoading
import io.novafoundation.nova.feature_account_api.data.repository.OnChainIdentityRepository
import io.novafoundation.nova.feature_account_api.domain.account.identity.Identity
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.OnChainReferendum
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.Proposal
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.ReferendumId
Expand All @@ -15,7 +16,6 @@ import io.novafoundation.nova.feature_governance_api.data.network.blockhain.mode
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.flattenCastingVotes
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.hash
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.proposal
import io.novafoundation.nova.feature_account_api.domain.account.identity.Identity
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.track
import io.novafoundation.nova.feature_governance_api.data.network.offchain.model.referendum.OffChainReferendumPreview
import io.novafoundation.nova.feature_governance_api.data.network.offchain.model.vote.UserVote
Expand All @@ -37,13 +37,14 @@ import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain
import io.novafoundation.nova.runtime.repository.ChainStateRepository
import io.novafoundation.nova.runtime.repository.blockDurationEstimator
import io.novafoundation.nova.runtime.util.blockInPast
import java.math.BigInteger
import io.novasama.substrate_sdk_android.extensions.requireHexPrefix
import io.novasama.substrate_sdk_android.extensions.toHexString
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flow
import java.math.BigInteger

class ReferendaState(
val voting: Map<TrackId, Voting>,
Expand Down Expand Up @@ -78,13 +79,12 @@ class RealReferendaCommonRepository(
val governanceSource = governanceSourceRegistry.sourceFor(governanceOption)
val tracksById = governanceSource.referenda.getTracksById(chain.id)

return chainStateRepository.currentBlockNumberFlow(chain.id).map { currentBlockNumber ->
return combine(
governanceSource.referendaOffChainInfoFlow(chain),
chainStateRepository.currentBlockNumberFlow(chain.id)
) { offChainInfo, currentBlockNumber ->
coroutineScope {
val onChainReferenda = async { governanceSource.referenda.getAllOnChainReferenda(chain.id) }
val offChainInfo = async {
governanceSource.offChainInfo.referendumPreviews(chain)
.associateBy(OffChainReferendumPreview::referendumId)
}
val electorate = async { governanceSource.referenda.electorate(chain.id) }

val onChainVoting = async { voter?.accountId?.let { governanceSource.convictionVoting.votingFor(it, chain.id) }.orEmpty() }
Expand All @@ -97,7 +97,7 @@ class RealReferendaCommonRepository(
selectedGovernanceOption = governanceOption,
tracksById = tracksById,
currentBlockNumber = currentBlockNumber,
offChainInfo = offChainInfo.await(),
offChainInfo = offChainInfo,
electorate = electorate.await()
)

Expand All @@ -118,13 +118,12 @@ class RealReferendaCommonRepository(
val governanceSource = governanceSourceRegistry.sourceFor(selectedGovernanceOption)
val tracksById = governanceSource.referenda.getTracksById(chain.id)

return chainStateRepository.currentBlockNumberFlow(chain.id).map { currentBlockNumber ->
return combine(
governanceSource.referendaOffChainInfoFlow(chain),
chainStateRepository.currentBlockNumberFlow(chain.id)
) { offChainInfo, currentBlockNumber ->
coroutineScope {
val onChainReferenda = async { governanceSource.referenda.getAllOnChainReferenda(chain.id) }
val offChainInfo = async {
governanceSource.offChainInfo.referendumPreviews(chain)
.associateBy(OffChainReferendumPreview::referendumId)
}
val electorate = async { governanceSource.referenda.electorate(chain.id) }

val onChainVoting = async { governanceSource.convictionVoting.votingFor(voter.accountId, chain.id) }
Expand All @@ -137,7 +136,7 @@ class RealReferendaCommonRepository(
selectedGovernanceOption = selectedGovernanceOption,
tracksById = tracksById,
currentBlockNumber = currentBlockNumber,
offChainInfo = offChainInfo.await(),
offChainInfo = offChainInfo,
electorate = electorate.await()
)

Expand All @@ -147,6 +146,17 @@ class RealReferendaCommonRepository(
}
}

private fun GovernanceSource.referendaOffChainInfoFlow(chain: Chain): Flow<Map<ReferendumId, OffChainReferendumPreview>> {
return flow {
emit(emptyMap())

val offChainInfo = offChainInfo.referendumPreviews(chain)
.associateBy(OffChainReferendumPreview::referendumId)

emit(offChainInfo)
}
}

private fun List<ReferendumPreview>.onlyVoted(): List<ReferendumPreview> {
return filter { it.referendumVote != null }
}
Expand Down Expand Up @@ -302,6 +312,7 @@ class RealReferendaCommonRepository(
ReferendumProposal.Hash(hashHex.requireHexPrefix())
}
}

null -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import io.novafoundation.nova.feature_wallet_api.data.source.CoinPriceRemoteData
import io.novafoundation.nova.feature_wallet_api.domain.interfaces.CoinPriceRepository
import io.novafoundation.nova.feature_wallet_api.domain.model.CoinRateChange
import io.novafoundation.nova.feature_wallet_api.domain.model.HistoricalCoinRate
import java.util.Calendar
import kotlin.time.Duration
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

private const val START_SYNCING_YEAR = 2010
private val MAX_ALLOWED_PRICE_RANGE = 365.days
private const val BASE_OFFSET = 1

class CoinPriceRepositoryImpl(
Expand Down Expand Up @@ -66,11 +65,9 @@ class CoinPriceRepositoryImpl(
}

private suspend fun loadAndCacheForAllTime(priceId: String, currency: Currency): List<HistoricalCoinRate> {
val startCalendar = Calendar.getInstance()
startCalendar.set(START_SYNCING_YEAR, 0, 0)
val from = startCalendar.time.time.milliseconds.inWholeSeconds
val to = System.currentTimeMillis().milliseconds.inWholeSeconds
val coinRate = remoteCoinPriceDataSource.getCoinPriceRange(priceId, currency, from, to)
val to = System.currentTimeMillis().milliseconds
val from = to - MAX_ALLOWED_PRICE_RANGE
val coinRate = remoteCoinPriceDataSource.getCoinPriceRange(priceId, currency, from.inWholeSeconds, to.inWholeSeconds)
if (coinRate.isNotEmpty()) {
cacheCoinPriceDataSource.updateCoinPrice(priceId, currency, coinRate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.novafoundation.nova.feature_wallet_impl.data.source
import io.novafoundation.nova.common.data.network.HttpExceptionHandler
import io.novafoundation.nova.common.utils.asQueryParam
import io.novafoundation.nova.common.utils.orZero
import io.novafoundation.nova.common.utils.second
import io.novafoundation.nova.feature_currency_api.domain.model.Currency
import io.novafoundation.nova.feature_wallet_api.data.network.coingecko.CoingeckoApi
import io.novafoundation.nova.feature_wallet_api.data.source.CoinPriceRemoteDataSource
Expand All @@ -18,10 +17,11 @@ class CoingeckoCoinPriceDataSource(

override suspend fun getCoinPriceRange(priceId: String, currency: Currency, fromTimestamp: Long, toTimestamp: Long): List<HistoricalCoinRate> {
val response = coingeckoApi.getCoinRange(priceId, currency.coingeckoId, fromTimestamp, toTimestamp)
return response.prices.map {

return response.prices.map { (timestampRaw, rateRaw) ->
HistoricalCoinRate(
it.first().toLong().milliseconds.inWholeSeconds,
it.second()
timestamp = timestampRaw.toLong().milliseconds.inWholeSeconds,
rate = rateRaw
)
}
}
Expand Down

0 comments on commit d8bee70

Please sign in to comment.