Updated on 2026-08-14

This commit is contained in:
Tangem 2024-03-05 13:45:30 +05:00
parent c50439d698
commit 95f1c123ba
2 changed files with 17 additions and 10 deletions

View file

@ -3,7 +3,6 @@ package com.tangem.domain.tokens
import arrow.core.Either
import arrow.core.raise.either
import com.tangem.domain.tokens.error.TokenListError
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.FeePaidCurrency
import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations
@ -35,17 +34,13 @@ class GetFeePaidCryptoCurrencyStatusSyncUseCase(
return either {
when (feePaidCurrency) {
FeePaidCurrency.Coin -> getCryptoCurrencyStatus(operations, cryptoCurrency.id)
FeePaidCurrency.Coin ->
operations
.getNetworkCoinSync(cryptoCurrency.network.id, cryptoCurrency.network.derivationPath)
.getOrNull()
FeePaidCurrency.SameCurrency -> cryptoCurrencyStatus
is FeePaidCurrency.Token -> getCryptoCurrencyStatus(operations, feePaidCurrency.tokenId)
is FeePaidCurrency.Token -> operations.getCurrencyStatusSync(feePaidCurrency.tokenId).getOrNull()
}
}
}
private suspend fun getCryptoCurrencyStatus(
operations: CurrenciesStatusesOperations,
cryptoCurrencyId: CryptoCurrency.ID,
): CryptoCurrencyStatus? {
return operations.getCurrencyStatusSync(cryptoCurrencyId).getOrNull()
}
}

View file

@ -109,6 +109,18 @@ internal class CurrenciesStatusesOperations(
}
}
suspend fun getNetworkCoinSync(
networkId: Network.ID,
derivationPath: Network.DerivationPath,
): Either<Error, CryptoCurrencyStatus> {
val currency = recover(
block = { getNetworkCoin(networkId, derivationPath) },
recover = { return it.left() },
)
return getCurrencyStatusSync(currency.id)
}
suspend fun getPrimaryCurrencyStatusSync(): Either<Error, CryptoCurrencyStatus> = either {
val currency = catch(
block = { currenciesRepository.getSingleCurrencyWalletPrimaryCurrency(userWalletId) },