@@ -186,57 +186,86 @@ export function CreateOrEditContent({
186186 ) ;
187187 } , [ intl , media . gtMd , vaultSettings ?. noteMaxLength , vaultSettings ?. withNote ] ) ;
188188
189+ const validateMemoField = useCallback (
190+ async ( value : string ) : Promise < string | undefined > => {
191+ if ( ! value ) return undefined ;
192+
193+ try {
194+ const validationResult =
195+ await backgroundApiProxy . serviceSend . validateMemo ( {
196+ networkId,
197+ memo : value ,
198+ } ) ;
199+ if ( ! validationResult . isValid ) {
200+ return validationResult . errorMessage ;
201+ }
202+ return undefined ;
203+ } catch ( error ) {
204+ // Fallback to client-side validation if Vault validation fails
205+ console . warn ( 'Vault validateMemo failed, using fallback:' , error ) ;
206+ }
207+
208+ // Fallback: use original logic
209+ const validateErrMsg = vaultSettings ?. numericOnlyMemo
210+ ? intl . formatMessage ( {
211+ id : ETranslations . send_field_only_integer ,
212+ } )
213+ : undefined ;
214+ const memoRegExp = vaultSettings ?. numericOnlyMemo
215+ ? / ^ [ 0 - 9 ] + $ /
216+ : undefined ;
217+
218+ if ( ! value || ! memoRegExp ) return undefined ;
219+ const result = ! memoRegExp . test ( value ) ;
220+ return result ? validateErrMsg : undefined ;
221+ } ,
222+ [ intl , networkId , vaultSettings ?. numericOnlyMemo ] ,
223+ ) ;
224+
189225 const renderMemoForm = useCallback ( ( ) => {
190226 if ( ! vaultSettings ?. withMemo ) return null ;
227+
191228 const maxLength = vaultSettings ?. memoMaxLength || 256 ;
192- const validateErrMsg = vaultSettings ?. numericOnlyMemo
193- ? intl . formatMessage ( {
194- id : ETranslations . send_field_only_integer ,
195- } )
196- : undefined ;
197- const memoRegExp = vaultSettings ?. numericOnlyMemo ? / ^ [ 0 - 9 ] + $ / : undefined ;
229+ const customValidate = vaultSettings ?. supportMemoValidation ;
198230
199231 return (
200- < >
201- < Form . Field
202- label = { intl . formatMessage ( { id : ETranslations . send_tag } ) }
203- optional
204- name = "memo"
205- rules = { {
206- maxLength : {
207- value : maxLength ,
208- message : intl . formatMessage (
209- {
210- id : ETranslations . dapp_connect_msg_description_can_be_up_to_int_characters ,
211- } ,
212- {
213- number : maxLength ,
214- } ,
215- ) ,
216- } ,
217- validate : ( value ) => {
218- if ( ! value || ! memoRegExp ) return undefined ;
219- const result = ! memoRegExp . test ( value ) ;
220- return result ? validateErrMsg : undefined ;
221- } ,
222- } }
223- >
224- < TextAreaInput
225- numberOfLines = { 2 }
226- size = { media . gtMd ? 'medium' : 'large' }
227- placeholder = { intl . formatMessage ( {
228- id : ETranslations . send_tag_placeholder ,
229- } ) }
230- />
231- </ Form . Field >
232- </ >
232+ < Form . Field
233+ label = { intl . formatMessage ( { id : ETranslations . send_tag } ) }
234+ optional
235+ name = "memo"
236+ rules = { {
237+ maxLength : customValidate
238+ ? undefined
239+ : {
240+ value : maxLength ,
241+ message : intl . formatMessage (
242+ {
243+ id : ETranslations . dapp_connect_msg_description_can_be_up_to_int_characters ,
244+ } ,
245+ {
246+ number : maxLength ,
247+ } ,
248+ ) ,
249+ } ,
250+ validate : validateMemoField ,
251+ } }
252+ >
253+ < TextAreaInput
254+ numberOfLines = { 2 }
255+ size = { media . gtMd ? 'medium' : 'large' }
256+ placeholder = { intl . formatMessage ( {
257+ id : ETranslations . send_tag_placeholder ,
258+ } ) }
259+ />
260+ </ Form . Field >
233261 ) ;
234262 } , [
235263 intl ,
236264 media . gtMd ,
265+ validateMemoField ,
237266 vaultSettings ?. memoMaxLength ,
238- vaultSettings ?. numericOnlyMemo ,
239267 vaultSettings ?. withMemo ,
268+ vaultSettings ?. supportMemoValidation ,
240269 ] ) ;
241270
242271 return (
0 commit comments