Skip to content

Commit

Permalink
Merge pull request #1682 from novasamatech/feature/swipe-gov-backend
Browse files Browse the repository at this point in the history
Feature/swipe gov backend
  • Loading branch information
antonijzelinskij authored Oct 4, 2024
2 parents 76d7695 + b1722e4 commit 2d235ba
Show file tree
Hide file tree
Showing 40 changed files with 540 additions and 594 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.noties.markwon.html.HtmlPlugin
import io.noties.markwon.image.coil.CoilImagesPlugin
import io.noties.markwon.linkify.LinkifyPlugin
import io.novafoundation.nova.common.di.scope.ScreenScope
import io.novafoundation.nova.common.utils.markdown.StylePlugin
import io.novafoundation.nova.common.utils.markdown.LinkStylePlugin

@Module
class MarkdownFullModule {
Expand All @@ -22,7 +22,7 @@ class MarkdownFullModule {
fun provideMarkwon(context: Context, imageLoader: ImageLoader): Markwon {
return Markwon.builder(context)
.usePlugin(LinkifyPlugin.create(Linkify.EMAIL_ADDRESSES or Linkify.WEB_URLS))
.usePlugin(StylePlugin(context))
.usePlugin(LinkStylePlugin(context))
.usePlugin(CoilImagesPlugin.create(context, imageLoader))
.usePlugin(StrikethroughPlugin.create())
.usePlugin(TablePlugin.create(context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.noties.markwon.html.HtmlPlugin
import io.noties.markwon.linkify.LinkifyPlugin
import io.novafoundation.nova.common.di.scope.ScreenScope
import io.novafoundation.nova.common.utils.markdown.RemoveHtmlTagsPlugin
import io.novafoundation.nova.common.utils.markdown.StylePlugin
import io.novafoundation.nova.common.utils.markdown.LinkStylePlugin

private const val IMG_HTML_TAG = "img"
private const val TABLE_HTML_TAG = "table"
Expand All @@ -24,7 +24,7 @@ class MarkdownShortModule {
return Markwon.builder(context)
.usePlugin(RemoveHtmlTagsPlugin(IMG_HTML_TAG, TABLE_HTML_TAG))
.usePlugin(LinkifyPlugin.create(Linkify.EMAIL_ADDRESSES or Linkify.WEB_URLS))
.usePlugin(StylePlugin(context))
.usePlugin(LinkStylePlugin(context))
.usePlugin(StrikethroughPlugin.create())
.usePlugin(HtmlPlugin.create())
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.novafoundation.nova.common.utils.markdown

import android.content.Context
import androidx.annotation.ColorRes
import androidx.annotation.FontRes
import androidx.core.content.res.ResourcesCompat
import io.noties.markwon.AbstractMarkwonPlugin
import io.noties.markwon.MarkwonConfiguration
import io.noties.markwon.MarkwonSpansFactory
import io.noties.markwon.RenderProps
import io.noties.markwon.SpanFactory
import io.novafoundation.nova.common.utils.colorSpan
import io.novafoundation.nova.common.utils.fontSpan
import org.commonmark.node.StrongEmphasis

class BoldStylePlugin(
private val context: Context,
@FontRes private val typefaceRes: Int,
@ColorRes private val colorRes: Int
) : AbstractMarkwonPlugin() {

override fun configureSpansFactory(builder: MarkwonSpansFactory.Builder) {
builder.setFactory(StrongEmphasis::class.java, BoldSpanFactory(context, typefaceRes, colorRes))
}
}

private class BoldSpanFactory(private val context: Context, private val typefaceRes: Int, private val colorRes: Int) : SpanFactory {

override fun getSpans(configuration: MarkwonConfiguration, props: RenderProps): Any {
val font = ResourcesCompat.getFont(context, typefaceRes)
return arrayOf(
fontSpan(font),
colorSpan(context.getColor(colorRes))
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.noties.markwon.AbstractMarkwonPlugin
import io.noties.markwon.core.MarkwonTheme
import io.novafoundation.nova.common.R

class StylePlugin(private val context: Context) : AbstractMarkwonPlugin() {
class LinkStylePlugin(private val context: Context) : AbstractMarkwonPlugin() {

override fun configureTheme(builder: MarkwonTheme.Builder) {
builder.isLinkUnderlined(false)
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<color name="link_text">#A3FFFFFF</color>
<color name="staking_type_banner_text">#A3FFFFFF</color>
<color name="staking_type_banner_text_inactive">#52FFFFFF</color>
<color name="tinder_gov_banner_secondary_text">#A3FFFFFF</color>

<color name="crowdloan_banner_gradient_start">#BD387F</color>
<color name="crowdloan_banner_gradient_end">#FF7A00</color>
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions feature-governance-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ android {
buildConfigField "String", "GOVERNANCE_DAPPS_URL", "\"https://raw.githubusercontent.com/novasamatech/nova-utils/master/governance/v2/dapps_dev.json\""

buildConfigField "String", "DELEGATION_TUTORIAL_URL", "\"https://docs.novawallet.io/nova-wallet-wiki/governance/add-delegate-information\""

buildConfigField "String", "SUMMARY_API_KEY", readStringSecret("POLKASSEMBLY_SUMMARY_API_KEY")
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2

import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query
import io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.request.ReferendumSummariesRequest
import io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.response.ReferendumSummaryResponse
import retrofit2.http.Body
import retrofit2.http.POST
import retrofit2.http.Url

interface ReferendumSummaryApi {

@GET
suspend fun getReferendumSummary(
@POST
suspend fun getReferendumSummaries(
@Url url: String,
@Header("x-network") networkHeader: String?,
@Header("x-ai-summary-api-key") summaryApiKey: String,
@Query("postId") postId: Int,
@Query("proposalType") proposalType: String = "referendums_v2"
): ReferendumSummaryResponse
@Body body: ReferendumSummariesRequest
): List<ReferendumSummaryResponse>
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2

import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.ReferendumId
import io.novafoundation.nova.feature_governance_impl.BuildConfig
import io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.request.ReferendumSummariesRequest
import io.novafoundation.nova.runtime.ext.summaryApiOrNull
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain

interface ReferendumSummaryDataSource {

suspend fun loadSummary(chain: Chain, id: ReferendumId, baseUrl: String): String
suspend fun loadSummaries(chain: Chain, ids: List<ReferendumId>, languageCode: String): Map<ReferendumId, String>?
}

class RealReferendumSummaryDataSource(
val api: ReferendumSummaryApi
) : ReferendumSummaryDataSource {

override suspend fun loadSummary(chain: Chain, id: ReferendumId, baseUrl: String): String {
val externalApi = chain.summaryApiOrNull()!!
override suspend fun loadSummaries(chain: Chain, ids: List<ReferendumId>, languageCode: String): Map<ReferendumId, String>? {
val summaryApi = chain.summaryApiOrNull() ?: return null

return api.getReferendumSummary(
baseUrl,
networkHeader = externalApi.network,
summaryApiKey = BuildConfig.SUMMARY_API_KEY,
postId = id.value.toInt()
).summary
val response = api.getReferendumSummaries(
summaryApi.url,
ReferendumSummariesRequest(
chainId = chain.id,
languageIsoCode = languageCode,
referendumIds = ids.map { it.value.toString() }
)
)

return response.associateBy { ReferendumId(it.referendumId.toBigInteger()) }
.mapValues { it.value.summary }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.request

class ReferendumSummariesRequest(
val chainId: String,
val languageIsoCode: String,
val referendumIds: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.response

class ReferendumSummaryResponse(val referendumId: Int, val summary: String)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package io.novafoundation.nova.feature_governance_impl.di.modules.screens

import dagger.Module
import dagger.Provides
import io.novafoundation.nova.common.data.memory.ComputationalCache
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.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 All @@ -20,9 +23,11 @@ import io.novafoundation.nova.feature_governance_impl.domain.referendum.details.
import io.novafoundation.nova.feature_governance_impl.domain.referendum.details.call.ReferendumPreImageParser
import io.novafoundation.nova.feature_governance_impl.domain.referendum.list.ReferendaSharedComputation
import io.novafoundation.nova.feature_governance_impl.domain.referendum.list.filtering.ReferendaFilteringProvider
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.RealTinderGovBasketInteractor
import io.novafoundation.nova.feature_governance_impl.domain.referendum.tindergov.RealTinderGovInteractor
import io.novafoundation.nova.feature_governance_impl.domain.summary.RealReferendaSummaryInteractor
import io.novafoundation.nova.feature_governance_impl.domain.summary.ReferendaSummarySharedComputation
import io.novafoundation.nova.feature_wallet_api.domain.AssetUseCase
import io.novafoundation.nova.feature_wallet_api.domain.interfaces.WalletRepository

@Module
class TinderGovModule {
Expand Down Expand Up @@ -69,23 +74,61 @@ class TinderGovModule {
governanceSharedState: GovernanceSharedState,
referendaSharedComputation: ReferendaSharedComputation,
accountRepository: AccountRepository,
referendumDetailsRepository: ReferendumDetailsRepository,
preImageParser: ReferendumPreImageParser,
tinderGovBasketRepository: TinderGovBasketRepository,
walletRepository: WalletRepository,
tinderGovVotingPowerRepository: TinderGovVotingPowerRepository,
referendaFilteringProvider: ReferendaFilteringProvider,
assetUseCase: AssetUseCase
): TinderGovInteractor = RealTinderGovInteractor(
governanceSharedState,
referendaSharedComputation,
accountRepository,
referendumDetailsRepository,
preImageParser,
tinderGovBasketRepository,
walletRepository,
tinderGovVotingPowerRepository,
referendaFilteringProvider,
assetUseCase
)

@Provides
@FeatureScope
fun provideReferendaSummarySharedComputation(
computationalCache: ComputationalCache,
referendumDetailsRepository: ReferendumDetailsRepository,
accountRepository: AccountRepository
) = ReferendaSummarySharedComputation(
computationalCache,
referendumDetailsRepository,
accountRepository
)

@Provides
@FeatureScope
fun provideReferendaSummaryInteractor(
governanceSharedState: GovernanceSharedState,
referendaSummarySharedComputation: ReferendaSummarySharedComputation
): ReferendaSummaryInteractor = RealReferendaSummaryInteractor(
governanceSharedState,
referendaSummarySharedComputation
)

@Provides
@FeatureScope
fun provideTinderGovBasketInteractor(
governanceSharedState: GovernanceSharedState,
referendaSharedComputation: ReferendaSharedComputation,
accountRepository: AccountRepository,
tinderGovBasketRepository: TinderGovBasketRepository,
tinderGovVotingPowerRepository: TinderGovVotingPowerRepository,
referendaFilteringProvider: ReferendaFilteringProvider,
assetUseCase: AssetUseCase,
tinderGovInteractor: TinderGovInteractor
): TinderGovBasketInteractor = RealTinderGovBasketInteractor(
governanceSharedState = governanceSharedState,
referendaSharedComputation = referendaSharedComputation,
accountRepository = accountRepository,
tinderGovBasketRepository = tinderGovBasketRepository,
tinderGovVotingPowerRepository = tinderGovVotingPowerRepository,
referendaFilteringProvider = referendaFilteringProvider,
assetUseCase = assetUseCase,
tinderGovInteractor = tinderGovInteractor
)
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package io.novafoundation.nova.feature_governance_impl.domain.referendum.details

import io.novafoundation.nova.core.model.Language
import io.novafoundation.nova.feature_governance_api.data.network.blockhain.model.ReferendumId
import io.novafoundation.nova.feature_governance_impl.data.offchain.referendum.summary.v2.ReferendumSummaryDataSource
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain

interface ReferendumDetailsRepository {

suspend fun loadSummary(chain: Chain, id: ReferendumId, baseUrl: String): String
suspend fun loadSummaries(chain: Chain, ids: List<ReferendumId>, selectedLanguage: Language): Map<ReferendumId, String>?
}

class RealReferendumDetailsRepository(
private val referendumSummaryDataSource: ReferendumSummaryDataSource
) : ReferendumDetailsRepository {

override suspend fun loadSummary(chain: Chain, id: ReferendumId, baseUrl: String): String {
return referendumSummaryDataSource.loadSummary(chain, id, baseUrl)
override suspend fun loadSummaries(chain: Chain, ids: List<ReferendumId>, selectedLanguage: Language): Map<ReferendumId, String>? {
return referendumSummaryDataSource.loadSummaries(chain, ids, selectedLanguage.iso639Code)
}
}
Loading

0 comments on commit 2d235ba

Please sign in to comment.