diff --git a/src/components/admin/ltokens/AdminLTokenAPR.tsx b/src/components/admin/ltokens/AdminLTokenAPR.tsx index 31b13d31..af09987e 100644 --- a/src/components/admin/ltokens/AdminLTokenAPR.tsx +++ b/src/components/admin/ltokens/AdminLTokenAPR.tsx @@ -1,69 +1,40 @@ -import { Address, Input, TxButton } from "@/components/ui"; +import { Card, Rate, TxButton } from "@/components/ui"; +import { RateInput } from "@/components/ui/RateInput"; +import { useReadLTokenGetApr, useSimulateLTokenSetApr } from "@/generated"; import { useContractAddress } from "@/hooks/useContractAddress"; -import { ChangeEvent, FC, useEffect, useCallback, useState } from "react"; -import { - useBlockNumber, - useReadContract, - useSimulateContract, - UseSimulateContractReturnType, -} from "wagmi"; -import { zeroAddress, Abi } from "viem"; -import { useContractAbi } from "@/hooks/useContractAbi"; +import { ChangeEvent, FC, useEffect, useState, useCallback } from "react"; +import { parseUnits } from "viem"; +import { AdminBrick } from "../AdminBrick"; +import { UseSimulateContractReturnType, useBlockNumber } from "wagmi"; import { useQueryClient } from "@tanstack/react-query"; -interface Props extends React.HTMLAttributes { - displayName?: string; - contractName: string; - getterFunctionName: string; - setterFunctionName: string; - txButtonName?: string; +interface Props extends React.ComponentPropsWithRef { + lTokenSymbol: string; } -export const AdminAddressSetter: FC = ({ - displayName = null, - contractName, - getterFunctionName, - setterFunctionName, - txButtonName = "Set", -}) => { - const contractAddress = useContractAddress(contractName); - const contractAbi = useContractAbi(contractName); - const { data: currentAddress, queryKey } = useReadContract({ - address: contractAddress, - abi: contractAbi, - functionName: getterFunctionName, +export const AdminLTokenAPR: FC = ({ className, lTokenSymbol }) => { + const lTokenAddress = useContractAddress(lTokenSymbol); + const { data: apr, queryKey } = useReadLTokenGetApr({ + address: lTokenAddress, }); - - const [newAddress, setNewAddress] = useState(zeroAddress); + const [newApr, setNewApr] = useState(0); const [hasUserInteracted, setHasUserInteracted] = useState(false); - const simulation = useSimulateContract({ - address: contractAddress, - abi: contractAbi as Abi, - functionName: setterFunctionName, - args: [newAddress] as const, + // Create the simulation with proper typing + const simulation = useSimulateLTokenSetApr({ + address: lTokenAddress, + args: [newApr], query: { - enabled: Boolean(contractAddress && contractAbi && newAddress && newAddress !== zeroAddress), + enabled: Boolean(lTokenAddress && newApr >= 0), }, }); - // Convert simulation to expected type - const preparation = { - ...simulation, - data: simulation.data - ? { - ...simulation.data, - request: { - ...simulation.data.request, - __mode: "prepared" as const, - }, - } - : undefined, - } as UseSimulateContractReturnType; + // Cast the simulation to the expected type + const preparation = simulation as unknown as UseSimulateContractReturnType; // Refresh data every 5 blocks - const { data: blockNumber } = useBlockNumber({ watch: true }); const queryClient = useQueryClient(); + const { data: blockNumber } = useBlockNumber({ watch: true }); const handleRefreshData = useCallback(() => { if (queryKey) { @@ -77,35 +48,33 @@ export const AdminAddressSetter: FC = ({ } }, [blockNumber, handleRefreshData]); - const handleAddressChange = (e: ChangeEvent) => { + const handleRateChange = (e: ChangeEvent) => { const value = e.target.value; - setNewAddress(value); + setNewApr(Number(parseUnits(value || "0", 3))); setHasUserInteracted(value !== ""); }; - if (!contractAddress || !contractAbi) return null; + if (!lTokenAddress) return null; return ( -
- {displayName &&

{displayName}

} +

- Current address:

+ Current value:

- - {txButtonName} + Set
-
+ ); }; \ No newline at end of file