diff --git a/backend/src/errors/codes.ts b/backend/src/errors/codes.ts index a73516d..3d02fd3 100644 --- a/backend/src/errors/codes.ts +++ b/backend/src/errors/codes.ts @@ -7,6 +7,7 @@ export enum ErrorCode { ALLOCATION_NOT_FOUND = "ALLOCATION_NOT_FOUND", AGREEMENT_NOT_FOUND = "AGREEMENT_NOT_FOUND", ALLOCATION_TOP_UP_FAILED = "ALLOCATION_TOP_UP_FAILED", + UNABLE_TO_CREATE_AGREEMENT = "UNABLE_TO_CREATE_AGREEMENT", } export const errorMessages = { @@ -26,6 +27,7 @@ export const errorMessages = { }: { allocationId: string; }) => `Allocation top up failed: ${allocationId}`, + [ErrorCode.UNABLE_TO_CREATE_AGREEMENT]: () => "Unable to create agreement", }; export type ErrorParams = { @@ -34,6 +36,7 @@ export type ErrorParams = { [ErrorCode.NO_ALLOCATION]: never; [ErrorCode.NO_WORKER]: never; [ErrorCode.USER_NOT_FOUND]: never; + [ErrorCode.UNABLE_TO_CREATE_AGREEMENT]: never; [ErrorCode.ALLOCATION_NOT_FOUND]: { allocationId: string; }; diff --git a/backend/src/services/user/service.ts b/backend/src/services/user/service.ts index 1544e49..d55dbb9 100644 --- a/backend/src/services/user/service.ts +++ b/backend/src/services/user/service.ts @@ -31,7 +31,6 @@ export const userService: IUserService = { //@ts-ignore getCurrentDeposit: async (userId: string): DepositData | null => { const user = await userModel.findOne({ _id: userId }); - console.log("user", user); if (!user) { throw new Error(`User not found with id ${userId}`); } diff --git a/backend/src/services/yagna/routes.ts b/backend/src/services/yagna/routes.ts index 05eaf2f..20d2504 100644 --- a/backend/src/services/yagna/routes.ts +++ b/backend/src/services/yagna/routes.ts @@ -90,8 +90,14 @@ export const Yagna = fastifyPlugin((fastify: FastifyInstance, opts, done) => { const Yagna = container.cradle.Yagna; try { await Yagna.makeAgreement(requestUser._id); + reply.code(201).send({ + message: "Agreement created", + }); } catch (e) { console.log("error", e); + reply.code(500).send({ + message: "Unable to create agreement", + }); } }, }); @@ -143,7 +149,6 @@ export const Yagna = fastifyPlugin((fastify: FastifyInstance, opts, done) => { const user = await container.cradle.userService.getUserById( requestUser._id ); - console.log("user", user); if (!user?.currentAllocationId) { reply.code(500).send({ message: "No allocation found", diff --git a/backend/src/services/yagna/service.ts b/backend/src/services/yagna/service.ts index 41ea798..1e79dc5 100644 --- a/backend/src/services/yagna/service.ts +++ b/backend/src/services/yagna/service.ts @@ -16,6 +16,7 @@ import { WorkContext } from "@golem-sdk/golem-js"; import { TaskExecutor } from "@golem-sdk/task-executor"; import { formatEther, parseEther } from "viem"; import { UUID } from "mongodb"; +import { debug } from "node:console"; export class Yagna { public debitNoteEvents: Subject; public invoiceEvents: Subject; @@ -93,20 +94,27 @@ export class Yagna { async makeAgreement(userId: string) { //creating executor by task executor makes agreement - const executor = await this.userContext.getExecutor(userId); - //in order to make sure agreement wont be automatically closed after 90s - //which is HARDCODED in yagna we make worker which under the hood makes activity - // which prevents agreement from closing - const worker = await this.getUserWorker(userId); - - const agreement = await worker.context?.activity.agreement; + debugLog("yagna", "making agreement", userId); + let executor, worker, agreement; + try { + executor = await this.userContext.getExecutor(userId); + debugLog("yagna", "making agreement, executor found", userId); + + //in order to make sure agreement wont be automatically closed after 90s + //which is HARDCODED in yagna we make worker which under the hood makes activity + // which prevents agreement from closing + worker = await this.getUserWorker(userId); + debugLog("yagna", "making agreement, worker found", userId); + agreement = await worker.context?.activity.agreement; + debugLog("yagna", "making agreement, agreement found", agreement); + } catch (e) { + console.log("Error", e); + } if (!agreement) { + debugLog("yagna", "Error making agreement, no agreement found", userId); throw new Error({ - code: ErrorCode.AGREEMENT_NOT_FOUND, - payload: { - agreementId: "", - }, + code: ErrorCode.UNABLE_TO_CREATE_AGREEMENT, }); } container.cradle.userService.setCurrentAgreementId(userId, agreement.id); @@ -234,7 +242,7 @@ export class Yagna { //task executor creates allocation as well async createExecutor(userId: string) { - debugLog("payments", "creating executor", userId); + debugLog("yagna", "creating executor", userId); const userService = container.cradle.userService; const userDeposit = await userService.getCurrentDeposit(userId); @@ -254,7 +262,7 @@ export class Yagna { //@ts-ignore if (allocation?.id) { - debugLog("payments", "allocation already exists, reusing", allocation); + debugLog("yagna", "allocation already exists, reusing", allocation); } const executor = await TaskExecutor.create({ @@ -281,11 +289,11 @@ export class Yagna { //task executor creates agreement and activity async getUserWorker(userId: string): Promise { - debugLog("payments", "getting user worker", userId); + debugLog("yagna", "getting user worker", userId); return new Promise(async (resolve, reject) => { const worker = this.userContext.getWorker(userId); if (worker) { - debugLog("yagna", "worker found", userId); + debugLog("yagna", "getUSerWorker: worker found", userId); const isConnected = await worker.isConnected(); if (isConnected) { debugLog("yagna", "worker connected", userId); @@ -308,18 +316,23 @@ export class Yagna { resolve(newWorker); return; } else { + debugLog("yagna", "creating worker, not mock getting deposit", userId); const userService = container.cradle.userService; const userDeposit = await userService.getCurrentDeposit(userId); + debugLog("yagna", "creating worker deposit found", userDeposit; if (!userDeposit) { throw new Error({ code: ErrorCode.NO_DEPOSIT }); } + debugLog("yagna", "creating worker, getting executor", userId); const executor = await this.userContext.getExecutor(userId); if (!executor) { throw new Error({ code: ErrorCode.NO_ALLOCATION }); } + debugLog("yagna", "creating worker, executor found getting agreement", userId); executor .run(async (ctx: WorkContext) => { + debugLog("yagna", "created worker", userId); newWorker.context = ctx; newWorker.setState("free"); @@ -328,7 +341,8 @@ export class Yagna { }) .catch((e: any) => { console.log("Error", e); - reject(); + debugLog("yagna", "error creating worker", e); + reject(e); }); } }); diff --git a/frontend/src/components/homePage/events/events.tsx b/frontend/src/components/homePage/events/events.tsx index ed7682b..07f13e5 100644 --- a/frontend/src/components/homePage/events/events.tsx +++ b/frontend/src/components/homePage/events/events.tsx @@ -29,7 +29,6 @@ export const Events = () => { const { events$: flowEvents$ } = useFlowEvents(); useEffect(() => { - console.log("events", events); flowEvents$ .pipe( finalize(() => { diff --git a/frontend/src/components/homePage/modals/deposit/extendDeposit.tsx b/frontend/src/components/homePage/modals/deposit/extendDeposit.tsx index 6f76ba0..131caca 100644 --- a/frontend/src/components/homePage/modals/deposit/extendDeposit.tsx +++ b/frontend/src/components/homePage/modals/deposit/extendDeposit.tsx @@ -45,7 +45,6 @@ export const ExtendDeposit = () => { setNonce(user.currentDeposit?.nonce); } if (isSuccessTransaction && additionalAmount > 0) { - console.log("topping up", additionalAmount, isSuccessTransaction); topUp(additionalAmount); hideModal(); } diff --git a/frontend/src/components/providers/blockchainProvider.tsx b/frontend/src/components/providers/blockchainProvider.tsx index 01fdbf8..c07d11c 100644 --- a/frontend/src/components/providers/blockchainProvider.tsx +++ b/frontend/src/components/providers/blockchainProvider.tsx @@ -88,7 +88,6 @@ const siweConfig = createSIWEConfig({ } const responseData = await response.json(); - console.log("nonce", responseData.nonce.toString()); return responseData.nonce.toString(); }, // @ts-ignore diff --git a/frontend/src/components/providers/userProvider.tsx b/frontend/src/components/providers/userProvider.tsx index 6c58ef7..b0fdf7c 100644 --- a/frontend/src/components/providers/userProvider.tsx +++ b/frontend/src/components/providers/userProvider.tsx @@ -236,7 +236,6 @@ export const UserProvider = ({ children }: PropsWithChildren<{}>) => { } }, [isUserLoading, userData, user.allowanceAmount, depositData]); - console.log("use allowance hook call"); const { isFetched: isAllowanceFetched, amount: allowanceAmount } = useAllowance(); diff --git a/frontend/src/hooks/depositContract/useWatchDepositPayments.ts b/frontend/src/hooks/depositContract/useWatchDepositPayments.ts deleted file mode 100644 index 6e539a4..0000000 --- a/frontend/src/hooks/depositContract/useWatchDepositPayments.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { config } from "config"; -import { holesky } from "viem/chains"; -import { useWatchContractEvent } from "wagmi"; -import { abi } from "./abi"; -import { useCallback } from "react"; -export const useWatchDepositPayments = () => { - const onLogs = useCallback((logs: any) => { - console.log("Deposit", logs); - }, []); - - useWatchContractEvent({ - address: config.depositContractAddress[holesky.id], - abi: abi, - eventName: "DepositFeeTransfer", - // args: { - // owner: address, - // spender: requestor?.wallet, - // }, - onLogs: onLogs, - }); -}; diff --git a/frontend/src/hooks/userUserData.ts b/frontend/src/hooks/userUserData.ts index 09ed5cb..2ae5a7e 100644 --- a/frontend/src/hooks/userUserData.ts +++ b/frontend/src/hooks/userUserData.ts @@ -21,7 +21,6 @@ export const useUserData = () => { const { data, error } = useSWRSubscription("userData", (key, { next }) => { socket.on("user", (data: any) => { - console.log("user", data); setIsLoading(false); next(null, data); }); diff --git a/frontend/src/hooks/yagna/useCreateAgreement.ts b/frontend/src/hooks/yagna/useCreateAgreement.ts index 8427ceb..ff9c9dc 100644 --- a/frontend/src/hooks/yagna/useCreateAgreement.ts +++ b/frontend/src/hooks/yagna/useCreateAgreement.ts @@ -1,9 +1,11 @@ import axios from "axios"; import useSWRMutation from "swr/mutation"; - +import { useSnackbar } from "notistack"; import { useActionDebounce } from "hooks/useActionDbounce"; +import { useEffect } from "react"; export const useCreateAgreement = () => { - const { trigger, isMutating } = useSWRMutation( + const { enqueueSnackbar } = useSnackbar(); + const { trigger, isMutating, error } = useSWRMutation( `${import.meta.env.VITE_BACKEND_HTTP_URL}/me`, function () { return axios.post( @@ -11,6 +13,14 @@ export const useCreateAgreement = () => { ); } ); + + useEffect(() => { + if (error) { + enqueueSnackbar("Error creating agreement", { variant: "error" }); + console.error("Error creating agreement", error); + } + }, [error]); + const isCreating = useActionDebounce(isMutating, 1000); return { createAgreement: trigger,