Skip to content

Commit

Permalink
Merge branch 'release-0.3.17' of https://github.com/spect-ai/circles.v1
Browse files Browse the repository at this point in the history
… into develop
  • Loading branch information
avp1598 committed Mar 31, 2023
2 parents 8654773 + 9038a5b commit dc1b42c
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 18 deletions.
64 changes: 48 additions & 16 deletions app/common/utils/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
import { create } from "ipfs-http-client";
import ImageKit from "imagekit-javascript";
// SDK initialization

var imagekit = new ImageKit({
publicKey: "public_CqD2Qv50op/DuvGfKx9tDIDqNTc=",
urlEndpoint: "https://ik.imagekit.io/spectcdn",
authenticationEndpoint: "https://circles.spect.network/api/authImageKit",
});

// URL generation

// Upload function internally uses the ImageKit.io javascript SDK
// function upload(data) {
// var file = document.getElementById("file1");
// imagekit.upload({
// file : file.files[0],
// fileName : "abc1.jpg",
// tags : ["tag1"]
// }, function(err, result) {
// console.log(arguments);
// console.log(imagekit.url({
// src: result.url,
// transformation : [{ height: 300, width: 400}]
// }));
// })
// }

export async function storeImage(imageFile: File) {
const projectId = "2E6toVcDcGO87J2tX6GHK4aBILR";
const projectSecret = "9f96144517b0a20eef70c46239ab0ad7";
const auth =
"Basic " + Buffer.from(projectId + ":" + projectSecret).toString("base64");

const client = create({
host: "ipfs.infura.io",
port: 5001,
protocol: "https",
headers: {
authorization: auth,
},
});
// const projectId = "2E6toVcDcGO87J2tX6GHK4aBILR";
// const projectSecret = "9f96144517b0a20eef70c46239ab0ad7";
// const auth =
// "Basic " + Buffer.from(projectId + ":" + projectSecret).toString("base64");

const res = await client.add(imageFile);
// const client = create({
// host: "ipfs.infura.io",
// port: 5001,
// protocol: "https",
// headers: {
// authorization: auth,
// },
// });

return { imageGatewayURL: `https://spect.infura-ipfs.io/ipfs/${res.cid}` };
// const res = await client.add(imageFile);

// return { imageGatewayURL: `https://spect.infura-ipfs.io/ipfs/${res.cid}` };

const res = await imagekit.upload({
file: imageFile,
fileName: imageFile.name,
});
console.log({ res });
return { imageGatewayURL: res.url };
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import {
hasClaimedSurveyToken,
isEligibleToClaimSurveyToken,
} from "@/app/services/SurveyProtocol";
import { socketAtom } from "@/app/state/global";
import { CollectionType, Registry } from "@/app/types";
import { TwitterOutlined } from "@ant-design/icons";
import { Box, IconDocumentsSolid, Stack, Text } from "degen";
import { BigNumber, ethers } from "ethers";
import { useAtom } from "jotai";
import _ from "lodash";
import { useEffect, useState } from "react";
import { useQuery } from "react-query";
import { TwitterShareButton } from "react-share";
Expand All @@ -35,6 +38,7 @@ const CollectERC20 = ({ form, setClaimedJustNow, preview }: Props) => {
useState(
form?.formMetadata?.transactionHashesOfUser?.surveyTokenClaim || ""
);
const [socket, setSocket] = useAtom(socketAtom);

const { address } = useAccount();

Expand All @@ -49,6 +53,24 @@ const CollectERC20 = ({ form, setClaimedJustNow, preview }: Props) => {
}
);

// useEffect(() => {
// console.log("on");
// if (socket)
// socket?.on(
// `${form.id}:responseAddedOnChain`,
// _.debounce(async (event: { userAddress: string }) => {
// if (event.userAddress === address) {
// setCanClaimSurveyToken(true);
// }
// }, 2000)
// );
// return () => {
// if (socket && socket.off) {
// socket.off(`${form.id}:responseAddedOnChain`);
// }
// };
// }, [socket]);

useEffect(() => {
fetchRegistry();
}, []);
Expand Down Expand Up @@ -346,6 +368,21 @@ const CollectERC20 = ({ form, setClaimedJustNow, preview }: Props) => {
</Stack>
</Stack>
)}
{(preview ||
(form.formMetadata?.previousResponses?.length > 0 &&
form.formMetadata?.surveyTokenId &&
surveyIsLotteryYetToBeDrawn &&
!escrowHasInsufficientBalance)) && (
<Stack direction="horizontal" align="flex-start" wrap>
<Stack>
<Text weight="semiBold" variant="large">
You have been automatically entered into a lottery for
responding to this form. You'll be notified via email if you
win.
</Text>
</Stack>
</Stack>
)}
</Box>
)}
</Box>
Expand Down
2 changes: 2 additions & 0 deletions app/modules/Plugins/erc20/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,14 @@ export default function DistributeERC20({
}
onClick={async () => {
try {
setIsLoading(true);
if (!registry) return;
if (
selectedToken?.value !== "0x0" &&
!currentUser?.ethAddress
) {
console.log("no eth address");
setIsLoading(false);
return;
}

Expand Down
8 changes: 6 additions & 2 deletions app/modules/PublicForm/FormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ function FormFields({ form, setForm }: Props) {
useEffect(() => {
if (form && form.formMetadata.previousResponses?.length > 0) {
setSubmitted(true);
setCurrentPage("submitted");

if (form.formMetadata.surveyTokenId) {
setCurrentPage("collect");
} else setCurrentPage("submitted");
}
}, [form?.name]);

Expand Down Expand Up @@ -484,6 +487,7 @@ function FormFields({ form, setForm }: Props) {
const pages = form.formMetadata.pages;
const pageOrder = form.formMetadata.pageOrder;
const fields = pages[currentPage || ""]?.properties;

return (
<FormFieldContainer
display="flex"
Expand All @@ -493,7 +497,7 @@ function FormFields({ form, setForm }: Props) {
>
<Stack>
{fields.map((field) => {
if (form.properties[field].isPartOfFormView) {
if (form.properties[field]?.isPartOfFormView) {
return (
<PublicField
form={form}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"export-to-csv": "^0.2.1",
"framer-motion": "^6.3.11",
"graphql": "^16.6.0",
"imagekit": "^4.1.3",
"imagekit-javascript": "^1.5.5",
"ipfs-http-client": "^57.0.3",
"jotai": "^1.8.4",
"match-sorter": "^6.3.1",
Expand Down
27 changes: 27 additions & 0 deletions pages/api/authImageKit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// auth image kit
import { NextApiRequest, NextApiResponse } from "next";
import ImageKit from "imagekit";

const imagekit = new ImageKit({
publicKey: "public_CqD2Qv50op/DuvGfKx9tDIDqNTc=",
urlEndpoint: "https://ik.imagekit.io/spectcdn",
privateKey: process.env.IMAGEKIT_PRIVATE_KEY || "",
});

export default async (req: NextApiRequest, res: NextApiResponse) => {
console.log("auth image kit");
try {
const signatureObj = imagekit.getAuthenticationParameters(
req.query.token as string,
parseInt(req.query.expire as string)
);

res.status(200).send(signatureObj);
} catch (err) {
console.error(
"Error while responding to auth request:",
JSON.stringify(err, undefined, 2)
);
res.status(500).send("Internal Server Error");
}
};
44 changes: 44 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6591,6 +6591,14 @@ axios@^0.26.1:
dependencies:
follow-redirects "^1.14.8"

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==
dependencies:
follow-redirects "^1.14.9"
form-data "^4.0.0"

axobject-query@^2.2.0:
version "2.2.0"
resolved "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz"
Expand Down Expand Up @@ -10229,6 +10237,11 @@ follow-redirects@^1.14.0, follow-redirects@^1.14.8:
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz"
integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==

follow-redirects@^1.14.9:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz"
Expand Down Expand Up @@ -10295,6 +10308,15 @@ form-data@^3.0.0:
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down Expand Up @@ -10752,6 +10774,11 @@ graphql@^16.5.0, graphql@^16.6.0:
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.6.0.tgz#c2dcffa4649db149f6282af726c8c83f1c7c5fdb"
integrity sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw==

hamming-distance@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hamming-distance/-/hamming-distance-1.0.0.tgz#39bfa46c61f39e87421e4035a1be4f725dd7b931"
integrity sha512-hYz2IIKtyuZGfOqCs7skNiFEATf+v9IUNSOaQSr6Ll4JOxxWhOvXvc3mIdCW82Z3xW+zUoto7N/ssD4bDxAWoA==

handlebars@^4.7.7:
version "4.7.7"
resolved "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz"
Expand Down Expand Up @@ -11192,6 +11219,23 @@ ignore@^5.2.0:
resolved "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz"
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==

imagekit-javascript@^1.5.5:
version "1.5.5"
resolved "https://registry.yarnpkg.com/imagekit-javascript/-/imagekit-javascript-1.5.5.tgz#2b31994111eb94426ba1abf527774af11e0decb4"
integrity sha512-WnEq7zIiYx+bN1fUzLEqSD33xOCEhHpDmlo3SxQkXPiLBnnnLGhBZi583wNhBXP3RB/yQQEKOBeOelnZ7WVgPA==

imagekit@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/imagekit/-/imagekit-4.1.3.tgz#fcf87ceb46bdfa8e160c330b00d49e061b15bd5e"
integrity sha512-umaeLfItgr3P7VIUIPkowbE3L+uGLl8pCg3NKiJTWiTl48qVVfXnqPJ81w5f/D4xQd5VyEub2dF7Md+LA61bgg==
dependencies:
axios "^0.27.2"
form-data "^4.0.0"
hamming-distance "^1.0.0"
lodash "^4.17.15"
tslib "^2.4.0"
uuid "^8.3.2"

import-fresh@^3.0.0, import-fresh@^3.1.0, import-fresh@^3.2.1:
version "3.3.0"
resolved "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz"
Expand Down

0 comments on commit dc1b42c

Please sign in to comment.