Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
applicationId = "ltd.grunt.brainwallet"
minSdk = 29
targetSdk = 35
versionCode = 202506331
versionCode = 202506332
versionName = "v4.9.2"
multiDexEnabled = true
base.archivesName.set("${defaultConfig.versionName}(${defaultConfig.versionCode})")
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/brainwallet/BrainwalletApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import com.brainwallet.tools.manager.AnalyticsManager
import com.brainwallet.tools.util.Utils
import com.brainwallet.constants.BWConstants
import com.google.firebase.crashlytics.FirebaseCrashlytics
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import org.koin.android.ext.android.inject
import timber.log.Timber
import timber.log.Timber.DebugTree
Expand All @@ -24,6 +28,12 @@ import java.util.concurrent.atomic.AtomicInteger
open class BrainwalletApp : Application() {

private val notificationHandler: NotificationHandler by inject()
val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)

override fun onTerminate() {
super.onTerminate()
applicationScope.cancel()
}

override fun onCreate() {
super.onCreate()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package com.brainwallet.data.repository
import com.brainwallet.data.source.RemoteConfigSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import timber.log.Timber
@Serializable
data class ShopCard(
@SerialName("country_code") val countryCode: String = "",
@SerialName("country_name") val countryName: String = "",
@SerialName("product_slug") val productSlug: String = "",
@SerialName("product_name") val productName: String = "",
@SerialName("product_url") val productUrl: String = "",
@SerialName("card_image_webp") val cardImageWebp: String = ""
)

@Serializable
data class ShopProxy(
@SerialName("widget_url") val widget: String = ""
@SerialName("widget_url") val widget: String = "",
@SerialName("cards") val cards: List<ShopCard> = emptyList()
)

interface ShopProxyRepository {
val shopProxy: StateFlow<List<ShopProxy>>
suspend fun refresh()
Expand All @@ -21,11 +32,15 @@ interface ShopProxyRepository {
class ShopProxyRepositoryImpl(
private val remoteConfigSource: RemoteConfigSource,
private val json: Json,
private val scope: CoroutineScope,
) : ShopProxyRepository {

private val _shopProxy = MutableStateFlow<List<ShopProxy>>(emptyList())
override val shopProxy: StateFlow<List<ShopProxy>> = _shopProxy.asStateFlow()

init {
scope.launch { refresh() }
}
override suspend fun refresh() {
runCatching { remoteConfigSource.fetchAndActivate() }
.onFailure { Timber.e(it, "RemoteConfig fetch failed") }
Expand All @@ -36,12 +51,12 @@ class ShopProxyRepositoryImpl(
runCatching {
val wrapper = json.decodeFromString<ShopProxyWrapper>(rawJson)
Timber.d("ShopProxy parsed: ${wrapper.shopProxy}")
_shopProxy.value = wrapper.shopProxy
}.onFailure { Timber.e(it, "RemoteConfig parse failed") }
_shopProxy.value = listOf(wrapper.shopProxy)
}.onFailure { Timber.e(it, "RemoteConfig parse failed: ${it.message}") }
}

@Serializable
private data class ShopProxyWrapper(
@SerialName("shop_data") val shopProxy: List<ShopProxy> = emptyList()
@SerialName("shop_data") val shopProxy: ShopProxy = ShopProxy()
)
}
8 changes: 7 additions & 1 deletion app/src/main/java/com/brainwallet/di/RemoteConfigModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ val remoteConfigModule = module {
}
single<RemoteConfigSource> { FirebaseRemoteConfigRepositoryImpl(get()) }
single<HubContentRepository> { HubContentRepositoryImpl(get(), get()) }
single<ShopProxyRepository> { ShopProxyRepositoryImpl(get(), get()) }
single<ShopProxyRepository> {
ShopProxyRepositoryImpl(
remoteConfigSource = get(),
json = get(),
scope = get(),
)
}
}
Loading