Updated on 2026-08-14

This commit is contained in:
Tangem 2025-09-26 20:48:51 +05:00
parent 1d06981060
commit 7b5a62d593
10 changed files with 82 additions and 20 deletions

View file

@ -0,0 +1,13 @@
package com.tangem.data.yield.supply
import com.tangem.domain.yield.supply.YieldSupplyError
import com.tangem.domain.yield.supply.YieldSupplyErrorResolver
internal data object DefaultYieldSupplyErrorResolver : YieldSupplyErrorResolver {
override fun resolve(throwable: Throwable): YieldSupplyError {
return when (throwable) {
is YieldSupplyError -> throwable
else -> YieldSupplyError.DataError(throwable)
}
}
}

View file

@ -17,6 +17,7 @@ import com.tangem.domain.utils.convertToSdkAmount
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.yield.supply.YieldSupplyTransactionRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.extensions.orZero
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.math.BigDecimal
@ -106,7 +107,7 @@ internal class DefaultYieldSupplyTransactionRepository(
decimals = cryptoCurrency.decimals,
),
)
}.onFailure(Timber::e).getOrNull()
}.onFailure(Timber::e).getOrThrow()
}
@Suppress("LongParameterList")
@ -173,14 +174,16 @@ internal class DefaultYieldSupplyTransactionRepository(
)
}
enterTransactions.add(
createEnterTransaction(
walletManager = walletManager,
cryptoCurrency = cryptoCurrency,
amount = amount,
yieldContractAddress = calculatedYieldContractAddress,
),
)
if (cryptoCurrencyStatus.value.amount.orZero() > BigDecimal.ZERO) {
enterTransactions.add(
createEnterTransaction(
walletManager = walletManager,
cryptoCurrency = cryptoCurrency,
amount = amount,
yieldContractAddress = calculatedYieldContractAddress,
),
)
}
return enterTransactions
}
@ -197,7 +200,7 @@ internal class DefaultYieldSupplyTransactionRepository(
derivationPath = cryptoCurrency.network.derivationPath.value,
) ?: error("Wallet manager not found")
walletManager.calculateYieldModuleAddress()
}.onFailure(Timber::e).getOrNull()
}.onFailure(Timber::e).getOrThrow()
}
override suspend fun getYieldContractAddress(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): String? =
@ -210,7 +213,7 @@ internal class DefaultYieldSupplyTransactionRepository(
derivationPath = cryptoCurrency.network.derivationPath.value,
) ?: error("Wallet manager not found")
walletManager.getYieldModuleAddress()
}.onFailure(Timber::e).getOrNull()
}.onFailure(Timber::e).getOrThrow()
}
private suspend fun getYieldTokenStatus(
@ -232,7 +235,7 @@ internal class DefaultYieldSupplyTransactionRepository(
isInitialized = sdkSupplyStatus?.isInitialized == true,
isAllowedToSpend = isAllowedToSpend,
)
}.onFailure(Timber::e).getOrNull()
}.onFailure(Timber::e).getOrThrow()
}
private fun createDeployTransaction(

View file

@ -1,11 +1,13 @@
package com.tangem.data.yield.supply.di
import com.tangem.data.yield.supply.DefaultYieldSupplyMarketRepository
import com.tangem.data.yield.supply.DefaultYieldSupplyErrorResolver
import com.tangem.data.yield.supply.DefaultYieldSupplyTransactionRepository
import com.tangem.datasource.api.tangemTech.YieldSupplyApi
import com.tangem.datasource.local.yieldsupply.YieldMarketsStore
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.yield.supply.YieldSupplyMarketRepository
import com.tangem.domain.yield.supply.YieldSupplyErrorResolver
import com.tangem.domain.yield.supply.YieldSupplyTransactionRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.Module
@ -43,4 +45,10 @@ internal object YieldSupplyDataModule {
dispatchers = dispatchers,
)
}
@Provides
@Singleton
fun provideYieldSupplyErrorResolver(): YieldSupplyErrorResolver {
return DefaultYieldSupplyErrorResolver
}
}