Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-16 10:47:36 +00:00
commit cff5cae478
3 changed files with 28 additions and 16 deletions

View file

@ -20,7 +20,8 @@ interface SendScreenActionUi : SendScreenAction
object ReleaseSendState : Action
data class PrepareSendScreen(
val amount: Amount,
val coinAmount: Amount?,
val tokenAmount: Amount? = null
) : SendScreenAction
// Address or PayId

View file

@ -54,13 +54,13 @@ private class EmptyReducer : SendInternalReducer {
private class PrepareSendScreenStatesReducer : SendInternalReducer {
override fun handle(action: SendScreenAction, sendState: SendState): SendState {
val amount = (action as PrepareSendScreen).amount
val amount = (action as PrepareSendScreen).tokenAmount ?: action.coinAmount
val walletManager = store.state.globalState.scanNoteResponse!!.walletManager!!
return sendState.copy(
amount = amount,
walletManager = walletManager,
currencyConverter = createCurrencyConverter(walletManager),
amountState = sendState.amountState.copy(balanceCrypto = amount.value ?: BigDecimal.ZERO)
amountState = sendState.amountState.copy(balanceCrypto = amount?.value ?: BigDecimal.ZERO)
)
}

View file

@ -3,6 +3,8 @@ package com.tangem.tap.features.wallet.redux
import android.content.Intent
import android.net.Uri
import androidx.core.content.ContextCompat
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.AmountType
import com.tangem.commands.common.network.Result
import com.tangem.common.CompletionResult
import com.tangem.common.extensions.toHexString
@ -20,6 +22,7 @@ import com.tangem.tap.tangemSdkManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.rekotlin.Action
import org.rekotlin.Middleware
@ -113,24 +116,32 @@ val walletMiddleware: Middleware<AppState> = { dispatch, state ->
ContextCompat.startActivity(action.context, intent, null)
}
is WalletAction.Send -> {
if (action.amount != null) {
store.dispatch(PrepareSendScreen(action.amount))
val newAction = prepareSendAction(action.amount)
store.dispatch(newAction)
if (newAction is PrepareSendScreen) {
store.dispatch(NavigationAction.NavigateTo(AppScreen.Send))
} else {
if (store.state.walletState.wallet?.amounts?.size ?: 0 > 1) {
store.dispatch(WalletAction.Send.ChooseCurrency)
} else {
val amount = store.state.walletState.wallet?.amounts?.toList()
?.get(0)?.second
if (amount != null) {
store.dispatch(PrepareSendScreen(amount))
store.dispatch(NavigationAction.NavigateTo(AppScreen.Send))
}
}
}
}
}
next(action)
}
}
}
private fun prepareSendAction(amount: Amount?): Action {
return if (amount != null) {
if (amount.type == AmountType.Token) {
PrepareSendScreen(store.state.walletState.wallet?.amounts?.get(AmountType.Coin), amount)
} else {
PrepareSendScreen(amount)
}
} else {
if (store.state.walletState.wallet?.amounts?.size ?: 0 > 1) {
WalletAction.Send.ChooseCurrency
} else {
val amountToSend = store.state.walletState.wallet?.amounts?.toList()?.get(0)?.second
PrepareSendScreen(amountToSend)
}
}
}