Skip to content

Commit

Permalink
Added temporary commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNilesh committed May 15, 2024
1 parent f257d7a commit 353b31d
Showing 1 changed file with 72 additions and 71 deletions.
143 changes: 72 additions & 71 deletions src/helpers/InputValidation.ts
Original file line number Diff line number Diff line change
@@ -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;
};
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;
};

0 comments on commit 353b31d

Please sign in to comment.