-
Notifications
You must be signed in to change notification settings - Fork 2
/
PostStartup.tsx
318 lines (282 loc) · 9.65 KB
/
PostStartup.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import { CoreContractAddress, CoreContractAbi } from "../constants/index";
import {
useAccount,
useContract,
useProvider,
useSigner,
useBalance,
} from "wagmi";
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import React, { useEffect, useMemo, useRef, useState } from "react";
import Link from "next/link";
import { Player, useAssetMetrics } from "@livepeer/react";
import { useRouter } from "next/router";
import {
LivepeerConfig,
createReactClient,
studioProvider,
} from "@livepeer/react";
function getKeys() {
return process.env.NEXT_PUBLIC_STUDIO_API_KEY;
}
const livepeerClient = createReactClient({
provider: studioProvider({
apiKey: getKeys() as string,
}),
});
import { HatcheryDaoAbi, HatcheryDaoAddress } from "../constants";
import Head from "next/head";
export default function PostStartup() {
return (
<div className="w-full">
<LivepeerConfig client={livepeerClient}>
<PostStartupExport />
</LivepeerConfig>
</div>
);
}
interface IStartups {
name: string;
tag: string;
desc: string;
amt: string;
// img : string;
// video : string;
}
interface IvidImg{
img : string;
vid : string;
}
function PostStartupExport() {
const provider = useProvider();
const { data: signer } = useSigner();
const { address, isConnected } = useAccount();
const core = useContract({
address: CoreContractAddress,
abi: CoreContractAbi,
signerOrProvider: signer || provider,
});
const sbt = useContract({
address: HatcheryDaoAddress,
abi: HatcheryDaoAbi,
signerOrProvider: signer || provider,
});
const [myStartup, setMyStartup] = useState<IStartups>({
name: "XXXXXX_XXXXX",
tag: "xxxxxxxxxxxXxXXXXxxxxxx XXXX xxxxxxxx XXXX",
desc: "xxxxxxxxxxxXxXXXXxxxxxx XXXX xxxxxxxx XXXX xxxxx yyyyy zzzzz aaa cccc ddddd ssss www www mmmmm fffff jjjj hhhhh hhhh dddd kkkkk gggggg lllllll CREATED BY @shikkhar_",
amt: "XXX XXX",
// img : "initial_img.jpg",
// video : "b66bkq9unt44br5k"
});
const img = useRef("initial_img.jpg");
const video = useRef("aaf8n564dj8nwh19");
const [ imgVid , setImgVid] = useState<IvidImg>({
img : "img/initial_img.jpg",
vid : "aaf8n564dj8nwh19"
})
async function getImgVideo() {
try {
const imgTx = await core?.getImageLink(address);
console.log(imgTx);
// imgTx === "initial_img"
// ? img.current = "initial_img.jpg"
// : img.current = `https://ipfs.io/ipfs/${imgTx}`;
const vidTx = await core?.getVideoHash(address)
console.log(vidTx);
// video.current = (vidTx && vidTx !== "NOT_UPLOADED_YET") ? vidTx : "aaf8n564dj8nwh19"
setImgVid({
img : imgTx === "initial_img" ? "img/initial_img.jpg" : `https://ipfs.io/ipfs/${imgTx}`,
vid : vidTx === "NOT_UPLOADED_YET" ? "aaf8n564dj8nwh19" : vidTx
})
} catch (err) {
toast("Recommended to upload a Video ;)" )
console.log("Recommended to upload a Video ;)");
}
}
const getDataTx = async () => {
try {
const checkS = await sbt?.isStartup(address);
const checkI = await sbt?.isInvestor(address);
console.log(checkS);
if (!(checkS || checkI)){
toast("Buy NFT First")
return;
}
const tx = await core?.getOwnerStartups();
setMyStartup({
name: tx.name,
tag: tx.tagline,
desc: tx.description,
amt: tx.amount.toString(),
// img : imgTx,
// video : vidTx ? vidTx : "b66bkq9unt44br5k"
});
console.log(tx);
getImgVideo();
} catch (err) {
console.log("Post about your Startup first ;)");
toast("Post about your Startup first ;)");
}
};
useEffect(() => {}, []);
return (
<div className=" w-full min-h-screen overflow-x-hidden flex flex-col bg-[url('/img/grad2.jpg')] bg-cover bg-no-repeat items-start gap-8 pt-20 justify-start ">
<Head>
<title>Post Startups</title>
<meta name="description" content="Created with <3 by Shikhar" />
<link rel="icon" href="/hatch.png" />
</Head>
<ToastContainer />
<div className="flex flex-wrap gap-2 ml-16">
<Link
href={{
pathname: "/EditPost",
query: { name: "POST_NEW" },
}}
// onClick={handleActive}
className="rounded-3xl bg-[#fff] hover:shadow-xl hover:scale-110 hover:shadow-purple-600 transition-all duration-200 ease-linear flex items-center justify-center py-1.5 px-3 "
>
<img src="img/plus.png" alt="img" className="sm:w-12 w-8 mr-2" />{" "}
<span>Post your Startup</span>
</Link>
<button
className="rounded-3xl bg-[#fff] hover:shadow-xl hover:scale-110 hover:shadow-purple-600 transition-all duration-200 ease-linear flex items-center justify-center py-0.5 px-2 ml-4 "
onClick={getDataTx}
>
<img src="img/refresh.png" alt="img" className="sm:w-8 w-6 mr-2" />{" "}
<span className="text-sm">Refresh</span>
</button>
</div>
{/* {isMystartup ? ( */}
<div className="w-full flex items-center justify-center">
<div className="sm:w-2/4 w-4/5 h-5/6 bg-white/10 transition-all duration-300 ease-linear backdrop-blur-md flex flex-col items-start justify-center rounded-xl font-jose relative ">
<img
src={imgVid.img}
alt="header"
className="h-60 w-full rounded-t-xl "
/>
<Link
href={{
pathname: "/EditPost",
query: { name: "IMAGE" },
}}
>
<img
src={`img/pencil.png`}
alt="header"
className=" absolute right-2 top-2 w-8 cursor-pointer"
// onClick={() => alert("i am touched")}
/>
</Link>
<div className=" w-9/12 flex items-center mt-4 ml-4 text-white">
<span className="text-2xl font-semibold">{myStartup.name}</span>
<Link
href={{
pathname: "/EditPost",
query: { name: "NAME" },
}}
>
<img
src={`img/pencil.png`}
alt="header"
className="ml-8 w-4 cursor-pointer"
/>
</Link>
</div>
<div className="flex items-center justify-between gap-8 ">
<span className="text-base mt-3 ml-4 text-white ">
Seeking - <b className="font-bold text-xl">${myStartup.amt}</b>
</span>
<Link
href={{
pathname: "/EditPost",
query: { name: "AMOUNT" },
}}
>
<img
src={`img/pencil.png`}
alt="header"
className="w-4 cursor-pointer"
// onClick={() => alert("i am touched")}
/>
</Link>
</div>
<div className="flex items-start flex-col flex-wrap justify-start text-white ">
<span className="mt-3 ml-4 flex items-center font-semibold justify-start text-base tracking-widest w-1/2 ">
Tagline
<Link
href={{
pathname: "/EditPost",
query: { name: "TAGLINE" },
}}
>
<img
src={`img/pencil.png`}
alt="header"
className="w-4 cursor-pointer"
// onClick={() => alert("i am touched")}
/>
</Link>
</span>
<p className=" mt-3 mx-4 text-zinc-300 flex-wrap">
{myStartup.tag}
</p>
</div>
<div className="flex items-start flex-col flex-wrap justify-start text-white ">
<span className="mt-3 ml-4 flex font-semibold items-center justify-start text-base tracking-widest w-1/2 ">
Description
<Link
href={{
pathname: "/EditPost",
query: { name: "DESCRIPTION" },
}}
>
<img
src={`img/pencil.png`}
alt="header"
className="w-4 cursor-pointer"
// onClick={() => alert("i am touched")}
/>
</Link>
</span>
<p className=" mt-3 mx-4 flex-wrap text-zinc-300">
{myStartup.desc}
</p>
</div>
<div className="flex items-start flex-col flex-wrap justify-center text-white w-full ">
<span className="mt-3 ml-4 flex font-semibold items-center justify-start text-base tracking-widest w-1/2 ">
Upload a Video ?
<Link
href={{
pathname: "/EditPost",
query: { name: "VIDEO" },
}}
>
<img
src={`img/pencil.png`}
alt="header"
className="w-4 ml-4 cursor-pointer"
// onClick={() => alert("i am touched")}
/>
</Link>
</span>
<div className="w-full my-4 flex items-center justify-center">
<Player
title={"Video"}
playbackId={imgVid.vid}
autoPlay
muted
autoUrlUpload={{
fallback: true,
ipfsGateway: "https://w3s.link",
}}
/>
</div>
</div>
</div>
</div>
</div>
);
}