Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-14 22:37:48 +03:00
parent 1010ab65f4
commit deee4fe183
11 changed files with 57 additions and 14 deletions

View file

@ -37,6 +37,9 @@ sealed class AddressPayIdVerifyAction : SendScreenAction {
ADDRESS_SAME_AS_WALLET
}
data class VerifyClipboard(val data: String?) : AddressPayIdVerifyAction()
data class ChangePasteBtnEnableState(val isEnabled: Boolean): AddressPayIdVerifyAction()
sealed class PayIdVerification : AddressPayIdVerifyAction() {
data class SetError(val payId: String, val error: Error) : PayIdVerification()
data class SetPayIdWalletAddress(val payId: String, val payIdWalletAddress: String) : PayIdVerification()

View file

@ -17,7 +17,12 @@ import org.rekotlin.DispatchFunction
[REDACTED_AUTHOR]
*/
internal class AddressPayIdMiddleware {
fun handle(data: String, appState: AppState?, dispatch: DispatchFunction) {
fun handle(data: String?, appState: AppState?, dispatch: DispatchFunction) {
if (data == null) {
dispatch(AddressVerification.SetError("", Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN))
return
}
val sendState = appState?.sendState ?: return
val walletManager = sendState.walletManager ?: return
if (data == sendState.addressPayIdState.etFieldValue) return

View file

@ -4,6 +4,7 @@ import com.tangem.blockchain.common.Amount
import com.tangem.common.CompletionResult
import com.tangem.tap.common.redux.AppState
import com.tangem.tap.features.send.redux.AddressPayIdActionUi.ChangeAddressOrPayId
import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.*
import com.tangem.tap.features.send.redux.AmountActionUi.CheckAmountToSend
import com.tangem.tap.features.send.redux.FeeAction.RequestFee
import com.tangem.tap.features.send.redux.SendAction
@ -22,6 +23,18 @@ val sendMiddleware: Middleware<AppState> = { dispatch, appState ->
{ action ->
when (action) {
is ChangeAddressOrPayId -> AddressPayIdMiddleware().handle(action.data, appState(), dispatch)
is VerifyClipboard -> {
AddressPayIdMiddleware().handle(action.data, appState()){
when(it) {
is AddressVerification.SetWalletAddress, is PayIdVerification.SetPayIdWalletAddress -> {
dispatch(ChangePasteBtnEnableState(true))
}
is AddressVerification.SetError, is PayIdVerification.SetError -> {
dispatch(ChangePasteBtnEnableState(false))
}
}
}
}
is CheckAmountToSend -> AmountMiddleware().handle(action.data, appState(), dispatch)
is RequestFee -> RequestFeeMiddleware().handle(appState(), dispatch)
is SendActionUi.SendAmountToRecipient -> verifyAndSendTransaction(appState(), dispatch)

View file

@ -36,6 +36,8 @@ class AddressPayIdReducer : SendInternalReducer {
is PayIdVerification.SetError -> state.copyPayIdError(action.payId, action.error)
is AddressVerification.SetWalletAddress -> state.copyWalletAddress(action.address)
is AddressVerification.SetError -> state.copyError(action.address, action.error)
is AddressPayIdVerifyAction.ChangePasteBtnEnableState -> state.copy(pasteIsEnabled = action.isEnabled)
is AddressPayIdVerifyAction.VerifyClipboard -> state
}
return updateLastState(sendState.copy(addressPayIdState = result), result)
}

View file

@ -9,7 +9,8 @@ data class AddressPayIdState(
val truncatedFieldValue: String? = null,
val recipientWalletAddress: String? = null,
val error: AddressPayIdVerifyAction.Error? = null,
val truncateHandler: ((String) -> String)? = null
val truncateHandler: ((String) -> String)? = null,
val pasteIsEnabled: Boolean = false
) : StateType {
fun isReady(): Boolean = error == null && recipientWalletAddress?.isNotEmpty() ?: false

View file

@ -17,13 +17,10 @@ import com.tangem.tap.common.qrCodeScan.ScanQrCodeActivity
import com.tangem.tap.common.snackBar.MaxAmountSnackbar
import com.tangem.tap.common.text.truncateMiddleWith
import com.tangem.tap.features.send.BaseStoreFragment
import com.tangem.tap.features.send.redux.*
import com.tangem.tap.features.send.redux.AddressPayIdActionUi.*
import com.tangem.tap.features.send.redux.AmountActionUi.*
import com.tangem.tap.features.send.redux.FeeAction
import com.tangem.tap.features.send.redux.FeeActionUi.*
import com.tangem.tap.features.send.redux.ReceiptAction
import com.tangem.tap.features.send.redux.ReleaseSendState
import com.tangem.tap.features.send.redux.SendActionUi
import com.tangem.tap.features.send.redux.states.FeeType
import com.tangem.tap.features.send.redux.states.MainCurrencyType
import com.tangem.tap.features.send.ui.stateSubscribers.SendStateSubscriber
@ -60,6 +57,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
private fun setupAddressOrPayIdLayout() {
store.dispatch(SetTruncateHandler { etAddressOrPayId.truncateMiddleWith(it, " *** ") })
store.dispatch(AddressPayIdVerifyAction.VerifyClipboard(requireContext().getFromClipboard()?.toString()))
etAddressOrPayId.setOnFocusChangeListener { v, hasFocus ->
store.dispatch(TruncateOrRestore(!hasFocus))

View file

@ -42,6 +42,7 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
}
fg.btnSend.isEnabled = state.sendButtonIsEnabled
fg.imvPaste.isEnabled = state.addressPayIdState.pasteIsEnabled
}
private fun handleAddressPayIdState(fg: BaseStoreFragment, state: AddressPayIdState) {