-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor cow amm to store create pool tx hash in local storage
- Loading branch information
1 parent
0b12176
commit 243235b
Showing
8 changed files
with
78 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { parseEventLogs } from "viem"; | ||
import { usePublicClient } from "wagmi"; | ||
import { abis } from "~~/contracts/abis"; | ||
import { usePoolCreationStore } from "~~/hooks/cow/usePoolCreationStore"; | ||
|
||
export const useWaitForTransactionReceipt = () => { | ||
const publicClient = usePublicClient(); | ||
const { poolCreation, updatePoolCreation } = usePoolCreationStore(); | ||
const createPoolTxHash = poolCreation?.createPoolTxHash; | ||
const poolAddress = poolCreation?.address; | ||
|
||
return useQuery({ | ||
queryKey: ["fetch-createPool-tx-receipt", createPoolTxHash], | ||
queryFn: async () => { | ||
if (!publicClient) throw new Error("Missing public client for fetching pool creation tx receipt"); | ||
if (!createPoolTxHash) return "No need to fetch receipt yet"; | ||
if (poolAddress) return poolAddress; | ||
|
||
const txReceipt = await publicClient.waitForTransactionReceipt({ hash: createPoolTxHash }); | ||
const logs = parseEventLogs({ | ||
abi: abis.CoW.BCoWFactory, | ||
logs: txReceipt.logs, | ||
}); | ||
|
||
const newPoolAddress = (logs[0].args as { caller: string; bPool: string }).bPool; | ||
if (!newPoolAddress) throw new Error("No new pool address from pool creation tx receipt"); | ||
|
||
updatePoolCreation({ address: newPoolAddress, step: 2 }); | ||
|
||
return newPoolAddress; | ||
}, | ||
}); | ||
}; |