Updated on 2026-08-14
This commit is contained in:
parent
007c47b6ed
commit
341cf5a0f4
4 changed files with 88 additions and 15 deletions
|
|
@ -0,0 +1,54 @@
|
|||
package com.tangem.tap.network.exchangeServices
|
||||
|
||||
import com.tangem.common.card.Card
|
||||
import com.tangem.domain.common.TapWorkarounds.isStart2Coin
|
||||
import com.tangem.tap.features.demo.isDemoCard
|
||||
import com.tangem.tap.features.wallet.models.Currency
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class CardExchangeRules(
|
||||
val cardProvider: () -> Card?,
|
||||
) : ExchangeRules {
|
||||
|
||||
override fun isBuyAllowed(): Boolean {
|
||||
val card = cardProvider() ?: return false
|
||||
|
||||
return when {
|
||||
card.isDemoCard() -> false
|
||||
card.isStart2Coin -> false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
override fun isSellAllowed(): Boolean {
|
||||
val card = cardProvider() ?: return false
|
||||
|
||||
return when {
|
||||
card.isDemoCard() -> false
|
||||
card.isStart2Coin -> false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
override fun availableForBuy(currency: Currency): Boolean {
|
||||
val card = cardProvider() ?: return false
|
||||
|
||||
return when {
|
||||
card.isDemoCard() -> false
|
||||
card.isStart2Coin -> false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
override fun availableForSell(currency: Currency): Boolean {
|
||||
val card = cardProvider() ?: return false
|
||||
|
||||
return when {
|
||||
card.isDemoCard() -> false
|
||||
card.isStart2Coin -> false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ import java.math.BigDecimal
|
|||
class CurrencyExchangeManager(
|
||||
private val buyService: ExchangeService,
|
||||
private val sellService: ExchangeService,
|
||||
private val primaryRules: ExchangeRules,
|
||||
) : ExchangeService, ExchangeUrlBuilder {
|
||||
|
||||
override suspend fun update() {
|
||||
|
|
@ -30,10 +31,16 @@ class CurrencyExchangeManager(
|
|||
sellService.update()
|
||||
}
|
||||
|
||||
override fun isBuyAllowed(): Boolean = buyService.isBuyAllowed()
|
||||
override fun isSellAllowed(): Boolean = sellService.isSellAllowed()
|
||||
override fun availableForBuy(currency: Currency): Boolean = buyService.availableForBuy(currency)
|
||||
override fun availableForSell(currency: Currency): Boolean = sellService.availableForSell(currency)
|
||||
override fun isBuyAllowed(): Boolean = primaryRules.isBuyAllowed() && buyService.isBuyAllowed()
|
||||
override fun isSellAllowed(): Boolean = primaryRules.isSellAllowed() && sellService.isSellAllowed()
|
||||
|
||||
override fun availableForBuy(currency: Currency): Boolean {
|
||||
return primaryRules.availableForBuy(currency) && buyService.availableForBuy(currency)
|
||||
}
|
||||
|
||||
override fun availableForSell(currency: Currency): Boolean {
|
||||
return primaryRules.availableForSell(currency) && sellService.availableForSell(currency)
|
||||
}
|
||||
|
||||
override fun getUrl(
|
||||
action: Action,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ package com.tangem.tap.network.exchangeServices
|
|||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.tap.features.wallet.models.Currency
|
||||
|
||||
interface ExchangeService {
|
||||
interface ExchangeService: ExchangeRules {
|
||||
suspend fun update()
|
||||
}
|
||||
|
||||
interface ExchangeRules {
|
||||
fun isBuyAllowed(): Boolean
|
||||
fun isSellAllowed(): Boolean
|
||||
fun availableForBuy(currency: Currency):Boolean
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue