From 1342f23eda469d518c4653ac17fd3505b31d248a Mon Sep 17 00:00:00 2001 From: Roshaan Siddiqui Date: Mon, 5 Jun 2023 14:53:11 -0500 Subject: [PATCH] [DPLT-1009] feat: contract validation with wild cards (#93) --- frontend/src/components/Editor/Editor.js | 17 ++++++----------- .../Form/BlockHeightOptionsInputGroup.jsx | 1 + frontend/src/utils/validators.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 frontend/src/utils/validators.js diff --git a/frontend/src/components/Editor/Editor.js b/frontend/src/components/Editor/Editor.js index 6aba22c91..708ee87b6 100644 --- a/frontend/src/components/Editor/Editor.js +++ b/frontend/src/components/Editor/Editor.js @@ -18,10 +18,8 @@ import EditorButtons from "./EditorButtons"; import { PublishModal } from "../Modals/PublishModal"; import {getLatestBlockHeight} from "../../utils/getLatestBlockHeight"; const BLOCKHEIGHT_LIMIT = 3600; +import { validateContractId } from "../../utils/validators" -const contractRegex = RegExp( - "^(([a-zd]+[-_])*[a-zd]+.)*([a-zd]+[-_])*[a-zd]+$" -); const Editor = ({ options, @@ -299,17 +297,14 @@ const Editor = ({ } function handleSetContractFilter(e) { - // check if contract filter is greater than 2 and less than or equal to 64 chars const contractFilter = e.target.value; setContractFilter(contractFilter); - if ( - contractFilter.length > 64 || - contractFilter.length < 2 || - !contractRegex.test(contractFilter) - ) { - setIsContractFilterValid(false); - } else { + const isValid = validateContractId(contractFilter); + + if (isValid) { setIsContractFilterValid(true); + } else { + setIsContractFilterValid(false); } } diff --git a/frontend/src/components/Form/BlockHeightOptionsInputGroup.jsx b/frontend/src/components/Form/BlockHeightOptionsInputGroup.jsx index 66d4391f1..1a0e86f91 100644 --- a/frontend/src/components/Form/BlockHeightOptionsInputGroup.jsx +++ b/frontend/src/components/Form/BlockHeightOptionsInputGroup.jsx @@ -39,6 +39,7 @@ const BlockHeightOptions = ({ = 2 && + accountId.length <= 64 && + CONTRACT_NAME_REGEX.test(accountId) + ); +} +