Skip to content

Commit

Permalink
chore: add debug logs to hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pociej committed Jun 14, 2024
1 parent 673bb9b commit 79d56aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions frontend/src/components/providers/userProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export const UserProvider = ({ children }: PropsWithChildren<{}>) => {
}
}, [isUserLoading, userData, user.allowanceAmount, depositData]);

console.log("use allowance hook call");
const { isFetched: isAllowanceFetched, amount: allowanceAmount } =
useAllowance();

Expand Down Expand Up @@ -267,6 +268,7 @@ export const UserProvider = ({ children }: PropsWithChildren<{}>) => {
if (isRegistered) {
if (isAllowanceFetched && allowanceAmount !== undefined) {
if (allowanceAmount > config.minimalAllowance) {
console.log("enough allowance");
dispatch({
kind: UserAction.ENOUGH_ALLOWANCE,
payload: { allowanceAmount },
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/hooks/GLM/useGLMApprove.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { useChainId } from "hooks/useChainId";
import { assertOptionalBigInt } from "types/assertBigInt";
import { TransactionExecutionError } from "viem";
import { useEffect, useState } from "react";
import { use } from "i18next";

const debug = require("debug")("useAllowance");

export function useAllowance(): {
isFetched: boolean;
Expand All @@ -20,7 +23,16 @@ export function useAllowance(): {
const chainId = useChainId();
const { address } = useAccount();

const { isFetched, data: allowanceAmount } = useReadContract({
useEffect(() => {
debug("Read allowance");
debug("from: ", address);
debug("to contact: ", config.GLMContractAddress[chainId]);
}, [address, chainId]);
const {
isFetched,
data: allowanceAmount,
isError,
} = useReadContract({
address: config.GLMContractAddress[chainId],
abi: abi,
functionName: "allowance",
Expand All @@ -31,6 +43,11 @@ export function useAllowance(): {
},
});

useEffect(() => {
debug("Allowance amount: ", allowanceAmount);
debug("isFetched: ", isFetched);
debug("isError: ", isError);
}, [allowanceAmount, isFetched]);
return {
isFetched,
amount: allowanceAmount,
Expand Down

0 comments on commit 79d56aa

Please sign in to comment.