Updated on 2026-08-14

This commit is contained in:
Tangem 2023-01-17 17:07:37 +03:00
commit e98780ff93
33 changed files with 643 additions and 207 deletions

View file

@ -28,7 +28,7 @@ import com.tangem.tap.store
import kotlinx.coroutines.launch
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import com.tangem.feature.swap.domain.models.Currency as SwapCurrency
import com.tangem.feature.swap.domain.models.domain.Currency as SwapCurrency
class TradeCryptoMiddleware {
fun handle(state: () -> AppState?, action: WalletAction.TradeCryptoAction) {

View file

@ -27,7 +27,6 @@ import com.tangem.tap.domain.tokens.models.BlockchainNetwork
import com.tangem.tap.store
import com.tangem.tap.tangemSdk
import java.math.BigDecimal
import java.math.BigInteger
class TransactionManagerImpl(
private val appStateHolder: AppStateHolder,
@ -38,6 +37,7 @@ class TransactionManagerImpl(
amountToSend: BigDecimal,
currencyToSend: Currency,
feeAmount: BigDecimal,
estimatedGas: Int,
destinationAddress: String,
dataToSign: String,
): SendTxResult {
@ -49,7 +49,7 @@ class TransactionManagerImpl(
amount = amount,
fee = Amount(value = feeAmount, blockchain = blockchain),
destination = destinationAddress,
).copy(hash = dataToSign, extras = createExtras(walletManager, feeAmount, dataToSign))
).copy(hash = dataToSign, extras = createExtras(walletManager, estimatedGas, dataToSign))
val signer = transactionSigner(walletManager)
@ -95,10 +95,6 @@ class TransactionManagerImpl(
}
}
override fun getNativeAddress(networkId: String): String {
return "" //todo implement
}
private fun handleSendResult(result: SimpleResult): SendTxResult {
when (result) {
is SimpleResult.Success -> {
@ -155,14 +151,14 @@ class TransactionManagerImpl(
private fun createExtras(
walletManager: WalletManager,
feeAmount: BigDecimal,
estimatedGas: Int,
transactionHash: String,
): TransactionExtras? {
return when (walletManager) {
is EthereumWalletManager -> {
return EthereumTransactionExtras(
data = transactionHash.removePrefix(HEX_PREFIX).hexToBytes(),
gasLimit = BigInteger.valueOf(DEFAULT_GAS_LIMIT),
gasLimit = estimatedGas.toBigInteger(),
)
}
else -> {

View file

@ -27,13 +27,13 @@ class UserWalletManagerImpl(
private val walletManagerFactory: WalletManagerFactory,
) : UserWalletManager {
override suspend fun getUserTokens(): List<Currency> {
override suspend fun getUserTokens(networkId: String): List<Currency> {
val card = appStateHolder.getActualCard()
val userTokensRepository =
requireNotNull(appStateHolder.userTokensRepository) { "userTokensRepository is null" }
if (card != null) {
return if (card != null) {
userTokensRepository.getUserTokens(card)
.filter { it.isToken() }
.filter { it.blockchain.toNetworkId() == networkId }
.map {
if (it is com.tangem.tap.features.wallet.models.Currency.Token) {
NonNativeToken(
@ -53,8 +53,9 @@ class UserWalletManagerImpl(
)
}
}
} else {
emptyList()
}
return emptyList()
}
override fun getWalletId(): String {