Skip to content

Commit

Permalink
using latest version of sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Oct 7, 2022
1 parent bad450c commit 846dd65
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 230 deletions.
2 changes: 1 addition & 1 deletion components/CreateChain/AddQuestBlock.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
3 changes: 1 addition & 2 deletions components/Review/ReviewCommentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions components/Review/SubmissionTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
64 changes: 8 additions & 56 deletions utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -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<string> => {
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<string> =>
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<string> => {
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<string> =>
uploader.uploadFiles(files as File[]);
120 changes: 0 additions & 120 deletions utils/schema.json

This file was deleted.

22 changes: 0 additions & 22 deletions utils/validate.ts

This file was deleted.

Loading

0 comments on commit 846dd65

Please sign in to comment.