@liberfi.io/wallet-connector 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -198,6 +198,6 @@ declare global {
198
198
  };
199
199
  }
200
200
  }
201
- declare const _default: "0.1.21";
201
+ declare const _default: "0.1.22";
202
202
 
203
203
  export { type AuthGuardedCallback, AuthProvider, type AuthProviderProps, type AuthenticatedUser, type Eip1193Provider, type EvmWalletAdapter, type WalletAdapter, WalletConnectorProvider, type WalletConnectorProviderProps, useAuth, useAuthCallback, useSwitchChain, useWalletConnector, useWallets, _default as version };
package/dist/index.d.ts CHANGED
@@ -198,6 +198,6 @@ declare global {
198
198
  };
199
199
  }
200
200
  }
201
- declare const _default: "0.1.21";
201
+ declare const _default: "0.1.22";
202
202
 
203
203
  export { type AuthGuardedCallback, AuthProvider, type AuthProviderProps, type AuthenticatedUser, type Eip1193Provider, type EvmWalletAdapter, type WalletAdapter, WalletConnectorProvider, type WalletConnectorProviderProps, useAuth, useAuthCallback, useSwitchChain, useWalletConnector, useWallets, _default as version };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),types=require('@liberfi.io/types'),utils=require('@liberfi.io/utils'),jsxRuntime=require('react/jsx-runtime');var n=react.createContext({});function u(){let t=react.useContext(n);if(!t)throw new Error("useAuth must be used within a AuthProvider");return t}function b(t,e){let{status:r,signIn:o}=u(),a=react.useRef(r);return a.current=r,react.useCallback(async(...c)=>{if(a.current!=="authenticated"){a.current==="unauthenticated"&&o();return}return t(...c)},[...e||[],o,t])}var i=react.createContext({});function s(){let t=react.useContext(i);if(!t)throw new Error("useWalletConnector must be used within a WalletConnectorProvider");return t}function l(){let{wallets:t}=s();return t}function J(){let t=l();return react.useCallback(async e=>{if(utils.chainToNamespace(e)===types.ChainNamespace.SOLANA)return;let r=t.filter(o=>"switchChain"in o&&o.isConnected);await Promise.all(r.map(o=>o.switchChain(e)));},[t])}function et({children:t,...e}){return jsxRuntime.jsx(n.Provider,{value:e,children:t})}function at({children:t,...e}){return jsxRuntime.jsx(i.Provider,{value:e,children:t})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/wallet-connector"]="0.1.21");var w="0.1.21";exports.AuthProvider=et;exports.WalletConnectorProvider=at;exports.useAuth=u;exports.useAuthCallback=b;exports.useSwitchChain=J;exports.useWalletConnector=s;exports.useWallets=l;exports.version=w;//# sourceMappingURL=index.js.map
1
+ 'use strict';var react=require('react'),types=require('@liberfi.io/types'),utils=require('@liberfi.io/utils'),jsxRuntime=require('react/jsx-runtime');var n=react.createContext({});function u(){let t=react.useContext(n);if(!t)throw new Error("useAuth must be used within a AuthProvider");return t}function b(t,e){let{status:r,signIn:o}=u(),a=react.useRef(r);return a.current=r,react.useCallback(async(...c)=>{if(a.current!=="authenticated"){a.current==="unauthenticated"&&o();return}return t(...c)},[...e||[],o,t])}var i=react.createContext({});function s(){let t=react.useContext(i);if(!t)throw new Error("useWalletConnector must be used within a WalletConnectorProvider");return t}function l(){let{wallets:t}=s();return t}function J(){let t=l();return react.useCallback(async e=>{if(utils.chainToNamespace(e)===types.ChainNamespace.SOLANA)return;let r=t.filter(o=>"switchChain"in o&&o.isConnected);await Promise.all(r.map(o=>o.switchChain(e)));},[t])}function et({children:t,...e}){return jsxRuntime.jsx(n.Provider,{value:e,children:t})}function at({children:t,...e}){return jsxRuntime.jsx(i.Provider,{value:e,children:t})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/wallet-connector"]="0.1.22");var w="0.1.22";exports.AuthProvider=et;exports.WalletConnectorProvider=at;exports.useAuth=u;exports.useAuthCallback=b;exports.useSwitchChain=J;exports.useWalletConnector=s;exports.useWallets=l;exports.version=w;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/providers/AuthContext.ts","../src/hooks/useAuth.ts","../src/hooks/useAuthCallback.ts","../src/providers/WalletConnectorContext.ts","../src/hooks/useWalletConnector.ts","../src/hooks/useWallets.ts","../src/hooks/useSwitchChain.ts","../src/providers/AuthProvider.tsx","../src/providers/WalletConnectorProvider.tsx","../src/version.ts"],"names":["AuthContext","createContext","useAuth","context","useContext","useAuthCallback","callback","deps","status","signIn","statusRef","useRef","useCallback","args","WalletConnectorContext","useWalletConnector","useWallets","wallets","useSwitchChain","chain","chainToNamespace","ChainNamespace","evmWallets","w","AuthProvider","children","value","jsx","WalletConnectorProvider","version_default"],"mappings":"sJAgBO,IAAMA,CAAAA,CAAcC,mBAAAA,CACzB,EACF,CAAA,CCPO,SAASC,CAAAA,EAAU,CACxB,IAAMC,CAAAA,CAAUC,gBAAAA,CAAWJ,CAAW,CAAA,CACtC,GAAI,CAACG,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,4CAA4C,CAAA,CAE9D,OAAOA,CACT,CCUO,SAASE,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACwB,CACxB,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,MAAA,CAAAC,CAAO,CAAA,CAAIP,CAAAA,EAAQ,CAE7BQ,CAAAA,CAAYC,YAAAA,CAAeH,CAAM,CAAA,CACvC,OAAAE,CAAAA,CAAU,OAAA,CAAUF,CAAAA,CAEbI,kBACL,MAAA,GACKC,CAAAA,GAC6C,CAChD,GAAIH,CAAAA,CAAU,OAAA,GAAY,eAAA,CAAiB,CACrCA,CAAAA,CAAU,OAAA,GAAY,iBAAA,EACxBD,CAAAA,EAAO,CAET,MACF,CACA,OAAOH,CAAAA,CAAS,GAAGO,CAAI,CACzB,CAAA,CACA,CAAC,GAAIN,CAAAA,EAAQ,EAAC,CAAIE,CAAAA,CAAQH,CAAQ,CACpC,CACF,CCzBO,IAAMQ,CAAAA,CACXb,mBA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O,mBAAA,CAAsB,MAAA,CAAO,mBAAA,EAAuB,EAAC,CAC5D,MAAA,CAAO,mBAAA,CAAoB,8BAA8B,CAAA,CAAI,QAAA,CAAA,KAGxDI,CAAAA,CAAQ","file":"index.js","sourcesContent":["import { createContext } from \"react\";\nimport { AuthenticatedUser } from \"../types\";\n\nexport interface AuthContextValue {\n /** authenticated user profile */\n user: AuthenticatedUser | null;\n /** authentication status */\n status: \"unauthenticated\" | \"authenticating\" | \"authenticated\";\n /** sign in to the IdP */\n signIn: () => void | Promise<void>;\n /** sign out from the IdP */\n signOut: () => void | Promise<void>;\n /** refresh the access token */\n refreshAccessToken: () => void | Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextValue>(\n {} as AuthContextValue,\n);\n","import { useContext } from \"react\";\nimport { AuthContext } from \"../providers/AuthContext\";\n\n/**\n * Returns the auth context value.\n *\n * Must be used within an {@link AuthProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link AuthContextValue} (user, status, signIn, signOut, refreshAccessToken).\n */\nexport function useAuth() {\n const context = useContext(AuthContext);\n if (!context) {\n throw new Error(\"useAuth must be used within a AuthProvider\");\n }\n return context;\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DependencyList, useCallback, useRef } from \"react\";\nimport { useAuth } from \"./useAuth\";\n\n/**\n * The return type of {@link useAuthCallback}.\n *\n * Accepts the same parameters as `T` but always returns a `Promise` that\n * resolves to `Awaited<ReturnType<T>>` when authenticated, or `undefined`\n * when the user is not yet authenticated.\n */\nexport type AuthGuardedCallback<T extends (...args: any[]) => any> = (\n ...args: Parameters<T>\n) => Promise<Awaited<ReturnType<T>> | undefined>;\n\n/**\n * Wraps a callback so it only executes when the user is authenticated.\n *\n * - **authenticated**: executes the callback and returns its result.\n * - **unauthenticated**: triggers `signIn()` and returns `undefined`.\n * - **authenticating**: returns `undefined` without re-triggering sign-in\n * (avoids conflicting with an in-progress auth flow).\n *\n * @param callback - The function to guard behind authentication.\n * @param deps - Optional dependency list (same semantics as `useCallback`).\n * @returns A wrapped callback that may resolve to `undefined` when not authenticated.\n */\nexport function useAuthCallback<T extends (...args: any[]) => any>(\n callback: T,\n deps?: DependencyList,\n): AuthGuardedCallback<T> {\n const { status, signIn } = useAuth();\n\n const statusRef = useRef<string>(status);\n statusRef.current = status;\n\n return useCallback(\n async (\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>> | undefined> => {\n if (statusRef.current !== \"authenticated\") {\n if (statusRef.current === \"unauthenticated\") {\n signIn();\n }\n return;\n }\n return callback(...args);\n },\n [...(deps || []), signIn, callback],\n );\n}\n","import { createContext } from \"react\";\nimport { WalletAdapter } from \"../types\";\n\nexport interface WalletConnectorContextValue {\n /**\n * detecting: is detecting connected wallets\n * connecting: is connecting to the first wallet\n * connected: is connected to at least one wallet\n * disconnecting: is disconnecting from the last connected wallet\n * disconnected: is disconnected from all wallets\n */\n status:\n | \"detecting\"\n | \"connecting\"\n | \"connected\"\n | \"disconnecting\"\n | \"disconnected\";\n // all wallets that can be used to take onchain actions when connected\n wallets: Array<WalletAdapter>;\n // if no wallets are connected, connect one or multiple wallets\n connect: () => Promise<void>;\n // disconnect all wallets\n disconnect: () => Promise<void>;\n}\n\nexport const WalletConnectorContext =\n createContext<WalletConnectorContextValue>({} as WalletConnectorContextValue);\n","import { useContext } from \"react\";\nimport { WalletConnectorContext } from \"../providers/WalletConnectorContext\";\n\n/**\n * Returns the wallet connector context value.\n *\n * Must be used within a {@link WalletConnectorProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link WalletConnectorContextValue} (status, wallets, connect, disconnect).\n */\nexport function useWalletConnector() {\n const context = useContext(WalletConnectorContext);\n if (!context) {\n throw new Error(\n \"useWalletConnector must be used within a WalletConnectorProvider\",\n );\n }\n return context;\n}\n","import { useWalletConnector } from \"./useWalletConnector\";\n\n/**\n * Convenience hook that returns the `wallets` array from the wallet connector context.\n *\n * Shorthand for `useWalletConnector().wallets`.\n *\n * @returns All wallets that can be used to take on-chain actions when connected.\n */\nexport function useWallets() {\n const { wallets } = useWalletConnector();\n return wallets;\n}\n","import { useCallback } from \"react\";\nimport { Chain, ChainNamespace } from \"@liberfi.io/types\";\nimport { chainToNamespace } from \"@liberfi.io/utils\";\nimport { EvmWalletAdapter } from \"../types\";\nimport { useWallets } from \"./useWallets\";\n\n/**\n * Returns a function that switches all connected EVM wallets to the given chain.\n *\n * Solana chains are automatically skipped (no-op). For EVM chains, the returned\n * function calls `switchChain` on every connected wallet that implements\n * {@link EvmWalletAdapter} in parallel.\n *\n * @returns An async function `(chain: Chain) => Promise<void>`.\n */\nexport function useSwitchChain() {\n const wallets = useWallets();\n\n return useCallback(\n async (chain: Chain) => {\n if (chainToNamespace(chain) === ChainNamespace.SOLANA) return;\n\n const evmWallets = wallets.filter(\n (w): w is EvmWalletAdapter => \"switchChain\" in w && w.isConnected,\n );\n await Promise.all(evmWallets.map((w) => w.switchChain(chain)));\n },\n [wallets],\n );\n}\n","import { PropsWithChildren } from \"react\";\nimport { AuthContext, AuthContextValue } from \"./AuthContext\";\n\n/** Props for {@link AuthProvider}. */\nexport type AuthProviderProps = PropsWithChildren<AuthContextValue>;\n\n/**\n * Provides authentication state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyAuthProvider`) typically wrap this component and supply the concrete\n * `user`, `status`, `signIn`, `signOut`, and `refreshAccessToken` values.\n */\nexport function AuthProvider({ children, ...value }: AuthProviderProps) {\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n","import { PropsWithChildren } from \"react\";\nimport {\n WalletConnectorContext,\n WalletConnectorContextValue,\n} from \"./WalletConnectorContext\";\n\n/** Props for {@link WalletConnectorProvider}. */\nexport type WalletConnectorProviderProps =\n PropsWithChildren<WalletConnectorContextValue>;\n\n/**\n * Provides wallet connection state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyWalletConnectorProvider`) typically wrap this component and supply\n * the concrete `status`, `wallets`, `connect`, and `disconnect` values.\n */\nexport function WalletConnectorProvider({\n children,\n ...value\n}: WalletConnectorProviderProps) {\n return (\n <WalletConnectorContext.Provider value={value}>\n {children}\n </WalletConnectorContext.Provider>\n );\n}\n","declare global {\n interface Window {\n __LIBERFI_VERSION__?: {\n [key: string]: string;\n };\n }\n}\nif (typeof window !== \"undefined\") {\n window.__LIBERFI_VERSION__ = window.__LIBERFI_VERSION__ || {};\n window.__LIBERFI_VERSION__[\"@liberfi.io/wallet-connector\"] = \"0.1.21\";\n}\n\nexport default \"0.1.21\";\n"]}
1
+ {"version":3,"sources":["../src/providers/AuthContext.ts","../src/hooks/useAuth.ts","../src/hooks/useAuthCallback.ts","../src/providers/WalletConnectorContext.ts","../src/hooks/useWalletConnector.ts","../src/hooks/useWallets.ts","../src/hooks/useSwitchChain.ts","../src/providers/AuthProvider.tsx","../src/providers/WalletConnectorProvider.tsx","../src/version.ts"],"names":["AuthContext","createContext","useAuth","context","useContext","useAuthCallback","callback","deps","status","signIn","statusRef","useRef","useCallback","args","WalletConnectorContext","useWalletConnector","useWallets","wallets","useSwitchChain","chain","chainToNamespace","ChainNamespace","evmWallets","w","AuthProvider","children","value","jsx","WalletConnectorProvider","version_default"],"mappings":"sJAgBO,IAAMA,CAAAA,CAAcC,mBAAAA,CACzB,EACF,CAAA,CCPO,SAASC,CAAAA,EAAU,CACxB,IAAMC,CAAAA,CAAUC,gBAAAA,CAAWJ,CAAW,CAAA,CACtC,GAAI,CAACG,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,4CAA4C,CAAA,CAE9D,OAAOA,CACT,CCUO,SAASE,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACwB,CACxB,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,MAAA,CAAAC,CAAO,CAAA,CAAIP,CAAAA,EAAQ,CAE7BQ,CAAAA,CAAYC,YAAAA,CAAeH,CAAM,CA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AAsB,CACtE,OAAOC,cAAAA,CAAC3B,CAAAA,CAAY,QAAA,CAAZ,CAAqB,KAAA,CAAO0B,CAAAA,CAAQ,QAAA,CAAAD,CAAAA,CAAS,CACvD,CCEO,SAASG,GAAwB,CACtC,QAAA,CAAAH,CAAAA,CACA,GAAGC,CACL,CAAA,CAAiC,CAC/B,OACEC,cAAAA,CAACb,CAAAA,CAAuB,QAAA,CAAvB,CAAgC,KAAA,CAAOY,CAAAA,CACrC,QAAA,CAAAD,CAAAA,CACH,CAEJ,CCpBI,OAAO,MAAA,CAAW,GAAA,GACpB,MAAA,CAAO,mBAAA,CAAsB,MAAA,CAAO,mBAAA,EAAuB,EAAC,CAC5D,MAAA,CAAO,mBAAA,CAAoB,8BAA8B,CAAA,CAAI,QAAA,CAAA,KAGxDI,CAAAA,CAAQ","file":"index.js","sourcesContent":["import { createContext } from \"react\";\nimport { AuthenticatedUser } from \"../types\";\n\nexport interface AuthContextValue {\n /** authenticated user profile */\n user: AuthenticatedUser | null;\n /** authentication status */\n status: \"unauthenticated\" | \"authenticating\" | \"authenticated\";\n /** sign in to the IdP */\n signIn: () => void | Promise<void>;\n /** sign out from the IdP */\n signOut: () => void | Promise<void>;\n /** refresh the access token */\n refreshAccessToken: () => void | Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextValue>(\n {} as AuthContextValue,\n);\n","import { useContext } from \"react\";\nimport { AuthContext } from \"../providers/AuthContext\";\n\n/**\n * Returns the auth context value.\n *\n * Must be used within an {@link AuthProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link AuthContextValue} (user, status, signIn, signOut, refreshAccessToken).\n */\nexport function useAuth() {\n const context = useContext(AuthContext);\n if (!context) {\n throw new Error(\"useAuth must be used within a AuthProvider\");\n }\n return context;\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DependencyList, useCallback, useRef } from \"react\";\nimport { useAuth } from \"./useAuth\";\n\n/**\n * The return type of {@link useAuthCallback}.\n *\n * Accepts the same parameters as `T` but always returns a `Promise` that\n * resolves to `Awaited<ReturnType<T>>` when authenticated, or `undefined`\n * when the user is not yet authenticated.\n */\nexport type AuthGuardedCallback<T extends (...args: any[]) => any> = (\n ...args: Parameters<T>\n) => Promise<Awaited<ReturnType<T>> | undefined>;\n\n/**\n * Wraps a callback so it only executes when the user is authenticated.\n *\n * - **authenticated**: executes the callback and returns its result.\n * - **unauthenticated**: triggers `signIn()` and returns `undefined`.\n * - **authenticating**: returns `undefined` without re-triggering sign-in\n * (avoids conflicting with an in-progress auth flow).\n *\n * @param callback - The function to guard behind authentication.\n * @param deps - Optional dependency list (same semantics as `useCallback`).\n * @returns A wrapped callback that may resolve to `undefined` when not authenticated.\n */\nexport function useAuthCallback<T extends (...args: any[]) => any>(\n callback: T,\n deps?: DependencyList,\n): AuthGuardedCallback<T> {\n const { status, signIn } = useAuth();\n\n const statusRef = useRef<string>(status);\n statusRef.current = status;\n\n return useCallback(\n async (\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>> | undefined> => {\n if (statusRef.current !== \"authenticated\") {\n if (statusRef.current === \"unauthenticated\") {\n signIn();\n }\n return;\n }\n return callback(...args);\n },\n [...(deps || []), signIn, callback],\n );\n}\n","import { createContext } from \"react\";\nimport { WalletAdapter } from \"../types\";\n\nexport interface WalletConnectorContextValue {\n /**\n * detecting: is detecting connected wallets\n * connecting: is connecting to the first wallet\n * connected: is connected to at least one wallet\n * disconnecting: is disconnecting from the last connected wallet\n * disconnected: is disconnected from all wallets\n */\n status:\n | \"detecting\"\n | \"connecting\"\n | \"connected\"\n | \"disconnecting\"\n | \"disconnected\";\n // all wallets that can be used to take onchain actions when connected\n wallets: Array<WalletAdapter>;\n // if no wallets are connected, connect one or multiple wallets\n connect: () => Promise<void>;\n // disconnect all wallets\n disconnect: () => Promise<void>;\n}\n\nexport const WalletConnectorContext =\n createContext<WalletConnectorContextValue>({} as WalletConnectorContextValue);\n","import { useContext } from \"react\";\nimport { WalletConnectorContext } from \"../providers/WalletConnectorContext\";\n\n/**\n * Returns the wallet connector context value.\n *\n * Must be used within a {@link WalletConnectorProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link WalletConnectorContextValue} (status, wallets, connect, disconnect).\n */\nexport function useWalletConnector() {\n const context = useContext(WalletConnectorContext);\n if (!context) {\n throw new Error(\n \"useWalletConnector must be used within a WalletConnectorProvider\",\n );\n }\n return context;\n}\n","import { useWalletConnector } from \"./useWalletConnector\";\n\n/**\n * Convenience hook that returns the `wallets` array from the wallet connector context.\n *\n * Shorthand for `useWalletConnector().wallets`.\n *\n * @returns All wallets that can be used to take on-chain actions when connected.\n */\nexport function useWallets() {\n const { wallets } = useWalletConnector();\n return wallets;\n}\n","import { useCallback } from \"react\";\nimport { Chain, ChainNamespace } from \"@liberfi.io/types\";\nimport { chainToNamespace } from \"@liberfi.io/utils\";\nimport { EvmWalletAdapter } from \"../types\";\nimport { useWallets } from \"./useWallets\";\n\n/**\n * Returns a function that switches all connected EVM wallets to the given chain.\n *\n * Solana chains are automatically skipped (no-op). For EVM chains, the returned\n * function calls `switchChain` on every connected wallet that implements\n * {@link EvmWalletAdapter} in parallel.\n *\n * @returns An async function `(chain: Chain) => Promise<void>`.\n */\nexport function useSwitchChain() {\n const wallets = useWallets();\n\n return useCallback(\n async (chain: Chain) => {\n if (chainToNamespace(chain) === ChainNamespace.SOLANA) return;\n\n const evmWallets = wallets.filter(\n (w): w is EvmWalletAdapter => \"switchChain\" in w && w.isConnected,\n );\n await Promise.all(evmWallets.map((w) => w.switchChain(chain)));\n },\n [wallets],\n );\n}\n","import { PropsWithChildren } from \"react\";\nimport { AuthContext, AuthContextValue } from \"./AuthContext\";\n\n/** Props for {@link AuthProvider}. */\nexport type AuthProviderProps = PropsWithChildren<AuthContextValue>;\n\n/**\n * Provides authentication state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyAuthProvider`) typically wrap this component and supply the concrete\n * `user`, `status`, `signIn`, `signOut`, and `refreshAccessToken` values.\n */\nexport function AuthProvider({ children, ...value }: AuthProviderProps) {\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n","import { PropsWithChildren } from \"react\";\nimport {\n WalletConnectorContext,\n WalletConnectorContextValue,\n} from \"./WalletConnectorContext\";\n\n/** Props for {@link WalletConnectorProvider}. */\nexport type WalletConnectorProviderProps =\n PropsWithChildren<WalletConnectorContextValue>;\n\n/**\n * Provides wallet connection state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyWalletConnectorProvider`) typically wrap this component and supply\n * the concrete `status`, `wallets`, `connect`, and `disconnect` values.\n */\nexport function WalletConnectorProvider({\n children,\n ...value\n}: WalletConnectorProviderProps) {\n return (\n <WalletConnectorContext.Provider value={value}>\n {children}\n </WalletConnectorContext.Provider>\n );\n}\n","declare global {\n interface Window {\n __LIBERFI_VERSION__?: {\n [key: string]: string;\n };\n }\n}\nif (typeof window !== \"undefined\") {\n window.__LIBERFI_VERSION__ = window.__LIBERFI_VERSION__ || {};\n window.__LIBERFI_VERSION__[\"@liberfi.io/wallet-connector\"] = \"0.1.22\";\n}\n\nexport default \"0.1.22\";\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {createContext,useContext,useRef,useCallback}from'react';import {ChainNamespace}from'@liberfi.io/types';import {chainToNamespace}from'@liberfi.io/utils';import {jsx}from'react/jsx-runtime';var n=createContext({});function u(){let t=useContext(n);if(!t)throw new Error("useAuth must be used within a AuthProvider");return t}function b(t,e){let{status:r,signIn:o}=u(),a=useRef(r);return a.current=r,useCallback(async(...c)=>{if(a.current!=="authenticated"){a.current==="unauthenticated"&&o();return}return t(...c)},[...e||[],o,t])}var i=createContext({});function s(){let t=useContext(i);if(!t)throw new Error("useWalletConnector must be used within a WalletConnectorProvider");return t}function l(){let{wallets:t}=s();return t}function J(){let t=l();return useCallback(async e=>{if(chainToNamespace(e)===ChainNamespace.SOLANA)return;let r=t.filter(o=>"switchChain"in o&&o.isConnected);await Promise.all(r.map(o=>o.switchChain(e)));},[t])}function et({children:t,...e}){return jsx(n.Provider,{value:e,children:t})}function at({children:t,...e}){return jsx(i.Provider,{value:e,children:t})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/wallet-connector"]="0.1.21");var w="0.1.21";export{et as AuthProvider,at as WalletConnectorProvider,u as useAuth,b as useAuthCallback,J as useSwitchChain,s as useWalletConnector,l as useWallets,w as version};//# sourceMappingURL=index.mjs.map
1
+ import {createContext,useContext,useRef,useCallback}from'react';import {ChainNamespace}from'@liberfi.io/types';import {chainToNamespace}from'@liberfi.io/utils';import {jsx}from'react/jsx-runtime';var n=createContext({});function u(){let t=useContext(n);if(!t)throw new Error("useAuth must be used within a AuthProvider");return t}function b(t,e){let{status:r,signIn:o}=u(),a=useRef(r);return a.current=r,useCallback(async(...c)=>{if(a.current!=="authenticated"){a.current==="unauthenticated"&&o();return}return t(...c)},[...e||[],o,t])}var i=createContext({});function s(){let t=useContext(i);if(!t)throw new Error("useWalletConnector must be used within a WalletConnectorProvider");return t}function l(){let{wallets:t}=s();return t}function J(){let t=l();return useCallback(async e=>{if(chainToNamespace(e)===ChainNamespace.SOLANA)return;let r=t.filter(o=>"switchChain"in o&&o.isConnected);await Promise.all(r.map(o=>o.switchChain(e)));},[t])}function et({children:t,...e}){return jsx(n.Provider,{value:e,children:t})}function at({children:t,...e}){return jsx(i.Provider,{value:e,children:t})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/wallet-connector"]="0.1.22");var w="0.1.22";export{et as AuthProvider,at as WalletConnectorProvider,u as useAuth,b as useAuthCallback,J as useSwitchChain,s as useWalletConnector,l as useWallets,w as version};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/providers/AuthContext.ts","../src/hooks/useAuth.ts","../src/hooks/useAuthCallback.ts","../src/providers/WalletConnectorContext.ts","../src/hooks/useWalletConnector.ts","../src/hooks/useWallets.ts","../src/hooks/useSwitchChain.ts","../src/providers/AuthProvider.tsx","../src/providers/WalletConnectorProvider.tsx","../src/version.ts"],"names":["AuthContext","createContext","useAuth","context","useContext","useAuthCallback","callback","deps","status","signIn","statusRef","useRef","useCallback","args","WalletConnectorContext","useWalletConnector","useWallets","wallets","useSwitchChain","chain","chainToNamespace","ChainNamespace","evmWallets","w","AuthProvider","children","value","jsx","WalletConnectorProvider","version_default"],"mappings":"oMAgBO,IAAMA,CAAAA,CAAcC,aAAAA,CACzB,EACF,CAAA,CCPO,SAASC,CAAAA,EAAU,CACxB,IAAMC,CAAAA,CAAUC,UAAAA,CAAWJ,CAAW,CAAA,CACtC,GAAI,CAACG,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,4CAA4C,CAAA,CAE9D,OAAOA,CACT,CCUO,SAASE,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACwB,CACxB,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,MAAA,CAAAC,CAAO,CAAA,CAAIP,CAAAA,EAAQ,CAE7BQ,CAAAA,CAAYC,MAAAA,CAAeH,CAAM,CAAA,CACvC,OAAAE,CAAAA,CAAU,OAAA,CAAUF,CAAAA,CAEbI,YACL,MAAA,GACKC,CAAAA,GAC6C,CAChD,GAAIH,CAAAA,CAAU,OAAA,GAAY,eAAA,CAAiB,CACrCA,CAAAA,CAAU,OAAA,GAAY,iBAAA,EACxBD,CAAAA,EAAO,CAET,MACF,CACA,OAAOH,CAAAA,CAAS,GAAGO,CAAI,CACzB,CAAA,CACA,CAAC,GAAIN,CAAAA,EAAQ,EAAC,CAAIE,CAAAA,CAAQH,CAAQ,CACpC,CACF,CCzBO,IAAMQ,CAAAA,CACXb,aAAAA,CAA2C,EAAiC,CAAA,C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BAAA,EAAuB,EAAC,CAC5D,MAAA,CAAO,mBAAA,CAAoB,8BAA8B,CAAA,CAAI,QAAA,CAAA,KAGxDI,CAAAA,CAAQ","file":"index.mjs","sourcesContent":["import { createContext } from \"react\";\nimport { AuthenticatedUser } from \"../types\";\n\nexport interface AuthContextValue {\n /** authenticated user profile */\n user: AuthenticatedUser | null;\n /** authentication status */\n status: \"unauthenticated\" | \"authenticating\" | \"authenticated\";\n /** sign in to the IdP */\n signIn: () => void | Promise<void>;\n /** sign out from the IdP */\n signOut: () => void | Promise<void>;\n /** refresh the access token */\n refreshAccessToken: () => void | Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextValue>(\n {} as AuthContextValue,\n);\n","import { useContext } from \"react\";\nimport { AuthContext } from \"../providers/AuthContext\";\n\n/**\n * Returns the auth context value.\n *\n * Must be used within an {@link AuthProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link AuthContextValue} (user, status, signIn, signOut, refreshAccessToken).\n */\nexport function useAuth() {\n const context = useContext(AuthContext);\n if (!context) {\n throw new Error(\"useAuth must be used within a AuthProvider\");\n }\n return context;\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DependencyList, useCallback, useRef } from \"react\";\nimport { useAuth } from \"./useAuth\";\n\n/**\n * The return type of {@link useAuthCallback}.\n *\n * Accepts the same parameters as `T` but always returns a `Promise` that\n * resolves to `Awaited<ReturnType<T>>` when authenticated, or `undefined`\n * when the user is not yet authenticated.\n */\nexport type AuthGuardedCallback<T extends (...args: any[]) => any> = (\n ...args: Parameters<T>\n) => Promise<Awaited<ReturnType<T>> | undefined>;\n\n/**\n * Wraps a callback so it only executes when the user is authenticated.\n *\n * - **authenticated**: executes the callback and returns its result.\n * - **unauthenticated**: triggers `signIn()` and returns `undefined`.\n * - **authenticating**: returns `undefined` without re-triggering sign-in\n * (avoids conflicting with an in-progress auth flow).\n *\n * @param callback - The function to guard behind authentication.\n * @param deps - Optional dependency list (same semantics as `useCallback`).\n * @returns A wrapped callback that may resolve to `undefined` when not authenticated.\n */\nexport function useAuthCallback<T extends (...args: any[]) => any>(\n callback: T,\n deps?: DependencyList,\n): AuthGuardedCallback<T> {\n const { status, signIn } = useAuth();\n\n const statusRef = useRef<string>(status);\n statusRef.current = status;\n\n return useCallback(\n async (\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>> | undefined> => {\n if (statusRef.current !== \"authenticated\") {\n if (statusRef.current === \"unauthenticated\") {\n signIn();\n }\n return;\n }\n return callback(...args);\n },\n [...(deps || []), signIn, callback],\n );\n}\n","import { createContext } from \"react\";\nimport { WalletAdapter } from \"../types\";\n\nexport interface WalletConnectorContextValue {\n /**\n * detecting: is detecting connected wallets\n * connecting: is connecting to the first wallet\n * connected: is connected to at least one wallet\n * disconnecting: is disconnecting from the last connected wallet\n * disconnected: is disconnected from all wallets\n */\n status:\n | \"detecting\"\n | \"connecting\"\n | \"connected\"\n | \"disconnecting\"\n | \"disconnected\";\n // all wallets that can be used to take onchain actions when connected\n wallets: Array<WalletAdapter>;\n // if no wallets are connected, connect one or multiple wallets\n connect: () => Promise<void>;\n // disconnect all wallets\n disconnect: () => Promise<void>;\n}\n\nexport const WalletConnectorContext =\n createContext<WalletConnectorContextValue>({} as WalletConnectorContextValue);\n","import { useContext } from \"react\";\nimport { WalletConnectorContext } from \"../providers/WalletConnectorContext\";\n\n/**\n * Returns the wallet connector context value.\n *\n * Must be used within a {@link WalletConnectorProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link WalletConnectorContextValue} (status, wallets, connect, disconnect).\n */\nexport function useWalletConnector() {\n const context = useContext(WalletConnectorContext);\n if (!context) {\n throw new Error(\n \"useWalletConnector must be used within a WalletConnectorProvider\",\n );\n }\n return context;\n}\n","import { useWalletConnector } from \"./useWalletConnector\";\n\n/**\n * Convenience hook that returns the `wallets` array from the wallet connector context.\n *\n * Shorthand for `useWalletConnector().wallets`.\n *\n * @returns All wallets that can be used to take on-chain actions when connected.\n */\nexport function useWallets() {\n const { wallets } = useWalletConnector();\n return wallets;\n}\n","import { useCallback } from \"react\";\nimport { Chain, ChainNamespace } from \"@liberfi.io/types\";\nimport { chainToNamespace } from \"@liberfi.io/utils\";\nimport { EvmWalletAdapter } from \"../types\";\nimport { useWallets } from \"./useWallets\";\n\n/**\n * Returns a function that switches all connected EVM wallets to the given chain.\n *\n * Solana chains are automatically skipped (no-op). For EVM chains, the returned\n * function calls `switchChain` on every connected wallet that implements\n * {@link EvmWalletAdapter} in parallel.\n *\n * @returns An async function `(chain: Chain) => Promise<void>`.\n */\nexport function useSwitchChain() {\n const wallets = useWallets();\n\n return useCallback(\n async (chain: Chain) => {\n if (chainToNamespace(chain) === ChainNamespace.SOLANA) return;\n\n const evmWallets = wallets.filter(\n (w): w is EvmWalletAdapter => \"switchChain\" in w && w.isConnected,\n );\n await Promise.all(evmWallets.map((w) => w.switchChain(chain)));\n },\n [wallets],\n );\n}\n","import { PropsWithChildren } from \"react\";\nimport { AuthContext, AuthContextValue } from \"./AuthContext\";\n\n/** Props for {@link AuthProvider}. */\nexport type AuthProviderProps = PropsWithChildren<AuthContextValue>;\n\n/**\n * Provides authentication state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyAuthProvider`) typically wrap this component and supply the concrete\n * `user`, `status`, `signIn`, `signOut`, and `refreshAccessToken` values.\n */\nexport function AuthProvider({ children, ...value }: AuthProviderProps) {\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n","import { PropsWithChildren } from \"react\";\nimport {\n WalletConnectorContext,\n WalletConnectorContextValue,\n} from \"./WalletConnectorContext\";\n\n/** Props for {@link WalletConnectorProvider}. */\nexport type WalletConnectorProviderProps =\n PropsWithChildren<WalletConnectorContextValue>;\n\n/**\n * Provides wallet connection state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyWalletConnectorProvider`) typically wrap this component and supply\n * the concrete `status`, `wallets`, `connect`, and `disconnect` values.\n */\nexport function WalletConnectorProvider({\n children,\n ...value\n}: WalletConnectorProviderProps) {\n return (\n <WalletConnectorContext.Provider value={value}>\n {children}\n </WalletConnectorContext.Provider>\n );\n}\n","declare global {\n interface Window {\n __LIBERFI_VERSION__?: {\n [key: string]: string;\n };\n }\n}\nif (typeof window !== \"undefined\") {\n window.__LIBERFI_VERSION__ = window.__LIBERFI_VERSION__ || {};\n window.__LIBERFI_VERSION__[\"@liberfi.io/wallet-connector\"] = \"0.1.21\";\n}\n\nexport default \"0.1.21\";\n"]}
1
+ {"version":3,"sources":["../src/providers/AuthContext.ts","../src/hooks/useAuth.ts","../src/hooks/useAuthCallback.ts","../src/providers/WalletConnectorContext.ts","../src/hooks/useWalletConnector.ts","../src/hooks/useWallets.ts","../src/hooks/useSwitchChain.ts","../src/providers/AuthProvider.tsx","../src/providers/WalletConnectorProvider.tsx","../src/version.ts"],"names":["AuthContext","createContext","useAuth","context","useContext","useAuthCallback","callback","deps","status","signIn","statusRef","useRef","useCallback","args","WalletConnectorContext","useWalletConnector","useWallets","wallets","useSwitchChain","chain","chainToNamespace","ChainNamespace","evmWallets","w","AuthProvider","children","value","jsx","WalletConnectorProvider","version_default"],"mappings":"oMAgBO,IAAMA,CAAAA,CAAcC,aAAAA,CACzB,EACF,CAAA,CCPO,SAASC,CAAAA,EAAU,CACxB,IAAMC,CAAAA,CAAUC,UAAAA,CAAWJ,CAAW,CAAA,CACtC,GAAI,CAACG,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,4CAA4C,CAAA,CAE9D,OAAOA,CACT,CCUO,SAASE,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACwB,CACxB,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,MAAA,CAAAC,CAAO,CAAA,CAAIP,CAAAA,EAAQ,CAE7BQ,CAAAA,CAAYC,MAAAA,CAAeH,CAAM,CAAA,CACvC,OAAAE,CAAAA,CAAU,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AAAA,CAAY,QAAA,CAAZ,CAAqB,KAAA,CAAO0B,CAAAA,CAAQ,QAAA,CAAAD,CAAAA,CAAS,CACvD,CCEO,SAASG,GAAwB,CACtC,QAAA,CAAAH,CAAAA,CACA,GAAGC,CACL,CAAA,CAAiC,CAC/B,OACEC,GAAAA,CAACb,CAAAA,CAAuB,QAAA,CAAvB,CAAgC,KAAA,CAAOY,CAAAA,CACrC,QAAA,CAAAD,CAAAA,CACH,CAEJ,CCpBI,OAAO,MAAA,CAAW,GAAA,GACpB,MAAA,CAAO,mBAAA,CAAsB,MAAA,CAAO,mBAAA,EAAuB,EAAC,CAC5D,MAAA,CAAO,mBAAA,CAAoB,8BAA8B,CAAA,CAAI,QAAA,CAAA,KAGxDI,CAAAA,CAAQ","file":"index.mjs","sourcesContent":["import { createContext } from \"react\";\nimport { AuthenticatedUser } from \"../types\";\n\nexport interface AuthContextValue {\n /** authenticated user profile */\n user: AuthenticatedUser | null;\n /** authentication status */\n status: \"unauthenticated\" | \"authenticating\" | \"authenticated\";\n /** sign in to the IdP */\n signIn: () => void | Promise<void>;\n /** sign out from the IdP */\n signOut: () => void | Promise<void>;\n /** refresh the access token */\n refreshAccessToken: () => void | Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextValue>(\n {} as AuthContextValue,\n);\n","import { useContext } from \"react\";\nimport { AuthContext } from \"../providers/AuthContext\";\n\n/**\n * Returns the auth context value.\n *\n * Must be used within an {@link AuthProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link AuthContextValue} (user, status, signIn, signOut, refreshAccessToken).\n */\nexport function useAuth() {\n const context = useContext(AuthContext);\n if (!context) {\n throw new Error(\"useAuth must be used within a AuthProvider\");\n }\n return context;\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DependencyList, useCallback, useRef } from \"react\";\nimport { useAuth } from \"./useAuth\";\n\n/**\n * The return type of {@link useAuthCallback}.\n *\n * Accepts the same parameters as `T` but always returns a `Promise` that\n * resolves to `Awaited<ReturnType<T>>` when authenticated, or `undefined`\n * when the user is not yet authenticated.\n */\nexport type AuthGuardedCallback<T extends (...args: any[]) => any> = (\n ...args: Parameters<T>\n) => Promise<Awaited<ReturnType<T>> | undefined>;\n\n/**\n * Wraps a callback so it only executes when the user is authenticated.\n *\n * - **authenticated**: executes the callback and returns its result.\n * - **unauthenticated**: triggers `signIn()` and returns `undefined`.\n * - **authenticating**: returns `undefined` without re-triggering sign-in\n * (avoids conflicting with an in-progress auth flow).\n *\n * @param callback - The function to guard behind authentication.\n * @param deps - Optional dependency list (same semantics as `useCallback`).\n * @returns A wrapped callback that may resolve to `undefined` when not authenticated.\n */\nexport function useAuthCallback<T extends (...args: any[]) => any>(\n callback: T,\n deps?: DependencyList,\n): AuthGuardedCallback<T> {\n const { status, signIn } = useAuth();\n\n const statusRef = useRef<string>(status);\n statusRef.current = status;\n\n return useCallback(\n async (\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>> | undefined> => {\n if (statusRef.current !== \"authenticated\") {\n if (statusRef.current === \"unauthenticated\") {\n signIn();\n }\n return;\n }\n return callback(...args);\n },\n [...(deps || []), signIn, callback],\n );\n}\n","import { createContext } from \"react\";\nimport { WalletAdapter } from \"../types\";\n\nexport interface WalletConnectorContextValue {\n /**\n * detecting: is detecting connected wallets\n * connecting: is connecting to the first wallet\n * connected: is connected to at least one wallet\n * disconnecting: is disconnecting from the last connected wallet\n * disconnected: is disconnected from all wallets\n */\n status:\n | \"detecting\"\n | \"connecting\"\n | \"connected\"\n | \"disconnecting\"\n | \"disconnected\";\n // all wallets that can be used to take onchain actions when connected\n wallets: Array<WalletAdapter>;\n // if no wallets are connected, connect one or multiple wallets\n connect: () => Promise<void>;\n // disconnect all wallets\n disconnect: () => Promise<void>;\n}\n\nexport const WalletConnectorContext =\n createContext<WalletConnectorContextValue>({} as WalletConnectorContextValue);\n","import { useContext } from \"react\";\nimport { WalletConnectorContext } from \"../providers/WalletConnectorContext\";\n\n/**\n * Returns the wallet connector context value.\n *\n * Must be used within a {@link WalletConnectorProvider}.\n * Throws if no provider is found in the component tree.\n *\n * @returns The current {@link WalletConnectorContextValue} (status, wallets, connect, disconnect).\n */\nexport function useWalletConnector() {\n const context = useContext(WalletConnectorContext);\n if (!context) {\n throw new Error(\n \"useWalletConnector must be used within a WalletConnectorProvider\",\n );\n }\n return context;\n}\n","import { useWalletConnector } from \"./useWalletConnector\";\n\n/**\n * Convenience hook that returns the `wallets` array from the wallet connector context.\n *\n * Shorthand for `useWalletConnector().wallets`.\n *\n * @returns All wallets that can be used to take on-chain actions when connected.\n */\nexport function useWallets() {\n const { wallets } = useWalletConnector();\n return wallets;\n}\n","import { useCallback } from \"react\";\nimport { Chain, ChainNamespace } from \"@liberfi.io/types\";\nimport { chainToNamespace } from \"@liberfi.io/utils\";\nimport { EvmWalletAdapter } from \"../types\";\nimport { useWallets } from \"./useWallets\";\n\n/**\n * Returns a function that switches all connected EVM wallets to the given chain.\n *\n * Solana chains are automatically skipped (no-op). For EVM chains, the returned\n * function calls `switchChain` on every connected wallet that implements\n * {@link EvmWalletAdapter} in parallel.\n *\n * @returns An async function `(chain: Chain) => Promise<void>`.\n */\nexport function useSwitchChain() {\n const wallets = useWallets();\n\n return useCallback(\n async (chain: Chain) => {\n if (chainToNamespace(chain) === ChainNamespace.SOLANA) return;\n\n const evmWallets = wallets.filter(\n (w): w is EvmWalletAdapter => \"switchChain\" in w && w.isConnected,\n );\n await Promise.all(evmWallets.map((w) => w.switchChain(chain)));\n },\n [wallets],\n );\n}\n","import { PropsWithChildren } from \"react\";\nimport { AuthContext, AuthContextValue } from \"./AuthContext\";\n\n/** Props for {@link AuthProvider}. */\nexport type AuthProviderProps = PropsWithChildren<AuthContextValue>;\n\n/**\n * Provides authentication state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyAuthProvider`) typically wrap this component and supply the concrete\n * `user`, `status`, `signIn`, `signOut`, and `refreshAccessToken` values.\n */\nexport function AuthProvider({ children, ...value }: AuthProviderProps) {\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n","import { PropsWithChildren } from \"react\";\nimport {\n WalletConnectorContext,\n WalletConnectorContextValue,\n} from \"./WalletConnectorContext\";\n\n/** Props for {@link WalletConnectorProvider}. */\nexport type WalletConnectorProviderProps =\n PropsWithChildren<WalletConnectorContextValue>;\n\n/**\n * Provides wallet connection state to the component tree.\n *\n * This is a passthrough provider — it accepts the full context value as props\n * and forwards it to React context. Implementation providers (e.g.\n * `PrivyWalletConnectorProvider`) typically wrap this component and supply\n * the concrete `status`, `wallets`, `connect`, and `disconnect` values.\n */\nexport function WalletConnectorProvider({\n children,\n ...value\n}: WalletConnectorProviderProps) {\n return (\n <WalletConnectorContext.Provider value={value}>\n {children}\n </WalletConnectorContext.Provider>\n );\n}\n","declare global {\n interface Window {\n __LIBERFI_VERSION__?: {\n [key: string]: string;\n };\n }\n}\nif (typeof window !== \"undefined\") {\n window.__LIBERFI_VERSION__ = window.__LIBERFI_VERSION__ || {};\n window.__LIBERFI_VERSION__[\"@liberfi.io/wallet-connector\"] = \"0.1.22\";\n}\n\nexport default \"0.1.22\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liberfi.io/wallet-connector",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "Base Wallet Connector for Liberfi React SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,8 +14,8 @@
14
14
  "access": "public"
15
15
  },
16
16
  "dependencies": {
17
- "@liberfi.io/types": "0.1.30",
18
- "@liberfi.io/utils": "0.1.27"
17
+ "@liberfi.io/types": "0.1.31",
18
+ "@liberfi.io/utils": "0.1.28"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@testing-library/dom": "^10.4.1",
@@ -31,13 +31,14 @@
31
31
  "ts-jest": "^29.4.6",
32
32
  "tsup": "^8.5.0",
33
33
  "typescript": "^5.9.2",
34
- "tsconfig": "0.1.18"
34
+ "tsconfig": "0.1.19"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": ">=18",
38
38
  "react-dom": ">=18"
39
39
  },
40
40
  "scripts": {
41
+ "dev": "tsup --watch",
41
42
  "build": "rimraf -rf dist && tsup",
42
43
  "test": "jest"
43
44
  }