Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-21 19:58:31 +03:00
parent b63e52d5b7
commit 5448004713
3 changed files with 16 additions and 18 deletions

View file

@ -41,14 +41,12 @@ val sendMiddleware: Middleware<AppState> = { dispatch, appState ->
private fun verifyAndSendTransaction(appState: AppState?, dispatch: (Action) -> Unit) {
val sendState = appState?.sendState ?: return
val walletManager = appState.globalState.scanNoteResponse?.walletManager ?: return
val recipientAddress = sendState.addressPayIdState.recipientWalletAddress ?: return
val typedAmount = sendState.amountState.amountToExtract ?: return
val blockchain = walletManager.wallet.blockchain
val recipientAddress = sendState.addressPayIdState.recipientWalletAddress!!
val feeAmount = Amount(sendState.feeState.getCurrentFee(), blockchain)
val amountToSend = Amount(sendState.getTotalAmountToSend(), blockchain, recipientAddress)
val txSender = walletManager as TransactionSender
val feeAmount = Amount(sendState.feeState.getCurrentFee(), walletManager.wallet.blockchain)
val totalToSend = sendState.getTotalAmountToSend()
val amountToSend = Amount(typedAmount.currencySymbol, totalToSend, recipientAddress, typedAmount.decimals, typedAmount.type)
val verifyResult = walletManager.validateTransaction(amountToSend, feeAmount)
if (verifyResult.isNotEmpty()) {
@ -59,7 +57,7 @@ private fun verifyAndSendTransaction(appState: AppState?, dispatch: (Action) ->
dispatch(SendAction.ChangeSendButtonState(SendButtonState.PROGRESS))
val txData = walletManager.createTransaction(amountToSend, feeAmount, recipientAddress)
scope.launch {
val result = txSender.send(txData, Signer(tangemSdk))
val result = (walletManager as TransactionSender).send(txData, Signer(tangemSdk))
withContext(Dispatchers.Main) {
when (result) {
is SimpleResult.Success -> {

View file

@ -56,8 +56,8 @@ private class PrepareSendScreenStatesReducer : SendInternalReducer {
override fun handle(action: SendScreenAction, sendState: SendState): SendState {
val prepareAction = action as PrepareSendScreen
val walletManager = store.state.globalState.scanNoteResponse!!.walletManager!!
val walletAmount = prepareAction.tokenAmount ?: prepareAction.coinAmount!!
val decimals = walletAmount.decimals
val amountToExtract = prepareAction.tokenAmount ?: prepareAction.coinAmount!!
val decimals = amountToExtract.decimals
val coinConverter = createCurrencyConverter(walletManager.wallet.blockchain.currency, decimals)
val tokenConverter = createCurrencyConverter(prepareAction.tokenAmount?.currencySymbol ?: "", decimals)
@ -66,12 +66,12 @@ private class PrepareSendScreenStatesReducer : SendInternalReducer {
coinConverter = coinConverter,
tokenConverter = tokenConverter,
amountState = sendState.amountState.copy(
walletAmount = walletAmount,
typeOfAmount = walletAmount.type,
balanceCrypto = walletAmount.value ?: BigDecimal.ZERO
amountToExtract = amountToExtract,
typeOfAmount = amountToExtract.type,
balanceCrypto = amountToExtract.value ?: BigDecimal.ZERO
),
feeState = sendState.feeState.copy(
includeFeeSwitcherIsEnabled = walletAmount.type == AmountType.Coin
includeFeeSwitcherIsEnabled = amountToExtract.type == AmountType.Coin
)
)
}

View file

@ -48,7 +48,7 @@ data class SendState(
fun getDecimals(type: MainCurrencyType): Int = when (type) {
MainCurrencyType.FIAT -> 2
MainCurrencyType.CRYPTO -> amountState.walletAmount?.decimals ?: 0
MainCurrencyType.CRYPTO -> amountState.amountToExtract?.decimals ?: 0
}
fun convertFiatToCoin(value: BigDecimal): BigDecimal {
@ -99,7 +99,7 @@ enum class SendButtonState {
}
data class AmountState(
val walletAmount: Amount? = null,
val amountToExtract: Amount? = null,
val typeOfAmount: AmountType = AmountType.Coin,
val viewAmountValue: InputViewValue = InputViewValue(BigDecimal.ZERO.toPlainString()),
val viewBalanceValue: String = BigDecimal.ZERO.toPlainString(),
@ -118,10 +118,10 @@ data class AmountState(
fun isCoinAmount(): Boolean = typeOfAmount == AmountType.Coin
fun createMainCurrency(type: MainCurrencyType, canSwitched: Boolean): MainCurrency {
return if (!canSwitched) MainCurrency(type, walletAmount?.currencySymbol ?: "NONE", false)
return if (!canSwitched) MainCurrency(type, amountToExtract?.currencySymbol ?: "NONE", false)
else when (type) {
MainCurrencyType.FIAT -> MainCurrency(type, store.state.globalState.appCurrency)
MainCurrencyType.CRYPTO -> MainCurrency(type, walletAmount?.currencySymbol ?: "NONE")
MainCurrencyType.CRYPTO -> MainCurrency(type, amountToExtract?.currencySymbol ?: "NONE")
}
}
}