mirror of
https://github.com/pezkuwichain/pezkuwi-wallet-android.git
synced 2026-04-22 02:07:58 +00:00
feat: replace dashboard image with Welati counter (Hejmara Kurd Le Cihane)
Remove telegram_welcome image from dashboard card, add live Welati citizen count fetched from kurds-counter API endpoint. Shows formatted count with "Hejmara Kurd Le Cihane" label in green.
This commit is contained in:
@@ -2766,4 +2766,5 @@
|
||||
<string name="pezkuwi_dashboard_trust_score">Trust Score</string>
|
||||
<string name="pezkuwi_dashboard_basvuru">Apply & Actions</string>
|
||||
<string name="pezkuwi_dashboard_info">Use our Telegram MiniApp for Digital Kurdistan citizenship services.\n\nTo earn PEZ rewards, you must hold a Welatî ticket and stake at least 10 HEZ.\n\nNon-citizens can only benefit from HEZ rewards.</string>
|
||||
<string name="pezkuwi_dashboard_kurds_title">Hejmara Kurd Le Cihane</string>
|
||||
</resources>
|
||||
|
||||
+2
-1
@@ -4,5 +4,6 @@ import java.math.BigInteger
|
||||
|
||||
data class PezkuwiDashboardData(
|
||||
val roles: List<String>,
|
||||
val trustScore: BigInteger
|
||||
val trustScore: BigInteger,
|
||||
val welatiCount: Int
|
||||
)
|
||||
|
||||
+18
-1
@@ -9,24 +9,41 @@ import io.novafoundation.nova.runtime.storage.source.StorageDataSource
|
||||
import io.novasama.substrate_sdk_android.runtime.AccountId
|
||||
import io.novasama.substrate_sdk_android.runtime.metadata.moduleOrNull
|
||||
import io.novasama.substrate_sdk_android.runtime.metadata.storage
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.json.JSONObject
|
||||
import java.math.BigInteger
|
||||
import java.net.URL
|
||||
|
||||
class PezkuwiDashboardRepository(
|
||||
private val remoteStorageDataSource: StorageDataSource
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private const val WELATI_COUNTER_URL = "https://subquery.pezkuwichain.io/kurds"
|
||||
}
|
||||
|
||||
suspend fun getDashboard(accountId: AccountId): PezkuwiDashboardData {
|
||||
val chainId = ChainGeneses.PEZKUWI_PEOPLE
|
||||
|
||||
val roles = queryRoles(chainId, accountId)
|
||||
val trustScore = queryTrustScore(chainId, accountId)
|
||||
val welatiCount = fetchWelatiCount()
|
||||
|
||||
return PezkuwiDashboardData(
|
||||
roles = roles.ifEmpty { listOf("Non-Citizen") },
|
||||
trustScore = trustScore
|
||||
trustScore = trustScore,
|
||||
welatiCount = welatiCount
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun fetchWelatiCount(): Int = withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
val response = URL(WELATI_COUNTER_URL).readText()
|
||||
JSONObject(response).getInt("count")
|
||||
}.getOrDefault(0)
|
||||
}
|
||||
|
||||
private suspend fun queryRoles(chainId: String, accountId: AccountId): List<String> = runCatching {
|
||||
remoteStorageDataSource.query(chainId) {
|
||||
val tikiModule = runtime.metadata.moduleOrNull("Tiki") ?: return@query emptyList()
|
||||
|
||||
+3
-1
@@ -64,6 +64,7 @@ import io.novafoundation.nova.feature_wallet_api.presentation.model.FractionPart
|
||||
import io.novafoundation.nova.feature_wallet_connect_api.domain.sessions.WalletConnectSessionsUseCase
|
||||
import io.novafoundation.nova.feature_wallet_connect_api.presentation.mapNumberOfActiveSessionsToUi
|
||||
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain
|
||||
import java.text.NumberFormat
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
@@ -228,7 +229,8 @@ class BalanceListViewModel(
|
||||
.map { data ->
|
||||
PezkuwiDashboardModel(
|
||||
roles = data.roles,
|
||||
trustScore = data.trustScore.toString()
|
||||
trustScore = data.trustScore.toString(),
|
||||
welatiCount = NumberFormat.getIntegerInstance().format(data.welatiCount)
|
||||
)
|
||||
}
|
||||
.getOrNull()
|
||||
|
||||
+2
-1
@@ -2,5 +2,6 @@ package io.novafoundation.nova.feature_assets.presentation.balance.list.model
|
||||
|
||||
data class PezkuwiDashboardModel(
|
||||
val roles: List<String>,
|
||||
val trustScore: String
|
||||
val trustScore: String,
|
||||
val welatiCount: String
|
||||
)
|
||||
|
||||
+1
@@ -58,6 +58,7 @@ class PezkuwiDashboardHolder(
|
||||
fun bind(model: PezkuwiDashboardModel) {
|
||||
bindRoles(model.roles)
|
||||
binder.pezkuwiDashboardTrustValue.text = model.trustScore
|
||||
binder.pezkuwiDashboardWelatiCount.text = model.welatiCount
|
||||
}
|
||||
|
||||
private fun bindRoles(roles: List<String>) {
|
||||
|
||||
@@ -72,15 +72,28 @@
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/pezkuwiDashboardLogo"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:src="@drawable/telegram_welcome"
|
||||
android:scaleType="fitCenter"
|
||||
android:adjustViewBounds="true"
|
||||
android:contentDescription="@string/pezkuwi_dashboard_title" />
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:layout_marginEnd="12dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pezkuwiDashboardWelatiCount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#4CAF50"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/pezkuwi_dashboard_kurds_title"
|
||||
android:textColor="#CFD8DC"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Info text -->
|
||||
|
||||
Reference in New Issue
Block a user