From 846dd65a44cfd2f560b12db019d9e2ab4d366a12 Mon Sep 17 00:00:00 2001 From: dan13ram Date: Fri, 7 Oct 2022 14:57:34 +0530 Subject: [PATCH] using latest version of sdk --- components/CreateChain/AddQuestBlock.tsx | 2 +- components/Review/ReviewCommentModal.tsx | 3 +- components/Review/SubmissionTile.tsx | 3 +- package.json | 7 +- utils/metadata.ts | 64 ++---------- utils/schema.json | 120 ---------------------- utils/validate.ts | 22 ---- yarn.lock | 125 +++++++++++++++++++---- 8 files changed, 116 insertions(+), 230 deletions(-) delete mode 100644 utils/schema.json delete mode 100644 utils/validate.ts diff --git a/components/CreateChain/AddQuestBlock.tsx b/components/CreateChain/AddQuestBlock.tsx index 3f89740b..7e8a5dfe 100644 --- a/components/CreateChain/AddQuestBlock.tsx +++ b/components/CreateChain/AddQuestBlock.tsx @@ -1,4 +1,4 @@ -import { Flex, FormControl, FormLabel, Input, VStack } from '@chakra-ui/react'; +import { FormControl, FormLabel, Input, VStack } from '@chakra-ui/react'; import { useCallback } from 'react'; import { toast } from 'react-hot-toast'; diff --git a/components/Review/ReviewCommentModal.tsx b/components/Review/ReviewCommentModal.tsx index f9a67ab9..4c687ced 100644 --- a/components/Review/ReviewCommentModal.tsx +++ b/components/Review/ReviewCommentModal.tsx @@ -19,8 +19,7 @@ import { MarkdownEditor } from '@/components/MarkdownEditor'; import { SubmissionType } from '@/components/Review/SubmissionTile'; import { useInputText } from '@/hooks/useInputText'; import { handleError } from '@/utils/helpers'; -import { uploadMetadata } from '@/utils/metadata'; -import { Metadata } from '@/utils/validate'; +import { Metadata, uploadMetadata } from '@/utils/metadata'; export const ReviewCommentModal: React.FC<{ isModalOpen: boolean; diff --git a/components/Review/SubmissionTile.tsx b/components/Review/SubmissionTile.tsx index 631a715e..527d8022 100644 --- a/components/Review/SubmissionTile.tsx +++ b/components/Review/SubmissionTile.tsx @@ -29,9 +29,8 @@ import { UserDisplay } from '@/components/UserDisplay'; import { useInputText } from '@/hooks/useInputText'; import { formatDate } from '@/utils/dateHelpers'; import { handleError } from '@/utils/helpers'; -import { uploadMetadata } from '@/utils/metadata'; +import { Metadata, uploadMetadata } from '@/utils/metadata'; import { ipfsUriToHttp } from '@/utils/uriHelpers'; -import { Metadata } from '@/utils/validate'; export type { SubmissionType }; diff --git a/package.json b/package.json index 73f1e4ff..ed96038b 100644 --- a/package.json +++ b/package.json @@ -18,19 +18,14 @@ "@emotion/react": "^11.10.4", "@emotion/styled": "^11.10.4", "@gnosis.pm/safe-apps-web3modal": "^17.0.0", - "@quest-chains/sdk": "^0.1.6", + "@quest-chains/sdk": "^0.1.11", "@react-three/drei": "9.26.1", "@react-three/fiber": "8.7.1", "@walletconnect/web3-provider": "^1.8.0", - "ajv": "^8.11.0", - "axios": "^0.27.2", "chakra-ui-markdown-renderer": "^4.1.0", "ethers": "^5.7.0", "fast-memoize": "^2.5.2", "framer-motion": "^7.2.1", - "graphql": "^16.6.0", - "graphql-request": "^5.0.0", - "graphql-tag": "^2.12.6", "html2canvas": "^1.4.1", "next": "12.2.5", "react": "18.2.0", diff --git a/utils/metadata.ts b/utils/metadata.ts index f3a39802..86340e63 100644 --- a/utils/metadata.ts +++ b/utils/metadata.ts @@ -1,63 +1,15 @@ -import axios, { AxiosError } from 'axios'; +import { metadata } from '@quest-chains/sdk'; import { API_URL } from './constants'; -import { Metadata as MetadataType, validateSchema } from './validate'; -export type Metadata = MetadataType; +export type Metadata = metadata.Metadata; -type HttpResponse = { response: unknown; error: string }; +const MetadataUploader = metadata.MetadataUploader; -export const uploadMetadata = async ( - metadata: MetadataType, -): Promise => { - const valid = validateSchema(metadata); - if (!valid) throw new Error('Invalid Metadata Schema'); +export const uploader = new MetadataUploader(API_URL); - const config = { - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - }; +export const uploadMetadata = async (metadata: Metadata): Promise => + uploader.uploadMetadata(metadata); - try { - const res = await axios.post(`${API_URL}/upload/json`, metadata, config); - return res.data.response; - } catch (error) { - throw new Error( - ((error as AxiosError).response?.data as HttpResponse).error, - ); - } -}; - -export const uploadFiles = async ( - files: File[] | FileList, -): Promise => { - const formData = new FormData(); - for (let i = 0; i < files.length; ++i) { - formData.append(files[i].name, files[i]); - } - - const config = { - headers: { - 'Content-Type': 'multipart/form-data', - Accept: 'application/json', - }, - onUploadProgress: (event: { loaded: number; total: number }) => { - // eslint-disable-next-line no-console - console.log( - `Current progress:`, - Math.round((event.loaded * 100) / event.total), - ); - }, - }; - - try { - const res = await axios.post(`${API_URL}/upload/files`, formData, config); - return res.data.response; - } catch (error) { - throw new Error( - ((error as AxiosError).response?.data as HttpResponse).error, - ); - } -}; +export const uploadFiles = async (files: File[] | FileList): Promise => + uploader.uploadFiles(files as File[]); diff --git a/utils/schema.json b/utils/schema.json deleted file mode 100644 index e7e949c3..00000000 --- a/utils/schema.json +++ /dev/null @@ -1,120 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema", - "type": "object", - "title": "Quest Chain Metadata", - "description": "This defines the schema for the metadata supported by Quest Chain System", - "default": {}, - "examples": [ - { - "name": "DAO Quest", - "description": "This describes the quest", - "image_url": "ipfs://QmZTzK8YAsPcLoKENzWmXv519pDmX1XgNQ6h9RtnSjwksn", - "external_url": "ipfs://QmZTzK8YAsPcLoKENzWmXv519pDmX1XgNQ6h9RtnSjwksn" - } - ], - "required": ["name", "description"], - "properties": { - "name": { - "$id": "#/properties/name", - "type": "string", - "title": "The name schema", - "description": "This property is the name of the item", - "default": "", - "examples": ["DAO Quest"] - }, - "description": { - "$id": "#/properties/description", - "type": "string", - "title": "The description schema", - "description": "This property is the description of the item in plain text or optionally in markdown", - "default": "", - "examples": ["This describes the quest"] - }, - "image_url": { - "$id": "#/properties/image_url", - "type": "string", - "title": "The image_url schema", - "description": "This property defines an optional image URL for the item", - "default": "", - "examples": ["ipfs://QmZTzK8YAsPcLoKENzWmXv519pDmX1XgNQ6h9RtnSjwksn"] - }, - "animation_url": { - "$id": "#/properties/animation_url", - "type": "string", - "title": "The animation_url schema", - "description": "This property defines an optional animation URL that can reference a multi-media attachment of the item", - "default": "", - "examples": ["ipfs://QmZTzK8YAsPcLoKENzWmXv519pDmX1XgNQ6h9RtnSjwksn"] - }, - "external_url": { - "$id": "#/properties/external_url", - "type": "string", - "title": "The external_url schema", - "description": "This property defines an optional external URL that can reference a webpage or external asset of the item", - "default": "", - "examples": ["ipfs://QmZTzK8YAsPcLoKENzWmXv519pDmX1XgNQ6h9RtnSjwksn"] - }, - "attributes": { - "$id": "#/properties/attributes", - "type": "array", - "title": "Attributes", - "description": "OpenSea NFT attributes", - "default": [], - "examples": [ - [ - { - "trait_type": "Base", - "value": "narwhal" - } - ] - ], - "items": { - "$id": "#/properties/attributes/items", - "anyOf": [ - { - "$id": "#/properties/attributes/items/anyOf/0", - "type": "object", - "title": "Attributes Item", - "description": "OpenSea NFT attribute", - "default": {}, - "examples": [ - { - "trait_type": "Base", - "value": "narwhal" - } - ], - "required": ["value"], - "properties": { - "display_type": { - "$id": "#/properties/attributes/items/anyOf/0/properties/display_type", - "type": "string", - "enum": ["number", "boost_number", "boost_percentage"], - "title": "Display Type", - "description": "OpenSea NFT attribute display type", - "default": "", - "examples": ["number"] - }, - "trait_type": { - "$id": "#/properties/attributes/items/anyOf/0/properties/trait_type", - "type": "string", - "title": "Trait Type", - "description": "OpenSea NFT attribute trait type", - "default": "", - "examples": ["Base"] - }, - "value": { - "$id": "#/properties/attributes/items/anyOf/0/properties/value", - "type": ["string", "number"], - "title": "Trait Value", - "description": "OpenSea NFT attribute value type", - "default": "", - "examples": ["narwhal", 5] - } - } - } - ] - } - } - }, - "additionalProperties": false -} diff --git a/utils/validate.ts b/utils/validate.ts deleted file mode 100644 index 6df829ba..00000000 --- a/utils/validate.ts +++ /dev/null @@ -1,22 +0,0 @@ -import Ajv from 'ajv'; - -import schema from './schema.json'; - -const ajv = new Ajv({ allowUnionTypes: true }); -const validate = ajv.compile(schema); - -export type Metadata = { - name: string; - description: string; - image_url?: string; - animation_url?: string; - external_url?: string; - attributes?: { - trait_type?: string; - value: string | number; - display_type?: 'number' | 'boost_number' | 'boost_percentage'; - }[]; -}; - -export const validateSchema = (metadata: Metadata): boolean => - validate(metadata); diff --git a/yarn.lock b/yarn.lock index 9df874ce..a7329b65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1487,6 +1487,13 @@ dependencies: "@ethersproject/logger" "^5.7.0" +"@ethersproject/networks@5.7.1": + version "5.7.1" + resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.7.1.tgz#118e1a981d757d45ccea6bb58d9fd3d9db14ead6" + integrity sha512-n/MufjFYv3yFcUyfhnXotyDlNdFb7onmkSy8aQERi2PjNcnWQ66xXxa3XlS8nCcA8aJKJjIIMNJTC7tu80GwpQ== + dependencies: + "@ethersproject/logger" "^5.7.0" + "@ethersproject/pbkdf2@5.6.1", "@ethersproject/pbkdf2@^5.6.1": version "5.6.1" resolved "https://registry.yarnpkg.com/@ethersproject/pbkdf2/-/pbkdf2-5.6.1.tgz#f462fe320b22c0d6b1d72a9920a3963b09eb82d1" @@ -1569,6 +1576,32 @@ bech32 "1.1.4" ws "7.4.6" +"@ethersproject/providers@5.7.1": + version "5.7.1" + resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.7.1.tgz#b0799b616d5579cd1067a8ebf1fc1ec74c1e122c" + integrity sha512-vZveG/DLyo+wk4Ga1yx6jSEHrLPgmTt+dFv0dv8URpVCRf0jVhalps1jq/emN/oXnMRsC7cQgAF32DcXLL7BPQ== + dependencies: + "@ethersproject/abstract-provider" "^5.7.0" + "@ethersproject/abstract-signer" "^5.7.0" + "@ethersproject/address" "^5.7.0" + "@ethersproject/base64" "^5.7.0" + "@ethersproject/basex" "^5.7.0" + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/constants" "^5.7.0" + "@ethersproject/hash" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/networks" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/random" "^5.7.0" + "@ethersproject/rlp" "^5.7.0" + "@ethersproject/sha2" "^5.7.0" + "@ethersproject/strings" "^5.7.0" + "@ethersproject/transactions" "^5.7.0" + "@ethersproject/web" "^5.7.0" + bech32 "1.1.4" + ws "7.4.6" + "@ethersproject/random@5.6.1", "@ethersproject/random@^5.6.1": version "5.6.1" resolved "https://registry.yarnpkg.com/@ethersproject/random/-/random-5.6.1.tgz#66915943981bcd3e11bbd43733f5c3ba5a790255" @@ -1797,6 +1830,17 @@ "@ethersproject/properties" "^5.7.0" "@ethersproject/strings" "^5.7.0" +"@ethersproject/web@5.7.1": + version "5.7.1" + resolved "https://registry.yarnpkg.com/@ethersproject/web/-/web-5.7.1.tgz#de1f285b373149bee5928f4eb7bcb87ee5fbb4ae" + integrity sha512-Gueu8lSvyjBWL4cYsWsjh6MtMwM0+H4HvqFPZfB6dV8ctbP9zFAO73VG1cMWae0FLPCtz0peKPpZY8/ugJJX2w== + dependencies: + "@ethersproject/base64" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/strings" "^5.7.0" + "@ethersproject/wordlists@5.6.1", "@ethersproject/wordlists@^5.6.1": version "5.6.1" resolved "https://registry.yarnpkg.com/@ethersproject/wordlists/-/wordlists-5.6.1.tgz#1e78e2740a8a21e9e99947e47979d72e130aeda1" @@ -2039,17 +2083,19 @@ resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.2.tgz#830beaec4b4091a9e9398ac50f865ddea52186b9" integrity sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA== -"@quest-chains/sdk@^0.1.6": - version "0.1.6" - resolved "https://registry.yarnpkg.com/@quest-chains/sdk/-/sdk-0.1.6.tgz#8f38ce354ee4c72311b5485b046e51643d8bc987" - integrity sha512-qKGU4Lkk+SUwA31bRhEEl8UhXb21XCypRmGAUrGleoJLZBL3f2ISG2dLhICAkyTN/fWz0cuxFYi4gCX9p19tXw== +"@quest-chains/sdk@^0.1.11": + version "0.1.11" + resolved "https://registry.yarnpkg.com/@quest-chains/sdk/-/sdk-0.1.11.tgz#fec53258b4c16d1ceb037eadd0565d392003da78" + integrity sha512-EVKK9CeMUTKMqyQEnYtYFvv3YLQhA9TDoHwjf673xGrfONW5jp8LWf2/lBTZtWmzHaca5KUM/+UqZo4HEtZk7A== dependencies: ajv "^8.11.0" - axios "^0.27.2" - ethers "^5.6.9" + axios "^1.1.1" + ethers "^5.7.1" fast-memoize "^2.5.2" + form-data "^4.0.0" graphql "^16.5.0" graphql-request "^5.0.0" + graphql-tag "^2.12.6" urql "^3.0.3" "@react-spring/animated@~9.4.4": @@ -2908,13 +2954,14 @@ axe-core@^4.4.2, axe-core@^4.4.3: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.3.tgz#11c74d23d5013c0fa5d183796729bc3482bd2f6f" integrity sha512-32+ub6kkdhhWick/UjvEwRchgoetXqTK14INLqbGm5U2TzBkBNF3nQtLYm8ovxSkQWArjEQvftCKryjZaATu3w== -axios@^0.27.2: - version "0.27.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" - integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== +axios@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.1.tgz#ce2fd17b4517150e0ff475922a70453d5e3f7f37" + integrity sha512-hUo0TDluM7WPGeM2834mualoT0vGt9vcA+02dgfCiSpSPGdKbMhNbnTUwDf5hs6e4oc8yO7jGI33sSKtW7FRDQ== dependencies: - follow-redirects "^1.14.9" + follow-redirects "^1.15.0" form-data "^4.0.0" + proxy-from-env "^1.1.0" axobject-query@^2.2.0: version "2.2.0" @@ -4367,7 +4414,7 @@ ethereumjs-vm@^2.3.4: rustbn.js "~0.2.0" safe-buffer "^5.1.1" -ethers@^5.6.8, ethers@^5.6.9: +ethers@^5.6.8: version "5.6.9" resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.6.9.tgz#4e12f8dfcb67b88ae7a78a9519b384c23c576a4d" integrity sha512-lMGC2zv9HC5EC+8r429WaWu3uWJUCgUCt8xxKCFqkrFuBDZXDYIdzDUECxzjf2BMF8IVBByY1EBoGSL3RTm8RA== @@ -4439,6 +4486,42 @@ ethers@^5.7.0: "@ethersproject/web" "5.7.0" "@ethersproject/wordlists" "5.7.0" +ethers@^5.7.1: + version "5.7.1" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.1.tgz#48c83a44900b5f006eb2f65d3ba6277047fd4f33" + integrity sha512-5krze4dRLITX7FpU8J4WscXqADiKmyeNlylmmDLbS95DaZpBhDe2YSwRQwKXWNyXcox7a3gBgm/MkGXV1O1S/Q== + dependencies: + "@ethersproject/abi" "5.7.0" + "@ethersproject/abstract-provider" "5.7.0" + "@ethersproject/abstract-signer" "5.7.0" + "@ethersproject/address" "5.7.0" + "@ethersproject/base64" "5.7.0" + "@ethersproject/basex" "5.7.0" + "@ethersproject/bignumber" "5.7.0" + "@ethersproject/bytes" "5.7.0" + "@ethersproject/constants" "5.7.0" + "@ethersproject/contracts" "5.7.0" + "@ethersproject/hash" "5.7.0" + "@ethersproject/hdnode" "5.7.0" + "@ethersproject/json-wallets" "5.7.0" + "@ethersproject/keccak256" "5.7.0" + "@ethersproject/logger" "5.7.0" + "@ethersproject/networks" "5.7.1" + "@ethersproject/pbkdf2" "5.7.0" + "@ethersproject/properties" "5.7.0" + "@ethersproject/providers" "5.7.1" + "@ethersproject/random" "5.7.0" + "@ethersproject/rlp" "5.7.0" + "@ethersproject/sha2" "5.7.0" + "@ethersproject/signing-key" "5.7.0" + "@ethersproject/solidity" "5.7.0" + "@ethersproject/strings" "5.7.0" + "@ethersproject/transactions" "5.7.0" + "@ethersproject/units" "5.7.0" + "@ethersproject/wallet" "5.7.0" + "@ethersproject/web" "5.7.1" + "@ethersproject/wordlists" "5.7.0" + ethjs-util@0.1.6, ethjs-util@^0.1.3: version "0.1.6" resolved "https://registry.yarnpkg.com/ethjs-util/-/ethjs-util-0.1.6.tgz#f308b62f185f9fe6237132fb2a9818866a5cd536" @@ -4635,10 +4718,10 @@ focus-lock@^0.11.2: dependencies: tslib "^2.0.3" -follow-redirects@^1.14.9: - version "1.15.1" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5" - integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA== +follow-redirects@^1.15.0: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== forever-agent@~0.6.1: version "0.6.1" @@ -4912,11 +4995,6 @@ graphql@^16.5.0: resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.5.0.tgz#41b5c1182eaac7f3d47164fb247f61e4dfb69c85" integrity sha512-qbHgh8Ix+j/qY+a/ZcJnFQ+j8ezakqPiHwPiZhV/3PgGlgf96QMBB5/f2rkiC9sgLoy/xvT6TSiaf2nTHJh5iA== -graphql@^16.6.0: - version "16.6.0" - resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.6.0.tgz#c2dcffa4649db149f6282af726c8c83f1c7c5fdb" - integrity sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw== - har-schema@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" @@ -6796,6 +6874,11 @@ property-information@^6.0.0: resolved "https://registry.yarnpkg.com/property-information/-/property-information-6.1.1.tgz#5ca85510a3019726cb9afed4197b7b8ac5926a22" integrity sha512-hrzC564QIl0r0vy4l6MvRLhafmUowhO/O3KgVSoXIbbA2Sz4j8HGpJc6T2cubRVwMwpdiG/vKGfhT4IixmKN9w== +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + prr@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"