Skip to content

Commit de0d98a

Browse files
committed
feat: add useOptions hook
1 parent d8533ed commit de0d98a

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export { SiweProvider } from "./siweProvider.js";
22
export { getSession, useSession } from "./useSession.js"
33
export { createMessage, getMessageBody, verify, useSignIn } from "./useSignIn.js"
44
export { signOut, useSignOut } from "./useSignOut.js"
5+
export { useOptions } from "./useOptions.js"
56
export type { UseSiweOptions } from "./types.js"

src/parseOptions.ts renamed to src/useOptions.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useContext } from "react";
2+
import { optionsContext } from "./siweProvider.js";
13
import { UseSiweOptions } from "./types.js"
24

35
const defaultOptions: Required<UseSiweOptions> = {
@@ -7,3 +9,8 @@ const defaultOptions: Required<UseSiweOptions> = {
79
export const parseOptions = (options: UseSiweOptions = {}) => {
810
return { ...defaultOptions, ...options };
911
}
12+
13+
export const useOptions = () => {
14+
const options = useContext(optionsContext);
15+
return parseOptions(options);
16+
}

src/useSession.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { useContext } from "react";
3-
import { parseOptions } from "./parseOptions.js";
3+
import { parseOptions } from "./useOptions.js";
44
import { queryContext, optionsContext } from "./siweProvider.js";
55
import { GetSessionResponse, UseSiweOptions } from "./types.js";
66

src/useSignIn.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient, UseQueryOptions } from "@tanstack/react-qu
22
import { useContext } from "react";
33
import { SiweMessage } from "siwe";
44
import { useAccount, useNetwork, useSignMessage } from "wagmi";
5-
import { parseOptions } from "./parseOptions.js";
5+
import { parseOptions } from "./useOptions.js";
66
import { optionsContext, queryContext } from "./siweProvider.js";
77
import { UseSiweOptions } from "./types.js";
88
import { useSession } from "./useSession.js";

src/useSignOut.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMutation, useQueryClient, UseQueryOptions } from "@tanstack/react-query";
22
import { useContext } from "react";
33
import { useAccount, useDisconnect } from "wagmi";
4-
import { parseOptions } from "./parseOptions.js";
4+
import { parseOptions } from "./useOptions.js";
55
import { optionsContext, queryContext } from "./siweProvider.js";
66
import { UseSiweOptions } from "./types.js";
77
import { useSession } from "./useSession.js";

0 commit comments

Comments
 (0)