Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit 2216809

Browse files
committed
fix: remove json validator
1 parent 4d094bd commit 2216809

8 files changed

Lines changed: 98 additions & 645 deletions

File tree

package-lock.json

Lines changed: 91 additions & 499 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@solana/wallet-adapter-react-ui": "^0.9.12",
4242
"@solana/wallet-adapter-wallets": "^0.17.2",
4343
"@solana/web3.js": "^1.44.2",
44-
"ajv": "^8.11.0",
4544
"axios": "^0.27.2",
4645
"bignumber.js": "^9.0.2",
4746
"crypto-browserify": "^3.12.0",

src/components/info/Acknowledgements.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ export const Acknowledgements: React.FC = () => (
5050
<br />
5151
@solana/web3.js (1.51.0), licenced MIT
5252
<br />
53-
ajv (8.11.0), licenced MIT
54-
<br />
5553
axios (0.27.2), licenced MIT
5654
<br />
5755
bignumber.js (9.0.2), licenced MIT

src/components/palette/import/AnchorJsonImport.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export const AnchorJsonImport: React.FC<{
66
setPreview: (tranaction: IPreview | undefined) => void;
77
setError: (error: string) => void;
88
}> = ({ setPreview, setError }) => {
9-
// TODO
10-
// const validate = useMemo(() => new Ajv().compile(JSON_SCHEMA), []);
11-
129
const parse = (json: string) => {
1310
if (!json) return;
1411

@@ -18,18 +15,11 @@ export const AnchorJsonImport: React.FC<{
1815
let prasedJson;
1916
try {
2017
prasedJson = JSON.parse(json);
18+
setPreview(mapIdlToIPreview(prasedJson, "anchorJson", ""));
2119
} catch (e) {
2220
setError("Invalid JSON");
2321
return;
2422
}
25-
26-
// TODO
27-
// if (!validate(prasedJson)) {
28-
// setError(validate.errors?.map((e) => e.message).join(", ")!);
29-
// return;
30-
// }
31-
32-
setPreview(mapIdlToIPreview(prasedJson, "anchorJson", ""));
3323
};
3424

3525
return (

src/components/palette/import/ShareJsonImport.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
import { Flex, Textarea } from "@chakra-ui/react";
2-
import Ajv from "ajv";
3-
import { useMemo } from "react";
42
import { mapITransactionExtToIPreview } from "../../../mappers/external-to-preview";
5-
import { JSON_SCHEMA } from "../../../types/external";
63
import { IPreview } from "../../../types/preview";
74

85
export const ShareJsonImport: React.FC<{
96
setPreview: (tranaction: IPreview | undefined) => void;
107
setError: (error: string) => void;
118
}> = ({ setPreview, setError }) => {
12-
const validate = useMemo(() => new Ajv().compile(JSON_SCHEMA), []);
13-
149
const parse = (json: string) => {
1510
if (!json) return;
1611

@@ -20,19 +15,13 @@ export const ShareJsonImport: React.FC<{
2015
let prasedJson;
2116
try {
2217
prasedJson = JSON.parse(json);
18+
setPreview(
19+
mapITransactionExtToIPreview(prasedJson as IPreview, "shareJson", "")
20+
);
2321
} catch (e) {
2422
setError("Invalid JSON");
2523
return;
2624
}
27-
28-
if (!validate(prasedJson)) {
29-
setError(validate.errors?.map((e) => e.message).join(", ")!);
30-
return;
31-
}
32-
33-
setPreview(
34-
mapITransactionExtToIPreview(prasedJson as IPreview, "shareJson", "")
35-
);
3625
};
3726

3827
return (

src/components/palette/import/ShareUrlImport.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { DownloadIcon } from "@chakra-ui/icons";
22
import { Flex, IconButton, Input, Tooltip } from "@chakra-ui/react";
3-
import Ajv from "ajv";
43
import axios from "axios";
5-
import { useMemo, useState } from "react";
4+
import { useState } from "react";
65
import { mapITransactionExtToIPreview } from "../../../mappers/external-to-preview";
7-
import { JSON_SCHEMA } from "../../../types/external";
86
import { IPreview } from "../../../types/preview";
97

108
export const ShareUrlImport: React.FC<{
@@ -13,7 +11,6 @@ export const ShareUrlImport: React.FC<{
1311
}> = ({ setPreview, setError }) => {
1412
const [url, setUrl] = useState("");
1513
const [inProgress, setInprogress] = useState(false);
16-
const validate = useMemo(() => new Ajv().compile(JSON_SCHEMA), []);
1714

1815
const fetch = async () => {
1916
if (!url) return;
@@ -24,10 +21,6 @@ export const ShareUrlImport: React.FC<{
2421

2522
try {
2623
const response = await axios.get(url);
27-
if (!validate(response.data)) {
28-
setError(validate.errors?.map((e) => e.message).join(", ")!);
29-
return;
30-
}
3124
setPreview(
3225
mapITransactionExtToIPreview(response.data as IPreview, "shareUrl", url)
3326
);

src/hooks/useImportFromUrl.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { useToast } from "@chakra-ui/react";
2-
import Ajv from "ajv";
32
import axios from "axios";
4-
import { useEffect, useMemo } from "react";
3+
import { useEffect } from "react";
54
import { useSearchParams } from "react-router-dom";
65
import { mapITransactionExtToIPreview } from "../mappers/external-to-preview";
76
import { mapTransactionResponseToIPreview } from "../mappers/web3js-to-preview";
8-
import { JSON_SCHEMA } from "../types/external";
97
import { IPreview } from "../types/preview";
108
import { useGetWeb3Transaction } from "./useGetWeb3Transaction";
119
import { usePersistentStore } from "./usePersistentStore";
@@ -60,8 +58,6 @@ export const useImport = () => {
6058
},
6159
});
6260

63-
const validate = useMemo(() => new Ajv().compile(JSON_SCHEMA), []);
64-
6561
// TODO load the transaction in the preview sidebar
6662
// const preview = searchParams.has("preview");
6763

@@ -88,19 +84,6 @@ export const useImport = () => {
8884
axios
8985
.get(share)
9086
.then((response) => {
91-
if (!validate(response.data)) {
92-
setIsLoading(false);
93-
// TODO why is this triggering 3 times?
94-
toast({
95-
title: "Transaction import failed",
96-
description: `Invalid JSON from URL`,
97-
status: "error",
98-
duration: 15000,
99-
isClosable: true,
100-
});
101-
return;
102-
}
103-
10487
set((state) => {
10588
state.import = {
10689
isLoading: false,
@@ -122,5 +105,5 @@ export const useImport = () => {
122105
isClosable: true,
123106
});
124107
});
125-
}, [share, set, setIsLoading, setSearchParams, toast, validate]);
108+
}, [share, set, setIsLoading, setSearchParams, toast]);
126109
};

src/types/external.ts

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -34,94 +34,3 @@ export interface ITransactionExt {
3434
description?: string;
3535
instructions: IInstructionExt[];
3636
}
37-
38-
// TODO add required fields for validation
39-
export const JSON_SCHEMA = {
40-
type: "object",
41-
properties: {
42-
name: { type: "string" },
43-
description: { type: "string" },
44-
instructions: {
45-
type: "array",
46-
items: {
47-
type: "object",
48-
properties: {
49-
name: { type: "string" },
50-
description: { type: "string" },
51-
programId: { type: "string" },
52-
accounts: {
53-
type: "array",
54-
items: {
55-
type: "object",
56-
properties: {
57-
name: { type: "string" },
58-
description: { type: "string" },
59-
pubkey: { type: "string" },
60-
isWritable: { type: "boolean" },
61-
isSigner: { type: "boolean" },
62-
},
63-
},
64-
},
65-
data: {
66-
type: "object",
67-
properties: {
68-
format: {
69-
type: "string",
70-
enum: ["raw", "bufferLayout", "borsh"],
71-
},
72-
value: {
73-
anyOf: [
74-
{ type: "string" },
75-
{
76-
type: "array",
77-
items: {
78-
type: "object",
79-
properties: {
80-
name: { type: "string" },
81-
description: { type: "string" },
82-
type: {
83-
type: "string",
84-
enum: [
85-
"string",
86-
"u8",
87-
"i8",
88-
"u16",
89-
"i16",
90-
"u32",
91-
"i32",
92-
"u64",
93-
"i64",
94-
"bool",
95-
"publicKey",
96-
],
97-
},
98-
value: {}, // match any
99-
},
100-
},
101-
},
102-
],
103-
},
104-
},
105-
},
106-
anchorMethod: {
107-
type: "string",
108-
},
109-
anchorAccounts: {
110-
type: "array",
111-
// TODO code duplication with the above
112-
items: {
113-
type: "object",
114-
properties: {
115-
name: { type: "string" },
116-
description: { type: "string" },
117-
pubkey: { type: "string" },
118-
isWritable: { type: "boolean" },
119-
isSigner: { type: "boolean" },
120-
},
121-
},
122-
},
123-
},
124-
},
125-
},
126-
},
127-
};

0 commit comments

Comments
 (0)