Skip to content

Commit

Permalink
additional check for signer being cooler owner (#2961)
Browse files Browse the repository at this point in the history
* additional check for signer being cooler owner

* use passed in walletAddress
  • Loading branch information
brightiron authored Sep 21, 2023
1 parent 385171c commit 6209593
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/views/Lending/Cooler/hooks/useGetCoolerForWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { useQuery } from "@tanstack/react-query";
import { CoolerFactory__factory } from "src/typechain";
import { Cooler__factory, CoolerFactory__factory } from "src/typechain";
import { useSigner } from "wagmi";

/**
* returns a cooler for a collateral & debt address
* - not actually dependent on a wallet address
*/
export const useGetCoolerForWallet = ({
walletAddress,
factoryAddress,
Expand All @@ -20,13 +16,19 @@ export const useGetCoolerForWallet = ({
const { data: signer } = useSigner();

const { data, isFetched, isLoading } = useQuery(
["getCoolerForWallet", factoryAddress, collateralAddress, debtAddress],
["getCoolerForWallet", factoryAddress, collateralAddress, debtAddress, walletAddress],
async () => {
if (!walletAddress || !factoryAddress || !collateralAddress || !debtAddress || !signer) return "";
const contract = CoolerFactory__factory.connect(factoryAddress, signer);
const address = await contract.callStatic.generateCooler(collateralAddress, debtAddress);
const isCreated = await contract.callStatic.created(address);
return isCreated ? address : "";
try {
const contract = CoolerFactory__factory.connect(factoryAddress, signer);
const address = await contract.callStatic.generateCooler(collateralAddress, debtAddress);
const isCreated = await contract.callStatic.created(address);
const cooler = Cooler__factory.connect(address, signer);
const coolerOwner = await cooler.owner();
return isCreated && walletAddress === coolerOwner ? address : "";
} catch {
return "";
}
},
{ enabled: !!walletAddress && !!factoryAddress && !!collateralAddress && !!debtAddress && !!signer },
);
Expand Down

0 comments on commit 6209593

Please sign in to comment.