Updated on 2026-08-14

This commit is contained in:
Tangem 2022-02-26 17:46:24 +03:00
parent 37fc177339
commit 2f6a07c01a
2 changed files with 26 additions and 9 deletions

View file

@ -1,5 +1,6 @@
package com.tangem.tap.features.demo
import com.tangem.blockchain.blockchains.bitcoin.BitcoinWalletManager
import com.tangem.blockchain.common.*
import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
@ -166,8 +167,18 @@ class DemoTransactionSender(
private val sender: TransactionSender = walletManager as TransactionSender
) : TransactionSender {
override suspend fun getFee(amount: Amount, destination: String): Result<List<Amount>> =
sender.getFee(amount, destination)
override suspend fun getFee(amount: Amount, destination: String): Result<List<Amount>> {
val blockchain = walletManager.wallet.blockchain
return when (walletManager) {
is BitcoinWalletManager -> Result.Success(listOf(
Amount(0.0001.toBigDecimal(), blockchain),
Amount(0.0003.toBigDecimal(), blockchain),
Amount(0.00055.toBigDecimal(), blockchain),
))
else -> sender.getFee(amount, destination)
}
}
override suspend fun send(transactionData: TransactionData, signer: TransactionSigner): SimpleResult {
val dataToSign = randomString(32).toByteArray()

View file

@ -6,6 +6,8 @@ import com.tangem.blockchain.common.TransactionSender
import com.tangem.blockchain.extensions.Result
import com.tangem.common.extensions.isZero
import com.tangem.tap.common.redux.AppState
import com.tangem.tap.features.demo.DemoTransactionSender
import com.tangem.tap.features.demo.isDemoWallet
import com.tangem.tap.features.send.redux.AmountActionUi
import com.tangem.tap.features.send.redux.FeeAction
import com.tangem.tap.features.send.redux.ReceiptAction
@ -38,7 +40,11 @@ class RequestFeeMiddleware {
val destinationAddress = sendState.addressPayIdState.destinationWalletAddress!!
val destinationAmount = Amount(typedAmount, sendState.amountState.amountToSendCrypto)
val txSender = walletManager as TransactionSender
val txSender = if (walletManager.isDemoWallet()) {
DemoTransactionSender(walletManager)
} else {
walletManager as TransactionSender
}
scope.launch {
val feeResult = txSender.getFee(destinationAmount, destinationAddress)
withContext(Dispatchers.Main) {
@ -84,15 +90,15 @@ class FeeMock {
suspend fun feeZero(blockchain: Blockchain): List<Amount> = listOf(Amount(BigDecimal.ZERO, blockchain))
suspend fun feeStandard(blockchain: Blockchain): List<Amount> = listOf(
Amount(0.001500.toBigDecimal(), blockchain),
Amount(0.0030.toBigDecimal(), blockchain),
Amount(0.0045001.toBigDecimal(), blockchain)
Amount(0.001500.toBigDecimal(), blockchain),
Amount(0.0030.toBigDecimal(), blockchain),
Amount(0.0045001.toBigDecimal(), blockchain)
)
suspend fun feeStandardBig(blockchain: Blockchain): List<Amount> = listOf(
Amount(1.76.toBigDecimal(), blockchain),
Amount(2.30.toBigDecimal(), blockchain),
Amount(3.45.toBigDecimal(), blockchain)
Amount(1.76.toBigDecimal(), blockchain),
Amount(2.30.toBigDecimal(), blockchain),
Amount(3.45.toBigDecimal(), blockchain)
)
suspend fun feeSingle(blockchain: Blockchain): List<Amount> = listOf(Amount(0.0015.toBigDecimal(), blockchain))