Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions client/app/components/Cards/BallotCards/ScoreBallot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ const ScoreBallot = ({
const newSum = sumWithoutCurrent + credits;

if (newSum > 100) {
toast.error("Credit Limit Exceeded !!");
console.log("Error credits");
return;
toast.error("Credit Limit Exceeded !!"); return;
}
newCreditScores[id] = credits;
const sum = SumOfArray(newCreditScores);
Expand Down
3 changes: 2 additions & 1 deletion client/app/components/ChatBot/ChatBot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useState, useRef, useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { ArrowUpIcon, ChatBubbleLeftRightIcon } from "@heroicons/react/24/solid";
import { XMarkIcon } from "@heroicons/react/24/outline"; // Corrected the import for XMarkIcon
import toast from "react-hot-toast";

interface Message {
content: string;
Expand Down Expand Up @@ -49,7 +50,7 @@ const ChatBot: React.FC = () => {
const reply: Message = { content: data.message, role: "assistant" };
setMessages((prevMessages) => [...prevMessages, reply]);
} catch (error) {
console.error("Error:", error);
toast.error("Failed to get response. Please try again.");
}
};

Expand Down
8 changes: 6 additions & 2 deletions client/app/components/Helper/CrossChain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import React, { useEffect, useState } from "react";
import { erc20Abi } from "viem";
import { avalancheFuji } from "viem/chains";
import { useAccount, useSwitchChain, useWriteContract } from "wagmi";
import logger from "@/app/helpers/logger";
import toast from "react-hot-toast";

const CrossChain = ({
electionAddress,
isEnded,
Expand Down Expand Up @@ -34,8 +37,9 @@ const CrossChain = ({
});
setbuttonValue(true);
} catch (error) {
console.log("Error : ", error);
}
logger.error("CrossChain: failed to add election", error);
toast.error("Failed to enable cross-chain support. Please try again.");
}
};
useEffect(() => {
setbuttonValue(isCrossChainEnabled);
Expand Down
5 changes: 3 additions & 2 deletions client/app/components/Modal/AddCandidate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ErrorMessage } from "../../helpers/ErrorMessage";
import { sepolia } from "viem/chains";
import { useElectionData } from "@/app/hooks/ElectionInfo";
import { pinJSONFile } from "@/app/helpers/pinToIPFS";
import logger from "@/app/helpers/logger";

const AddCandidate = ({
openModal,
Expand Down Expand Up @@ -51,8 +52,8 @@ const AddCandidate = ({
});
toast.success(`${name} Added to Election`);
} catch (error) {
console.log("Error ", error);
toast.error(ErrorMessage(error));
logger.error("AddCandidate: failed to add candidate", error);
toast.error(ErrorMessage(error));
}
setopenModal(false);
};
Expand Down
4 changes: 2 additions & 2 deletions client/app/components/Modal/Vote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useElectionModal } from "@/app/hooks/ElectionModal";
import React, { useEffect } from "react";
import toast from "react-hot-toast";
import { useAccount, useWriteContract } from "wagmi";
import logger from "@/app/helpers/logger";

const Vote = ({
disabled,
Expand All @@ -20,7 +21,6 @@ const Vote = ({
const { writeContractAsync } = useWriteContract();
const { chain } = useAccount();
const vote = async () => {
console.log("Vote array", voteArray);
try {
if (chain?.id === 43113) {
await writeContractAsync({
Expand All @@ -40,7 +40,7 @@ const Vote = ({
toast.success(`Voted Casted `);
setelectionModal(false);
} catch (error) {
console.log("Error", error);
logger.error("Vote: failed to cast vote", error);
toast.error(ErrorMessage(error));
}
};
Expand Down
3 changes: 2 additions & 1 deletion client/app/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { sepolia } from "viem/chains";
import { ArrowPathIcon , PlusIcon, TrashIcon} from "@heroicons/react/24/solid";
import { useRouter } from "next/navigation";
import ElectionInfoPopup from "../components/Modal/ElectionInfoPopup";
import logger from "@/app/helpers/logger";

const CreatePage: React.FC = () => {
const router = useRouter();
Expand Down Expand Up @@ -93,7 +94,7 @@ const CreatePage: React.FC = () => {
toast.success("Election created successfully!");
router.push("/");
} catch (error) {
console.error("Error creating election:", error);
logger.error("CreateElection: failed to create election", error);
toast.error(ErrorMessage(error));
}
};
Expand Down
4 changes: 3 additions & 1 deletion client/app/helpers/ErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logger from "@/app/helpers/logger";

const errorMessages = {
ElectionInactive: "Election is Not Active",
OwnerPermissioned: "Must be Owner of Election",
Expand All @@ -13,7 +15,7 @@ const errorMessages = {
};

export const ErrorMessage = (error: any) => {
console.log("Error : ", error);
logger.error("ErrorMessage helper received error", error);
for (const [key, message] of Object.entries(errorMessages)) {
if (error.message.includes(key)) {
return message;
Expand Down
4 changes: 3 additions & 1 deletion client/app/helpers/fetchFileFromIPFS.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logger from "@/app/helpers/logger";

const GATEWAY = "orange-confused-boar-516.mypinata.cloud";
const JWT = process.env.NEXT_PUBLIC_PINATA_JWT;

Expand All @@ -8,6 +10,6 @@ export async function fetchFileFromIPFS(CID: String) {
const response = await request.json();
return response;
} catch (error) {
console.log(error);
logger.error("fetchFileFromIPFS: failed to fetch file from IPFS", error);
}
}
9 changes: 9 additions & 0 deletions client/app/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import log from "loglevel";

if (process.env.NODE_ENV === "production") {
log.setLevel("warn");
} else {
log.setLevel("debug");
}

export default log;
6 changes: 3 additions & 3 deletions client/app/helpers/pinToIPFS.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logger from "@/app/helpers/logger";
const JWT = process.env.NEXT_PUBLIC_PINATA_JWT;

export const pinJSONFile = async (body: any) => {
Expand All @@ -16,10 +17,9 @@ export const pinJSONFile = async (body: any) => {
options
);
const data = await response.json();
console.log(data);
return data;
} catch (err) {
console.error(err);
logger.error("pinJSONFile: failed to pin JSON to IPFS", err);
throw err; // rethrow the error to be handled by the caller
}
};
Expand All @@ -33,7 +33,7 @@ export const unpinJSONFile = async (CID: String) => {
try {
await fetch(`https://api.pinata.cloud/pinning/unpin/${CID}`, options);
} catch (err) {
console.error(err);
logger.error("unpinJSONFile: failed to unpin JSON from IPFS", err);
throw err; // rethrow the error to be handled by the caller
}
};
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@vanilla-extract/sprinkles": "^1.6.3",
"daisyui": "^4.12.10",
"framer-motion": "^11.2.12",
"loglevel": "^1.9.2",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
Expand Down