Updated on 2026-08-14
This commit is contained in:
parent
aebd525721
commit
fa75773471
13 changed files with 112 additions and 35 deletions
|
|
@ -39,7 +39,6 @@ val store = Store(
|
|||
middleware = AppState.getMiddleware(),
|
||||
state = AppState()
|
||||
)
|
||||
val logConfig = LogConfig()
|
||||
|
||||
lateinit var foregroundActivityObserver: ForegroundActivityObserver
|
||||
|
||||
|
|
@ -76,13 +75,17 @@ class TapApplication : Application(), ImageLoaderFactory {
|
|||
initFeedbackManager()
|
||||
loadConfigs()
|
||||
|
||||
BlockchainSdkRetrofitBuilder.enableNetworkLogging = BuildConfig.DEBUG
|
||||
BlockchainSdkRetrofitBuilder.enableNetworkLogging =
|
||||
store.state.domainState.globalState.logConfig.network.blockchainSdkNetwork
|
||||
|
||||
initAppsFlyer()
|
||||
}
|
||||
|
||||
override fun newImageLoader(): ImageLoader {
|
||||
return createCoilImageLoader(context = this)
|
||||
return createCoilImageLoader(
|
||||
context = this,
|
||||
logEnabled = store.state.domainState.globalState.logConfig.imageLoader
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadConfigs() {
|
||||
|
|
@ -132,6 +135,7 @@ class TapApplication : Application(), ImageLoaderFactory {
|
|||
infoHolder = infoHolder,
|
||||
logCollector = logWriter,
|
||||
preferencesStorage = preferencesStorage,
|
||||
logEnabled = store.state.domainState.globalState.logConfig.zendesk,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -144,10 +148,4 @@ class TapApplication : Application(), ImageLoaderFactory {
|
|||
val analyticsHandler = GlobalAnalyticsHandler.createDefaultAnalyticHandlers(this)
|
||||
store.dispatch(GlobalAction.SetAnanlyticHandlers(analyticsHandler))
|
||||
}
|
||||
}
|
||||
|
||||
data class LogConfig(
|
||||
val coil: Boolean = BuildConfig.DEBUG,
|
||||
val storeAction: Boolean = BuildConfig.DEBUG,
|
||||
val zendesk: Boolean = BuildConfig.DEBUG,
|
||||
)
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@ import com.tangem.tap.common.extensions.sendEmail
|
|||
import com.tangem.tap.common.log.TangemLogCollector
|
||||
import com.tangem.tap.common.zendesk.ZendeskConfig
|
||||
import com.tangem.tap.foregroundActivityObserver
|
||||
import com.tangem.tap.logConfig
|
||||
import com.tangem.tap.persistence.PreferencesStorage
|
||||
import com.tangem.tap.withForegroundActivity
|
||||
import com.tangem.wallet.R
|
||||
|
|
@ -31,6 +30,7 @@ class FeedbackManager(
|
|||
val infoHolder: AdditionalFeedbackInfo,
|
||||
private val logCollector: TangemLogCollector,
|
||||
private val preferencesStorage: PreferencesStorage,
|
||||
private val logEnabled: Boolean = false,
|
||||
) {
|
||||
fun initChat(
|
||||
context: Context,
|
||||
|
|
@ -43,7 +43,7 @@ class FeedbackManager(
|
|||
)
|
||||
|
||||
// Zendesk logs
|
||||
Logger.setLoggable(logConfig.zendesk)
|
||||
Logger.setLoggable(logEnabled)
|
||||
}
|
||||
|
||||
fun sendEmail(feedbackData: FeedbackData, onFail: ((Exception) -> Unit)? = null) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import android.content.Context
|
|||
import android.util.Log
|
||||
import coil.ImageLoader
|
||||
import coil.util.Logger
|
||||
import com.tangem.tap.logConfig
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import timber.log.Timber
|
||||
|
|
@ -12,11 +11,12 @@ import timber.log.Timber
|
|||
private const val COIL_LOG_TAG = "COIL"
|
||||
|
||||
fun createCoilImageLoader(
|
||||
context: Context
|
||||
context: Context,
|
||||
logEnabled: Boolean = false,
|
||||
): ImageLoader {
|
||||
return ImageLoader.Builder(context)
|
||||
.apply {
|
||||
if (!logConfig.coil) return@apply
|
||||
if (!logEnabled) return@apply
|
||||
|
||||
logger(CoilTimberLogger())
|
||||
okHttpClient {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.tap.common.redux
|
||||
|
||||
import com.tangem.tap.logConfig
|
||||
import com.tangem.tap.store
|
||||
import org.rekotlin.Middleware
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
@ -10,7 +10,9 @@ import timber.log.Timber
|
|||
val logMiddleware: Middleware<AppState> = { dispatch, appState ->
|
||||
{ nextDispatch ->
|
||||
{ action ->
|
||||
if (logConfig.storeAction) Timber.d("Dispatch action: $action")
|
||||
if (store.state.domainState.globalState.logConfig.storeAction) {
|
||||
Timber.d("Dispatch action: $action")
|
||||
}
|
||||
nextDispatch(action)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,9 @@ private fun handleAction(action: Action, appState: () -> AppState?, dispatch: Di
|
|||
?.setWalletsInfo(action.walletManagers)
|
||||
}
|
||||
is GlobalAction.ExchangeManager.Init -> {
|
||||
val config = appState()?.globalState?.configManager?.config
|
||||
val appStateSafe = appState() ?: return
|
||||
val config = appStateSafe.globalState.configManager?.config
|
||||
val logConfig = appStateSafe.domainState.globalState.logConfig
|
||||
ifNotNull(
|
||||
config?.mercuryoWidgetId,
|
||||
config?.mercuryoSecret,
|
||||
|
|
@ -108,8 +110,13 @@ private fun handleAction(action: Action, appState: () -> AppState?, dispatch: Di
|
|||
apiVersion = MercuryoApi.API_VERSION,
|
||||
mercuryoWidgetId = mercuryoWidgetId,
|
||||
secret = mercuryoSecret,
|
||||
logEnabled = logConfig.network.mercuryoService,
|
||||
)
|
||||
val sellService = MoonPayService(
|
||||
apiKey = moonPayKey,
|
||||
secretKey = moonPaySecretKey,
|
||||
logEnabled = logConfig.network.moonPayService,
|
||||
)
|
||||
val sellService = MoonPayService(moonPayKey, moonPaySecretKey)
|
||||
val cardProvider = { store.state.globalState.scanResponse?.card }
|
||||
|
||||
val exchangeManager = CurrencyExchangeManager(
|
||||
|
|
|
|||
|
|
@ -20,10 +20,13 @@ class MercuryoService(
|
|||
private val apiVersion: String,
|
||||
private val mercuryoWidgetId: String,
|
||||
private val secret: String,
|
||||
private val logEnabled: Boolean,
|
||||
) : ExchangeService, ExchangeUrlBuilder {
|
||||
|
||||
private val api: MercuryoApi = createRetrofitInstance(MercuryoApi.BASE_URL)
|
||||
.create(MercuryoApi::class.java)
|
||||
private val api: MercuryoApi = createRetrofitInstance(
|
||||
baseUrl = MercuryoApi.BASE_URL,
|
||||
logEnabled = logEnabled,
|
||||
).create(MercuryoApi::class.java)
|
||||
|
||||
private val blockchainsAvailableToBuy = mutableListOf<Blockchain>()
|
||||
private val tokensAvailableToBy = mutableMapOf<String, MutableList<Blockchain>>()
|
||||
|
|
|
|||
|
|
@ -20,11 +20,14 @@ import javax.crypto.spec.SecretKeySpec
|
|||
class MoonPayService(
|
||||
private val apiKey: String,
|
||||
private val secretKey: String,
|
||||
private val logEnabled: Boolean,
|
||||
) : ExchangeService, ExchangeUrlBuilder {
|
||||
|
||||
private val api: MoonPayApi by lazy {
|
||||
createRetrofitInstance(MoonPayApi.MOOONPAY_BASE_URL)
|
||||
.create(MoonPayApi::class.java)
|
||||
createRetrofitInstance(
|
||||
baseUrl = MoonPayApi.MOOONPAY_BASE_URL,
|
||||
logEnabled = logEnabled,
|
||||
).create(MoonPayApi::class.java)
|
||||
}
|
||||
|
||||
private var status: MoonPayStatus? = null
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ class PayIdService {
|
|||
return performRequest { payIdApi.setPayId(cardId, publicKey, payId, address, network) }
|
||||
}
|
||||
|
||||
private fun provideRetrofit(): Retrofit = createRetrofitInstance("https://tangem.com/")
|
||||
private fun provideRetrofit(): Retrofit = createRetrofitInstance(
|
||||
baseUrl = "https://tangem.com/",
|
||||
logEnabled = false,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,13 @@ import com.tangem.network.common.createRetrofitInstance
|
|||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class PayIdVerifyService(
|
||||
private val baseUrl: String
|
||||
private val baseUrl: String,
|
||||
) {
|
||||
|
||||
private val api = createRetrofitInstance(baseUrl).create(PayIdVerifyApi::class.java)
|
||||
private val api = createRetrofitInstance(
|
||||
baseUrl = baseUrl,
|
||||
logEnabled = false,
|
||||
).create(PayIdVerifyApi::class.java)
|
||||
|
||||
suspend fun verifyAddress(user: String, network: String): Result<VerifyPayIdResponse> {
|
||||
return performRequest { api.verifyAddress(user, createNetworkHeader(network)) }
|
||||
|
|
|
|||
51
domain/src/main/java/com/tangem/domain/common/LogConfig.kt
Normal file
51
domain/src/main/java/com/tangem/domain/common/LogConfig.kt
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package com.tangem.domain.common
|
||||
|
||||
import com.tangem.domain.features.BuildConfig
|
||||
|
||||
data class LogConfig(
|
||||
val imageLoader: Boolean,
|
||||
val storeAction: Boolean,
|
||||
val zendesk: Boolean,
|
||||
val network: NetworkLogConfig,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
fun buildBased(): LogConfig = LogConfig(
|
||||
imageLoader = BuildConfig.DEBUG,
|
||||
storeAction = BuildConfig.DEBUG,
|
||||
zendesk = BuildConfig.DEBUG,
|
||||
network = NetworkLogConfig.buildBased(),
|
||||
)
|
||||
|
||||
fun custom(): LogConfig = LogConfig(
|
||||
imageLoader = false,
|
||||
storeAction = false,
|
||||
zendesk = false,
|
||||
network = NetworkLogConfig.custom(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class NetworkLogConfig(
|
||||
val mercuryoService: Boolean,
|
||||
val moonPayService: Boolean,
|
||||
val tangemTechService: Boolean,
|
||||
val blockchainSdkNetwork: Boolean,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
fun buildBased(): NetworkLogConfig = NetworkLogConfig(
|
||||
mercuryoService = BuildConfig.DEBUG,
|
||||
moonPayService = BuildConfig.DEBUG,
|
||||
tangemTechService = BuildConfig.DEBUG,
|
||||
blockchainSdkNetwork = BuildConfig.DEBUG,
|
||||
)
|
||||
|
||||
fun custom(): NetworkLogConfig = NetworkLogConfig(
|
||||
mercuryoService = false,
|
||||
moonPayService = false,
|
||||
tangemTechService = false,
|
||||
blockchainSdkNetwork = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package com.tangem.domain.redux.global
|
||||
|
||||
import com.tangem.domain.DomainDialog
|
||||
import com.tangem.domain.common.LogConfig
|
||||
import com.tangem.domain.common.NetworkLogConfig
|
||||
import com.tangem.domain.common.ScanResponse
|
||||
import com.tangem.network.api.tangemTech.TangemTechService
|
||||
|
||||
|
|
@ -12,10 +14,12 @@ data class DomainGlobalState(
|
|||
// It updates on GlobalAction.SaveScanNoteResponse -> DomainGlobalAction.SaveScanNoteResponse(scanResponse)
|
||||
val scanResponse: ScanResponse? = null,
|
||||
//
|
||||
val networkServices: NetworkServices = NetworkServices(),
|
||||
val logConfig: LogConfig = LogConfig.buildBased(),
|
||||
val networkServices: NetworkServices = NetworkServices(logConfig.network),
|
||||
val dialog: DomainDialog? = null,
|
||||
)
|
||||
|
||||
data class NetworkServices(
|
||||
val tangemTechService: TangemTechService = TangemTechService()
|
||||
val networkLogConfig: NetworkLogConfig,
|
||||
val tangemTechService: TangemTechService = TangemTechService(networkLogConfig.tangemTechService)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,9 +11,12 @@ import kotlinx.coroutines.withContext
|
|||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class TangemTechService {
|
||||
class TangemTechService(
|
||||
private val logIsEnabled: Boolean = false,
|
||||
) {
|
||||
|
||||
private val headerInterceptors = mutableListOf<AddHeaderInterceptor>(
|
||||
CacheControlHttpInterceptor(cacheMaxAge)
|
||||
CacheControlHttpInterceptor(cacheMaxAge),
|
||||
)
|
||||
|
||||
private var api: TangemTechApi = createApi()
|
||||
|
|
@ -24,7 +27,7 @@ class TangemTechService {
|
|||
active: Boolean? = null,
|
||||
searchText: String? = null,
|
||||
offset: Int? = null,
|
||||
limit: Int? = null
|
||||
limit: Int? = null,
|
||||
): Result<CoinsResponse> = withContext(Dispatchers.IO) {
|
||||
performRequest {
|
||||
api.coins(
|
||||
|
|
@ -33,14 +36,14 @@ class TangemTechService {
|
|||
active = active,
|
||||
searchText = searchText,
|
||||
offset = offset,
|
||||
limit = limit
|
||||
limit = limit,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun rates(
|
||||
currency: String,
|
||||
ids: List<String>
|
||||
ids: List<String>,
|
||||
): Result<RatesResponse> = withContext(Dispatchers.IO) {
|
||||
performRequest {
|
||||
api.rates(currency.lowercase(), ids.joinToString(","))
|
||||
|
|
@ -65,7 +68,7 @@ class TangemTechService {
|
|||
val retrofit = createRetrofitInstance(
|
||||
baseUrl = baseUrl,
|
||||
interceptors = headerInterceptors.toList(),
|
||||
// logEnabled = true,
|
||||
logEnabled = logIsEnabled,
|
||||
)
|
||||
return retrofit.create(TangemTechApi::class.java)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fun createRetrofitInstance(
|
|||
okHttpBuilder: OkHttpClient.Builder = OkHttpClient.Builder(),
|
||||
interceptors: List<Interceptor> = emptyList(),
|
||||
converterFactory: Converter.Factory = MoshiConverter.createFactory(),
|
||||
logEnabled: Boolean = false
|
||||
logEnabled: Boolean,
|
||||
): Retrofit {
|
||||
okHttpBuilder.apply {
|
||||
callTimeout(10, TimeUnit.SECONDS)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue