Skip to content

Commit

Permalink
Merge pull request #653 from 0xPolygonID/feature/support-positive-non…
Browse files Browse the repository at this point in the history
…-negative-integers

feat: add custom positive-integer/non-negative-integer formats
  • Loading branch information
volodymyr-basiuk authored Apr 12, 2024
2 parents a6a1550 + b48a30d commit a449cb1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ui/src/components/credentials/IssueCredentialForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ export function IssueCredentialForm({

const [refreshServiceChecked, setRefreshServiceChecked] = useState(false);

const isPositiveBigInt = (x: string) => {
try {
return BigInt(x).toString() === x && BigInt(x) > 0;
} catch {
return false;
}
};

const isNonNegativeBigInt = (x: string) => {
try {
return BigInt(x).toString() === x && BigInt(x) >= 0;
} catch {
return false;
}
};

function isFormValid(value: Record<string, unknown>, objectAttribute: ObjectAttribute): boolean {
if (isAsyncTaskDataAvailable(jsonSchema)) {
const serializedSchemaForm = serializeSchemaForm({
Expand All @@ -126,6 +142,14 @@ export function IssueCredentialForm({
? new Ajv2020({ allErrors: true })
: new Ajv({ allErrors: true });
addFormats(ajv);
ajv.addFormat("positive-integer", {
type: "string",
validate: isPositiveBigInt,
});
ajv.addFormat("non-negative-integer", {
type: "string",
validate: isNonNegativeBigInt,
});
ajv.addVocabulary(["$metadata"]);
applyDraft2019Formats(ajv);

Expand Down

0 comments on commit a449cb1

Please sign in to comment.