timelock-sdk 0.0.26 → 0.0.27

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/client.cjs CHANGED
@@ -179,20 +179,21 @@ const useTimelockConfig = () => {
179
179
 
180
180
  //#endregion
181
181
  //#region src/hooks/market/useMarketData.ts
182
+ const selectMarket = (data) => ({
183
+ ...data.TimelockMarket[0],
184
+ pool: data.TimelockMarket[0].pool,
185
+ vault: data.TimelockMarket[0].vault,
186
+ optionAsset: data.TimelockMarket[0].optionAsset,
187
+ payoutAsset: data.TimelockMarket[0].payoutAsset,
188
+ optionsCount: BigInt(data.TimelockMarket[0].optionsCount),
189
+ tradersCount: BigInt(data.TimelockMarket[0].tradersCount)
190
+ });
182
191
  const useMarketData = (marketAddr) => {
183
192
  const { graphqlClient } = useTimelockConfig();
184
193
  const { data } = (0, __tanstack_react_query.useQuery)({
185
194
  queryKey: ["marketData", marketAddr || "--"],
186
195
  queryFn: () => graphqlClient.GetMarketData({ marketAddr: marketAddr.toLowerCase() }),
187
- select: (data$1) => ({
188
- ...data$1.TimelockMarket[0],
189
- pool: data$1.TimelockMarket[0].pool,
190
- vault: data$1.TimelockMarket[0].vault,
191
- optionAsset: data$1.TimelockMarket[0].optionAsset,
192
- payoutAsset: data$1.TimelockMarket[0].payoutAsset,
193
- optionsCount: BigInt(data$1.TimelockMarket[0].optionsCount),
194
- tradersCount: BigInt(data$1.TimelockMarket[0].tradersCount)
195
- }),
196
+ select: selectMarket,
196
197
  enabled: !!marketAddr && !!graphqlClient
197
198
  });
198
199
  return data || {};
@@ -441,38 +442,39 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration) => {
441
442
 
442
443
  //#endregion
443
444
  //#region src/hooks/market/useUserOptions.ts
445
+ const selectOptions = (data) => {
446
+ if (!(data === null || data === void 0 ? void 0 : data.UserOption)) return [];
447
+ return data.UserOption.map((option) => ({
448
+ ...option,
449
+ id: BigInt(option.id),
450
+ marketAddr: option.marketAddr,
451
+ optionType: option.optionType,
452
+ createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
453
+ expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
454
+ premiumPaid: BigInt(option.premiumPaid),
455
+ realizedPayout: BigInt(option.realizedPayout),
456
+ liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
457
+ liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
458
+ positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
459
+ positionSizeCurrent: BigInt(option.positionSizeCurrent),
460
+ strikePrice: BigInt(option.strikePrice),
461
+ entryPrice: BigInt(option.entryPrice)
462
+ })).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
463
+ };
444
464
  const useUserOptions = (user, active = false) => {
445
465
  const { graphqlClient } = useTimelockConfig();
446
- const { data: options,...rest } = (0, __tanstack_react_query.useQuery)({
466
+ const { data,...rest } = (0, __tanstack_react_query.useQuery)({
447
467
  queryKey: [
448
468
  "userTrades",
449
469
  user || "--",
450
470
  active
451
471
  ],
452
472
  queryFn: () => active ? graphqlClient === null || graphqlClient === void 0 ? void 0 : graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : graphqlClient === null || graphqlClient === void 0 ? void 0 : graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() }),
453
- select: (data) => {
454
- var _data$UserOption;
455
- return data === null || data === void 0 || (_data$UserOption = data.UserOption) === null || _data$UserOption === void 0 ? void 0 : _data$UserOption.map((option) => ({
456
- ...option,
457
- id: BigInt(option.id),
458
- marketAddr: option.marketAddr,
459
- optionType: option.optionType,
460
- createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
461
- expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
462
- premiumPaid: BigInt(option.premiumPaid),
463
- realizedPayout: BigInt(option.realizedPayout),
464
- liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
465
- liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
466
- positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
467
- positionSizeCurrent: BigInt(option.positionSizeCurrent),
468
- strikePrice: BigInt(option.strikePrice),
469
- entryPrice: BigInt(option.entryPrice)
470
- }));
471
- },
473
+ select: selectOptions,
472
474
  enabled: !!user && !!graphqlClient
473
475
  });
474
476
  return {
475
- data: (0, react.useMemo)(() => [...options || []].sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()), [options]),
477
+ data: data || [],
476
478
  ...rest
477
479
  };
478
480
  };