-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.js
More file actions
530 lines (438 loc) · 14.5 KB
/
Copy pathcreate.js
File metadata and controls
530 lines (438 loc) · 14.5 KB
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
// import { createBounty, showToast } from "./dashboard.js";
// import { getConnectedWallet } from "./wallet.js";
let currentStep = 1;
const steps = [
document.getElementById("step1"),
document.getElementById("step2"),
document.getElementById("step3"),
document.getElementById("step4"),
];
const pages = [
document.getElementById("page1"),
document.getElementById("page2"),
document.getElementById("page3"),
document.getElementById("page4"),
];
const nextBtn = document.getElementById("nextBtn");
const backBtn = document.getElementById("backBtn");
function updateSteps() {
steps.forEach((step) => {
step.classList.remove("bg-pink-500");
step.classList.add("bg-gray-800");
});
pages.forEach((page) => {
page.classList.add("hidden");
});
for (let i = 0; i < currentStep; i++) {
steps[i].classList.remove("bg-gray-800");
steps[i].classList.add("bg-pink-500");
}
pages[currentStep - 1].classList.remove("hidden");
// Change button text on step 4
if (currentStep === 4) {
nextBtn.textContent = "Create Task";
} else {
nextBtn.textContent = "Next";
}
}
nextBtn.addEventListener("click", () => {
if (currentStep < 4) {
currentStep++;
updateSteps();
}
});
backBtn.addEventListener("click", () => {
if (currentStep > 1) {
currentStep--;
updateSteps();
}
});
// Run once when page loads
updateSteps();
//===========
//FOR AFTER WHEN YOU HAVE CLICK ON CREATE
//===========
// nextBtn.addEventListener("click", () => {
// if (currentStep < 4) {
// currentStep++;
// updateSteps();
// } else {
//===========
// // Step 4 → go to another page
//=========
// window.location.href = "success.html";
// }
// });
//
//TOGGLE FOR SELECT MUTIPE
const toggle = document.getElementById("toggle");
const dropdown = document.getElementById("dropdown");
toggle.addEventListener("change", () => {
dropdown.classList.toggle("hidden", !toggle.checked);
});
//FOR INFORMATION
const inf = document.getElementById("infom");
const inf1 = document.getElementById("infomenu");
if (inf && inf1) {
inf.addEventListener("click", () => {
inf1.classList.toggle("hidden");
});
}
if (inf && inf1) {
inf.addEventListener("mouseleave", () => {
inf1.classList.add("hidden");
});
}
document.addEventListener("DOMContentLoaded", () => {
function closeAllMenus() {
document.querySelectorAll(".plusmenu, .profilemenu").forEach((menu) => {
menu.classList.add("hidden");
});
}
// OPEN PLUS MENU
document.querySelectorAll(".plusbtn").forEach((btn) => {
btn.addEventListener("click", (e) => {
e.stopPropagation();
closeAllMenus(); // close others first
const menu = btn.closest(".plus-wrapper").querySelector(".plusmenu");
menu.classList.remove("hidden");
});
});
// OPEN PROFILE MENU
document.querySelectorAll(".profile").forEach((btn) => {
btn.addEventListener("click", (e) => {
e.stopPropagation();
closeAllMenus(); // close others first
const menu = btn.closest(".profile-wrapper").querySelector(".profilemenu");
menu.classList.remove("hidden");
});
});
// CLOSE BUTTONS
document.querySelectorAll(".close-btn").forEach((btn) => {
btn.addEventListener("click", (e) => {
e.stopPropagation();
btn.parentElement.classList.add("hidden");
});
});
// CLICK OUTSIDE closes all
document.addEventListener("click", closeAllMenus);
});
// cj starts here
/*
// ==================== COLLECT BOUNTY DATA FROM FORM ====================
function collectBountyData() {
// Step 1: Network & Category
const network = document.querySelector("input[list='networks']")?.value || "";
const category =
document.querySelector("input[list='categories']")?.value || "";
// Step 2: Task Details
const title =
document.querySelector("#page2 input[type='text']")?.value || "";
const description = document.querySelector("#page2 textarea")?.value || "";
// Tags - collect from your tag buttons
const tags = collectTags(); // You'll need to implement this based on your tag UI
// Timeline - get from date pickers
const startDate =
document.querySelector("#page2 button:contains('Start') + input")?.value ||
getDefaultStartDate();
const deadline =
document.querySelector("#page2 button:contains('Stop') + input")?.value ||
getDefaultDeadline();
// Origin Link
const originLink =
document.querySelector("#page2 input[type='url']")?.value || "";
// Step 3: Reward Info
const multipleWinner = document.getElementById("toggle")?.checked || false;
const payoutType = getPayoutType(); // "equal" or "percentage"
const percentages = getPercentages(); // Array if percentage split
const token =
document.querySelector("input[list='network1']")?.value || "USDC";
const rewardInput =
document.querySelector("#page3 input[type='number']")?.value || "0";
const reward = parseFloat(rewardInput);
// Validate required fields
if (!title || !description || !reward || reward <= 0) {
throw new Error("Please fill all required fields");
}
// Build the bounty data object
return {
// Basic Info
title,
description,
category,
tags,
// Timeline
startDate: new Date(startDate).toISOString(),
deadline: new Date(deadline).toISOString(),
// Links
originLink,
// Network
network,
// Reward
reward,
token,
// Winners
winnersAllowed: multipleWinner ? 2 : 1, // Default to 2 if multiple enabled
payoutType: multipleWinner ? payoutType : "single",
percentages:
multipleWinner && payoutType === "percentage" ? percentages : [],
};
}
// Helper: Collect tags (implement based on your UI)
function collectTags() {
// Example: If you have tag buttons with class "tag-selected"
const tagElements = document.querySelectorAll(".tag-selected");
return Array.from(tagElements).map((el) => el.textContent);
// Or if you have an input with comma-separated tags:
// const tagInput = document.querySelector("#tags-input").value;
// return tagInput.split(",").map(t => t.trim()).filter(t => t);
}
// Helper: Get payout type from UI
function getPayoutType() {
const activeButton = document.querySelector("#dropdown button.bg-pink-500");
if (activeButton) {
return activeButton.textContent.toLowerCase().includes("equal")
? "equal"
: "percentage";
}
return "equal";
}
// Helper: Get percentages for split
function getPercentages() {
// If you have percentage inputs, collect them
const percentageInputs = document.querySelectorAll(".percentage-input");
if (percentageInputs.length > 0) {
return Array.from(percentageInputs).map(
(input) => parseInt(input.value) || 0,
);
}
return [];
}
// Helper: Default dates
function getDefaultStartDate() {
const date = new Date();
return date.toISOString().split("T")[0]; // YYYY-MM-DD
}
function getDefaultDeadline() {
const date = new Date();
date.setDate(date.getDate() + 30); // 30 days from now
return date.toISOString().split("T")[0];
}
// ==================== FORM SUBMISSION ====================
async function submitBounty() {
try {
// Check if wallet is connected
const wallet = await getConnectedWallet();
if (!wallet) {
showToast("Please connect your wallet first", "warning");
return;
}
// Show loading state
const submitBtn = document.getElementById("nextBtn");
const originalText = submitBtn.textContent;
originalText = "Creating...";
submitBtn.disabled = true;
// Collect form data
const bountyData = collectBountyData();
// Add creator wallet
bountyData.creator = wallet;
console.log("📦 Submitting bounty data:", bountyData);
// Send to backend
const result = await createBounty(bountyData);
if (result.success) {
// Success message and redirect handled in createBounty
}
} catch (error) {
console.error("❌ Error:", error);
showToast(error.message || "Failed to create bounty", "error");
// Reset button
const submitBtn = document.getElementById("nextBtn");
submitBtn.textContent = "Next";
submitBtn.disabled = false;
}
}
// ==================== STEP NAVIGATION ====================
document
.getElementById("nextBtn")
?.addEventListener("click", async function (e) {
e.preventDefault();
const totalSteps = 4;
if (currentStep < totalSteps) {
// Validate current step before proceeding
if (!validateStep(currentStep)) {
return;
}
// Hide current page, show next
document.getElementById(`page${currentStep}`).classList.add("hidden");
currentStep++;
document.getElementById(`page${currentStep}`).classList.remove("hidden");
// Update progress bar
updateProgress(currentStep);
// Update button text on last step
if (currentStep === totalSteps) {
this.textContent = "Create Bounty";
}
} else {
// On last step, submit the bounty
await submitBounty();
}
});
document.getElementById("backBtn")?.addEventListener("click", function (e) {
e.preventDefault();
if (currentStep > 1) {
document.getElementById(`page${currentStep}`).classList.add("hidden");
currentStep--;
document.getElementById(`page${currentStep}`).classList.remove("hidden");
updateProgress(currentStep);
// Update button text
const nextBtn = document.getElementById("nextBtn");
nextBtn.textContent = currentStep === 4 ? "Create Bounty" : "Next";
}
});
// ==================== STEP VALIDATION ====================
function validateStep(step) {
switch (step) {
case 1:
const network = document.querySelector("input[list='networks']")?.value;
const category = document.querySelector(
"input[list='categories']",
)?.value;
if (!network || !category) {
showToast("Please select network and category", "warning");
return false;
}
break;
case 2:
const title = document.querySelector("#page2 input[type='text']")?.value;
const description = document.querySelector("#page2 textarea")?.value;
if (!title || !description) {
showToast("Please enter title and description", "warning");
return false;
}
break;
case 3:
const reward = document.querySelector(
"#page3 input[type='number']",
)?.value;
const token = document.querySelector("input[list='network1']")?.value;
if (!reward || parseFloat(reward) <= 0 || !token) {
showToast("Please enter valid reward amount and token", "warning");
return false;
}
break;
}
return true;
}
// ==================== UPDATE PROGRESS BAR ====================
function updateProgress(step) {
for (let i = 1; i <= 4; i++) {
const progressEl = document.getElementById(`step${i}`);
if (progressEl) {
if (i <= step) {
progressEl.classList.remove("bg-gray-800");
progressEl.classList.add("bg-pink-500");
} else {
progressEl.classList.remove("bg-pink-500");
progressEl.classList.add("bg-gray-800");
}
}
}
}
// ==================== MULTIPLE WINNERS TOGGLE ====================
document.getElementById("toggle")?.addEventListener("change", function (e) {
const dropdown = document.getElementById("dropdown");
if (dropdown) {
if (this.checked) {
dropdown.classList.remove("hidden");
} else {
dropdown.classList.add("hidden");
}
}
});
// ==================== INFO BUTTON TOOLTIP ====================
document.getElementById("infom")?.addEventListener("click", function (e) {
e.stopPropagation();
const menu = document.getElementById("infomenu");
if (menu) {
menu.classList.toggle("hidden");
}
});
// Close info menu when clicking outside
document.addEventListener("click", function () {
const menu = document.getElementById("infomenu");
if (menu && !menu.classList.contains("hidden")) {
menu.classList.add("hidden");
}
});
// Initialize on page load
document.addEventListener("DOMContentLoaded", () => {
// Show first page
updateProgress(1);
});*/
// Get buttons and modals
const equalBtn = document.getElementById("equalBtn");
const percentBtn = document.getElementById("percentBtn");
const equalModal = document.getElementById("equalModal");
const percentModal = document.getElementById("percentModal");
const equalConfirm = document.getElementById("closeEqual");
const percentConfirm = document.getElementById("closePercent");
// Open modals
equalBtn.addEventListener("click", () => {
equalModal.classList.remove("hidden");
});
percentBtn.addEventListener("click", () => {
percentModal.classList.remove("hidden");
});
// Close modals on confirm
equalConfirm.addEventListener("click", () => {
equalModal.classList.add("hidden");
});
percentConfirm.addEventListener("click", () => {
percentModal.classList.add("hidden");
});
const presetButtons = document.querySelectorAll(".preset-btn");
presetButtons.forEach((btn) => {
btn.addEventListener("click", () => {
const selected = btn.dataset.value; // get the data-value
console.log("Selected preset:", selected);
// you can now store it or update an input
});
});
// Get the selected token value (this returns "INJ", "wETH", "USDT", or "USDC")
document.addEventListener("DOMContentLoaded", function () {
const tokenSelect = document.getElementById("network1");
// Only proceed if token select exists on this page
if (!tokenSelect) return;
// Map token values to display symbols
const tokenSymbolMap = {
INJ: "INJ",
wETH: "wINJ",
USDT: "USDT",
USDC: "USDC",
};
// Function to update token displays - ONLY runs when value changes
function updateTokenDisplay() {
const selectedValue = tokenSelect.value;
const displaySymbol = tokenSymbolMap[selectedValue] || "USDC";
console.log(`Token changed to: ${displaySymbol}`);
// Update all token type elements
const tokenElements = document.querySelectorAll(
".tokenType, .token-symbol",
);
tokenElements.forEach((el) => {
el.textContent = displaySymbol;
});
// Update balance displays (preserve the number)
const balanceElements = document.querySelectorAll(".balance");
balanceElements.forEach((el) => {
// Extract number if it exists, otherwise use default
const match = el.textContent.match(/[\d.]+/);
const number = match ? match[0] : "0.0000";
el.textContent = `${number} ${displaySymbol}`;
});
}
// ONLY run when the select value changes - THIS IS THE KEY
tokenSelect.addEventListener("change", updateTokenDisplay);
// Initial update (runs once when page loads)
updateTokenDisplay();
});