Updated on 2026-08-14
This commit is contained in:
parent
7e35a4de75
commit
c0471dbf9f
20 changed files with 315 additions and 133 deletions
|
|
@ -19,7 +19,6 @@ import com.tangem.domain.wallets.models.UserWalletId
|
|||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal class DefaultTransactionRepository(
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
|
|
@ -34,7 +33,6 @@ internal class DefaultTransactionRepository(
|
|||
destination: String,
|
||||
userWalletId: UserWalletId,
|
||||
network: Network,
|
||||
isSwap: Boolean,
|
||||
txExtras: TransactionExtras?,
|
||||
hash: String?,
|
||||
): TransactionData? = withContext(coroutineDispatcherProvider.io) {
|
||||
|
|
@ -51,7 +49,6 @@ internal class DefaultTransactionRepository(
|
|||
memo = memo,
|
||||
destination = destination,
|
||||
network = network,
|
||||
isSwap = isSwap,
|
||||
txExtras = txExtras,
|
||||
hash = hash,
|
||||
)
|
||||
|
|
@ -84,7 +81,6 @@ internal class DefaultTransactionRepository(
|
|||
memo = memo,
|
||||
destination = destination,
|
||||
network = network,
|
||||
isSwap = isSwap,
|
||||
txExtras = txExtras,
|
||||
hash = hash,
|
||||
)
|
||||
|
|
@ -118,23 +114,15 @@ internal class DefaultTransactionRepository(
|
|||
memo: String?,
|
||||
destination: String,
|
||||
network: Network,
|
||||
isSwap: Boolean,
|
||||
txExtras: TransactionExtras?,
|
||||
hash: String?,
|
||||
): TransactionData {
|
||||
// TODO: refactor workaround to use general mechanism in bsdk for build tx for DEX
|
||||
val txAmount = if (isSwap) {
|
||||
createAmountForSwap(amount)
|
||||
} else {
|
||||
amount
|
||||
}
|
||||
|
||||
if (txExtras != null && memo != null) {
|
||||
// throw error for now to avoid programmers errors when use extras
|
||||
error("Both txExtras and memo provided, use only one of them")
|
||||
}
|
||||
val extras = txExtras ?: getMemoExtras(network.id.value, memo)
|
||||
return createTransaction(txAmount, fee, destination).copy(
|
||||
return createTransaction(amount, fee, destination).copy(
|
||||
hash = hash,
|
||||
extras = extras,
|
||||
)
|
||||
|
|
@ -163,19 +151,4 @@ internal class DefaultTransactionRepository(
|
|||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun createAmountForSwap(amount: Amount): Amount {
|
||||
return when (amount.type) {
|
||||
is AmountType.Coin -> amount
|
||||
else -> {
|
||||
// 1. when creates swap amount for NonNativeToken, amount should be ZERO
|
||||
// 2. Amount has .Coin type, as workaround to use destinationAddress in bsdk, not contractAddress
|
||||
Amount(
|
||||
currencySymbol = amount.currencySymbol,
|
||||
value = BigDecimal.ZERO,
|
||||
decimals = amount.decimals,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue