timelock-sdk 0.0.53 → 0.0.54

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
@@ -253,11 +253,17 @@ const useExerciseOption = (marketAddr) => {
253
253
  const { vault, pool } = useMarketData(marketAddr);
254
254
  const { fee } = usePoolData(pool);
255
255
  const { timelockLens } = useLens();
256
+ const queryClient = (0, __tanstack_react_query.useQueryClient)();
256
257
  const client = (0, wagmi.useClient)();
258
+ const { address } = (0, wagmi.useAccount)();
257
259
  const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
258
260
  const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
259
261
  const exerciseOption = async (option, liquidities) => {
260
- if (!client || !timelockLens || !vault || !marketAddr || !fee) throw new Error("Wallet not connected");
262
+ if (!client || !address) throw new Error("Wallet not connected");
263
+ if (!marketAddr) throw new Error("Market address not available");
264
+ if (!timelockLens) throw new Error("Timelock lens not available");
265
+ if (!vault) throw new Error("Vault not available");
266
+ if (!fee) throw new Error("Pool data not available");
261
267
  const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
262
268
  const hash$1 = await writeContractAsync({
263
269
  address: marketAddr,
@@ -273,6 +279,7 @@ const useExerciseOption = (marketAddr) => {
273
279
  ]
274
280
  });
275
281
  await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
282
+ await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
276
283
  return hash$1;
277
284
  };
278
285
  return {
@@ -355,6 +362,7 @@ const useMintOption = (marketAddr) => {
355
362
  const { exact: currentTick } = useCurrentTick(pool);
356
363
  const client = (0, wagmi.useClient)();
357
364
  const { address } = (0, wagmi.useAccount)();
365
+ const queryClient = (0, __tanstack_react_query.useQueryClient)();
358
366
  const { writeContractAsync, data: hash, isPending, error } = (0, wagmi.useWriteContract)();
359
367
  const { isLoading: isConfirming, isSuccess } = (0, wagmi.useWaitForTransactionReceipt)({ hash });
360
368
  const askForApproval = async (premiumAmount) => {
@@ -368,7 +376,7 @@ const useMintOption = (marketAddr) => {
368
376
  }) });
369
377
  };
370
378
  const mintOption = async (optionType, amount, duration, strikeTick) => {
371
- if (!client) throw new Error("Wallet not connected");
379
+ if (!client || !address) throw new Error("Wallet not connected");
372
380
  if (!marketAddr) throw new Error("Market address not available");
373
381
  if (!timelockLens) throw new Error("Timelock lens not available");
374
382
  if (!vault) throw new Error("Vault not available");
@@ -397,6 +405,7 @@ const useMintOption = (marketAddr) => {
397
405
  ]
398
406
  });
399
407
  await (0, viem_actions.waitForTransactionReceipt)(client, { hash: hash$1 });
408
+ await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
400
409
  return hash$1;
401
410
  };
402
411
  return {
@@ -493,15 +502,16 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration, strike
493
502
  //#region src/hooks/market/useUserOptions.ts
494
503
  const useUserOptions = (user, active = false) => {
495
504
  const { graphqlClient } = useTimelockConfig();
505
+ user = user === null || user === void 0 ? void 0 : user.toLowerCase();
496
506
  const { data,...rest } = (0, __tanstack_react_query.useQuery)({
497
507
  queryKey: [
498
- "userTrades",
508
+ "userOptions",
499
509
  user || "--",
500
510
  active
501
511
  ],
502
512
  queryFn: async () => {
503
- if (!graphqlClient) return [];
504
- return (active ? await graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : await graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() })).UserOption.map((option) => ({
513
+ if (!graphqlClient || !user) return [];
514
+ return (active ? await graphqlClient.GetActiveUserOptions({ user }) : await graphqlClient.GetClosedUserOptions({ user })).UserOption.map((option) => ({
505
515
  ...option,
506
516
  optionId: BigInt(option.optionId),
507
517
  marketAddr: option.marketAddr,