diff --git a/components/factory/components/DenomImage.tsx b/components/factory/components/DenomImage.tsx index 01594f1..34f8528 100644 --- a/components/factory/components/DenomImage.tsx +++ b/components/factory/components/DenomImage.tsx @@ -68,7 +68,7 @@ export const DenomImage = ({ denom }: { denom: any }) => { useEffect(() => { const checkUri = async () => { if (denom?.uri) { - setIsSupported(isUrlSupported(denom.uri)); + setIsSupported(isUrlSupported(denom?.uri)); // Simulate a delay to show the loading state await new Promise(resolve => setTimeout(resolve, 1000)); } @@ -110,7 +110,7 @@ export const DenomImage = ({ denom }: { denom: any }) => { Token Icon setImageError(true)} className="rounded-full w-[32px] h-[32px]" diff --git a/components/factory/forms/TokenDetailsForm.tsx b/components/factory/forms/TokenDetailsForm.tsx index 1166d2b..f1cdb8f 100644 --- a/components/factory/forms/TokenDetailsForm.tsx +++ b/components/factory/forms/TokenDetailsForm.tsx @@ -3,7 +3,7 @@ import { DenomUnit } from '@chalabi/manifestjs/dist/codegen/cosmos/bank/v1beta1/ import { Formik, Form, Field } from 'formik'; import Yup from '@/utils/yupExtensions'; import { TextInput, TextArea } from '@/components/react/inputs'; - +//TODO: validation doesnt occur on denom unit entries when creating or updating const TokenDetailsSchema = Yup.object().shape({ subdenom: Yup.string().required('Subdenom is required'), display: Yup.string().required('Display is required').noProfanity(), diff --git a/components/factory/modals/updateDenomMetadata.tsx b/components/factory/modals/updateDenomMetadata.tsx index 74ed0c1..4a4c6c1 100644 --- a/components/factory/modals/updateDenomMetadata.tsx +++ b/components/factory/modals/updateDenomMetadata.tsx @@ -5,6 +5,49 @@ import { useTx } from '@/hooks/useTx'; import { osmosis } from '@chalabi/manifestjs'; import { chainName } from '@/config'; import { DenomUnit } from '@chalabi/manifestjs/dist/codegen/cosmos/bank/v1beta1/bank'; +import { Formik, Form } from 'formik'; +import Yup from '@/utils/yupExtensions'; +import { TextInput, TextArea } from '@/components/react/inputs'; +//TODO: validation doesnt occur on denom unit entries when creating or updating +const TokenDetailsSchema = Yup.object().shape({ + subdenom: Yup.string().required('Subdenom is required'), + display: Yup.string().required('Display is required').noProfanity(), + name: Yup.string().required('Name is required').noProfanity(), + symbol: Yup.string().required('Symbol is required').noProfanity(), + description: Yup.string() + .required('Description is required') + .min(10, 'Description must be at least 10 characters long') + .noProfanity(), + uri: Yup.string().url('Must be a valid URL'), + uriHash: Yup.string(), + denomUnits: Yup.array() + .of( + Yup.object().shape({ + denom: Yup.string().required('Denom is required'), + exponent: Yup.number().required('Exponent is required'), + aliases: Yup.array().of(Yup.string()), + }) + ) + .test('valid-denom-units', 'Invalid denom units', function (denomUnits) { + if (!denomUnits || denomUnits.length < 2) return false; + + const additionalDenom = denomUnits[1]; + if (!additionalDenom.denom) { + return this.createError({ + path: 'denomUnits[1].denom', + message: 'Additional denom is required', + }); + } + if (![6, 9, 12, 18].includes(additionalDenom.exponent || 0)) { + return this.createError({ + path: 'denomUnits[1].exponent', + message: 'Exponent must be 6, 9, 12, or 18', + }); + } + + return true; + }), +}); export function UpdateDenomMetadataModal({ denom, @@ -99,174 +142,163 @@ export function UpdateDenomMetadataModal({

Update Denom Metadata

-
- -
-
-
-
- - updateField('display', e.target.value)} - required - /> -
-
- - updateField('name', e.target.value)} - required - /> -
-
- - updateField('symbol', e.target.value)} - required - /> -
-
- -
- - -
+ + {({ isValid, dirty, setFieldValue }) => ( +
+
+ ) => { + updateField('display', e.target.value); + setFieldValue('display', e.target.value); + }} + /> + ) => { + updateField('name', e.target.value); + setFieldValue('name', e.target.value); + }} + /> + ) => { + updateField('symbol', e.target.value); + setFieldValue('symbol', e.target.value); + }} + /> +
-
-
- - updateField('uri', e.target.value)} - /> -
-
- - updateField('uriHash', e.target.value)} +