-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuseUserDataAllStrategies.ts
56 lines (53 loc) · 1.61 KB
/
useUserDataAllStrategies.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { useQuery } from "@tanstack/react-query"
import { getUserDataAllStrategies } from "data/actions/common/getUserDataAllStrategies"
import { useAccount, useWalletClient } from "wagmi"
import { useAllContracts } from "./useAllContracts"
import { useAllStrategiesData } from "./useAllStrategiesData"
import { useCoinGeckoPrice } from "./useCoinGeckoPrice"
import { getChainByViemId } from "data/chainConfig"
import { tokenConfig } from "data/tokenConfig"
export const useUserDataAllStrategies = () => {
const { data: walletClient } = useWalletClient()
const { address, chain: viemChain } = useAccount()
const { data: allContracts } = useAllContracts()
const strategies = useAllStrategiesData()
const chain = getChainByViemId(viemChain?.name)
const sommToken = tokenConfig.find(
(token) =>
token.coinGeckoId === "sommelier" &&
token.chain ===
(chain.id || "ethereum")
)!
const sommPrice = useCoinGeckoPrice(sommToken)
const query = useQuery({
queryKey: [
"USE_USER_DATA_ALL_STRATEGIES",
{
allContracts: !!allContracts,
signer: walletClient,
userAddress: address,
},
],
queryFn: async () => {
return await getUserDataAllStrategies({
allContracts: allContracts!,
strategiesData: strategies.data!,
userAddress: address!,
sommPrice: sommPrice.data!,
chain: chain.id,
})
},
enabled:
!!allContracts &&
!!walletClient &&
!!strategies.data &&
!!address &&
!!sommPrice.data &&
!!chain.id,
}
)
return {
...query,
isError: query.isError,
}
}