Updated on 2026-08-14
This commit is contained in:
parent
cb1e0d3f7b
commit
a07da07f47
4 changed files with 31 additions and 8 deletions
|
|
@ -54,7 +54,7 @@ class TransactionExtrasReducer : SendInternalReducer {
|
|||
sendState: SendState,
|
||||
infoState: TransactionExtrasState,
|
||||
): SendState {
|
||||
fun clearMemo(memo: XlmMemoState): XlmMemoState = memo.copy(text = null, id = null)
|
||||
fun clearMemo(memo: XlmMemoState): XlmMemoState = memo.copy(text = null, id = null, error = null)
|
||||
|
||||
val result = when (action) {
|
||||
// is XlmMemo.ChangeSelectedMemo -> {
|
||||
|
|
@ -74,8 +74,16 @@ class TransactionExtrasReducer : SendInternalReducer {
|
|||
memo = when (infoState.xlmMemo?.selectedMemoType) {
|
||||
XlmMemoType.TEXT -> memo.copy(text = StellarMemo.Text(action.data))
|
||||
XlmMemoType.ID -> {
|
||||
val id = action.data.toIntOrNull()?.toBigInteger()
|
||||
if (id != null) memo.copy(id = StellarMemo.Id(id)) else memo
|
||||
val id = action.data.toBigIntegerOrNull()
|
||||
if (id != null) {
|
||||
if (id > XlmMemoState.MAX_NUMBER) {
|
||||
memo.copy(error = TransactionExtraError.INVALID_XLM_MEMO)
|
||||
} else {
|
||||
memo.copy(id = StellarMemo.Id(id))
|
||||
}
|
||||
} else {
|
||||
memo
|
||||
}
|
||||
}
|
||||
null -> memo
|
||||
}
|
||||
|
|
@ -98,7 +106,7 @@ class TransactionExtrasReducer : SendInternalReducer {
|
|||
val tagState = if (tag <= XrpDestinationTagState.MAX_NUMBER){
|
||||
XrpDestinationTagState(input, tag)
|
||||
} else {
|
||||
XrpDestinationTagState(input, error = XrpDestinationTagError.INVALID_TAG)
|
||||
XrpDestinationTagState(input, error = TransactionExtraError.INVALID_DESTINATION_TAG)
|
||||
}
|
||||
infoState.copy(xrpDestinationTag = tagState)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tangem.tap.features.send.redux.states
|
|||
|
||||
import com.tangem.blockchain.blockchains.stellar.StellarMemo
|
||||
import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction
|
||||
import java.math.BigInteger
|
||||
|
||||
data class AddressPayIdState(
|
||||
val viewFieldValue: InputViewValue = InputViewValue(""),
|
||||
|
|
@ -39,25 +40,31 @@ data class XlmMemoState(
|
|||
val selectedMemoType: XlmMemoType = XlmMemoType.ID,
|
||||
val text: StellarMemo.Text? = null,
|
||||
val id: StellarMemo.Id? = null,
|
||||
val error: TransactionExtraError? = null,
|
||||
) {
|
||||
val memo: StellarMemo?
|
||||
get() = when (selectedMemoType) {
|
||||
XlmMemoType.TEXT -> text
|
||||
XlmMemoType.ID -> id
|
||||
}
|
||||
|
||||
companion object {
|
||||
val MAX_NUMBER: BigInteger = BigInteger("FFFFFFFFFFFFFFFF", 16)
|
||||
}
|
||||
}
|
||||
|
||||
// tag must contains only digits
|
||||
data class XrpDestinationTagState(
|
||||
val viewFieldValue: InputViewValue = InputViewValue(""),
|
||||
val tag: Long? = null,
|
||||
val error: XrpDestinationTagError? = null
|
||||
val error: TransactionExtraError? = null
|
||||
) {
|
||||
companion object {
|
||||
const val MAX_NUMBER: Long = 4294967295
|
||||
}
|
||||
}
|
||||
|
||||
enum class XrpDestinationTagError {
|
||||
INVALID_TAG
|
||||
enum class TransactionExtraError {
|
||||
INVALID_DESTINATION_TAG,
|
||||
INVALID_XLM_MEMO
|
||||
}
|
||||
|
|
@ -70,10 +70,17 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
|
|||
XlmMemoType.ID -> InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
if (!it.viewFieldValue.isFromUserInput) fg.etMemo.setText(it.viewFieldValue.value)
|
||||
if (it.error != null) {
|
||||
if (it.error == TransactionExtraError.INVALID_XLM_MEMO) {
|
||||
fg.tilMemo.error = fg.getText(R.string.send_error_invalid_memo_id)
|
||||
}
|
||||
} else {
|
||||
fg.tilMemo.error = null
|
||||
}
|
||||
}
|
||||
infoState.xrpDestinationTag?.let {
|
||||
if (infoState.xrpDestinationTag.error != null) {
|
||||
if (infoState.xrpDestinationTag.error == XrpDestinationTagError.INVALID_TAG) {
|
||||
if (infoState.xrpDestinationTag.error == TransactionExtraError.INVALID_DESTINATION_TAG) {
|
||||
fg.tilDestinationTag.error = fg.getText(R.string.send_error_invalid_destination_tag)
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ this wallet.
|
|||
<string name="send_extras_hint_memo" translatable="false">Memo</string>
|
||||
<string name="send_extras_hint_destination_tag" translatable="false">Destination tag</string>
|
||||
<string name="send_error_invalid_destination_tag" translatable="false">Invalid destination tag. It won\'t be added to the transaction</string>
|
||||
<string name="send_error_invalid_memo_id" translatable="false">Invalid Memo ID. It won\'t be added to the transaction</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue