-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a580afd
commit 2ed8421
Showing
5 changed files
with
42 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useCallback } from "react"; | ||
import useSWR from "swr"; | ||
import { isAddress } from "viem"; | ||
import { useFetchNewPoolCallback } from "./useFetchNewPoolCallback"; | ||
import { useUserPools } from "./useUserPools"; | ||
|
||
export function useSelectedPool(poolId: string) { | ||
const { data: pools } = useUserPools(); | ||
const fetchNewPoolCallback = useFetchNewPoolCallback(); | ||
|
||
const getSelectedPoolCallback = useCallback( | ||
async (_poolId: string) => { | ||
const poolsSearch = pools?.find( | ||
(pool) => pool.id.toLowerCase() === _poolId.toLowerCase(), | ||
); | ||
if (poolsSearch) return poolsSearch; | ||
|
||
if (!fetchNewPoolCallback) return; | ||
if (!isAddress(_poolId)) return; | ||
|
||
const fetchedNewPool = await fetchNewPoolCallback(_poolId); | ||
return fetchedNewPool; | ||
}, | ||
[pools, fetchNewPoolCallback], | ||
); | ||
|
||
return useSWR(poolId, getSelectedPoolCallback); | ||
} |
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