Updated on 2026-08-14
This commit is contained in:
parent
7d6e78559d
commit
ccdd5fa083
8 changed files with 7 additions and 96 deletions
|
|
@ -1,8 +0,0 @@
|
|||
package com.tangem.tap.common.feature
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
interface Feature {
|
||||
fun featureIsSwitchedOn(): Boolean
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ import com.tangem.domain.models.scan.ScanResponse
|
|||
import com.tangem.domain.redux.StateDialog
|
||||
import com.tangem.tap.common.extensions.*
|
||||
import com.tangem.tap.common.redux.AppState
|
||||
import com.tangem.tap.network.exchangeServices.BuyExchangeService
|
||||
import com.tangem.tap.network.exchangeServices.CardExchangeRules
|
||||
import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager
|
||||
import com.tangem.tap.network.exchangeServices.ExchangeService
|
||||
|
|
@ -148,15 +147,10 @@ private fun makeSellExchangeService(environmentConfig: EnvironmentConfig): Excha
|
|||
}
|
||||
|
||||
private fun makeBuyExchangeService(environmentConfig: EnvironmentConfig): ExchangeService {
|
||||
return BuyExchangeService(
|
||||
mercuryoService = makeMercuryoExchangeService(environmentConfig),
|
||||
return MercuryoService(
|
||||
environment = MercuryoEnvironment.prod(
|
||||
widgetId = environmentConfig.mercuryoWidgetId,
|
||||
secret = environmentConfig.mercuryoSecret,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun makeMercuryoExchangeService(environmentConfig: EnvironmentConfig): MercuryoService {
|
||||
val mercuryoEnvironment = MercuryoEnvironment.prod(
|
||||
environmentConfig.mercuryoWidgetId,
|
||||
environmentConfig.mercuryoSecret,
|
||||
)
|
||||
return MercuryoService(mercuryoEnvironment)
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package com.tangem.tap.network.exchangeServices
|
||||
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.tap.domain.model.Currency
|
||||
import com.tangem.tap.network.exchangeServices.mercuryo.MercuryoService
|
||||
import com.tangem.tap.scope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
* Temporary wrapper for the buy services. Service switches based on selected product type.
|
||||
*/
|
||||
internal class BuyExchangeService(
|
||||
private val mercuryoService: MercuryoService,
|
||||
) : ExchangeService, ExchangeUrlBuilder {
|
||||
|
||||
init {
|
||||
scope.launch {
|
||||
mercuryoService.update()
|
||||
}
|
||||
}
|
||||
|
||||
private val currentService: ExchangeService = mercuryoService
|
||||
|
||||
override suspend fun update() {
|
||||
currentService.update()
|
||||
}
|
||||
|
||||
override fun featureIsSwitchedOn(): Boolean = currentService.featureIsSwitchedOn()
|
||||
|
||||
override fun isBuyAllowed(): Boolean = currentService.isBuyAllowed()
|
||||
|
||||
override fun isSellAllowed(): Boolean = currentService.isSellAllowed()
|
||||
|
||||
override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean =
|
||||
currentService.availableForBuy(scanResponse, currency)
|
||||
|
||||
override fun availableForSell(currency: Currency): Boolean = currentService.availableForSell(currency)
|
||||
|
||||
override fun getUrl(
|
||||
action: CurrencyExchangeManager.Action,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
fiatCurrencyName: String,
|
||||
walletAddress: String,
|
||||
isDarkTheme: Boolean,
|
||||
): String? {
|
||||
return currentService.getUrl(
|
||||
action,
|
||||
cryptoCurrency,
|
||||
fiatCurrencyName,
|
||||
walletAddress,
|
||||
isDarkTheme,
|
||||
)
|
||||
}
|
||||
|
||||
override fun getSellCryptoReceiptUrl(action: CurrencyExchangeManager.Action, transactionId: String): String? {
|
||||
return currentService.getSellCryptoReceiptUrl(action, transactionId)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,12 +13,6 @@ class CardExchangeRules(
|
|||
val cardProvider: () -> CardDTO?,
|
||||
) : ExchangeRules {
|
||||
|
||||
override fun featureIsSwitchedOn(): Boolean {
|
||||
val card = cardProvider() ?: return false
|
||||
|
||||
return !card.isStart2Coin
|
||||
}
|
||||
|
||||
override fun isBuyAllowed(): Boolean {
|
||||
val card = cardProvider() ?: return false
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,6 @@ class CurrencyExchangeManager(
|
|||
private val primaryRules: ExchangeRules,
|
||||
) : ExchangeService {
|
||||
|
||||
override fun featureIsSwitchedOn(): Boolean = primaryRules.featureIsSwitchedOn()
|
||||
|
||||
override suspend fun update() {
|
||||
buyService.update()
|
||||
sellService.update()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.tangem.tap.network.exchangeServices
|
|||
|
||||
import com.tangem.domain.models.scan.ScanResponse
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.tap.common.feature.Feature
|
||||
import com.tangem.tap.domain.model.Currency
|
||||
|
||||
interface Exchanger {
|
||||
|
|
@ -12,12 +11,11 @@ interface Exchanger {
|
|||
fun availableForSell(currency: Currency): Boolean
|
||||
}
|
||||
|
||||
interface ExchangeService : Feature, Exchanger, ExchangeUrlBuilder {
|
||||
interface ExchangeService : Exchanger, ExchangeUrlBuilder {
|
||||
suspend fun update()
|
||||
|
||||
companion object {
|
||||
fun dummy(): ExchangeService = object : ExchangeService {
|
||||
override fun featureIsSwitchedOn(): Boolean = false
|
||||
override suspend fun update() {}
|
||||
override fun isBuyAllowed(): Boolean = false
|
||||
override fun isSellAllowed(): Boolean = false
|
||||
|
|
@ -39,11 +37,10 @@ interface ExchangeService : Feature, Exchanger, ExchangeUrlBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
interface ExchangeRules : Feature, Exchanger {
|
||||
interface ExchangeRules : Exchanger {
|
||||
|
||||
companion object {
|
||||
fun dummy(): ExchangeRules = object : ExchangeRules {
|
||||
override fun featureIsSwitchedOn(): Boolean = false
|
||||
override fun isBuyAllowed(): Boolean = false
|
||||
override fun isSellAllowed(): Boolean = false
|
||||
override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean = false
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ internal class MercuryoService(private val environment: MercuryoEnvironment) : E
|
|||
|
||||
private val availableMercuryoCurrencies = CopyOnWriteArrayList<MercuryoCurrenciesResponse.MercuryoCryptoCurrency>()
|
||||
|
||||
override fun featureIsSwitchedOn(): Boolean = true
|
||||
|
||||
override fun isBuyAllowed(): Boolean = true
|
||||
|
||||
override fun isSellAllowed(): Boolean = false
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ class MoonPayService(
|
|||
|
||||
private var status: MoonPayStatus? = null
|
||||
|
||||
override fun featureIsSwitchedOn(): Boolean = true
|
||||
|
||||
override suspend fun update() {
|
||||
withIOContext {
|
||||
performRequest {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue