@dynamic-labs-sdk/react-hooks 1.3.0 → 1.4.0
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/exports/index.d.ts +2 -1
- package/dist/exports/index.d.ts.map +1 -1
- package/dist/foundation/{useClientState/useClientState.d.ts → useBaseState/useBaseState.d.ts} +2 -2
- package/dist/foundation/useBaseState/useBaseState.d.ts.map +1 -0
- package/dist/hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData.d.ts +7 -0
- package/dist/hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData.d.ts.map +1 -0
- package/dist/hooks/useInitStatus/useInitStatus.d.ts.map +1 -1
- package/dist/hooks/useNetworksData/useNetworksData.d.ts +8 -0
- package/dist/hooks/useNetworksData/useNetworksData.d.ts.map +1 -0
- package/dist/hooks/useSessionExpiresAt/useSessionExpiresAt.d.ts.map +1 -1
- package/dist/hooks/useSocialAccounts/useSocialAccounts.d.ts.map +1 -1
- package/dist/hooks/useUser/useUser.d.ts.map +1 -1
- package/dist/index.cjs +21 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +21 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/dist/foundation/useClientState/useClientState.d.ts.map +0 -1
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +0 -7
- package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +0 -1
package/dist/exports/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { useEvent } from '../hooks/useEvent/useEvent';
|
|
2
2
|
export { useInitStatus } from '../hooks/useInitStatus/useInitStatus';
|
|
3
|
+
export { useNetworksData } from '../hooks/useNetworksData/useNetworksData';
|
|
3
4
|
export { useSessionExpiresAt } from '../hooks/useSessionExpiresAt/useSessionExpiresAt';
|
|
4
5
|
export { useSocialAccounts } from '../hooks/useSocialAccounts/useSocialAccounts';
|
|
5
6
|
export { useUser } from '../hooks/useUser/useUser';
|
|
6
7
|
export { useWalletAccounts } from '../hooks/useWalletAccounts/useWalletAccounts';
|
|
7
|
-
export {
|
|
8
|
+
export { useAvailableWalletProvidersData } from '../hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData';
|
|
8
9
|
export { DynamicProvider, useDynamicClient } from '../modules/DynamicContext';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAAE,+BAA+B,EAAE,MAAM,0EAA0E,CAAC;AAC3H,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/foundation/{useClientState/useClientState.d.ts → useBaseState/useBaseState.d.ts}
RENAMED
|
@@ -5,5 +5,5 @@ import type { DynamicClient } from '@dynamic-labs-sdk/client';
|
|
|
5
5
|
* Subscribes to a client event and re-derives a snapshot via the selector
|
|
6
6
|
* each time the event fires, using useSyncExternalStore for tear-free reads.
|
|
7
7
|
*/
|
|
8
|
-
export declare const
|
|
9
|
-
//# sourceMappingURL=
|
|
8
|
+
export declare const useBaseState: <T>(eventName: keyof DynamicEvents, getSnapshot: (client: DynamicClient) => T) => T;
|
|
9
|
+
//# sourceMappingURL=useBaseState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBaseState.d.ts","sourceRoot":"","sources":["../../../src/foundation/useBaseState/useBaseState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAM9D;;;;;GAKG;AAEH,eAAO,MAAM,YAAY,GAAI,CAAC,aACjB,MAAM,aAAa,eACjB,CAAC,MAAM,EAAE,aAAa,KAAK,CAAC,KACxC,CAoBF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the available wallet providers and their data.
|
|
3
|
+
*
|
|
4
|
+
* Re-renders when a wallet provider changes (e.g. network switch).
|
|
5
|
+
*/
|
|
6
|
+
export declare const useAvailableWalletProvidersData: () => import("@dynamic-labs-sdk/client").WalletProviderData[];
|
|
7
|
+
//# sourceMappingURL=useAvailableWalletProvidersData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAvailableWalletProvidersData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,+DAGzC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInitStatus.d.ts","sourceRoot":"","sources":["../../../src/hooks/useInitStatus/useInitStatus.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"useInitStatus.d.ts","sourceRoot":"","sources":["../../../src/hooks/useInitStatus/useInitStatus.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,aAAa,4DACwC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NetworkData } from '@dynamic-labs-sdk/client';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the network configurations for all networks enabled in the Dynamic project.
|
|
4
|
+
*
|
|
5
|
+
* Re-renders when project settings change.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useNetworksData: () => NetworkData[];
|
|
8
|
+
//# sourceMappingURL=useNetworksData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNetworksData.d.ts","sourceRoot":"","sources":["../../../src/hooks/useNetworksData/useNetworksData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAK5D;;;;GAIG;AACH,eAAO,MAAM,eAAe,QAAO,WAAW,EAC+B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionExpiresAt.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSessionExpiresAt/useSessionExpiresAt.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"useSessionExpiresAt.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSessionExpiresAt/useSessionExpiresAt.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,mBACkC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSocialAccounts.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSocialAccounts/useSocialAccounts.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"useSocialAccounts.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSocialAccounts/useSocialAccounts.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,0DAC0C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUser.d.ts","sourceRoot":"","sources":["../../../src/hooks/useUser/useUser.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"useUser.d.ts","sourceRoot":"","sources":["../../../src/hooks/useUser/useUser.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,OAAO,2DACkC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
5
5
|
|
|
6
6
|
//#region package.json
|
|
7
7
|
var name = "@dynamic-labs-sdk/react-hooks";
|
|
8
|
-
var version = "1.
|
|
8
|
+
var version = "1.4.0";
|
|
9
9
|
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/modules/DynamicContext/DynamicContext.ts
|
|
@@ -74,14 +74,14 @@ const useEvent = ({ event, listener }) => {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
//#endregion
|
|
77
|
-
//#region src/foundation/
|
|
77
|
+
//#region src/foundation/useBaseState/useBaseState.ts
|
|
78
78
|
/**
|
|
79
79
|
* Internal hook that bridges Dynamic client event-driven state to React.
|
|
80
80
|
*
|
|
81
81
|
* Subscribes to a client event and re-derives a snapshot via the selector
|
|
82
82
|
* each time the event fires, using useSyncExternalStore for tear-free reads.
|
|
83
83
|
*/
|
|
84
|
-
const
|
|
84
|
+
const useBaseState = (eventName, getSnapshot) => {
|
|
85
85
|
const client = useDynamicClient();
|
|
86
86
|
const valueRef = (0, react.useRef)(getSnapshot(client));
|
|
87
87
|
return (0, react.useSyncExternalStore)((onStoreChange) => (0, _dynamic_labs_sdk_client.onEvent)({
|
|
@@ -100,7 +100,16 @@ const useClientState = (eventName, getSnapshot) => {
|
|
|
100
100
|
*
|
|
101
101
|
* Possible values: 'uninitialized', 'in-progress', 'finished', 'failed'.
|
|
102
102
|
*/
|
|
103
|
-
const useInitStatus = () =>
|
|
103
|
+
const useInitStatus = () => useBaseState("initStatusChanged", (client) => client.initStatus);
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/hooks/useNetworksData/useNetworksData.ts
|
|
107
|
+
/**
|
|
108
|
+
* Returns the network configurations for all networks enabled in the Dynamic project.
|
|
109
|
+
*
|
|
110
|
+
* Re-renders when project settings change.
|
|
111
|
+
*/
|
|
112
|
+
const useNetworksData = () => useBaseState("projectSettingsChanged", (client) => (0, _dynamic_labs_sdk_client.getNetworksData)(client));
|
|
104
113
|
|
|
105
114
|
//#endregion
|
|
106
115
|
//#region src/hooks/useSessionExpiresAt/useSessionExpiresAt.ts
|
|
@@ -109,7 +118,7 @@ const useInitStatus = () => useClientState("initStatusChanged", (client) => clie
|
|
|
109
118
|
*
|
|
110
119
|
* Re-renders when the user changes (which includes session updates).
|
|
111
120
|
*/
|
|
112
|
-
const useSessionExpiresAt = () =>
|
|
121
|
+
const useSessionExpiresAt = () => useBaseState("userChanged", (client) => client.sessionExpiresAt);
|
|
113
122
|
|
|
114
123
|
//#endregion
|
|
115
124
|
//#region src/hooks/useSocialAccounts/useSocialAccounts.ts
|
|
@@ -118,7 +127,7 @@ const useSessionExpiresAt = () => useClientState("userChanged", (client) => clie
|
|
|
118
127
|
*
|
|
119
128
|
* Re-renders when the user changes.
|
|
120
129
|
*/
|
|
121
|
-
const useSocialAccounts = () =>
|
|
130
|
+
const useSocialAccounts = () => useBaseState("userChanged", (client) => (0, _dynamic_labs_sdk_client.getUserSocialAccounts)(client));
|
|
122
131
|
|
|
123
132
|
//#endregion
|
|
124
133
|
//#region src/hooks/useUser/useUser.ts
|
|
@@ -127,7 +136,7 @@ const useSocialAccounts = () => useClientState("userChanged", (client) => (0, _d
|
|
|
127
136
|
*
|
|
128
137
|
* Re-renders when the user changes (login, logout, profile update).
|
|
129
138
|
*/
|
|
130
|
-
const useUser = () =>
|
|
139
|
+
const useUser = () => useBaseState("userChanged", (client) => client.user);
|
|
131
140
|
|
|
132
141
|
//#endregion
|
|
133
142
|
//#region src/hooks/useWalletAccounts/useWalletAccounts.ts
|
|
@@ -136,16 +145,16 @@ const useUser = () => useClientState("userChanged", (client) => client.user);
|
|
|
136
145
|
*
|
|
137
146
|
* Re-renders when wallet accounts change (connect, disconnect, verify).
|
|
138
147
|
*/
|
|
139
|
-
const useWalletAccounts = () =>
|
|
148
|
+
const useWalletAccounts = () => useBaseState("walletAccountsChanged", (client) => (0, _dynamic_labs_sdk_client.getWalletAccounts)(client));
|
|
140
149
|
|
|
141
150
|
//#endregion
|
|
142
|
-
//#region src/hooks/
|
|
151
|
+
//#region src/hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData.ts
|
|
143
152
|
/**
|
|
144
153
|
* Returns the available wallet providers and their data.
|
|
145
154
|
*
|
|
146
155
|
* Re-renders when a wallet provider changes (e.g. network switch).
|
|
147
156
|
*/
|
|
148
|
-
const
|
|
157
|
+
const useAvailableWalletProvidersData = () => useBaseState("walletProviderChanged", (client) => (0, _dynamic_labs_sdk_client.getAvailableWalletProvidersData)(client));
|
|
149
158
|
|
|
150
159
|
//#endregion
|
|
151
160
|
//#region src/exports/index.ts
|
|
@@ -153,12 +162,13 @@ const useWalletProviders = () => useClientState("walletProviderChanged", (client
|
|
|
153
162
|
|
|
154
163
|
//#endregion
|
|
155
164
|
exports.DynamicProvider = DynamicProvider;
|
|
165
|
+
exports.useAvailableWalletProvidersData = useAvailableWalletProvidersData;
|
|
156
166
|
exports.useDynamicClient = useDynamicClient;
|
|
157
167
|
exports.useEvent = useEvent;
|
|
158
168
|
exports.useInitStatus = useInitStatus;
|
|
169
|
+
exports.useNetworksData = useNetworksData;
|
|
159
170
|
exports.useSessionExpiresAt = useSessionExpiresAt;
|
|
160
171
|
exports.useSocialAccounts = useSocialAccounts;
|
|
161
172
|
exports.useUser = useUser;
|
|
162
173
|
exports.useWalletAccounts = useWalletAccounts;
|
|
163
|
-
exports.useWalletProviders = useWalletProviders;
|
|
164
174
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["BaseError","packageName","packageVersion"],"sources":["../package.json","../src/modules/DynamicContext/DynamicContext.ts","../src/modules/DynamicContext/DynamicProvider.tsx","../src/errors/MissingProviderError/MissingProviderError.ts","../src/modules/DynamicContext/useDynamicClient.ts","../src/hooks/useEvent/useEvent.ts","../src/foundation/
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["BaseError","packageName","packageVersion"],"sources":["../package.json","../src/modules/DynamicContext/DynamicContext.ts","../src/modules/DynamicContext/DynamicProvider.tsx","../src/errors/MissingProviderError/MissingProviderError.ts","../src/modules/DynamicContext/useDynamicClient.ts","../src/hooks/useEvent/useEvent.ts","../src/foundation/useBaseState/useBaseState.ts","../src/hooks/useInitStatus/useInitStatus.ts","../src/hooks/useNetworksData/useNetworksData.ts","../src/hooks/useSessionExpiresAt/useSessionExpiresAt.ts","../src/hooks/useSocialAccounts/useSocialAccounts.ts","../src/hooks/useUser/useUser.ts","../src/hooks/useWalletAccounts/useWalletAccounts.ts","../src/hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData.ts","../src/exports/index.ts"],"sourcesContent":["","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { createContext } from 'react';\n\n/**\n * Internal React context for providing the DynamicClient instance to hooks.\n */\nexport const DynamicContext = createContext<DynamicClient | null>(null);\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { PropsWithChildren } from 'react';\n\nimport { DynamicContext } from './DynamicContext';\n\ntype DynamicProviderProps = PropsWithChildren<{\n client: DynamicClient;\n}>;\n\n/**\n * Provides the DynamicClient instance to all child hooks.\n *\n * Wrap your application with this provider and pass your client instance\n * so that hooks like useUser, useWalletAccounts, etc. can access it.\n */\nexport const DynamicProvider = ({ children, client }: DynamicProviderProps) => (\n <DynamicContext.Provider value={client}>{children}</DynamicContext.Provider>\n);\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class MissingProviderError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'MISSING_PROVIDER',\n docsUrl: null,\n name: 'MissingProviderError',\n shortMessage:\n 'Hook must be used within a <DynamicProvider>.\\nWrap your component tree with <DynamicProvider client={client}>.',\n });\n }\n}\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { useContext } from 'react';\n\nimport { MissingProviderError } from '../../errors/MissingProviderError/MissingProviderError';\nimport { DynamicContext } from './DynamicContext';\n\n/**\n * Internal hook to access the DynamicClient from context.\n * Throws if used outside of DynamicProvider.\n */\nexport const useDynamicClient = (): DynamicClient => {\n const client = useContext(DynamicContext);\n\n if (!client) {\n throw new MissingProviderError();\n }\n\n return client;\n};\n","import { type OnEventParams, onEvent } from '@dynamic-labs-sdk/client';\nimport { useEffect, useRef } from 'react';\n\nimport { useDynamicClient } from '../../modules/DynamicContext';\n\n/**\n * Subscribes to a Dynamic client event.\n *\n * Uses a ref to always call the latest listener without re-subscribing,\n * and cleans up the subscription on unmount or event name change.\n */\nexport const useEvent = <E extends keyof DynamicEvents>({\n event,\n listener,\n}: OnEventParams<E>) => {\n const client = useDynamicClient();\n const callbackRef = useRef(listener);\n\n callbackRef.current = listener;\n\n useEffect(\n () =>\n onEvent(\n {\n event,\n listener: (...args: any[]) => {\n // @ts-expect-error - Ignore the type error because we are using the ref\n callbackRef.current(...args);\n },\n },\n client\n ),\n [event, client]\n );\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { onEvent } from '@dynamic-labs-sdk/client';\nimport { useRef, useSyncExternalStore } from 'react';\n\nimport { useDynamicClient } from '../../modules/DynamicContext';\n\n/**\n * Internal hook that bridges Dynamic client event-driven state to React.\n *\n * Subscribes to a client event and re-derives a snapshot via the selector\n * each time the event fires, using useSyncExternalStore for tear-free reads.\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const useBaseState = <T>(\n eventName: keyof DynamicEvents,\n getSnapshot: (client: DynamicClient) => T\n): T => {\n const client = useDynamicClient();\n const valueRef = useRef(getSnapshot(client));\n\n return useSyncExternalStore(\n (onStoreChange: VoidFunction) =>\n onEvent(\n {\n event: eventName,\n listener: () => {\n valueRef.current = getSnapshot(client);\n\n onStoreChange();\n },\n },\n client\n ),\n () => valueRef.current,\n () => valueRef.current\n );\n};\n","import { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the current initialization status of the Dynamic client.\n *\n * Possible values: 'uninitialized', 'in-progress', 'finished', 'failed'.\n */\nexport const useInitStatus = () =>\n useBaseState('initStatusChanged', (client) => client.initStatus);\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getNetworksData } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the network configurations for all networks enabled in the Dynamic project.\n *\n * Re-renders when project settings change.\n */\nexport const useNetworksData = (): NetworkData[] =>\n useBaseState('projectSettingsChanged', (client) => getNetworksData(client));\n","import { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the session expiration date, or null if no active session.\n *\n * Re-renders when the user changes (which includes session updates).\n */\nexport const useSessionExpiresAt = () =>\n useBaseState('userChanged', (client) => client.sessionExpiresAt);\n","import { getUserSocialAccounts } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the current user's linked social accounts.\n *\n * Re-renders when the user changes.\n */\nexport const useSocialAccounts = () =>\n useBaseState('userChanged', (client) => getUserSocialAccounts(client));\n","import { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the current authenticated user, or null if not authenticated.\n *\n * Re-renders when the user changes (login, logout, profile update).\n */\nexport const useUser = () =>\n useBaseState('userChanged', (client) => client.user);\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\nimport { getWalletAccounts } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns all wallet accounts connected to the current user.\n *\n * Re-renders when wallet accounts change (connect, disconnect, verify).\n */\nexport const useWalletAccounts = (): WalletAccount[] =>\n useBaseState('walletAccountsChanged', (client) =>\n getWalletAccounts(client)\n );\n","import { getAvailableWalletProvidersData } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the available wallet providers and their data.\n *\n * Re-renders when a wallet provider changes (e.g. network switch).\n */\nexport const useAvailableWalletProvidersData = () =>\n useBaseState('walletProviderChanged', (client) =>\n getAvailableWalletProvidersData(client)\n );\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { useEvent } from '../hooks/useEvent/useEvent';\nexport { useInitStatus } from '../hooks/useInitStatus/useInitStatus';\nexport { useNetworksData } from '../hooks/useNetworksData/useNetworksData';\nexport { useSessionExpiresAt } from '../hooks/useSessionExpiresAt/useSessionExpiresAt';\nexport { useSocialAccounts } from '../hooks/useSocialAccounts/useSocialAccounts';\nexport { useUser } from '../hooks/useUser/useUser';\nexport { useWalletAccounts } from '../hooks/useWalletAccounts/useWalletAccounts';\nexport { useAvailableWalletProvidersData } from '../hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData';\nexport { DynamicProvider, useDynamicClient } from '../modules/DynamicContext';\n"],"mappings":";;;;;;;;;;;;;;ACMA,MAAa,0CAAqD,KAAK;;;;;;;;;;ACSvE,MAAa,mBAAmB,EAAE,UAAU,aAC1C,2CAAC,eAAe;CAAS,OAAO;CAAS;EAAmC;;;;ACd9E,IAAa,uBAAb,cAA0CA,mCAAU;CAClD,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cACE;GACH,CAAC;;;;;;;;;;ACDN,MAAa,yBAAwC;CACnD,MAAM,+BAAoB,eAAe;AAEzC,KAAI,CAAC,OACH,OAAM,IAAI,sBAAsB;AAGlC,QAAO;;;;;;;;;;;ACNT,MAAa,YAA2C,EACtD,OACA,eACsB;CACtB,MAAM,SAAS,kBAAkB;CACjC,MAAM,gCAAqB,SAAS;AAEpC,aAAY,UAAU;AAEtB,kEAGM;EACE;EACA,WAAW,GAAG,SAAgB;AAE5B,eAAY,QAAQ,GAAG,KAAK;;EAE/B,EACD,OACD,EACH,CAAC,OAAO,OAAO,CAChB;;;;;;;;;;;ACpBH,MAAa,gBACX,WACA,gBACM;CACN,MAAM,SAAS,kBAAkB;CACjC,MAAM,6BAAkB,YAAY,OAAO,CAAC;AAE5C,yCACG,wDAEG;EACE,OAAO;EACP,gBAAgB;AACd,YAAS,UAAU,YAAY,OAAO;AAEtC,kBAAe;;EAElB,EACD,OACD,QACG,SAAS,eACT,SAAS,QAChB;;;;;;;;;;AC5BH,MAAa,sBACX,aAAa,sBAAsB,WAAW,OAAO,WAAW;;;;;;;;;ACElE,MAAa,wBACX,aAAa,2BAA2B,yDAA2B,OAAO,CAAC;;;;;;;;;ACJ7E,MAAa,4BACX,aAAa,gBAAgB,WAAW,OAAO,iBAAiB;;;;;;;;;ACClE,MAAa,0BACX,aAAa,gBAAgB,+DAAiC,OAAO,CAAC;;;;;;;;;ACHxE,MAAa,gBACX,aAAa,gBAAgB,WAAW,OAAO,KAAK;;;;;;;;;ACEtD,MAAa,0BACX,aAAa,0BAA0B,2DACnB,OAAO,CAC1B;;;;;;;;;ACJH,MAAa,wCACX,aAAa,0BAA0B,yEACL,OAAO,CACxC;;;;mECNkBC,MAAaC,QAAe"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
2
|
-
import { BaseError, getAvailableWalletProvidersData, getUserSocialAccounts, getWalletAccounts, onEvent } from "@dynamic-labs-sdk/client";
|
|
2
|
+
import { BaseError, getAvailableWalletProvidersData, getNetworksData, getUserSocialAccounts, getWalletAccounts, onEvent } from "@dynamic-labs-sdk/client";
|
|
3
3
|
import { createContext, useContext, useEffect, useRef, useSyncExternalStore } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region package.json
|
|
7
7
|
var name = "@dynamic-labs-sdk/react-hooks";
|
|
8
|
-
var version = "1.
|
|
8
|
+
var version = "1.4.0";
|
|
9
9
|
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/modules/DynamicContext/DynamicContext.ts
|
|
@@ -74,14 +74,14 @@ const useEvent = ({ event, listener }) => {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
//#endregion
|
|
77
|
-
//#region src/foundation/
|
|
77
|
+
//#region src/foundation/useBaseState/useBaseState.ts
|
|
78
78
|
/**
|
|
79
79
|
* Internal hook that bridges Dynamic client event-driven state to React.
|
|
80
80
|
*
|
|
81
81
|
* Subscribes to a client event and re-derives a snapshot via the selector
|
|
82
82
|
* each time the event fires, using useSyncExternalStore for tear-free reads.
|
|
83
83
|
*/
|
|
84
|
-
const
|
|
84
|
+
const useBaseState = (eventName, getSnapshot) => {
|
|
85
85
|
const client = useDynamicClient();
|
|
86
86
|
const valueRef = useRef(getSnapshot(client));
|
|
87
87
|
return useSyncExternalStore((onStoreChange) => onEvent({
|
|
@@ -100,7 +100,16 @@ const useClientState = (eventName, getSnapshot) => {
|
|
|
100
100
|
*
|
|
101
101
|
* Possible values: 'uninitialized', 'in-progress', 'finished', 'failed'.
|
|
102
102
|
*/
|
|
103
|
-
const useInitStatus = () =>
|
|
103
|
+
const useInitStatus = () => useBaseState("initStatusChanged", (client) => client.initStatus);
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/hooks/useNetworksData/useNetworksData.ts
|
|
107
|
+
/**
|
|
108
|
+
* Returns the network configurations for all networks enabled in the Dynamic project.
|
|
109
|
+
*
|
|
110
|
+
* Re-renders when project settings change.
|
|
111
|
+
*/
|
|
112
|
+
const useNetworksData = () => useBaseState("projectSettingsChanged", (client) => getNetworksData(client));
|
|
104
113
|
|
|
105
114
|
//#endregion
|
|
106
115
|
//#region src/hooks/useSessionExpiresAt/useSessionExpiresAt.ts
|
|
@@ -109,7 +118,7 @@ const useInitStatus = () => useClientState("initStatusChanged", (client) => clie
|
|
|
109
118
|
*
|
|
110
119
|
* Re-renders when the user changes (which includes session updates).
|
|
111
120
|
*/
|
|
112
|
-
const useSessionExpiresAt = () =>
|
|
121
|
+
const useSessionExpiresAt = () => useBaseState("userChanged", (client) => client.sessionExpiresAt);
|
|
113
122
|
|
|
114
123
|
//#endregion
|
|
115
124
|
//#region src/hooks/useSocialAccounts/useSocialAccounts.ts
|
|
@@ -118,7 +127,7 @@ const useSessionExpiresAt = () => useClientState("userChanged", (client) => clie
|
|
|
118
127
|
*
|
|
119
128
|
* Re-renders when the user changes.
|
|
120
129
|
*/
|
|
121
|
-
const useSocialAccounts = () =>
|
|
130
|
+
const useSocialAccounts = () => useBaseState("userChanged", (client) => getUserSocialAccounts(client));
|
|
122
131
|
|
|
123
132
|
//#endregion
|
|
124
133
|
//#region src/hooks/useUser/useUser.ts
|
|
@@ -127,7 +136,7 @@ const useSocialAccounts = () => useClientState("userChanged", (client) => getUse
|
|
|
127
136
|
*
|
|
128
137
|
* Re-renders when the user changes (login, logout, profile update).
|
|
129
138
|
*/
|
|
130
|
-
const useUser = () =>
|
|
139
|
+
const useUser = () => useBaseState("userChanged", (client) => client.user);
|
|
131
140
|
|
|
132
141
|
//#endregion
|
|
133
142
|
//#region src/hooks/useWalletAccounts/useWalletAccounts.ts
|
|
@@ -136,21 +145,21 @@ const useUser = () => useClientState("userChanged", (client) => client.user);
|
|
|
136
145
|
*
|
|
137
146
|
* Re-renders when wallet accounts change (connect, disconnect, verify).
|
|
138
147
|
*/
|
|
139
|
-
const useWalletAccounts = () =>
|
|
148
|
+
const useWalletAccounts = () => useBaseState("walletAccountsChanged", (client) => getWalletAccounts(client));
|
|
140
149
|
|
|
141
150
|
//#endregion
|
|
142
|
-
//#region src/hooks/
|
|
151
|
+
//#region src/hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData.ts
|
|
143
152
|
/**
|
|
144
153
|
* Returns the available wallet providers and their data.
|
|
145
154
|
*
|
|
146
155
|
* Re-renders when a wallet provider changes (e.g. network switch).
|
|
147
156
|
*/
|
|
148
|
-
const
|
|
157
|
+
const useAvailableWalletProvidersData = () => useBaseState("walletProviderChanged", (client) => getAvailableWalletProvidersData(client));
|
|
149
158
|
|
|
150
159
|
//#endregion
|
|
151
160
|
//#region src/exports/index.ts
|
|
152
161
|
assertPackageVersion(name, version);
|
|
153
162
|
|
|
154
163
|
//#endregion
|
|
155
|
-
export { DynamicProvider, useDynamicClient, useEvent, useInitStatus, useSessionExpiresAt, useSocialAccounts, useUser, useWalletAccounts
|
|
164
|
+
export { DynamicProvider, useAvailableWalletProvidersData, useDynamicClient, useEvent, useInitStatus, useNetworksData, useSessionExpiresAt, useSocialAccounts, useUser, useWalletAccounts };
|
|
156
165
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","names":["packageName","packageVersion"],"sources":["../package.json","../src/modules/DynamicContext/DynamicContext.ts","../src/modules/DynamicContext/DynamicProvider.tsx","../src/errors/MissingProviderError/MissingProviderError.ts","../src/modules/DynamicContext/useDynamicClient.ts","../src/hooks/useEvent/useEvent.ts","../src/foundation/
|
|
1
|
+
{"version":3,"file":"index.esm.js","names":["packageName","packageVersion"],"sources":["../package.json","../src/modules/DynamicContext/DynamicContext.ts","../src/modules/DynamicContext/DynamicProvider.tsx","../src/errors/MissingProviderError/MissingProviderError.ts","../src/modules/DynamicContext/useDynamicClient.ts","../src/hooks/useEvent/useEvent.ts","../src/foundation/useBaseState/useBaseState.ts","../src/hooks/useInitStatus/useInitStatus.ts","../src/hooks/useNetworksData/useNetworksData.ts","../src/hooks/useSessionExpiresAt/useSessionExpiresAt.ts","../src/hooks/useSocialAccounts/useSocialAccounts.ts","../src/hooks/useUser/useUser.ts","../src/hooks/useWalletAccounts/useWalletAccounts.ts","../src/hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData.ts","../src/exports/index.ts"],"sourcesContent":["","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { createContext } from 'react';\n\n/**\n * Internal React context for providing the DynamicClient instance to hooks.\n */\nexport const DynamicContext = createContext<DynamicClient | null>(null);\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { PropsWithChildren } from 'react';\n\nimport { DynamicContext } from './DynamicContext';\n\ntype DynamicProviderProps = PropsWithChildren<{\n client: DynamicClient;\n}>;\n\n/**\n * Provides the DynamicClient instance to all child hooks.\n *\n * Wrap your application with this provider and pass your client instance\n * so that hooks like useUser, useWalletAccounts, etc. can access it.\n */\nexport const DynamicProvider = ({ children, client }: DynamicProviderProps) => (\n <DynamicContext.Provider value={client}>{children}</DynamicContext.Provider>\n);\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class MissingProviderError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'MISSING_PROVIDER',\n docsUrl: null,\n name: 'MissingProviderError',\n shortMessage:\n 'Hook must be used within a <DynamicProvider>.\\nWrap your component tree with <DynamicProvider client={client}>.',\n });\n }\n}\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { useContext } from 'react';\n\nimport { MissingProviderError } from '../../errors/MissingProviderError/MissingProviderError';\nimport { DynamicContext } from './DynamicContext';\n\n/**\n * Internal hook to access the DynamicClient from context.\n * Throws if used outside of DynamicProvider.\n */\nexport const useDynamicClient = (): DynamicClient => {\n const client = useContext(DynamicContext);\n\n if (!client) {\n throw new MissingProviderError();\n }\n\n return client;\n};\n","import { type OnEventParams, onEvent } from '@dynamic-labs-sdk/client';\nimport { useEffect, useRef } from 'react';\n\nimport { useDynamicClient } from '../../modules/DynamicContext';\n\n/**\n * Subscribes to a Dynamic client event.\n *\n * Uses a ref to always call the latest listener without re-subscribing,\n * and cleans up the subscription on unmount or event name change.\n */\nexport const useEvent = <E extends keyof DynamicEvents>({\n event,\n listener,\n}: OnEventParams<E>) => {\n const client = useDynamicClient();\n const callbackRef = useRef(listener);\n\n callbackRef.current = listener;\n\n useEffect(\n () =>\n onEvent(\n {\n event,\n listener: (...args: any[]) => {\n // @ts-expect-error - Ignore the type error because we are using the ref\n callbackRef.current(...args);\n },\n },\n client\n ),\n [event, client]\n );\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { onEvent } from '@dynamic-labs-sdk/client';\nimport { useRef, useSyncExternalStore } from 'react';\n\nimport { useDynamicClient } from '../../modules/DynamicContext';\n\n/**\n * Internal hook that bridges Dynamic client event-driven state to React.\n *\n * Subscribes to a client event and re-derives a snapshot via the selector\n * each time the event fires, using useSyncExternalStore for tear-free reads.\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const useBaseState = <T>(\n eventName: keyof DynamicEvents,\n getSnapshot: (client: DynamicClient) => T\n): T => {\n const client = useDynamicClient();\n const valueRef = useRef(getSnapshot(client));\n\n return useSyncExternalStore(\n (onStoreChange: VoidFunction) =>\n onEvent(\n {\n event: eventName,\n listener: () => {\n valueRef.current = getSnapshot(client);\n\n onStoreChange();\n },\n },\n client\n ),\n () => valueRef.current,\n () => valueRef.current\n );\n};\n","import { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the current initialization status of the Dynamic client.\n *\n * Possible values: 'uninitialized', 'in-progress', 'finished', 'failed'.\n */\nexport const useInitStatus = () =>\n useBaseState('initStatusChanged', (client) => client.initStatus);\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getNetworksData } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the network configurations for all networks enabled in the Dynamic project.\n *\n * Re-renders when project settings change.\n */\nexport const useNetworksData = (): NetworkData[] =>\n useBaseState('projectSettingsChanged', (client) => getNetworksData(client));\n","import { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the session expiration date, or null if no active session.\n *\n * Re-renders when the user changes (which includes session updates).\n */\nexport const useSessionExpiresAt = () =>\n useBaseState('userChanged', (client) => client.sessionExpiresAt);\n","import { getUserSocialAccounts } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the current user's linked social accounts.\n *\n * Re-renders when the user changes.\n */\nexport const useSocialAccounts = () =>\n useBaseState('userChanged', (client) => getUserSocialAccounts(client));\n","import { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the current authenticated user, or null if not authenticated.\n *\n * Re-renders when the user changes (login, logout, profile update).\n */\nexport const useUser = () =>\n useBaseState('userChanged', (client) => client.user);\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\nimport { getWalletAccounts } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns all wallet accounts connected to the current user.\n *\n * Re-renders when wallet accounts change (connect, disconnect, verify).\n */\nexport const useWalletAccounts = (): WalletAccount[] =>\n useBaseState('walletAccountsChanged', (client) =>\n getWalletAccounts(client)\n );\n","import { getAvailableWalletProvidersData } from '@dynamic-labs-sdk/client';\n\nimport { useBaseState } from '../../foundation/useBaseState/useBaseState';\n\n/**\n * Returns the available wallet providers and their data.\n *\n * Re-renders when a wallet provider changes (e.g. network switch).\n */\nexport const useAvailableWalletProvidersData = () =>\n useBaseState('walletProviderChanged', (client) =>\n getAvailableWalletProvidersData(client)\n );\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { useEvent } from '../hooks/useEvent/useEvent';\nexport { useInitStatus } from '../hooks/useInitStatus/useInitStatus';\nexport { useNetworksData } from '../hooks/useNetworksData/useNetworksData';\nexport { useSessionExpiresAt } from '../hooks/useSessionExpiresAt/useSessionExpiresAt';\nexport { useSocialAccounts } from '../hooks/useSocialAccounts/useSocialAccounts';\nexport { useUser } from '../hooks/useUser/useUser';\nexport { useWalletAccounts } from '../hooks/useWalletAccounts/useWalletAccounts';\nexport { useAvailableWalletProvidersData } from '../hooks/useAvailableWalletProvidersData/useAvailableWalletProvidersData';\nexport { DynamicProvider, useDynamicClient } from '../modules/DynamicContext';\n"],"mappings":";;;;;;;;;;;;;;ACMA,MAAa,iBAAiB,cAAoC,KAAK;;;;;;;;;;ACSvE,MAAa,mBAAmB,EAAE,UAAU,aAC1C,oBAAC,eAAe;CAAS,OAAO;CAAS;EAAmC;;;;ACd9E,IAAa,uBAAb,cAA0C,UAAU;CAClD,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cACE;GACH,CAAC;;;;;;;;;;ACDN,MAAa,yBAAwC;CACnD,MAAM,SAAS,WAAW,eAAe;AAEzC,KAAI,CAAC,OACH,OAAM,IAAI,sBAAsB;AAGlC,QAAO;;;;;;;;;;;ACNT,MAAa,YAA2C,EACtD,OACA,eACsB;CACtB,MAAM,SAAS,kBAAkB;CACjC,MAAM,cAAc,OAAO,SAAS;AAEpC,aAAY,UAAU;AAEtB,iBAEI,QACE;EACE;EACA,WAAW,GAAG,SAAgB;AAE5B,eAAY,QAAQ,GAAG,KAAK;;EAE/B,EACD,OACD,EACH,CAAC,OAAO,OAAO,CAChB;;;;;;;;;;;ACpBH,MAAa,gBACX,WACA,gBACM;CACN,MAAM,SAAS,kBAAkB;CACjC,MAAM,WAAW,OAAO,YAAY,OAAO,CAAC;AAE5C,QAAO,sBACJ,kBACC,QACE;EACE,OAAO;EACP,gBAAgB;AACd,YAAS,UAAU,YAAY,OAAO;AAEtC,kBAAe;;EAElB,EACD,OACD,QACG,SAAS,eACT,SAAS,QAChB;;;;;;;;;;AC5BH,MAAa,sBACX,aAAa,sBAAsB,WAAW,OAAO,WAAW;;;;;;;;;ACElE,MAAa,wBACX,aAAa,2BAA2B,WAAW,gBAAgB,OAAO,CAAC;;;;;;;;;ACJ7E,MAAa,4BACX,aAAa,gBAAgB,WAAW,OAAO,iBAAiB;;;;;;;;;ACClE,MAAa,0BACX,aAAa,gBAAgB,WAAW,sBAAsB,OAAO,CAAC;;;;;;;;;ACHxE,MAAa,gBACX,aAAa,gBAAgB,WAAW,OAAO,KAAK;;;;;;;;;ACEtD,MAAa,0BACX,aAAa,0BAA0B,WACrC,kBAAkB,OAAO,CAC1B;;;;;;;;;ACJH,MAAa,wCACX,aAAa,0BAA0B,WACrC,gCAAgC,OAAO,CACxC;;;;ACNH,qBAAqBA,MAAaC,QAAe"}
|