@dynamic-labs-sdk/react-hooks 1.17.0 → 1.17.1
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/foundation/useBaseQuery/index.d.ts +1 -1
- package/dist/foundation/useBaseQuery/index.d.ts.map +1 -1
- package/dist/foundation/useBaseQuery/useBaseQuery.d.ts +29 -15
- package/dist/foundation/useBaseQuery/useBaseQuery.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useDeletePasskey/useDeletePasskey.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetActiveNetworkData/useGetActiveNetworkData.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetActiveNetworkId/useGetActiveNetworkId.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetAvailableWalletProvidersData/useGetAvailableWalletProvidersData.d.ts +4 -1
- package/dist/hooks/wrappers/functions/useGetAvailableWalletProvidersData/useGetAvailableWalletProvidersData.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetConnectedAddresses/useGetConnectedAddresses.d.ts +4 -1
- package/dist/hooks/wrappers/functions/useGetConnectedAddresses/useGetConnectedAddresses.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetGoogleDriveBackupReadiness/useGetGoogleDriveBackupReadiness.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetGoogleDriveBackupReadiness/useGetGoogleDriveBackupReadiness.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetKrakenAccounts/useGetKrakenAccounts.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetKrakenAccounts/useGetKrakenAccounts.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetKrakenWhitelistedAddresses/useGetKrakenWhitelistedAddresses.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetKrakenWhitelistedAddresses/useGetKrakenWhitelistedAddresses.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetMfaDevices/useGetMfaDevices.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetMfaDevices/useGetMfaDevices.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetMfaMethods/useGetMfaMethods.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetMfaMethods/useGetMfaMethods.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetMfaRecoveryCodes/useGetMfaRecoveryCodes.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetMfaRecoveryCodes/useGetMfaRecoveryCodes.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetNativeBalance/useGetNativeBalance.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetPasskeys/useGetPasskeys.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetPasskeys/useGetPasskeys.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetRegisteredDevices/useGetRegisteredDevices.d.ts +4 -0
- package/dist/hooks/wrappers/functions/useGetRegisteredDevices/useGetRegisteredDevices.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetTokenBalances/useGetTokenBalances.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetTransactionHistory/useGetTransactionHistory.d.ts +1 -1
- package/dist/hooks/wrappers/functions/useGetTransactionHistory/useGetTransactionHistory.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useGetWalletOptionsCatalogue/useGetWalletOptionsCatalogue.d.ts +8 -1
- package/dist/hooks/wrappers/functions/useGetWalletOptionsCatalogue/useGetWalletOptionsCatalogue.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useOnWalletProviderEvent/useOnWalletProviderEvent.d.ts +14 -2
- package/dist/hooks/wrappers/functions/useOnWalletProviderEvent/useOnWalletProviderEvent.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useRegisterPasskey/useRegisterPasskey.d.ts.map +1 -1
- package/dist/hooks/wrappers/functions/useSwitchActiveNetwork/useSwitchActiveNetwork.d.ts.map +1 -1
- package/dist/index.cjs +302 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +302 -68
- package/dist/index.esm.js.map +1 -1
- package/dist/middlewares/invalidateOnEvent/index.d.ts +2 -0
- package/dist/middlewares/invalidateOnEvent/index.d.ts.map +1 -0
- package/dist/middlewares/invalidateOnEvent/invalidateOnEvent.d.ts +29 -0
- package/dist/middlewares/invalidateOnEvent/invalidateOnEvent.d.ts.map +1 -0
- package/dist/middlewares/invalidateOnUserSwitch/index.d.ts +2 -0
- package/dist/middlewares/invalidateOnUserSwitch/index.d.ts.map +1 -0
- package/dist/middlewares/invalidateOnUserSwitch/invalidateOnUserSwitch.d.ts +27 -0
- package/dist/middlewares/invalidateOnUserSwitch/invalidateOnUserSwitch.d.ts.map +1 -0
- package/dist/middlewares/invalidateOnWalletProviderEvent/index.d.ts +2 -0
- package/dist/middlewares/invalidateOnWalletProviderEvent/index.d.ts.map +1 -0
- package/dist/middlewares/invalidateOnWalletProviderEvent/invalidateOnWalletProviderEvent.d.ts +36 -0
- package/dist/middlewares/invalidateOnWalletProviderEvent/invalidateOnWalletProviderEvent.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
|
|
|
7
7
|
|
|
8
8
|
//#region package.json
|
|
9
9
|
var name = "@dynamic-labs-sdk/react-hooks";
|
|
10
|
-
var version = "1.17.
|
|
10
|
+
var version = "1.17.1";
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/modules/DynamicContext/DynamicContext.ts
|
|
@@ -132,8 +132,8 @@ const QUERY_KEY_PREFIX = [HOOK_KEY_NAMESPACE, "query"];
|
|
|
132
132
|
//#endregion
|
|
133
133
|
//#region src/foundation/useBaseQuery/useBaseQuery.ts
|
|
134
134
|
/**
|
|
135
|
-
* Stable empty default for the `middlewares` param so the common
|
|
136
|
-
*
|
|
135
|
+
* Stable empty default for the `middlewares` param so the common case never
|
|
136
|
+
* allocates a fresh array per render.
|
|
137
137
|
*/
|
|
138
138
|
const EMPTY_MIDDLEWARES = [];
|
|
139
139
|
/**
|
|
@@ -147,24 +147,105 @@ const EMPTY_MIDDLEWARES = [];
|
|
|
147
147
|
* so consumers can opt into retries / custom staleTime / etc.
|
|
148
148
|
* - Callers pass `enabled: false` (typically derived from whether their
|
|
149
149
|
* pseudo-required arguments are present) to short-circuit fetches.
|
|
150
|
-
* - Callers pass `middlewares` (named hooks that
|
|
151
|
-
*
|
|
152
|
-
* `true`.
|
|
150
|
+
* - Callers pass `middlewares` (named hooks that run reactive subscriptions
|
|
151
|
+
* such as cache invalidation); each runs on every render.
|
|
153
152
|
*
|
|
154
153
|
* Returns the full `useQuery` result — `data`, `error`, `isLoading`,
|
|
155
154
|
* `isFetching`, `isSuccess`, `refetch`, `status`, etc.
|
|
156
155
|
*/
|
|
157
156
|
const useBaseQuery = ({ enabled = true, middlewares = EMPTY_MIDDLEWARES, queryFn, queryKey, queryParams }) => {
|
|
158
157
|
const client = useDynamicClient();
|
|
159
|
-
const
|
|
158
|
+
const fullQueryKey = (0, react.useMemo)(() => [...QUERY_KEY_PREFIX, ...queryKey], [queryKey]);
|
|
159
|
+
middlewares.forEach((useMiddleware) => useMiddleware({ queryKey: fullQueryKey }));
|
|
160
160
|
return (0, _tanstack_react_query.useQuery)({
|
|
161
161
|
queryFn: async () => {
|
|
162
162
|
await (0, _dynamic_labs_sdk_client.waitForClientInitialized)(client);
|
|
163
163
|
return queryFn(client);
|
|
164
164
|
},
|
|
165
|
-
queryKey:
|
|
165
|
+
queryKey: fullQueryKey,
|
|
166
166
|
...queryParams,
|
|
167
|
-
enabled: enabled &&
|
|
167
|
+
enabled: enabled && queryParams?.enabled !== false
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/hooks/wrappers/functions/useOnWalletProviderEvent/useOnWalletProviderEvent.ts
|
|
173
|
+
/**
|
|
174
|
+
* Subscribes to an event emitted by a specific wallet provider.
|
|
175
|
+
*
|
|
176
|
+
* Wraps `onWalletProviderEvent` from `@dynamic-labs-sdk/client`. Uses a ref to
|
|
177
|
+
* always call the latest callback without re-subscribing, and cleans up the
|
|
178
|
+
* subscription on unmount or when `event` / `walletProviderKey` change. When
|
|
179
|
+
* `walletProviderKey` is `undefined` the hook subscribes to nothing.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```tsx
|
|
183
|
+
* useOnWalletProviderEvent({
|
|
184
|
+
* walletProviderKey: 'metamaskevm',
|
|
185
|
+
* event: 'accountsChanged',
|
|
186
|
+
* callback: ({ addresses }) => console.log(addresses),
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
const useOnWalletProviderEvent = ({ callback, event, walletProviderKey }) => {
|
|
191
|
+
const client = useDynamicClient();
|
|
192
|
+
const callbackRef = (0, react.useRef)(callback);
|
|
193
|
+
callbackRef.current = callback;
|
|
194
|
+
(0, react.useEffect)(() => {
|
|
195
|
+
if (walletProviderKey === void 0) return;
|
|
196
|
+
return (0, _dynamic_labs_sdk_client.onWalletProviderEvent)({
|
|
197
|
+
callback: ((...args) => {
|
|
198
|
+
callbackRef.current(...args);
|
|
199
|
+
}),
|
|
200
|
+
event,
|
|
201
|
+
walletProviderKey
|
|
202
|
+
}, client);
|
|
203
|
+
}, [
|
|
204
|
+
event,
|
|
205
|
+
walletProviderKey,
|
|
206
|
+
client
|
|
207
|
+
]);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/middlewares/invalidateOnWalletProviderEvent/invalidateOnWalletProviderEvent.ts
|
|
212
|
+
/**
|
|
213
|
+
* Query middleware factory that refetches the query whenever the given wallet
|
|
214
|
+
* account's provider emits `event` (e.g. `networkChanged`).
|
|
215
|
+
*
|
|
216
|
+
* It only wires up the subscription, invalidating the query's own cache key so
|
|
217
|
+
* any mounted consumer refetches. This replaces the manual
|
|
218
|
+
* `useOnWalletProviderEvent` + `refetch` boilerplate consumers would otherwise
|
|
219
|
+
* pair with the hook. When `walletAccount` is undefined the subscription is a
|
|
220
|
+
* no-op. The subscription lives here, not in `useBaseQuery`.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* useBaseQuery({
|
|
225
|
+
* middlewares: [
|
|
226
|
+
* invalidateOnWalletProviderEvent({ event: 'networkChanged', walletAccount }),
|
|
227
|
+
* ],
|
|
228
|
+
* queryFn: (client) => getActiveNetworkData({ walletAccount }, client),
|
|
229
|
+
* queryKey: ['useGetActiveNetworkData', walletAccount],
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
const invalidateOnWalletProviderEvent = ({ event, walletAccount }) => (context) => {
|
|
234
|
+
const client = useDynamicClient();
|
|
235
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
236
|
+
useOnWalletProviderEvent({
|
|
237
|
+
callback: () => {
|
|
238
|
+
if (!context) return;
|
|
239
|
+
queryClient.invalidateQueries({ queryKey: context.queryKey }).catch((error) => {
|
|
240
|
+
(0, _dynamic_labs_sdk_client_core.getCore)(client).logger.debug("[invalidateOnWalletProviderEvent] failed to invalidate query", {
|
|
241
|
+
error,
|
|
242
|
+
queryKey: context.queryKey,
|
|
243
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
event,
|
|
248
|
+
walletProviderKey: walletAccount?.walletProviderKey
|
|
168
249
|
});
|
|
169
250
|
};
|
|
170
251
|
|
|
@@ -179,6 +260,10 @@ const useBaseQuery = ({ enabled = true, middlewares = EMPTY_MIDDLEWARES, queryFn
|
|
|
179
260
|
* ```
|
|
180
261
|
*/
|
|
181
262
|
const useGetActiveNetworkData = ({ queryParams, ...args }) => useBaseQuery({
|
|
263
|
+
middlewares: [invalidateOnWalletProviderEvent({
|
|
264
|
+
event: "networkChanged",
|
|
265
|
+
walletAccount: args.walletAccount
|
|
266
|
+
})],
|
|
182
267
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getActiveNetworkData)(args, client),
|
|
183
268
|
queryKey: ["useGetActiveNetworkData", args],
|
|
184
269
|
queryParams
|
|
@@ -192,6 +277,10 @@ const useGetActiveNetworkData = ({ queryParams, ...args }) => useBaseQuery({
|
|
|
192
277
|
* Wraps `getActiveNetworkId` from `@dynamic-labs-sdk/client`.
|
|
193
278
|
*/
|
|
194
279
|
const useGetActiveNetworkId = ({ queryParams, ...args }) => useBaseQuery({
|
|
280
|
+
middlewares: [invalidateOnWalletProviderEvent({
|
|
281
|
+
event: "networkChanged",
|
|
282
|
+
walletAccount: args.walletAccount
|
|
283
|
+
})],
|
|
195
284
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getActiveNetworkId)(args, client),
|
|
196
285
|
queryKey: ["useGetActiveNetworkId", args],
|
|
197
286
|
queryParams
|
|
@@ -484,11 +573,17 @@ const useBaseState = ({ event, queryKey, queryParams, selector, defaultValue, sk
|
|
|
484
573
|
/**
|
|
485
574
|
* Returns the available wallet providers and their data.
|
|
486
575
|
*
|
|
487
|
-
* Re-renders when
|
|
576
|
+
* Re-renders when the wallet provider registry changes. `walletProviderChanged`
|
|
577
|
+
* fires on register / priority update but NOT on removal, so
|
|
578
|
+
* `walletProviderUnregistered` is wired too — otherwise a removed provider
|
|
579
|
+
* would linger in the returned list.
|
|
488
580
|
*/
|
|
489
581
|
const useGetAvailableWalletProvidersData = () => useBaseState({
|
|
490
582
|
defaultValue: [],
|
|
491
|
-
event:
|
|
583
|
+
event: {
|
|
584
|
+
walletProviderChanged: true,
|
|
585
|
+
walletProviderUnregistered: true
|
|
586
|
+
},
|
|
492
587
|
queryKey: ["useGetAvailableWalletProvidersData"],
|
|
493
588
|
selector: (client) => (0, _dynamic_labs_sdk_client.getAvailableWalletProvidersData)(client)
|
|
494
589
|
});
|
|
@@ -698,14 +793,82 @@ const useConnectAndVerifyWithWalletProvider = ({ mutateParams } = {}) => useBase
|
|
|
698
793
|
mutationFn: ({ client, variables }) => (0, _dynamic_labs_sdk_client.connectAndVerifyWithWalletProvider)(variables, client)
|
|
699
794
|
});
|
|
700
795
|
|
|
796
|
+
//#endregion
|
|
797
|
+
//#region src/hooks/wrappers/functions/useOnEvent/useOnEvent.ts
|
|
798
|
+
/**
|
|
799
|
+
* Subscribes to a Dynamic client event.
|
|
800
|
+
*
|
|
801
|
+
* Uses a ref to always call the latest listener without re-subscribing,
|
|
802
|
+
* and cleans up the subscription on unmount or event name change.
|
|
803
|
+
*/
|
|
804
|
+
const useOnEvent = ({ event, listener }) => {
|
|
805
|
+
const client = useDynamicClient();
|
|
806
|
+
const callbackRef = (0, react.useRef)(listener);
|
|
807
|
+
callbackRef.current = listener;
|
|
808
|
+
(0, react.useEffect)(() => (0, _dynamic_labs_sdk_client.onEvent)({
|
|
809
|
+
event,
|
|
810
|
+
listener: (...args) => {
|
|
811
|
+
callbackRef.current(...args);
|
|
812
|
+
}
|
|
813
|
+
}, client), [event, client]);
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/middlewares/invalidateOnEvent/invalidateOnEvent.ts
|
|
818
|
+
/**
|
|
819
|
+
* Query middleware factory that refetches the query whenever the given client
|
|
820
|
+
* event fires (e.g. `walletAccountsChanged`).
|
|
821
|
+
*
|
|
822
|
+
* It only wires up the subscription, invalidating the query's own cache key so
|
|
823
|
+
* any mounted consumer refetches. This replaces the manual `useOnEvent` +
|
|
824
|
+
* `refetch` boilerplate consumers would otherwise pair with the hook. It is the
|
|
825
|
+
* client-event counterpart to `invalidateOnWalletProviderEvent` (which listens
|
|
826
|
+
* on a single wallet account's provider). The subscription lives here, not in
|
|
827
|
+
* `useBaseQuery`.
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```ts
|
|
831
|
+
* useBaseQuery({
|
|
832
|
+
* middlewares: [invalidateOnEvent({ event: 'walletAccountsChanged' })],
|
|
833
|
+
* queryFn: (client) => getConnectedAddresses(args, client),
|
|
834
|
+
* queryKey: ['useGetConnectedAddresses', args],
|
|
835
|
+
* });
|
|
836
|
+
* ```
|
|
837
|
+
*/
|
|
838
|
+
const invalidateOnEvent = ({ event }) => (context) => {
|
|
839
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
840
|
+
const client = useDynamicClient();
|
|
841
|
+
useOnEvent({
|
|
842
|
+
event,
|
|
843
|
+
listener: (() => {
|
|
844
|
+
if (!context) return;
|
|
845
|
+
(0, _dynamic_labs_sdk_client_core.getCore)(client).logger.debug("[invalidateOnEvent] invalidating query on event", {
|
|
846
|
+
event,
|
|
847
|
+
queryKey: context.queryKey
|
|
848
|
+
});
|
|
849
|
+
queryClient.invalidateQueries({ queryKey: context.queryKey }).catch((error) => {
|
|
850
|
+
(0, _dynamic_labs_sdk_client_core.getCore)(client).logger.debug("[invalidateOnEvent] failed to invalidate query", {
|
|
851
|
+
error,
|
|
852
|
+
queryKey: context.queryKey,
|
|
853
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
})
|
|
857
|
+
});
|
|
858
|
+
};
|
|
859
|
+
|
|
701
860
|
//#endregion
|
|
702
861
|
//#region src/hooks/wrappers/functions/useGetConnectedAddresses/useGetConnectedAddresses.ts
|
|
703
862
|
/**
|
|
704
863
|
* Returns the connected addresses for the given wallet provider.
|
|
705
864
|
*
|
|
706
|
-
* Wraps `getConnectedAddresses` from `@dynamic-labs-sdk/client`.
|
|
865
|
+
* Wraps `getConnectedAddresses` from `@dynamic-labs-sdk/client`. Automatically
|
|
866
|
+
* refetches when wallet accounts change (connect / disconnect / verify), so
|
|
867
|
+
* consumers don't have to pair it with a manual `walletAccountsChanged`
|
|
868
|
+
* listener.
|
|
707
869
|
*/
|
|
708
870
|
const useGetConnectedAddresses = ({ queryParams, ...args }) => useBaseQuery({
|
|
871
|
+
middlewares: [invalidateOnEvent({ event: "walletAccountsChanged" })],
|
|
709
872
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getConnectedAddresses)(args, client),
|
|
710
873
|
queryKey: ["useGetConnectedAddresses", args],
|
|
711
874
|
queryParams
|
|
@@ -837,6 +1000,7 @@ const useDeleteMfaDevice = ({ mutateParams } = {}) => {
|
|
|
837
1000
|
* ```
|
|
838
1001
|
*/
|
|
839
1002
|
const useDeletePasskey = ({ mutateParams } = {}) => useBaseMutation({
|
|
1003
|
+
middlewares: [invalidatesQueries("useGetPasskeys")],
|
|
840
1004
|
mutateParams,
|
|
841
1005
|
mutationFn: ({ client, variables }) => (0, _dynamic_labs_sdk_client.deletePasskey)(variables, client)
|
|
842
1006
|
});
|
|
@@ -863,26 +1027,6 @@ const useDeleteUser = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
863
1027
|
mutationFn: ({ client }) => (0, _dynamic_labs_sdk_client.deleteUser)(client)
|
|
864
1028
|
});
|
|
865
1029
|
|
|
866
|
-
//#endregion
|
|
867
|
-
//#region src/hooks/wrappers/functions/useOnEvent/useOnEvent.ts
|
|
868
|
-
/**
|
|
869
|
-
* Subscribes to a Dynamic client event.
|
|
870
|
-
*
|
|
871
|
-
* Uses a ref to always call the latest listener without re-subscribing,
|
|
872
|
-
* and cleans up the subscription on unmount or event name change.
|
|
873
|
-
*/
|
|
874
|
-
const useOnEvent = ({ event, listener }) => {
|
|
875
|
-
const client = useDynamicClient();
|
|
876
|
-
const callbackRef = (0, react.useRef)(listener);
|
|
877
|
-
callbackRef.current = listener;
|
|
878
|
-
(0, react.useEffect)(() => (0, _dynamic_labs_sdk_client.onEvent)({
|
|
879
|
-
event,
|
|
880
|
-
listener: (...args) => {
|
|
881
|
-
callbackRef.current(...args);
|
|
882
|
-
}
|
|
883
|
-
}, client), [event, client]);
|
|
884
|
-
};
|
|
885
|
-
|
|
886
1030
|
//#endregion
|
|
887
1031
|
//#region src/hooks/wrappers/functions/useExecuteSwapTransaction/useExecuteSwapTransaction.ts
|
|
888
1032
|
/**
|
|
@@ -961,17 +1105,73 @@ const usePrepareFlowSigning = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
961
1105
|
mutationFn: ({ client, variables }) => (0, _dynamic_labs_sdk_client.prepareFlowSigning)(variables, client)
|
|
962
1106
|
});
|
|
963
1107
|
|
|
1108
|
+
//#endregion
|
|
1109
|
+
//#region src/middlewares/invalidateOnUserSwitch/invalidateOnUserSwitch.ts
|
|
1110
|
+
const USER_CHANGED_EVENT = "userChanged";
|
|
1111
|
+
/**
|
|
1112
|
+
* Query middleware factory that refetches the query when a *different* user
|
|
1113
|
+
* becomes the current user (login or account switch).
|
|
1114
|
+
*
|
|
1115
|
+
* Unlike `invalidateOnEvent({ event: 'userChanged' })`, this never invalidates
|
|
1116
|
+
* on:
|
|
1117
|
+
* - logout (the user becomes `undefined`) — the refetch would just 401 and the
|
|
1118
|
+
* cleared session leaves nothing to refetch; and
|
|
1119
|
+
* - same-user `userChanged` fires (e.g. linking a credential or a profile
|
|
1120
|
+
* update) — the data still belongs to the same user, whose own mutations
|
|
1121
|
+
* already invalidate it within the session.
|
|
1122
|
+
*
|
|
1123
|
+
* It tracks the previous user id across renders (seeded from the user present
|
|
1124
|
+
* at mount) and only invalidates when the new id is defined and differs.
|
|
1125
|
+
*
|
|
1126
|
+
* @example
|
|
1127
|
+
* ```ts
|
|
1128
|
+
* useBaseQuery({
|
|
1129
|
+
* middlewares: [invalidateOnUserSwitch()],
|
|
1130
|
+
* queryFn: (client) => getMfaDevices(client),
|
|
1131
|
+
* queryKey: ['useGetMfaDevices'],
|
|
1132
|
+
* });
|
|
1133
|
+
* ```
|
|
1134
|
+
*/
|
|
1135
|
+
const invalidateOnUserSwitch = () => (context) => {
|
|
1136
|
+
const client = useDynamicClient();
|
|
1137
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
1138
|
+
const previousUserIdRef = (0, react.useRef)(client.user?.id);
|
|
1139
|
+
useOnEvent({
|
|
1140
|
+
event: USER_CHANGED_EVENT,
|
|
1141
|
+
listener: ((args) => {
|
|
1142
|
+
const nextUserId = args.user?.id;
|
|
1143
|
+
const previousUserId = previousUserIdRef.current;
|
|
1144
|
+
previousUserIdRef.current = nextUserId;
|
|
1145
|
+
if (nextUserId === void 0 || nextUserId === previousUserId) return;
|
|
1146
|
+
if (!context) return;
|
|
1147
|
+
(0, _dynamic_labs_sdk_client_core.getCore)(client).logger.debug("[invalidateOnUserSwitch] invalidating query on new user", { queryKey: context.queryKey });
|
|
1148
|
+
queryClient.invalidateQueries({ queryKey: context.queryKey }).catch((error) => {
|
|
1149
|
+
(0, _dynamic_labs_sdk_client_core.getCore)(client).logger.debug("[invalidateOnUserSwitch] failed to invalidate query", {
|
|
1150
|
+
error,
|
|
1151
|
+
queryKey: context.queryKey,
|
|
1152
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
1153
|
+
});
|
|
1154
|
+
});
|
|
1155
|
+
})
|
|
1156
|
+
});
|
|
1157
|
+
};
|
|
1158
|
+
|
|
964
1159
|
//#endregion
|
|
965
1160
|
//#region src/hooks/wrappers/functions/useGetGoogleDriveBackupReadiness/useGetGoogleDriveBackupReadiness.ts
|
|
966
1161
|
/**
|
|
967
1162
|
* Wraps `getGoogleDriveBackupReadiness` from `@dynamic-labs-sdk/client`. Reports whether the user's Google Drive backup is set up and available.
|
|
968
1163
|
*
|
|
1164
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1165
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1166
|
+
* `userChanged` listener.
|
|
1167
|
+
*
|
|
969
1168
|
* @example
|
|
970
1169
|
* ```tsx
|
|
971
1170
|
* const { data: readiness, isLoading } = useGetGoogleDriveBackupReadiness();
|
|
972
1171
|
* ```
|
|
973
1172
|
*/
|
|
974
1173
|
const useGetGoogleDriveBackupReadiness = ({ queryParams } = {}) => useBaseQuery({
|
|
1174
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
975
1175
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getGoogleDriveBackupReadiness)(client),
|
|
976
1176
|
queryKey: ["useGetGoogleDriveBackupReadiness"],
|
|
977
1177
|
queryParams
|
|
@@ -995,12 +1195,17 @@ const useIsMfaRequiredForAction = ({ queryParams, ...args }) => useBaseQuery({
|
|
|
995
1195
|
/**
|
|
996
1196
|
* Wraps `getKrakenAccounts` from `@dynamic-labs-sdk/client`. Returns the authenticated user's Kraken accounts (with balances), optionally filtered by chain/network.
|
|
997
1197
|
*
|
|
1198
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1199
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1200
|
+
* `userChanged` listener.
|
|
1201
|
+
*
|
|
998
1202
|
* @example
|
|
999
1203
|
* ```tsx
|
|
1000
1204
|
* const { data: accounts, isLoading } = useGetKrakenAccounts();
|
|
1001
1205
|
* ```
|
|
1002
1206
|
*/
|
|
1003
1207
|
const useGetKrakenAccounts = ({ queryParams, ...args } = {}) => useBaseQuery({
|
|
1208
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
1004
1209
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getKrakenAccounts)(args, client),
|
|
1005
1210
|
queryKey: ["useGetKrakenAccounts", args],
|
|
1006
1211
|
queryParams
|
|
@@ -1027,12 +1232,17 @@ const useCreateKrakenExchangeTransfer = ({ mutateParams } = {}) => useBaseMutati
|
|
|
1027
1232
|
/**
|
|
1028
1233
|
* Wraps `getKrakenWhitelistedAddresses` from `@dynamic-labs-sdk/client`. Returns the destination addresses whitelisted for Kraken withdrawals.
|
|
1029
1234
|
*
|
|
1235
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1236
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1237
|
+
* `userChanged` listener.
|
|
1238
|
+
*
|
|
1030
1239
|
* @example
|
|
1031
1240
|
* ```tsx
|
|
1032
1241
|
* const { data: addresses, isLoading } = useGetKrakenWhitelistedAddresses();
|
|
1033
1242
|
* ```
|
|
1034
1243
|
*/
|
|
1035
1244
|
const useGetKrakenWhitelistedAddresses = ({ queryParams } = {}) => useBaseQuery({
|
|
1245
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
1036
1246
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getKrakenWhitelistedAddresses)(client),
|
|
1037
1247
|
queryKey: ["useGetKrakenWhitelistedAddresses"],
|
|
1038
1248
|
queryParams
|
|
@@ -1065,12 +1275,17 @@ const useLogout = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
1065
1275
|
*
|
|
1066
1276
|
* Wraps `getMfaDevices` from `@dynamic-labs-sdk/client`.
|
|
1067
1277
|
*
|
|
1278
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1279
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1280
|
+
* `userChanged` listener.
|
|
1281
|
+
*
|
|
1068
1282
|
* @example
|
|
1069
1283
|
* ```tsx
|
|
1070
1284
|
* const { data: mfaDevices, isLoading, refetch } = useGetMfaDevices();
|
|
1071
1285
|
* ```
|
|
1072
1286
|
*/
|
|
1073
1287
|
const useGetMfaDevices = ({ queryParams } = {}) => useBaseQuery({
|
|
1288
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
1074
1289
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getMfaDevices)(client),
|
|
1075
1290
|
queryKey: ["useGetMfaDevices"],
|
|
1076
1291
|
queryParams
|
|
@@ -1084,12 +1299,17 @@ const useGetMfaDevices = ({ queryParams } = {}) => useBaseQuery({
|
|
|
1084
1299
|
*
|
|
1085
1300
|
* Wraps `getMfaMethods` from `@dynamic-labs-sdk/client`.
|
|
1086
1301
|
*
|
|
1302
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1303
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1304
|
+
* `userChanged` listener.
|
|
1305
|
+
*
|
|
1087
1306
|
* @example
|
|
1088
1307
|
* ```tsx
|
|
1089
1308
|
* const { data: mfaMethods, isLoading, refetch } = useGetMfaMethods();
|
|
1090
1309
|
* ```
|
|
1091
1310
|
*/
|
|
1092
1311
|
const useGetMfaMethods = ({ queryParams } = {}) => useBaseQuery({
|
|
1312
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
1093
1313
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getMfaMethods)(client),
|
|
1094
1314
|
queryKey: ["useGetMfaMethods"],
|
|
1095
1315
|
queryParams
|
|
@@ -1102,12 +1322,17 @@ const useGetMfaMethods = ({ queryParams } = {}) => useBaseQuery({
|
|
|
1102
1322
|
*
|
|
1103
1323
|
* Wraps `getMfaRecoveryCodes` from `@dynamic-labs-sdk/client`.
|
|
1104
1324
|
*
|
|
1325
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1326
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1327
|
+
* `userChanged` listener.
|
|
1328
|
+
*
|
|
1105
1329
|
* @example
|
|
1106
1330
|
* ```tsx
|
|
1107
1331
|
* const { data: recoveryCodes, isLoading, refetch } = useGetMfaRecoveryCodes();
|
|
1108
1332
|
* ```
|
|
1109
1333
|
*/
|
|
1110
1334
|
const useGetMfaRecoveryCodes = ({ queryParams } = {}) => useBaseQuery({
|
|
1335
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
1111
1336
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getMfaRecoveryCodes)(client),
|
|
1112
1337
|
queryKey: ["useGetMfaRecoveryCodes"],
|
|
1113
1338
|
queryParams
|
|
@@ -1185,6 +1410,10 @@ const useGetMultichainTokenBalances = ({ balanceRequest, queryParams }) => useBa
|
|
|
1185
1410
|
*/
|
|
1186
1411
|
const useGetNativeBalance = ({ walletAccount, queryParams }) => useBaseQuery({
|
|
1187
1412
|
enabled: walletAccount !== void 0,
|
|
1413
|
+
middlewares: [invalidateOnWalletProviderEvent({
|
|
1414
|
+
event: "networkChanged",
|
|
1415
|
+
walletAccount
|
|
1416
|
+
})],
|
|
1188
1417
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getNativeBalance)({ walletAccount }, client),
|
|
1189
1418
|
queryKey: ["useGetNativeBalance", walletAccount?.id],
|
|
1190
1419
|
queryParams
|
|
@@ -1226,12 +1455,17 @@ const useOnceEvent = ({ event, listener }) => {
|
|
|
1226
1455
|
*
|
|
1227
1456
|
* Wraps `getPasskeys` from `@dynamic-labs-sdk/client`.
|
|
1228
1457
|
*
|
|
1458
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1459
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1460
|
+
* `userChanged` listener.
|
|
1461
|
+
*
|
|
1229
1462
|
* @example
|
|
1230
1463
|
* ```tsx
|
|
1231
1464
|
* const { data: passkeys, isLoading, refetch } = useGetPasskeys();
|
|
1232
1465
|
* ```
|
|
1233
1466
|
*/
|
|
1234
1467
|
const useGetPasskeys = ({ queryParams } = {}) => useBaseQuery({
|
|
1468
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
1235
1469
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getPasskeys)(client),
|
|
1236
1470
|
queryKey: ["useGetPasskeys"],
|
|
1237
1471
|
queryParams
|
|
@@ -1281,12 +1515,17 @@ const useRefreshAuth = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
1281
1515
|
* {@link useRevokeRegisteredDevice} to let users revoke a device from the
|
|
1282
1516
|
* list.
|
|
1283
1517
|
*
|
|
1518
|
+
* Automatically refetches when a different user becomes current (login or
|
|
1519
|
+
* account switch), so consumers don't have to pair it with a manual
|
|
1520
|
+
* `userChanged` listener.
|
|
1521
|
+
*
|
|
1284
1522
|
* @example
|
|
1285
1523
|
* ```tsx
|
|
1286
1524
|
* const { data: devices, isLoading, refetch } = useGetRegisteredDevices();
|
|
1287
1525
|
* ```
|
|
1288
1526
|
*/
|
|
1289
1527
|
const useGetRegisteredDevices = ({ queryParams } = {}) => useBaseQuery({
|
|
1528
|
+
middlewares: [invalidateOnUserSwitch()],
|
|
1290
1529
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getRegisteredDevices)(client),
|
|
1291
1530
|
queryKey: ["useGetRegisteredDevices"],
|
|
1292
1531
|
queryParams
|
|
@@ -1310,6 +1549,7 @@ const useGetRegisteredDevices = ({ queryParams } = {}) => useBaseQuery({
|
|
|
1310
1549
|
* ```
|
|
1311
1550
|
*/
|
|
1312
1551
|
const useRegisterPasskey = ({ mutateParams } = {}) => useBaseMutation({
|
|
1552
|
+
middlewares: [invalidatesQueries("useGetPasskeys")],
|
|
1313
1553
|
mutateParams,
|
|
1314
1554
|
mutationFn: ({ client, variables }) => (0, _dynamic_labs_sdk_client.registerPasskey)(variables, client)
|
|
1315
1555
|
});
|
|
@@ -1680,6 +1920,7 @@ const useGetSwapStatus = ({ queryParams, ...args }) => useBaseQuery({
|
|
|
1680
1920
|
* ```
|
|
1681
1921
|
*/
|
|
1682
1922
|
const useSwitchActiveNetwork = ({ mutateParams } = {}) => useBaseMutation({
|
|
1923
|
+
middlewares: [invalidatesQueries("useGetActiveNetworkData", "useGetActiveNetworkId")],
|
|
1683
1924
|
mutateParams,
|
|
1684
1925
|
mutationFn: ({ client, variables }) => (0, _dynamic_labs_sdk_client.switchActiveNetwork)(variables, client)
|
|
1685
1926
|
});
|
|
@@ -1703,6 +1944,10 @@ const useSwitchActiveNetwork = ({ mutateParams } = {}) => useBaseMutation({
|
|
|
1703
1944
|
*/
|
|
1704
1945
|
const useGetTokenBalances = ({ walletAccount, queryParams, ...rest }) => useBaseQuery({
|
|
1705
1946
|
enabled: walletAccount !== void 0,
|
|
1947
|
+
middlewares: [invalidateOnWalletProviderEvent({
|
|
1948
|
+
event: "networkChanged",
|
|
1949
|
+
walletAccount
|
|
1950
|
+
})],
|
|
1706
1951
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getTokenBalances)({
|
|
1707
1952
|
walletAccount,
|
|
1708
1953
|
...rest
|
|
@@ -1965,54 +2210,43 @@ const useGetWalletConnectCatalogWalletByWalletProviderKey = ({ queryParams, ...a
|
|
|
1965
2210
|
//#endregion
|
|
1966
2211
|
//#region src/hooks/wrappers/functions/useGetWalletOptionsCatalogue/useGetWalletOptionsCatalogue.ts
|
|
1967
2212
|
/**
|
|
2213
|
+
* Freshness window for the catalogue, in milliseconds.
|
|
2214
|
+
*
|
|
2215
|
+
* The catalogue is derived from two near-static sources: the in-memory wallet
|
|
2216
|
+
* provider registry and the wallet-book document served from a CDN. With
|
|
2217
|
+
* react-query's default `staleTime: 0` the data is stale the instant it
|
|
2218
|
+
* arrives, so every new mount/observer (e.g. reopening the wallet list)
|
|
2219
|
+
* refetches the CDN document even though nothing changed — needlessly
|
|
2220
|
+
* hammering the CDN. A 1h window serves cached data to remounts; the registry
|
|
2221
|
+
* event middlewares below still force an immediate refetch on any real change,
|
|
2222
|
+
* so reactivity is preserved.
|
|
2223
|
+
*/
|
|
2224
|
+
const CATALOGUE_STALE_TIME_MS = 36e5;
|
|
2225
|
+
/**
|
|
1968
2226
|
* Wraps `getWalletOptionsCatalogue` from `@dynamic-labs-sdk/client`. Returns the catalogue of wallet options the project supports.
|
|
1969
2227
|
*
|
|
2228
|
+
* Automatically refetches when the wallet provider registry changes: EIP-6963
|
|
2229
|
+
* wallets fill the registry asynchronously after mount, and the registry emits
|
|
2230
|
+
* `walletProviderChanged` (on register / priority update) and
|
|
2231
|
+
* `walletProviderUnregistered` (on removal). Wiring both keeps the catalogue in
|
|
2232
|
+
* sync without consumers pairing the hook with a manual listener.
|
|
2233
|
+
*
|
|
1970
2234
|
* @example
|
|
1971
2235
|
* ```tsx
|
|
1972
2236
|
* const { data: catalogue, isLoading } = useGetWalletOptionsCatalogue();
|
|
1973
2237
|
* ```
|
|
1974
2238
|
*/
|
|
1975
2239
|
const useGetWalletOptionsCatalogue = ({ queryParams, ...args } = {}) => useBaseQuery({
|
|
2240
|
+
middlewares: [invalidateOnEvent({ event: "walletProviderChanged" }), invalidateOnEvent({ event: "walletProviderUnregistered" })],
|
|
1976
2241
|
queryFn: (client) => (0, _dynamic_labs_sdk_client.getWalletOptionsCatalogue)(args, client),
|
|
1977
2242
|
queryKey: ["useGetWalletOptionsCatalogue", args],
|
|
1978
|
-
queryParams
|
|
2243
|
+
queryParams: {
|
|
2244
|
+
retry: false,
|
|
2245
|
+
staleTime: CATALOGUE_STALE_TIME_MS,
|
|
2246
|
+
...queryParams
|
|
2247
|
+
}
|
|
1979
2248
|
});
|
|
1980
2249
|
|
|
1981
|
-
//#endregion
|
|
1982
|
-
//#region src/hooks/wrappers/functions/useOnWalletProviderEvent/useOnWalletProviderEvent.ts
|
|
1983
|
-
/**
|
|
1984
|
-
* Subscribes to an event emitted by a specific wallet provider.
|
|
1985
|
-
*
|
|
1986
|
-
* Wraps `onWalletProviderEvent` from `@dynamic-labs-sdk/client`. Uses a ref to
|
|
1987
|
-
* always call the latest callback without re-subscribing, and cleans up the
|
|
1988
|
-
* subscription on unmount or when `event` / `walletProviderKey` change.
|
|
1989
|
-
*
|
|
1990
|
-
* @example
|
|
1991
|
-
* ```tsx
|
|
1992
|
-
* useOnWalletProviderEvent({
|
|
1993
|
-
* walletProviderKey: 'metamaskevm',
|
|
1994
|
-
* event: 'accountsChanged',
|
|
1995
|
-
* callback: ({ addresses }) => console.log(addresses),
|
|
1996
|
-
* });
|
|
1997
|
-
* ```
|
|
1998
|
-
*/
|
|
1999
|
-
const useOnWalletProviderEvent = ({ callback, event, walletProviderKey }) => {
|
|
2000
|
-
const client = useDynamicClient();
|
|
2001
|
-
const callbackRef = (0, react.useRef)(callback);
|
|
2002
|
-
callbackRef.current = callback;
|
|
2003
|
-
(0, react.useEffect)(() => (0, _dynamic_labs_sdk_client.onWalletProviderEvent)({
|
|
2004
|
-
callback: ((...args) => {
|
|
2005
|
-
callbackRef.current(...args);
|
|
2006
|
-
}),
|
|
2007
|
-
event,
|
|
2008
|
-
walletProviderKey
|
|
2009
|
-
}, client), [
|
|
2010
|
-
event,
|
|
2011
|
-
walletProviderKey,
|
|
2012
|
-
client
|
|
2013
|
-
]);
|
|
2014
|
-
};
|
|
2015
|
-
|
|
2016
2250
|
//#endregion
|
|
2017
2251
|
//#region src/hooks/wrappers/state/useInitStatus/useInitStatus.ts
|
|
2018
2252
|
/**
|