diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt b/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt index 8a87b6108f..36e7ae943b 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt @@ -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 diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt index 115c1c2033..b24e7916db 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt @@ -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 diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt index 527d3f6545..e6ab87ef01 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt @@ -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, diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt index 8570250b54..af6ceb3d2d 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/WalletMiddleware.kt @@ -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) } } diff --git a/app/src/main/res/layout/item_currency_wallet.xml b/app/src/main/res/layout/item_currency_wallet.xml index 09b7dd4cc9..be3b049566 100644 --- a/app/src/main/res/layout/item_currency_wallet.xml +++ b/app/src/main/res/layout/item_currency_wallet.xml @@ -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" />