From 353b31dff4ff4393fa7b54a51312846427f1b1e7 Mon Sep 17 00:00:00 2001 From: Nilesh Gupta Date: Thu, 16 May 2024 00:22:37 +0530 Subject: [PATCH] Added temporary commit --- src/helpers/InputValidation.ts | 143 +++++++++++++++++---------------- 1 file changed, 72 insertions(+), 71 deletions(-) diff --git a/src/helpers/InputValidation.ts b/src/helpers/InputValidation.ts index dc57fa8c8f..ad92141097 100644 --- a/src/helpers/InputValidation.ts +++ b/src/helpers/InputValidation.ts @@ -1,89 +1,90 @@ -import { isLengthValid, isValidAddress, isValidUrl } from "./ValidationHelper"; - - +import { isLengthValid, isValidAddress, isValidUrl } from './ValidationHelper'; export const isEmpty = (field) => { - if (field.trim().length == 0) { - return true; - } - - return false; - }; - - export const isAllFilledAndValid = ({ - setErrorInfo, - channelName, - channelInfo, - channelURL, - channelAlias, - chainDetails, - coreChainId - }): boolean => { - setErrorInfo(''); - - if (isEmpty(channelName) || isEmpty(channelInfo) || isEmpty(channelURL) || (isEmpty(channelAlias) && chainDetails !== coreChainId)){ - if ( - isEmpty(channelName) - ) { - setErrorInfo(x => ({ - ...x, - name: 'Please, enter the channel name.', - })); - } - - if (isEmpty(channelInfo)) { - setErrorInfo(x => ({ - ...x, - description: 'Please, enter the channel description', - })); - } + if (field.trim().length == 0) { + return true; + } - if (isEmpty(channelURL)) { - setErrorInfo(x => ({ - ...x, - url: 'Please, enter the channel url', - })); - } + return false; +}; - if (isEmpty(channelAlias) && chainDetails !== coreChainId) { - setErrorInfo(x => ({ - ...x, - address:'Please, enter the channel address', - })); - } - return false - } +export const isAllFilledAndValid = ({ + setErrorInfo, + channelName, + channelInfo, + channelURL, + channelAlias, + chainDetails, + coreChainId, +}): boolean => { + setErrorInfo(''); - if (!isLengthValid(channelName, 125)) { - setErrorInfo(x => ({ + if ( + isEmpty(channelName) || + isEmpty(channelInfo) || + isEmpty(channelURL) || + (isEmpty(channelAlias) && chainDetails !== coreChainId) + ) { + if (isEmpty(channelName)) { + setErrorInfo((x) => ({ ...x, - name: 'Channel Name should not exceed 125 characters! Please retry!', + name: 'Please, enter the channel ', })); - - return false; } - if (!isLengthValid(channelURL, 125)) { - setErrorInfo(x => ({ + + if (isEmpty(channelInfo)) { + setErrorInfo((x) => ({ ...x, - url: 'Channel Url should not exceed 125 characters! Please retry!', + description: 'Please, enter the channel description', })); - return false; } - if(chainDetails !== coreChainId && !isValidAddress(channelAlias)) { - setErrorInfo(x => ({ + + if (isEmpty(channelURL)) { + setErrorInfo((x) => ({ ...x, - address: 'Channel Alias address is invalid! Please enter a valid address!', + url: 'Please, enter the channel url', })); - - return false; } - if (!isValidUrl(channelURL)) { - setErrorInfo(x => ({ + + if (isEmpty(channelAlias) && chainDetails !== coreChainId) { + setErrorInfo((x) => ({ ...x, - url: 'Channel URL is invalid! Please enter a valid url!', + address: 'Please, enter the channel address', })); - return false; } + return false; + } - return true; - }; \ No newline at end of file + if (!isLengthValid(channelName, 125)) { + setErrorInfo((x) => ({ + ...x, + name: 'Channel Name should not exceed 125 characters! Please retry!', + })); + + return false; + } + if (!isLengthValid(channelURL, 125)) { + setErrorInfo((x) => ({ + ...x, + url: 'Channel Url should not exceed 125 characters! Please retry!', + })); + return false; + } + if (chainDetails !== coreChainId && !isValidAddress(channelAlias)) { + setErrorInfo((x) => ({ + ...x, + address: 'Channel Alias address is invalid! Please enter a valid address!', + })); + + return false; + } + if (!isValidUrl(channelURL)) { + setErrorInfo((x) => ({ + ...x, + url: 'Channel URL is invalid! Please enter a valid url!', + })); + return false; + } + + return true; +};