-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathhooks.ts
More file actions
26 lines (21 loc) · 764 Bytes
/
hooks.ts
File metadata and controls
26 lines (21 loc) · 764 Bytes
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
import useSWR from "swr";
import { NATIVE_TOKEN_ID } from "@/common/constants";
import type { ConditionalActivation } from "@/common/types";
import { client } from "./client";
export const useNativeTokenUsdPrice = (
{ enabled = true }: ConditionalActivation | undefined = { enabled: true },
) =>
useSWR(
() => (!enabled ? null : ["oneNativeTokenUsdPrice", NATIVE_TOKEN_ID.toLowerCase()]),
([_queryKeyHead, tokenId]) =>
client
.get(`/simple/price?ids=${tokenId}&vs_currencies=usd`)
.then((response: { data: { [key: string]: { usd: number } } }) =>
response.data[tokenId].usd.toString(),
),
{
revalidateIfStale: false,
revalidateOnFocus: false,
revalidateOnReconnect: false,
},
);