Skip to content

Commit cf412aa

Browse files
authored
Merge pull request #57 from macalinao/igm/key-cleanup
Clean up various query keys
2 parents 434c49d + bf01031 commit cf412aa

File tree

13 files changed

+66
-21
lines changed

13 files changed

+66
-21
lines changed

.changeset/gentle-jeans-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@macalinao/grill": patch
3+
---
4+
5+
Query key cleanup

.changeset/tangy-emus-enter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@macalinao/grill": patch
3+
---
4+
5+
Grill hook client key cleanup

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Grill is a modern Solana development kit monorepo that provides React components
1616
- **Routing**: @tanstack/react-router (in example-dapp)
1717
- **Styling**: Tailwind CSS v4 with shadcn/ui components
1818
- **Code Quality**: Biome for formatting, ESLint for linting
19-
- **Testing**: Vitest
19+
- **Testing**: Bun Test via `bun run test`
2020

2121
## Essential Commands
2222

packages/grill/src/constants.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/grill/src/hooks/create-pda-hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQuery } from "@tanstack/react-query";
2-
import { GRILL_HOOK_CLIENT_KEY } from "../constants.js";
2+
import { createPdaQueryKey } from "../query-keys.js";
33

44
/**
55
* A function that computes a PDA from some arguments.
@@ -44,7 +44,7 @@ export function createPdaHook<TArgs, TResult>(
4444
args: TArgs | null | undefined,
4545
): TResult | null | undefined {
4646
const { data } = useQuery<TResult | null>({
47-
queryKey: [GRILL_HOOK_CLIENT_KEY, "pda", queryKeyPrefix, args] as const,
47+
queryKey: createPdaQueryKey(queryKeyPrefix, args),
4848
queryFn: async () => {
4949
if (!args) {
5050
return null;

packages/grill/src/hooks/use-account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { GillUseRpcHook } from "./types.js";
1010
import { fetchAndDecodeAccount } from "@macalinao/gill-extra";
1111
import { useQuery } from "@tanstack/react-query";
1212
import { useGrillContext } from "../contexts/grill-context.js";
13-
import { createAccountQueryKey } from "../utils/account-helpers.js";
13+
import { createAccountQueryKey } from "../query-keys.js";
1414

1515
type RpcConfig = Simplify<Omit<FetchAccountConfig, "abortSignal">>;
1616

packages/grill/src/hooks/use-accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { GillUseRpcHook } from "./types.js";
99
import { fetchAndDecodeAccount } from "@macalinao/gill-extra";
1010
import { useQueries } from "@tanstack/react-query";
1111
import { useGrillContext } from "../contexts/grill-context.js";
12-
import { createAccountQueryKey } from "../utils/account-helpers.js";
12+
import { createAccountQueryKey } from "../query-keys.js";
1313

1414
type RpcConfig = Simplify<Omit<FetchAccountConfig, "abortSignal">>;
1515

packages/grill/src/hooks/use-token-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { UseQueryResult } from "@tanstack/react-query";
44
import { createTokenInfo } from "@macalinao/token-utils";
55
import { tokenMetadataSchema } from "@macalinao/zod-solana";
66
import { useQuery } from "@tanstack/react-query";
7-
import { GRILL_HOOK_CLIENT_KEY } from "../constants.js";
7+
import { createTokenInfoQueryKey } from "../query-keys.js";
88
import { useMintAccount } from "./use-mint-account.js";
99
import { useTokenMetadataAccount } from "./use-token-metadata-account.js";
1010

@@ -23,7 +23,7 @@ export function useTokenInfo({
2323

2424
return useQuery<TokenInfo | null>({
2525
// eslint-disable-next-line @tanstack/query/exhaustive-deps
26-
queryKey: [GRILL_HOOK_CLIENT_KEY, "tokenInfo", mint] as const,
26+
queryKey: createTokenInfoQueryKey(mint),
2727
queryFn: async () => {
2828
if (!mint || decimals === undefined) {
2929
return null;

packages/grill/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export * from "@macalinao/gill-extra";
22
export * from "./contexts/index.js";
33
export * from "./hooks/index.js";
44
export * from "./providers/index.js";
5+
export * from "./query-keys.js";
56
export * from "./types.js";
67
export * from "./utils/index.js";

packages/grill/src/query-keys.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { Address } from "@solana/kit";
2+
3+
export const GRILL_REACT_QUERY_NAMESPACE = "solana" as const;
4+
5+
// Type definitions for query keys
6+
export type AccountQueryKey = readonly ["solana", "account", Address];
7+
export type TokenInfoQueryKey = readonly [
8+
"solana",
9+
"tokenInfo",
10+
Address | null | undefined,
11+
];
12+
export type PdaQueryKey<TArgs> = readonly [
13+
"solana",
14+
"pda",
15+
string,
16+
TArgs | null | undefined,
17+
];
18+
19+
/**
20+
* Create a query key for the account query
21+
* @param address - The address of the account
22+
* @returns The query key
23+
*/
24+
export const createAccountQueryKey = (address: Address): AccountQueryKey =>
25+
[GRILL_REACT_QUERY_NAMESPACE, "account", address] as const;
26+
27+
/**
28+
* Create a query key for token info query
29+
* @param mint - The mint address
30+
* @returns The query key
31+
*/
32+
export const createTokenInfoQueryKey = (
33+
mint: Address | null | undefined,
34+
): TokenInfoQueryKey =>
35+
[GRILL_REACT_QUERY_NAMESPACE, "tokenInfo", mint] as const;
36+
37+
/**
38+
* Create a query key for PDA queries
39+
* @param queryKeyPrefix - The PDA type prefix
40+
* @param args - The arguments for the PDA
41+
* @returns The query key
42+
*/
43+
export const createPdaQueryKey = <TArgs>(
44+
queryKeyPrefix: string,
45+
args: TArgs | null | undefined,
46+
): PdaQueryKey<TArgs> =>
47+
[GRILL_REACT_QUERY_NAMESPACE, "pda", queryKeyPrefix, args] as const;

0 commit comments

Comments
 (0)