Updated on 2026-08-14
This commit is contained in:
parent
1db7ea1f49
commit
c5fbb3fa7a
2 changed files with 17 additions and 14 deletions
|
|
@ -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