Updated on 2026-08-14
This commit is contained in:
parent
1db7ea1f49
commit
c5fbb3fa7a
2 changed files with 17 additions and 14 deletions
|
|
@ -19,6 +19,7 @@ import com.tangem.tap.store
|
|||
import com.tangem.tap.tangemSdkManager
|
||||
import kotlinx.coroutines.launch
|
||||
import org.rekotlin.Middleware
|
||||
import timber.log.Timber
|
||||
|
||||
class GlobalMiddleware {
|
||||
companion object {
|
||||
|
|
@ -78,11 +79,12 @@ private val globalMiddlewareHandler: Middleware<AppState> = { dispatch, appState
|
|||
val apiKey = appState()?.globalState?.configManager?.config?.moonPayApiKey
|
||||
if (apiKey != null) {
|
||||
scope.launch {
|
||||
val moonpayStatus = MoonpayService().getMoonpayStatus(apiKey)
|
||||
if (moonpayStatus is Result.Success) {
|
||||
store.dispatchOnMain(
|
||||
GlobalAction.GetMoonPayStatus.Success(moonpayStatus.data)
|
||||
)
|
||||
val result = MoonpayService().getMoonpayStatus(apiKey)
|
||||
when (result) {
|
||||
is Result.Success -> {
|
||||
store.dispatchOnMain(GlobalAction.GetMoonPayStatus.Success(result.data))
|
||||
}
|
||||
is Result.Failure -> Timber.e(result.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,32 +3,33 @@ package com.tangem.tap.network.moonpay
|
|||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.tangem.common.services.Result
|
||||
import com.tangem.common.services.retryIO
|
||||
import com.tangem.common.services.performRequest
|
||||
import com.tangem.tap.network.createRetrofitInstance
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
|
||||
class MoonpayService {
|
||||
|
||||
private val moonpayApi: MoonpayApi by lazy {
|
||||
createRetrofitInstance(MoonpayApi.MOOONPAY_BASE_URL)
|
||||
.create(MoonpayApi::class.java)
|
||||
.create(MoonpayApi::class.java)
|
||||
}
|
||||
|
||||
suspend fun getMoonpayStatus(moonpayApiKey: String): Result<MoonpayStatus> {
|
||||
return try {
|
||||
coroutineScope {
|
||||
val userStatusResult = performRequest { moonpayApi.getUserStatus(moonpayApiKey) }
|
||||
if (userStatusResult is Result.Failure) return@coroutineScope userStatusResult
|
||||
|
||||
val userStatusDeferred =
|
||||
retryIO { async { moonpayApi.getUserStatus(moonpayApiKey) } }
|
||||
val currenciesDeferred =
|
||||
retryIO { async { moonpayApi.getCurrencies(moonpayApiKey) } }
|
||||
val userStatus = userStatusDeferred.await()
|
||||
val currenciesResult = performRequest { moonpayApi.getCurrencies(moonpayApiKey) }
|
||||
if (currenciesResult is Result.Failure) return@coroutineScope currenciesResult
|
||||
|
||||
val userStatus = (userStatusResult as Result.Success).data
|
||||
val currencies = (currenciesResult as Result.Success).data
|
||||
|
||||
val currenciesToBuy = mutableListOf<String>()
|
||||
val currenciesToSell = mutableListOf<String>()
|
||||
|
||||
currenciesDeferred.await().forEach { currencyStatus ->
|
||||
currencies.forEach { currencyStatus ->
|
||||
if (currencyStatus.type != "crypto" || currencyStatus.isSuspended ||
|
||||
!currencyStatus.supportsLiveMode
|
||||
) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue