Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate ticker contains subdenom #123

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions components/factory/modals/updateDenomMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@
import { truncateString, ExtendedMetadataSDKType } from '@/utils';
import { useEffect } from 'react';

const TokenDetailsSchema = Yup.object().shape({
display: Yup.string().noProfanity(),
name: Yup.string().noProfanity(),
description: Yup.string()
.min(10, 'Description must be at least 10 characters long')
.noProfanity(),
uri: Yup.string()
.url('Must be a valid URL')
.matches(/^https:\/\//i, 'URL must use HTTPS protocol')
.matches(/\.(jpg|jpeg|png|gif)$/i, 'URL must point to an image file')
.supportedImageUrl(),
});
const TokenDetailsSchema = (context: { subdenom: string }) =>
Yup.object().shape({
display: Yup.string()
.required('Display is required')
.noProfanity()
.test('display-contains-subdenom', 'Display must contain subdenom', function (value) {
const subdenom = context.subdenom;
return !subdenom || value.toLowerCase().includes(subdenom.slice(1).toLowerCase());
}),
name: Yup.string().required('Name 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')
.matches(/^https:\/\//i, 'URL must use HTTPS protocol')
.matches(/\.(jpg|jpeg|png|gif)$/i, 'URL must point to an image file')

Check warning on line 29 in components/factory/modals/updateDenomMetadata.tsx

View check run for this annotation

Codecov / codecov/patch

components/factory/modals/updateDenomMetadata.tsx#L12-L29

Added lines #L12 - L29 were not covered by tests
.supportedImageUrl(),
});

export function UpdateDenomMetadataModal({
openUpdateDenomMetadataModal,
Expand Down Expand Up @@ -116,7 +124,7 @@
<dialog id={modalId} className={`modal ${openUpdateDenomMetadataModal ? 'modal-open' : ''}`}>
<Formik
initialValues={formData}
validationSchema={TokenDetailsSchema}
validationSchema={() => TokenDetailsSchema({ subdenom: baseDenom })}
onSubmit={(values, { resetForm }) => handleUpdate(values, resetForm)}
validateOnChange={true}
validateOnBlur={true}
Expand Down Expand Up @@ -144,7 +152,14 @@

<Form className="py-4 space-y-6">
<div className="grid gap-6 sm:grid-cols-2">
<TextInput label="SUBDENOM" name="subdemom" value={fullDenom} disabled={true} />
<TextInput
label="SUBDENOM"
name="subdenom"
value={fullDenom}
title={fullDenom}
disabled={true}
helperText="This field cannot be modified"
/>
<TextInput
label="NAME"
name="name"
Expand Down
Loading