Updated on 2026-08-14

This commit is contained in:
Tangem 2021-03-30 15:31:47 +03:00
parent edb2613eec
commit 8ac90772f9
5 changed files with 18 additions and 13 deletions

View file

@ -3,6 +3,7 @@ package com.tangem.tap.features.send.redux
import com.tangem.Message
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.WalletManager
import com.tangem.tap.common.redux.ErrorAction
import com.tangem.tap.common.redux.ToastNotificationAction
import com.tangem.tap.domain.TapError
@ -25,6 +26,7 @@ object ReleaseSendState : Action
data class PrepareSendScreen(
val coinAmount: Amount?,
val coinRate: BigDecimal?,
val walletManager: WalletManager?,
val tokenAmount: Amount? = null,
val tokenRate: BigDecimal? = null
) : SendScreenAction

View file

@ -56,8 +56,8 @@ private fun verifyAndSendTransaction(
action: SendActionUi.SendAmountToRecipient, appState: AppState?, dispatch: (Action) -> Unit,
) {
val sendState = appState?.sendState ?: return
val walletManager = appState.globalState.scanNoteResponse?.walletManager ?: return
val card = appState.globalState.scanNoteResponse.card
val walletManager = sendState.walletManager ?: return
val card = appState.globalState.scanNoteResponse?.card ?: return
val destinationAddress = sendState.addressPayIdState.destinationWalletAddress ?: return
val typedAmount = sendState.amountState.amountToExtract ?: return
val feeAmount = sendState.feeState.currentFee ?: return

View file

@ -60,14 +60,15 @@ private class EmptyReducer : SendInternalReducer {
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 walletManager = action.walletManager
?: store.state.globalState.scanNoteResponse!!.walletManager!!
val amountToExtract = prepareAction.tokenAmount ?: prepareAction.coinAmount!!
val decimals = amountToExtract.decimals
return sendState.copy(
walletManager = walletManager,
coinConverter = action.coinRate?.let { CurrencyConverter(it, decimals) },
tokenConverter = action.tokenRate?. let { CurrencyConverter(it, decimals) },
tokenConverter = action.tokenRate?.let { CurrencyConverter(it, decimals) },
amountState = sendState.amountState.copy(
amountToExtract = amountToExtract,
typeOfAmount = amountToExtract.type,

View file

@ -193,13 +193,14 @@ class WalletMiddleware {
private fun prepareSendAction(amount: Amount?, state: WalletState?): Action {
val selectedWalletData = state?.getSelectedWalletData()
val currency = selectedWalletData?.currencyData?.currencySymbol
val wallet = currency?.let { state.getWalletManager(currency)?.wallet }
val walletManager = state?.getWalletManager(currency)
val wallet = walletManager?.wallet
return if (amount != null) {
if (amount.type is AmountType.Token) {
prepareSendActionForToken(amount, state, selectedWalletData, wallet)
prepareSendActionForToken(amount, state, selectedWalletData, wallet, walletManager)
} else {
PrepareSendScreen(amount, selectedWalletData?.fiatRate)
PrepareSendScreen(amount, selectedWalletData?.fiatRate, walletManager)
}
} else {
val amounts = wallet?.amounts?.toSendableAmounts()
@ -207,23 +208,24 @@ class WalletMiddleware {
val amountToSend = amounts?.find { it.currencySymbol == currency }
?: return WalletAction.Send.ChooseCurrency(amounts)
if (amountToSend.type is AmountType.Token) {
prepareSendActionForToken(amount, state, selectedWalletData, wallet)
prepareSendActionForToken(amount, state, selectedWalletData, wallet, walletManager)
} else {
PrepareSendScreen(amountToSend, selectedWalletData.fiatRate)
PrepareSendScreen(amountToSend, selectedWalletData.fiatRate, walletManager)
}
} else {
if (amounts?.size ?: 0 > 1) {
WalletAction.Send.ChooseCurrency(amounts)
} else {
val amountToSend = amounts?.first()
PrepareSendScreen(amountToSend, selectedWalletData?.fiatRate)
PrepareSendScreen(amountToSend, selectedWalletData?.fiatRate, walletManager)
}
}
}
}
private fun prepareSendActionForToken(
amount: Amount?, state: WalletState?, selectedWalletData: WalletData?, wallet: Wallet?
amount: Amount?, state: WalletState?, selectedWalletData: WalletData?, wallet: Wallet?,
walletManager: WalletManager?
): PrepareSendScreen {
val coinRate = state?.getWalletData(wallet?.blockchain?.currency)?.fiatRate
val tokenRate = if (state?.isMultiwalletAllowed == true) {
@ -232,7 +234,7 @@ class WalletMiddleware {
selectedWalletData?.currencyData?.token?.fiatRate
}
return PrepareSendScreen(
wallet?.amounts?.get(AmountType.Coin), coinRate,
wallet?.amounts?.get(AmountType.Coin), coinRate, walletManager,
amount, tokenRate)
}
}

View file

@ -124,7 +124,7 @@
android:textColor="@color/darkGray2"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_exchange_rate"
app:layout_constraintBottom_toBottomOf="@id/iv_currency"
tools:text="0.43 USD" />
</androidx.constraintlayout.widget.ConstraintLayout>