diff --git a/packages/react-app/src/hooks/queries/useGenericQuery.ts b/packages/react-app/src/hooks/queries/useGenericQuery.ts index 7c44a4b..0777912 100644 --- a/packages/react-app/src/hooks/queries/useGenericQuery.ts +++ b/packages/react-app/src/hooks/queries/useGenericQuery.ts @@ -2,7 +2,8 @@ import { useQuery } from "@tanstack/react-query"; export const useGenericQuery = ( queryKey: string[], - queryFn: () => Promise + queryFn: () => Promise, + enabled: boolean = true ) => { const { data, @@ -12,6 +13,7 @@ export const useGenericQuery = ( } = useQuery({ queryKey: queryKey, queryFn: queryFn, + enabled: enabled, }); const refetch = async () => { diff --git a/packages/react-app/src/hooks/queries/useGetMember.tsx b/packages/react-app/src/hooks/queries/useGetMember.tsx index 2874011..ddba622 100644 --- a/packages/react-app/src/hooks/queries/useGetMember.tsx +++ b/packages/react-app/src/hooks/queries/useGetMember.tsx @@ -88,8 +88,7 @@ export const useGetMemberTrusters = (memberId: string) => { }; export const useGetMember = (memberId: string) => { - const queryKey = ["member", memberId]; const queryFn = () => fetchMemberData(memberId); - return useGenericQuery(queryKey, queryFn); + return useGenericQuery(queryKey, queryFn, !!memberId && memberId.length > 0); }; diff --git a/packages/react-app/src/screens/TrustAction.tsx b/packages/react-app/src/screens/TrustAction.tsx index 0b23af3..ed25d58 100644 --- a/packages/react-app/src/screens/TrustAction.tsx +++ b/packages/react-app/src/screens/TrustAction.tsx @@ -4,7 +4,7 @@ import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { useToast } from "@/hooks/use-toast"; -import { useWriteContract, useAccount } from "wagmi"; +import { useWriteContract, useAccount, useReadContract } from "wagmi"; import ABI from "../abis/CFAv1Forwarder.json"; import { GOODDOLLAR, SF_FORWARDER, POOL_CONTRACT } from "@/env"; import { @@ -16,21 +16,25 @@ import { import { Loader2 } from "lucide-react"; import { useNavigate } from "react-router-dom"; import { PasteInput } from "@/components/PasteInput"; -import { useGetMember } from "@/hooks/queries/useGetMember"; import { truncateAddress } from "@/utils"; // @ts-expect-error const isMiniPay = window?.ethereum?.isMiniPay; const gasOpts = isMiniPay ? {} : { - maxFeePerGas: BigInt(5e9), - maxPriorityFeePerGas: BigInt(0) -} - + maxFeePerGas: BigInt(25.1e9), + maxPriorityFeePerGas: BigInt(1e8) +}; + const useGetFlowRate = (sender: string | undefined) => { - if (!sender) return undefined; - const memberData = useGetMember(sender); - // @ts-ignore - return memberData.status === "success" ? BigInt(memberData.data?.data?.outFlowRate || 0) : undefined + const result = useReadContract({ + address: SF_FORWARDER, + abi: [{ name: "getFlowrate", type: "function", stateMutability: "view", inputs: [{ name: "token", type: "address" }, { name: "sender", type: "address" }, { name: "receiver", type: "address" }], outputs: [{ name: "", type: "int96" }] }], + functionName: "getFlowrate", + args: [GOODDOLLAR as `0x${string}`, (sender || "0x0000000000000000000000000000000000000000") as `0x${string}`, POOL_CONTRACT as `0x${string}`], + query: { enabled: !!sender }, + }); + if (!sender || !result.data) return 0n; + return BigInt(result.data); }; export const QrScan = () => { @@ -38,7 +42,6 @@ export const QrScan = () => { const account = useAccount(); const existingFlowRate = useGetFlowRate(account.address); - console.log({ existingFlowRate }); const { writeContractAsync } = useWriteContract(); const [result, setResult] = useState(undefined); @@ -50,17 +53,15 @@ export const QrScan = () => { const validRecipient = isAddress(result || ""); const handleScan = (result: IDetectedBarcode[]) => { - console.log(result); if (result.length > 0) { setResult(result[0].rawValue); } }; const trust = async () => { - if (existingFlowRate !== undefined && result) { + if (result) { const monthlyTrustRate = parseEther(amount.toString()) / BigInt(60 * 60 * 24 * 30); - console.log("Trusting:", { existingFlowRate, result, monthlyTrustRate }); const newFlowRate = existingFlowRate + monthlyTrustRate; const userData = encodeAbiParameters( @@ -90,7 +91,6 @@ export const QrScan = () => { }); navigation("/"); } catch (e: any) { - console.log({ e }) setLoading(false); toast({ title: "Transaction failed",