-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1682 from novasamatech/feature/swipe-gov-backend
Feature/swipe gov backend
- Loading branch information
Showing
40 changed files
with
540 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
common/src/main/java/io/novafoundation/nova/common/utils/markdown/BoldStylePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
...ava/io/novafoundation/nova/feature_governance_api/domain/tindergov/TinderGovInteractor.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 8 additions & 10 deletions
18
.../nova/feature_governance_impl/data/offchain/referendum/summary/v2/ReferendumSummaryApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
25 changes: 15 additions & 10 deletions
25
...eature_governance_impl/data/offchain/referendum/summary/v2/ReferendumSummaryDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
.../feature_governance_impl/data/offchain/referendum/summary/v2/ReferendumSummaryResponse.kt
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...governance_impl/data/offchain/referendum/summary/v2/request/ReferendumSummariesRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) |
3 changes: 3 additions & 0 deletions
3
...governance_impl/data/offchain/referendum/summary/v2/response/ReferendumSummaryResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...ion/nova/feature_governance_impl/domain/referendum/details/ReferendumDetailsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.