Updated on 2026-08-14
This commit is contained in:
parent
9e948f7703
commit
147625bda1
40 changed files with 254 additions and 131 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package com.tangem.blockchainsdk.di
|
||||
|
||||
import com.tangem.blockchainsdk.providers.BlockchainProvidersResponseMerger
|
||||
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
|
||||
import com.tangem.core.analytics.api.AnalyticsExceptionHandler
|
||||
import com.tangem.core.configtoggle.blockchain.ExcludedBlockchainsManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
|
@ -17,4 +19,12 @@ internal object ExcludedBlockchainsModule {
|
|||
fun bindExcludedBlockchains(excludedBlockchainsManager: ExcludedBlockchainsManager): ExcludedBlockchains {
|
||||
return ExcludedBlockchains(excludedBlockchainsManager)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun bindBlockchainProvidersResponseMerger(
|
||||
analyticsExceptionHandler: AnalyticsExceptionHandler,
|
||||
): BlockchainProvidersResponseMerger {
|
||||
return BlockchainProvidersResponseMerger(analyticsExceptionHandler)
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ import javax.inject.Singleton
|
|||
internal class BlockchainProvidersResponseLoader @Inject constructor(
|
||||
private val tangemTechApi: TangemTechApi,
|
||||
private val blockchainProvidersStorage: BlockchainProvidersStorage,
|
||||
private val blockchainProvidersResponseMerger: BlockchainProvidersResponseMerger,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) {
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ internal class BlockchainProvidersResponseLoader @Inject constructor(
|
|||
|
||||
return loadRemote().fold(
|
||||
onSuccess = { remoteResponse ->
|
||||
BlockchainProvidersResponseMerger.merge(
|
||||
blockchainProvidersResponseMerger.merge(
|
||||
local = localResponse,
|
||||
remote = remoteResponse,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
package com.tangem.blockchainsdk.providers
|
||||
|
||||
import androidx.core.util.PatternsCompat
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import com.tangem.blockchainsdk.BlockchainProvidersResponse
|
||||
import com.tangem.core.analytics.api.AnalyticsExceptionHandler
|
||||
import com.tangem.core.analytics.models.ExceptionAnalyticsEvent
|
||||
import com.tangem.datasource.local.config.providers.models.ProviderModel
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* Merger of [BlockchainProvidersResponse]
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal object BlockchainProvidersResponseMerger {
|
||||
|
||||
private val firebaseCrashlytics by lazy(FirebaseCrashlytics::getInstance)
|
||||
internal class BlockchainProvidersResponseMerger @Inject internal constructor(
|
||||
private val analyticsExceptionHandler: AnalyticsExceptionHandler,
|
||||
) {
|
||||
|
||||
private val forbiddenSchemes = listOf("wss://")
|
||||
|
||||
|
|
@ -41,7 +43,7 @@ internal object BlockchainProvidersResponseMerger {
|
|||
val missingBlockchains = result.keys - remote.keys
|
||||
val blockchainsWithoutProviders = remote.filterValues { it.isEmpty() }.keys
|
||||
|
||||
recordException(missingBlockchains = missingBlockchains + blockchainsWithoutProviders)
|
||||
logException(missingBlockchains = missingBlockchains + blockchainsWithoutProviders)
|
||||
}
|
||||
|
||||
return result.guaranteeUrlsEndWithSlash()
|
||||
|
|
@ -74,15 +76,19 @@ internal object BlockchainProvidersResponseMerger {
|
|||
return PatternsCompat.WEB_URL.matcher(inputUrl).matches()
|
||||
}
|
||||
|
||||
private fun recordException(missingBlockchains: Set<String>) {
|
||||
private fun logException(missingBlockchains: Set<String>) {
|
||||
val exception = IllegalStateException(
|
||||
"Remote config does not contain required blockchains or providers information: " +
|
||||
missingBlockchains.joinToString(),
|
||||
"Remote config does not contain some blockchains or providers information",
|
||||
)
|
||||
|
||||
Timber.e(exception)
|
||||
|
||||
firebaseCrashlytics.recordException(exception)
|
||||
analyticsExceptionHandler.sendException(
|
||||
ExceptionAnalyticsEvent(
|
||||
exception = exception,
|
||||
params = mapOf("Missing blockchains" to missingBlockchains.joinToString()),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue