-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |