Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Global/FileUploadInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Icon from '../Icon'
import { useEffect, useState } from 'react'
import * as utils from '@/utils'
interface IFileUploadInputProps {
export interface IFileUploadInputProps {
attachmentOptions: {
fileUrl: string | undefined
message: string | undefined
Expand Down
6 changes: 5 additions & 1 deletion src/components/Request/Create/Views/Initial.view.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TokenAmountInput from '@/components/Global/TokenAmountInput'
import * as _consts from '../Create.consts'
import FileUploadInput from '@/components/Global/FileUploadInput'
import FileUploadInput, { IFileUploadInputProps } from '@/components/Global/FileUploadInput'
import { useContext, useEffect, useState, useCallback } from 'react'
import * as context from '@/context'
import Loading from '@/components/Global/Loading'
Expand Down Expand Up @@ -53,13 +53,15 @@ export const InitialView = ({
userBalances,
tokenValue,
tokenData,
attachmentOptions,
}: {
recipientAddress: string | undefined
tokenAddress: string
chainId: string
userBalances: IUserBalance[]
tokenValue: string | undefined
tokenData: Pick<IToken, 'chainId' | 'address' | 'decimals' | 'symbol'> | undefined
attachmentOptions: IFileUploadInputProps['attachmentOptions']
Comment on lines +56 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add validation for attachment data

The attachmentOptions parameter is added but there's no validation before passing to the SDK.

Consider adding validation:

const validateAttachment = (
    attachmentOptions: IFileUploadInputProps['attachmentOptions']
): { isValid: boolean; error?: string } => {
    if (!attachmentOptions) return { isValid: true }
    
    if (attachmentOptions.rawFile && attachmentOptions.rawFile.size > 5242880) {
        return { isValid: false, error: 'Attachment file size exceeds 5MB limit' }
    }
    
    if (attachmentOptions.message && attachmentOptions.message.length > 140) {
        return { isValid: false, error: 'Reference message exceeds 140 characters' }
    }
    
    return { isValid: true }
}

Then use it in handleOnNext:

     try {
+        const { isValid, error } = validateAttachment(attachmentOptions)
+        if (!isValid) {
+            setErrorState({
+                showError: true,
+                errorMessage: error || 'Invalid attachment',
+            })
+            return
+        }
         let inputValue = tokenValue

}) => {
if (!recipientAddress) {
setErrorState({
Expand Down Expand Up @@ -173,6 +175,7 @@ export const InitialView = ({
userBalances: balances,
tokenValue,
tokenData: selectedTokenData,
attachmentOptions,
})
}}
/>
Expand Down Expand Up @@ -202,6 +205,7 @@ export const InitialView = ({
userBalances: balances,
tokenValue,
tokenData: selectedTokenData,
attachmentOptions,
})
}}
disabled={!isValidRecipient || inputChanging || isLoading || !_tokenValue}
Expand Down
Loading