timelock-sdk 0.0.26 → 0.0.28

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
@@ -151,12 +151,18 @@ const TimelockMarketProvider = ({ children, marketData, envioGraphqlUrl }) => {
151
151
  const chainId = (0, wagmi.useChainId)();
152
152
  const lensAddr = require_numberUtils.timelockLenses[chainId];
153
153
  const uniswapMathLensAddr = require_numberUtils.uniswapMathLenses[chainId];
154
- return /* @__PURE__ */ react.default.createElement(TimelockMarketContext.Provider, { value: {
154
+ const contextValue = (0, react.useMemo)(() => ({
155
155
  marketData: marketData || {},
156
156
  lensAddr,
157
157
  uniswapMathLensAddr,
158
158
  envioGraphqlUrl
159
- } }, children);
159
+ }), [
160
+ marketData,
161
+ lensAddr,
162
+ uniswapMathLensAddr,
163
+ envioGraphqlUrl
164
+ ]);
165
+ return /* @__PURE__ */ react.default.createElement(TimelockMarketContext.Provider, { value: contextValue }, children);
160
166
  };
161
167
  const useCurrentMarket = () => {
162
168
  const context = (0, react.useContext)(TimelockMarketContext);
@@ -179,20 +185,21 @@ const useTimelockConfig = () => {
179
185
 
180
186
  //#endregion
181
187
  //#region src/hooks/market/useMarketData.ts
188
+ const selectMarket = (data) => ({
189
+ ...data.TimelockMarket[0],
190
+ pool: data.TimelockMarket[0].pool,
191
+ vault: data.TimelockMarket[0].vault,
192
+ optionAsset: data.TimelockMarket[0].optionAsset,
193
+ payoutAsset: data.TimelockMarket[0].payoutAsset,
194
+ optionsCount: BigInt(data.TimelockMarket[0].optionsCount),
195
+ tradersCount: BigInt(data.TimelockMarket[0].tradersCount)
196
+ });
182
197
  const useMarketData = (marketAddr) => {
183
198
  const { graphqlClient } = useTimelockConfig();
184
199
  const { data } = (0, __tanstack_react_query.useQuery)({
185
200
  queryKey: ["marketData", marketAddr || "--"],
186
201
  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
- }),
202
+ select: selectMarket,
196
203
  enabled: !!marketAddr && !!graphqlClient
197
204
  });
198
205
  return data || {};
@@ -441,38 +448,39 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration) => {
441
448
 
442
449
  //#endregion
443
450
  //#region src/hooks/market/useUserOptions.ts
451
+ const selectOptions = (data) => {
452
+ if (!(data === null || data === void 0 ? void 0 : data.UserOption)) return [];
453
+ return data.UserOption.map((option) => ({
454
+ ...option,
455
+ id: BigInt(option.id),
456
+ marketAddr: option.marketAddr,
457
+ optionType: option.optionType,
458
+ createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
459
+ expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
460
+ premiumPaid: BigInt(option.premiumPaid),
461
+ realizedPayout: BigInt(option.realizedPayout),
462
+ liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
463
+ liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
464
+ positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
465
+ positionSizeCurrent: BigInt(option.positionSizeCurrent),
466
+ strikePrice: BigInt(option.strikePrice),
467
+ entryPrice: BigInt(option.entryPrice)
468
+ })).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
469
+ };
444
470
  const useUserOptions = (user, active = false) => {
445
471
  const { graphqlClient } = useTimelockConfig();
446
- const { data: options,...rest } = (0, __tanstack_react_query.useQuery)({
472
+ const { data,...rest } = (0, __tanstack_react_query.useQuery)({
447
473
  queryKey: [
448
474
  "userTrades",
449
475
  user || "--",
450
476
  active
451
477
  ],
452
478
  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
- },
479
+ select: selectOptions,
472
480
  enabled: !!user && !!graphqlClient
473
481
  });
474
482
  return {
475
- data: (0, react.useMemo)(() => [...options || []].sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()), [options]),
483
+ data: data || [],
476
484
  ...rest
477
485
  };
478
486
  };