From f6368ec5daf98ff6b5a92b999af69210953fc1b4 Mon Sep 17 00:00:00 2001 From: pociej Date: Fri, 14 Jun 2024 07:45:33 +0200 Subject: [PATCH] chore: cleanup #62 --- .../homePage/modals/extendDepositForm.tsx | 139 ------------------ .../providers/blockchainProvider.tsx | 51 ++++--- .../src/components/providers/userProvider.tsx | 1 - frontend/src/hooks/GLM/useAllowanceTx.tsx | 1 - frontend/src/hooks/useSaveDeposit.tsx | 5 - frontend/src/hooks/useScanResults.tsx | 2 - frontend/src/hooks/useWatchContractEvents.ts | 22 --- .../src/hooks/yagna/useCurrentAgreement.ts | 6 +- .../src/hooks/yagna/useCurrentAllocation.ts | 2 - 9 files changed, 28 insertions(+), 201 deletions(-) delete mode 100644 frontend/src/components/homePage/modals/extendDepositForm.tsx diff --git a/frontend/src/components/homePage/modals/extendDepositForm.tsx b/frontend/src/components/homePage/modals/extendDepositForm.tsx deleted file mode 100644 index 5afc2e1..0000000 --- a/frontend/src/components/homePage/modals/extendDepositForm.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import dayjs from "dayjs"; -import { - useExtendDeposit, - useUserCurrentDeposit, -} from "hooks/depositContract/useDeposit"; -import { useUser } from "hooks/useUser"; -import { useEffect } from "react"; -import { Button, Input, Loading } from "react-daisyui"; -import { useAccount, useWaitForTransactionReceipt } from "wagmi"; -import { useTopUpAllocation } from "hooks/useTopUpAllocation"; -import { GolemCoinIcon } from "./atoms/golem.coin.icon"; -import { match, P } from "ts-pattern"; - -export const DepositForm = ({ mode }: { mode: "create" | "extend" }) => { - const { - additionalAmount, - data, - extendDeposit, - setAdditionalAmount, - setNewValidToTimestamp, - setAdditionalFee, - setNonce, - isPending, - newValidToTimeStamp, - } = useExtendDeposit(); - - const { - isSuccess: isSuccessTransaction, - isError: isErrorTransaction, - isLoading: isLoadingTransaction, - } = useWaitForTransactionReceipt({ - hash: data, - }); - - const { user } = useUser(); - - const currentDeposit = useUserCurrentDeposit(); - const { trigger: topUp, isMutating: isAmendingAllocation } = - useTopUpAllocation(); - useEffect(() => { - if (user.currentDeposit) { - setNonce(user.currentDeposit?.nonce); - } - if (isSuccessTransaction && additionalAmount > 0) { - topUp(additionalAmount); - } - }, [isSuccessTransaction]); - - useEffect(() => { - console.log("newValidToTimeStamp", newValidToTimeStamp); - console.log( - "dd", - dayjs(Number(newValidToTimeStamp) * 1000).format("YYYY-MM-DD") - ); - }, [newValidToTimeStamp]); - // useEffect(() => { - // if (isSuccessTransaction) { - // hide(); - // } - // }, [isSuccessTransaction]); - - - - return ( - <> -
- {match(mode) - .with("create", () => ( -

Create deposit

- )) - .with("extend", () => ( -

Extend deposit

- )) - .exhaustive()} -
-
- {match(mode) - .with("create", () =>
Deposit creation text here
) - .with("extend", () =>
Deposit extension text here
) - .exhaustive()} -
-
- - - { - console.log("e.target.value", e.target.value); - setNewValidToTimestamp(dayjs(e.target.value).unix()); - }} - style={{ - color: "gray", - }} - /> -
-
- {" "} -
- - ); -}; diff --git a/frontend/src/components/providers/blockchainProvider.tsx b/frontend/src/components/providers/blockchainProvider.tsx index a13ed3c..01fdbf8 100644 --- a/frontend/src/components/providers/blockchainProvider.tsx +++ b/frontend/src/components/providers/blockchainProvider.tsx @@ -1,6 +1,10 @@ import { createWeb3Modal } from "@web3modal/wagmi/react"; import { defaultWagmiConfig } from "@web3modal/wagmi/react/config"; -import { SIWECreateMessageArgs, createSIWEConfig, formatMessage } from "@web3modal/siwe"; +import { + SIWECreateMessageArgs, + createSIWEConfig, + formatMessage, +} from "@web3modal/siwe"; import { SiweMessage } from "siwe"; import { WagmiProvider, http } from "wagmi"; @@ -29,14 +33,7 @@ const wagmiConfig = defaultWagmiConfig({ metadata, }); - - - function createMessage({ nonce, address, chainId }: any) { - console.log('creating message '); - console.log('nonce', nonce); - console.log('address', address); - console.log('chainId', chainId); const message = new SiweMessage({ version: "1", domain: window.location.host, @@ -46,8 +43,6 @@ function createMessage({ nonce, address, chainId }: any) { nonce: nonce.toString(), statement: "Sign in with ethereum", }); -console.log("message", message); -console.log("message.prepareMessage()", message.prepareMessage()); return message.prepareMessage(); } @@ -59,17 +54,18 @@ console.log("message.prepareMessage()", message.prepareMessage()); // signOut // }) -async function getMessageParams(){ +async function getMessageParams() { return { domain: window.location.host, uri: window.location.origin, chains: [1, 2020], - statement: 'Please sign with your account' - } + statement: "Please sign with your account", + }; } // // @ts-ignore const siweConfig = createSIWEConfig({ - createMessage: ({ address, ...args }: SIWECreateMessageArgs) => formatMessage(args, address), + createMessage: ({ address, ...args }: SIWECreateMessageArgs) => + formatMessage(args, address), getMessageParams, getNonce: async (address) => { if (!address) { @@ -97,12 +93,15 @@ const siweConfig = createSIWEConfig({ }, // @ts-ignore async getSession() { - return new Promise((resolve) => setTimeout( ()=> { - resolve({ - // @ts-ignore - address: localStorage.getItem("address"), - chainId: 1, - })}, 1000)); + return new Promise((resolve) => + setTimeout(() => { + resolve({ + // @ts-ignore + address: localStorage.getItem("address"), + chainId: 1, + }); + }, 1000) + ); }, verifyMessage: async ({ message, signature }) => { const res = await fetch(`${import.meta.env.VITE_BACKEND_HTTP_URL}/login`, { @@ -122,8 +121,12 @@ const siweConfig = createSIWEConfig({ localStorage.setItem("accessToken", data.accessToken); localStorage.setItem("refreshToken", data.refreshToken); - window.dispatchEvent(new StorageEvent("storage", { key : 'accessToken', newValue : data.accessToken })); - + window.dispatchEvent( + new StorageEvent("storage", { + key: "accessToken", + newValue: data.accessToken, + }) + ); return true; }, @@ -131,9 +134,9 @@ const siweConfig = createSIWEConfig({ localStorage.removeItem("accessToken"); localStorage.removeItem("refreshToken"); localStorage.removeItem("address"); - + return false; - } + }, }); createWeb3Modal({ diff --git a/frontend/src/components/providers/userProvider.tsx b/frontend/src/components/providers/userProvider.tsx index 5c63b59..4c69e79 100644 --- a/frontend/src/components/providers/userProvider.tsx +++ b/frontend/src/components/providers/userProvider.tsx @@ -96,7 +96,6 @@ const withUserInterface = function ( return !!user.currentAllocation?.id; }, hasAgreement() { - console.log("user.currentAgreement", user.currentAgreement); return !!user.currentAgreement?.id; }, }; diff --git a/frontend/src/hooks/GLM/useAllowanceTx.tsx b/frontend/src/hooks/GLM/useAllowanceTx.tsx index cb97611..af91771 100644 --- a/frontend/src/hooks/GLM/useAllowanceTx.tsx +++ b/frontend/src/hooks/GLM/useAllowanceTx.tsx @@ -54,7 +54,6 @@ export const useAllowanceTx = () => { fetchLogs().then((logs) => { const sortedLogs = logs.sort(compareBlockNumbers); if (sortedLogs.length > 0) { - console.log("hh"); setTxHash(sortedLogs[logs.length - 1].transactionHash); } }); diff --git a/frontend/src/hooks/useSaveDeposit.tsx b/frontend/src/hooks/useSaveDeposit.tsx index e74494d..111aecd 100644 --- a/frontend/src/hooks/useSaveDeposit.tsx +++ b/frontend/src/hooks/useSaveDeposit.tsx @@ -11,9 +11,6 @@ async function saveDeposit({ nonce: number; id: string; }): Promise<{ result: boolean }> { - console.log("nonce", nonce); - console.log("funder", funder); - console.log("id", id); const response = await fetch( `${import.meta.env.VITE_BACKEND_HTTP_URL}/create-deposit`, { @@ -26,8 +23,6 @@ async function saveDeposit({ } ); - console.log("response", response); - if (!response.ok) throw new Error(`Error registering user: ${response.statusText}`); diff --git a/frontend/src/hooks/useScanResults.tsx b/frontend/src/hooks/useScanResults.tsx index cdeb5d8..8943b63 100644 --- a/frontend/src/hooks/useScanResults.tsx +++ b/frontend/src/hooks/useScanResults.tsx @@ -9,7 +9,6 @@ export const useScanResults = () => { const { emit, events$, clean } = useEvents({ key: "scanResults", eventKind: (s: any) => { - console.log("Event kind", s); return match(s) .with(fileStatus.CLEAN, () => Event.FILE_SCAN_OK) .with(fileStatus.INFECTED, () => Event.FILE_SCAN_ERROR) @@ -26,7 +25,6 @@ export const useScanResults = () => { eventSource.addEventListener("message", (event) => { const file = JSON.parse(event.data); - console.log("Emmiting event", file); removeFile(file.id); emit(file, file.result); }); diff --git a/frontend/src/hooks/useWatchContractEvents.ts b/frontend/src/hooks/useWatchContractEvents.ts index 5fb4bf1..9eb8e05 100644 --- a/frontend/src/hooks/useWatchContractEvents.ts +++ b/frontend/src/hooks/useWatchContractEvents.ts @@ -29,30 +29,8 @@ export const useContractEvent = ({ eventName, onLogs: (logs: any[]) => { logs.forEach((log) => { - console.log("log", log); emit(log); }); }, }); }; -// 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/yagna/useCurrentAgreement.ts b/frontend/src/hooks/yagna/useCurrentAgreement.ts index 9c2e759..a7fa8ee 100644 --- a/frontend/src/hooks/yagna/useCurrentAgreement.ts +++ b/frontend/src/hooks/yagna/useCurrentAgreement.ts @@ -1,16 +1,12 @@ import axios from "axios"; import { useUser } from "hooks/useUser"; -import { use } from "i18next"; -import { useEffect } from "react"; import useSWR from "swr"; import * as YaTsClient from "ya-ts-client"; export type AgreementDTO = YaTsClient.MarketApi.AgreementDTO; export const useCurrentAgreement = () => { - const { user } = useUser(); - - const { data, error } = useSWR( + const { data } = useSWR( `${import.meta.env.VITE_BACKEND_HTTP_URL}/agreement`, async (url) => { const response = await axios.get(url); diff --git a/frontend/src/hooks/yagna/useCurrentAllocation.ts b/frontend/src/hooks/yagna/useCurrentAllocation.ts index 143260e..e8bf15b 100644 --- a/frontend/src/hooks/yagna/useCurrentAllocation.ts +++ b/frontend/src/hooks/yagna/useCurrentAllocation.ts @@ -1,7 +1,5 @@ import axios from "axios"; import { useUser } from "hooks/useUser"; -import { use } from "i18next"; -import { set } from "ramda"; import { useEffect, useState } from "react"; import useSWR from "swr"; import { parseEther } from "viem";