Updated on 2026-08-14
This commit is contained in:
parent
305e86960f
commit
db03d6d860
17 changed files with 80 additions and 29 deletions
|
|
@ -23,6 +23,7 @@ internal class NetworkYieldSupplyStatusConverter(
|
|||
isActive = it.isActive,
|
||||
isInitialized = it.isInitialized,
|
||||
isAllowedToSpend = it.isAllowedToSpend,
|
||||
effectiveProtocolBalance = it.effectiveProtocolBalance,
|
||||
)
|
||||
|
||||
id to status
|
||||
|
|
@ -38,6 +39,7 @@ internal class NetworkYieldSupplyStatusConverter(
|
|||
isActive = yieldSupplyStatus.isActive,
|
||||
isInitialized = yieldSupplyStatus.isInitialized,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
effectiveProtocolBalance = yieldSupplyStatus.effectiveProtocolBalance,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ internal class NetworkStatusDataModelConverterTest {
|
|||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
effectiveProtocolBalance = BigDecimal.ONE,
|
||||
),
|
||||
ID(
|
||||
prefix = Prefix.COIN_PREFIX,
|
||||
|
|
@ -94,6 +95,7 @@ internal class NetworkStatusDataModelConverterTest {
|
|||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
effectiveProtocolBalance = BigDecimal.ONE,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.tangem.domain.models.network.Network
|
|||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import java.math.BigDecimal
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
internal class NetworkYieldSupplyStatusConverterTest {
|
||||
|
|
@ -21,6 +22,7 @@ internal class NetworkYieldSupplyStatusConverterTest {
|
|||
isActive = true,
|
||||
isInitialized = true,
|
||||
isAllowedToSpend = true,
|
||||
effectiveProtocolBalance = BigDecimal.ONE,
|
||||
)
|
||||
|
||||
@Test
|
||||
|
|
@ -70,6 +72,7 @@ internal class NetworkYieldSupplyStatusConverterTest {
|
|||
isActive = true,
|
||||
isInitialized = true,
|
||||
isAllowedToSpend = true,
|
||||
effectiveProtocolBalance = BigDecimal.ONE,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -68,6 +68,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
effectiveProtocolBalance = BigDecimal.ONE,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -103,6 +104,7 @@ internal class SimpleNetworkStatusConverterTest {
|
|||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
effectiveProtocolBalance = BigDecimal.ONE,
|
||||
),
|
||||
),
|
||||
source = StatusSource.CACHE,
|
||||
|
|
|
|||
|
|
@ -272,6 +272,7 @@ internal class NetworkStatusFactoryTest(private val model: Model) {
|
|||
isActive = false,
|
||||
isInitialized = false,
|
||||
isAllowedToSpend = false,
|
||||
effectiveProtocolBalance = BigDecimal.ONE,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ internal class DefaultCurrencyChecksRepository(
|
|||
blockchain = token.network.toBlockchain(),
|
||||
derivationPath = token.network.derivationPath.value,
|
||||
) ?: error("Wallet manager not found")
|
||||
walletManager.getProtocolBalance(
|
||||
walletManager.getEffectiveProtocolBalance(
|
||||
token = Token(
|
||||
symbol = token.symbol,
|
||||
contractAddress = token.contractAddress,
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ internal class UpdateWalletManagerResultFactory {
|
|||
isActive = type.isActive,
|
||||
isInitialized = type.isInitialized,
|
||||
isAllowedToSpend = type.isAllowedToSpend,
|
||||
effectiveProtocolBalance = type.effectiveProtocolBalance,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,24 +91,26 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
)
|
||||
}
|
||||
|
||||
override suspend fun getProtocolBalance(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): BigDecimal? =
|
||||
withContext(dispatchers.io) {
|
||||
require(cryptoCurrency is CryptoCurrency.Token)
|
||||
runCatching {
|
||||
val walletManager = walletManagersFacade.getOrCreateWalletManager(
|
||||
userWalletId = userWalletId,
|
||||
blockchain = cryptoCurrency.network.toBlockchain(),
|
||||
derivationPath = cryptoCurrency.network.derivationPath.value,
|
||||
) ?: error("Wallet manager not found")
|
||||
walletManager.getProtocolBalance(
|
||||
token = Token(
|
||||
symbol = cryptoCurrency.symbol,
|
||||
contractAddress = cryptoCurrency.contractAddress,
|
||||
decimals = cryptoCurrency.decimals,
|
||||
),
|
||||
)
|
||||
}.onFailure(Timber::e).getOrThrow()
|
||||
}
|
||||
override suspend fun getEffectiveProtocolBalance(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
): BigDecimal? = withContext(dispatchers.io) {
|
||||
require(cryptoCurrency is CryptoCurrency.Token)
|
||||
runCatching {
|
||||
val walletManager = walletManagersFacade.getOrCreateWalletManager(
|
||||
userWalletId = userWalletId,
|
||||
blockchain = cryptoCurrency.network.toBlockchain(),
|
||||
derivationPath = cryptoCurrency.network.derivationPath.value,
|
||||
) ?: error("Wallet manager not found")
|
||||
walletManager.getEffectiveProtocolBalance(
|
||||
token = Token(
|
||||
symbol = cryptoCurrency.symbol,
|
||||
contractAddress = cryptoCurrency.contractAddress,
|
||||
decimals = cryptoCurrency.decimals,
|
||||
),
|
||||
)
|
||||
}.onFailure(Timber::e).getOrThrow()
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
private suspend fun buildEnterTransactions(
|
||||
|
|
@ -222,6 +224,17 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
): YieldSupplyStatus? = withContext(dispatchers.io) {
|
||||
runCatching {
|
||||
val sdkSupplyStatus = walletManager.getYieldSupplyStatus(cryptoCurrency.contractAddress)
|
||||
val protocolBalance = if (sdkSupplyStatus?.isActive == true) {
|
||||
walletManager.getEffectiveProtocolBalance(
|
||||
token = Token(
|
||||
symbol = cryptoCurrency.symbol,
|
||||
contractAddress = cryptoCurrency.contractAddress,
|
||||
decimals = cryptoCurrency.decimals,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val isAllowedToSpend = walletManager.isAllowedToSpend(
|
||||
Token(
|
||||
symbol = cryptoCurrency.symbol,
|
||||
|
|
@ -234,6 +247,7 @@ internal class DefaultYieldSupplyTransactionRepository(
|
|||
isActive = sdkSupplyStatus?.isActive == true,
|
||||
isInitialized = sdkSupplyStatus?.isInitialized == true,
|
||||
isAllowedToSpend = isAllowedToSpend,
|
||||
effectiveProtocolBalance = protocolBalance,
|
||||
)
|
||||
}.onFailure(Timber::e).getOrNull()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue