@sodax/dapp-kit 1.2.3-beta → 1.2.5-beta

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/README.md CHANGED
@@ -266,7 +266,8 @@ const { data: hasWithdrawAllowed, isLoading: isWithdrawAllowanceLoading } = useM
266
266
  };
267
267
 
268
268
  // Get user's supplied assets
269
- const userReserves = useUserReservesData(chainId);
269
+ const { address } = useXAccount(chainId);
270
+ const { data: userReserves } = useUserReservesData({ spokeChainId: chainId, userAddress: address });
270
271
  }
271
272
 
272
273
  // Wallet Address Derivation
package/dist/index.d.mts CHANGED
@@ -316,17 +316,29 @@ interface WithdrawResponse {
316
316
  */
317
317
  declare function useWithdraw(): UseMutationResult<WithdrawResponse, MoneyMarketError<'CREATE_WITHDRAW_INTENT_FAILED' | 'WITHDRAW_UNKNOWN_ERROR' | RelayErrorCode>, UseWithdrawParams>;
318
318
 
319
- type UseUserReservesDataParams = {
319
+ type BaseQueryOptions$1 = {
320
+ queryOptions?: UseQueryOptions<readonly [readonly UserReserveData[], number], Error>;
321
+ };
322
+ type NewParams$1 = BaseQueryOptions$1 & {
323
+ /** Spoke chain id (e.g. '0xa86a.avax') */
324
+ spokeChainId: SpokeChainId$1 | undefined;
325
+ /** User wallet address on the spoke chain */
326
+ userAddress: string | undefined;
327
+ };
328
+ /** @deprecated Use `{ spokeChainId, userAddress }` instead */
329
+ type LegacyParams$1 = BaseQueryOptions$1 & {
330
+ /** @deprecated Use `spokeChainId` instead */
320
331
  spokeProvider: SpokeProvider | undefined;
332
+ /** @deprecated Use `userAddress` instead */
321
333
  address: string | undefined;
322
- queryOptions?: UseQueryOptions<readonly [readonly UserReserveData[], number], Error>;
323
334
  };
335
+ type UseUserReservesDataParams = NewParams$1 | LegacyParams$1;
324
336
  /**
325
337
  * Hook for fetching user reserves data from the Sodax money market.
326
338
  *
327
339
  * @param params (optional) - Object including:
328
- * - spokeProvider: The SpokeProvider instance required for data fetching. If not provided, data fetching is disabled.
329
- * - address: The user's address (string) whose reserves data will be fetched. If not provided, data fetching is disabled.
340
+ * - spokeChainId: The spoke chain id whose reserves data will be fetched. If not provided, data fetching is disabled.
341
+ * - userAddress: The user's address (string) whose reserves data will be fetched. If not provided, data fetching is disabled.
330
342
  * - queryOptions: (optional) Custom React Query options such as `queryKey`, `enabled`, or cache policy.
331
343
  *
332
344
  * @returns {UseQueryResult<readonly [readonly UserReserveData[], number], Error>} React Query result object containing:
@@ -337,8 +349,8 @@ type UseUserReservesDataParams = {
337
349
  *
338
350
  * @example
339
351
  * const { data: userReservesData, isLoading, error } = useUserReservesData({
340
- * spokeProvider,
341
- * address,
352
+ * spokeChainId,
353
+ * userAddress,
342
354
  * });
343
355
  */
344
356
  declare function useUserReservesData(params?: UseUserReservesDataParams): UseQueryResult<readonly [readonly UserReserveData[], number], Error>;
@@ -516,26 +528,30 @@ declare function useReservesUsdFormat(params?: UseReservesUsdFormatParams): UseQ
516
528
  priceInMarketReferenceCurrency: string;
517
529
  } & FormatReserveUSDResponse)[], Error>;
518
530
 
519
- type UseUserFormattedSummaryParams = {
520
- spokeProvider?: SpokeProvider;
521
- address?: string;
531
+ type BaseQueryOptions = {
522
532
  queryOptions?: UseQueryOptions<FormatUserSummaryResponse<FormatReserveUSDResponse>, Error>;
523
533
  };
534
+ type NewParams = BaseQueryOptions & {
535
+ /** Spoke chain id (e.g. '0xa86a.avax') */
536
+ spokeChainId: SpokeChainId$1 | undefined;
537
+ /** User wallet address on the spoke chain */
538
+ userAddress: string | undefined;
539
+ };
540
+ /** @deprecated Use `{ spokeChainId, userAddress }` instead */
541
+ type LegacyParams = BaseQueryOptions & {
542
+ /** @deprecated Use `spokeChainId` instead */
543
+ spokeProvider: SpokeProvider | undefined;
544
+ /** @deprecated Use `userAddress` instead */
545
+ address: string | undefined;
546
+ };
547
+ type UseUserFormattedSummaryParams = NewParams | LegacyParams;
524
548
  /**
525
549
  * React hook to fetch a formatted summary of a user's Sodax money market portfolio.
526
550
  *
527
- * Accepts an optional params object:
528
- * - `spokeProvider`: The SpokeProvider instance for the target chain
529
- * - `address`: The user wallet address to get the summary for
530
- * - `queryOptions`: Optional React Query options (key, caching, intervals, etc)
531
- *
532
- * The hook returns a React Query result object containing the formatted summary, loading and error state.
533
- * The query is enabled only if both the spokeProvider and address are provided.
534
- *
535
- * @param params Optional parameters:
536
- * - spokeProvider: SpokeProvider to query chain data (required for enabled query)
537
- * - address: User account address (required for enabled query)
538
- * - queryOptions: React Query options for customization (optional)
551
+ * @param params (optional) - Object including:
552
+ * - spokeChainId: The spoke chain id whose data will be fetched. If not provided, data fetching is disabled.
553
+ * - userAddress: The user's address (string) whose summary will be fetched. If not provided, data fetching is disabled.
554
+ * - queryOptions: (optional) Custom React Query options such as `queryKey`, `enabled`, or cache policy.
539
555
  *
540
556
  * @returns {UseQueryResult<FormatUserSummaryResponse<FormatReserveUSDResponse>, Error>}
541
557
  * A result object from React Query including:
@@ -545,7 +561,7 @@ type UseUserFormattedSummaryParams = {
545
561
  * - error: Error if thrown in fetching
546
562
  *
547
563
  * @example
548
- * const { data, isLoading, error } = useUserFormattedSummary({ spokeProvider, address });
564
+ * const { data, isLoading, error } = useUserFormattedSummary({ spokeChainId, userAddress });
549
565
  */
550
566
  declare function useUserFormattedSummary(params?: UseUserFormattedSummaryParams): UseQueryResult<FormatUserSummaryResponse<FormatReserveUSDResponse>, Error>;
551
567
 
package/dist/index.d.ts CHANGED
@@ -316,17 +316,29 @@ interface WithdrawResponse {
316
316
  */
317
317
  declare function useWithdraw(): UseMutationResult<WithdrawResponse, MoneyMarketError<'CREATE_WITHDRAW_INTENT_FAILED' | 'WITHDRAW_UNKNOWN_ERROR' | RelayErrorCode>, UseWithdrawParams>;
318
318
 
319
- type UseUserReservesDataParams = {
319
+ type BaseQueryOptions$1 = {
320
+ queryOptions?: UseQueryOptions<readonly [readonly UserReserveData[], number], Error>;
321
+ };
322
+ type NewParams$1 = BaseQueryOptions$1 & {
323
+ /** Spoke chain id (e.g. '0xa86a.avax') */
324
+ spokeChainId: SpokeChainId$1 | undefined;
325
+ /** User wallet address on the spoke chain */
326
+ userAddress: string | undefined;
327
+ };
328
+ /** @deprecated Use `{ spokeChainId, userAddress }` instead */
329
+ type LegacyParams$1 = BaseQueryOptions$1 & {
330
+ /** @deprecated Use `spokeChainId` instead */
320
331
  spokeProvider: SpokeProvider | undefined;
332
+ /** @deprecated Use `userAddress` instead */
321
333
  address: string | undefined;
322
- queryOptions?: UseQueryOptions<readonly [readonly UserReserveData[], number], Error>;
323
334
  };
335
+ type UseUserReservesDataParams = NewParams$1 | LegacyParams$1;
324
336
  /**
325
337
  * Hook for fetching user reserves data from the Sodax money market.
326
338
  *
327
339
  * @param params (optional) - Object including:
328
- * - spokeProvider: The SpokeProvider instance required for data fetching. If not provided, data fetching is disabled.
329
- * - address: The user's address (string) whose reserves data will be fetched. If not provided, data fetching is disabled.
340
+ * - spokeChainId: The spoke chain id whose reserves data will be fetched. If not provided, data fetching is disabled.
341
+ * - userAddress: The user's address (string) whose reserves data will be fetched. If not provided, data fetching is disabled.
330
342
  * - queryOptions: (optional) Custom React Query options such as `queryKey`, `enabled`, or cache policy.
331
343
  *
332
344
  * @returns {UseQueryResult<readonly [readonly UserReserveData[], number], Error>} React Query result object containing:
@@ -337,8 +349,8 @@ type UseUserReservesDataParams = {
337
349
  *
338
350
  * @example
339
351
  * const { data: userReservesData, isLoading, error } = useUserReservesData({
340
- * spokeProvider,
341
- * address,
352
+ * spokeChainId,
353
+ * userAddress,
342
354
  * });
343
355
  */
344
356
  declare function useUserReservesData(params?: UseUserReservesDataParams): UseQueryResult<readonly [readonly UserReserveData[], number], Error>;
@@ -516,26 +528,30 @@ declare function useReservesUsdFormat(params?: UseReservesUsdFormatParams): UseQ
516
528
  priceInMarketReferenceCurrency: string;
517
529
  } & FormatReserveUSDResponse)[], Error>;
518
530
 
519
- type UseUserFormattedSummaryParams = {
520
- spokeProvider?: SpokeProvider;
521
- address?: string;
531
+ type BaseQueryOptions = {
522
532
  queryOptions?: UseQueryOptions<FormatUserSummaryResponse<FormatReserveUSDResponse>, Error>;
523
533
  };
534
+ type NewParams = BaseQueryOptions & {
535
+ /** Spoke chain id (e.g. '0xa86a.avax') */
536
+ spokeChainId: SpokeChainId$1 | undefined;
537
+ /** User wallet address on the spoke chain */
538
+ userAddress: string | undefined;
539
+ };
540
+ /** @deprecated Use `{ spokeChainId, userAddress }` instead */
541
+ type LegacyParams = BaseQueryOptions & {
542
+ /** @deprecated Use `spokeChainId` instead */
543
+ spokeProvider: SpokeProvider | undefined;
544
+ /** @deprecated Use `userAddress` instead */
545
+ address: string | undefined;
546
+ };
547
+ type UseUserFormattedSummaryParams = NewParams | LegacyParams;
524
548
  /**
525
549
  * React hook to fetch a formatted summary of a user's Sodax money market portfolio.
526
550
  *
527
- * Accepts an optional params object:
528
- * - `spokeProvider`: The SpokeProvider instance for the target chain
529
- * - `address`: The user wallet address to get the summary for
530
- * - `queryOptions`: Optional React Query options (key, caching, intervals, etc)
531
- *
532
- * The hook returns a React Query result object containing the formatted summary, loading and error state.
533
- * The query is enabled only if both the spokeProvider and address are provided.
534
- *
535
- * @param params Optional parameters:
536
- * - spokeProvider: SpokeProvider to query chain data (required for enabled query)
537
- * - address: User account address (required for enabled query)
538
- * - queryOptions: React Query options for customization (optional)
551
+ * @param params (optional) - Object including:
552
+ * - spokeChainId: The spoke chain id whose data will be fetched. If not provided, data fetching is disabled.
553
+ * - userAddress: The user's address (string) whose summary will be fetched. If not provided, data fetching is disabled.
554
+ * - queryOptions: (optional) Custom React Query options such as `queryKey`, `enabled`, or cache policy.
539
555
  *
540
556
  * @returns {UseQueryResult<FormatUserSummaryResponse<FormatReserveUSDResponse>, Error>}
541
557
  * A result object from React Query including:
@@ -545,7 +561,7 @@ type UseUserFormattedSummaryParams = {
545
561
  * - error: Error if thrown in fetching
546
562
  *
547
563
  * @example
548
- * const { data, isLoading, error } = useUserFormattedSummary({ spokeProvider, address });
564
+ * const { data, isLoading, error } = useUserFormattedSummary({ spokeChainId, userAddress });
549
565
  */
550
566
  declare function useUserFormattedSummary(params?: UseUserFormattedSummaryParams): UseQueryResult<FormatUserSummaryResponse<FormatReserveUSDResponse>, Error>;
551
567
 
package/dist/index.js CHANGED
@@ -257,11 +257,24 @@ function useWithdraw() {
257
257
  }
258
258
  });
259
259
  }
260
+ function isLegacyParams(params) {
261
+ return "spokeProvider" in params || "address" in params;
262
+ }
263
+ function resolveParams(params) {
264
+ if (isLegacyParams(params)) {
265
+ return {
266
+ spokeChainId: params.spokeProvider?.chainConfig.chain.id,
267
+ userAddress: params.address
268
+ };
269
+ }
270
+ return { spokeChainId: params.spokeChainId, userAddress: params.userAddress };
271
+ }
260
272
  function useUserReservesData(params) {
261
273
  const { sodax } = useSodaxContext();
274
+ const resolved = params ? resolveParams(params) : { spokeChainId: void 0, userAddress: void 0 };
262
275
  const defaultQueryOptions = {
263
- queryKey: ["mm", "userReservesData", params?.spokeProvider?.chainConfig.chain.id, params?.address],
264
- enabled: !!params?.spokeProvider && !!params?.address,
276
+ queryKey: ["mm", "userReservesData", resolved.spokeChainId, resolved.userAddress],
277
+ enabled: !!resolved.spokeChainId && !!resolved.userAddress,
265
278
  refetchInterval: 5e3
266
279
  };
267
280
  const queryOptions = {
@@ -272,10 +285,10 @@ function useUserReservesData(params) {
272
285
  return reactQuery.useQuery({
273
286
  ...queryOptions,
274
287
  queryFn: async () => {
275
- if (!params?.spokeProvider || !params?.address) {
276
- throw new Error("Spoke provider or address is not defined");
288
+ if (!resolved.spokeChainId || !resolved.userAddress) {
289
+ throw new Error("spokeChainId or userAddress is not defined");
277
290
  }
278
- return await sodax.moneyMarket.data.getUserReservesData(params.spokeProvider);
291
+ return await sodax.moneyMarket.data.getUserReservesData(resolved.spokeChainId, resolved.userAddress);
279
292
  }
280
293
  });
281
294
  }
@@ -433,11 +446,24 @@ function useReservesUsdFormat(params) {
433
446
  }
434
447
  });
435
448
  }
449
+ function isLegacyParams2(params) {
450
+ return "spokeProvider" in params || "address" in params;
451
+ }
452
+ function resolveParams2(params) {
453
+ if (isLegacyParams2(params)) {
454
+ return {
455
+ spokeChainId: params.spokeProvider?.chainConfig.chain.id,
456
+ userAddress: params.address
457
+ };
458
+ }
459
+ return { spokeChainId: params.spokeChainId, userAddress: params.userAddress };
460
+ }
436
461
  function useUserFormattedSummary(params) {
437
462
  const { sodax } = useSodaxContext();
463
+ const resolved = params ? resolveParams2(params) : { spokeChainId: void 0, userAddress: void 0 };
438
464
  const defaultQueryOptions = {
439
- queryKey: ["mm", "userFormattedSummary", params?.spokeProvider?.chainConfig.chain.id, params?.address],
440
- enabled: !!params?.spokeProvider && !!params?.address,
465
+ queryKey: ["mm", "userFormattedSummary", resolved.spokeChainId, resolved.userAddress],
466
+ enabled: !!resolved.spokeChainId && !!resolved.userAddress,
441
467
  refetchInterval: 5e3
442
468
  };
443
469
  const queryOptions = {
@@ -448,14 +474,17 @@ function useUserFormattedSummary(params) {
448
474
  return reactQuery.useQuery({
449
475
  ...queryOptions,
450
476
  queryFn: async () => {
451
- if (!params?.spokeProvider || !params?.address) {
452
- throw new Error("Spoke provider or address is not defined");
477
+ if (!resolved.spokeChainId || !resolved.userAddress) {
478
+ throw new Error("spokeChainId or userAddress is not defined");
453
479
  }
454
480
  const reserves = await sodax.moneyMarket.data.getReservesHumanized();
455
481
  const formattedReserves = sodax.moneyMarket.data.formatReservesUSD(
456
482
  sodax.moneyMarket.data.buildReserveDataWithPrice(reserves)
457
483
  );
458
- const userReserves = await sodax.moneyMarket.data.getUserReservesHumanized(params?.spokeProvider);
484
+ const userReserves = await sodax.moneyMarket.data.getUserReservesHumanized(
485
+ resolved.spokeChainId,
486
+ resolved.userAddress
487
+ );
459
488
  return sodax.moneyMarket.data.formatUserSummary(
460
489
  sodax.moneyMarket.data.buildUserSummaryRequest(reserves, formattedReserves, userReserves)
461
490
  );