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.js CHANGED
@@ -144,12 +144,18 @@ const TimelockMarketProvider = ({ children, marketData, envioGraphqlUrl }) => {
144
144
  const chainId = useChainId();
145
145
  const lensAddr = timelockLenses[chainId];
146
146
  const uniswapMathLensAddr = uniswapMathLenses[chainId];
147
- return /* @__PURE__ */ React.createElement(TimelockMarketContext.Provider, { value: {
147
+ const contextValue = useMemo(() => ({
148
148
  marketData: marketData || {},
149
149
  lensAddr,
150
150
  uniswapMathLensAddr,
151
151
  envioGraphqlUrl
152
- } }, children);
152
+ }), [
153
+ marketData,
154
+ lensAddr,
155
+ uniswapMathLensAddr,
156
+ envioGraphqlUrl
157
+ ]);
158
+ return /* @__PURE__ */ React.createElement(TimelockMarketContext.Provider, { value: contextValue }, children);
153
159
  };
154
160
  const useCurrentMarket = () => {
155
161
  const context = useContext(TimelockMarketContext);
@@ -172,20 +178,21 @@ const useTimelockConfig = () => {
172
178
 
173
179
  //#endregion
174
180
  //#region src/hooks/market/useMarketData.ts
181
+ const selectMarket = (data) => ({
182
+ ...data.TimelockMarket[0],
183
+ pool: data.TimelockMarket[0].pool,
184
+ vault: data.TimelockMarket[0].vault,
185
+ optionAsset: data.TimelockMarket[0].optionAsset,
186
+ payoutAsset: data.TimelockMarket[0].payoutAsset,
187
+ optionsCount: BigInt(data.TimelockMarket[0].optionsCount),
188
+ tradersCount: BigInt(data.TimelockMarket[0].tradersCount)
189
+ });
175
190
  const useMarketData = (marketAddr) => {
176
191
  const { graphqlClient } = useTimelockConfig();
177
192
  const { data } = useQuery({
178
193
  queryKey: ["marketData", marketAddr || "--"],
179
194
  queryFn: () => graphqlClient.GetMarketData({ marketAddr: marketAddr.toLowerCase() }),
180
- select: (data$1) => ({
181
- ...data$1.TimelockMarket[0],
182
- pool: data$1.TimelockMarket[0].pool,
183
- vault: data$1.TimelockMarket[0].vault,
184
- optionAsset: data$1.TimelockMarket[0].optionAsset,
185
- payoutAsset: data$1.TimelockMarket[0].payoutAsset,
186
- optionsCount: BigInt(data$1.TimelockMarket[0].optionsCount),
187
- tradersCount: BigInt(data$1.TimelockMarket[0].tradersCount)
188
- }),
195
+ select: selectMarket,
189
196
  enabled: !!marketAddr && !!graphqlClient
190
197
  });
191
198
  return data || {};
@@ -434,38 +441,39 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration) => {
434
441
 
435
442
  //#endregion
436
443
  //#region src/hooks/market/useUserOptions.ts
444
+ const selectOptions = (data) => {
445
+ if (!(data === null || data === void 0 ? void 0 : data.UserOption)) return [];
446
+ return data.UserOption.map((option) => ({
447
+ ...option,
448
+ id: BigInt(option.id),
449
+ marketAddr: option.marketAddr,
450
+ optionType: option.optionType,
451
+ createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
452
+ expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
453
+ premiumPaid: BigInt(option.premiumPaid),
454
+ realizedPayout: BigInt(option.realizedPayout),
455
+ liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
456
+ liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
457
+ positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
458
+ positionSizeCurrent: BigInt(option.positionSizeCurrent),
459
+ strikePrice: BigInt(option.strikePrice),
460
+ entryPrice: BigInt(option.entryPrice)
461
+ })).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
462
+ };
437
463
  const useUserOptions = (user, active = false) => {
438
464
  const { graphqlClient } = useTimelockConfig();
439
- const { data: options,...rest } = useQuery({
465
+ const { data,...rest } = useQuery({
440
466
  queryKey: [
441
467
  "userTrades",
442
468
  user || "--",
443
469
  active
444
470
  ],
445
471
  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() }),
446
- select: (data) => {
447
- var _data$UserOption;
448
- return data === null || data === void 0 || (_data$UserOption = data.UserOption) === null || _data$UserOption === void 0 ? void 0 : _data$UserOption.map((option) => ({
449
- ...option,
450
- id: BigInt(option.id),
451
- marketAddr: option.marketAddr,
452
- optionType: option.optionType,
453
- createdAt: /* @__PURE__ */ new Date(Number(option.createdAt) * 1e3),
454
- expiresAt: /* @__PURE__ */ new Date(Number(option.expiresAt) * 1e3),
455
- premiumPaid: BigInt(option.premiumPaid),
456
- realizedPayout: BigInt(option.realizedPayout),
457
- liquiditiesAtOpen: option.liquiditiesAtOpen.map((liquidity) => BigInt(liquidity)),
458
- liquiditiesCurrent: option.liquiditiesCurrent.map((liquidity) => BigInt(liquidity)),
459
- positionSizeAtOpen: BigInt(option.positionSizeAtOpen),
460
- positionSizeCurrent: BigInt(option.positionSizeCurrent),
461
- strikePrice: BigInt(option.strikePrice),
462
- entryPrice: BigInt(option.entryPrice)
463
- }));
464
- },
472
+ select: selectOptions,
465
473
  enabled: !!user && !!graphqlClient
466
474
  });
467
475
  return {
468
- data: useMemo(() => [...options || []].sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()), [options]),
476
+ data: data || [],
469
477
  ...rest
470
478
  };
471
479
  };