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.js CHANGED
@@ -10,7 +10,7 @@ import { useAccount, useChainId, useClient, useReadContract, useWaitForTransacti
10
10
  import { GraphQLClient, RequestOptions } from "graphql-request";
11
11
  import gql from "graphql-tag";
12
12
  import { waitForTransactionReceipt } from "viem/actions";
13
- import { useQuery } from "@tanstack/react-query";
13
+ import { useQuery, useQueryClient } from "@tanstack/react-query";
14
14
 
15
15
  //#region src/generated/graphql.ts
16
16
  const GetActiveUserOptionsDocument = gql`
@@ -246,11 +246,17 @@ const useExerciseOption = (marketAddr) => {
246
246
  const { vault, pool } = useMarketData(marketAddr);
247
247
  const { fee } = usePoolData(pool);
248
248
  const { timelockLens } = useLens();
249
+ const queryClient = useQueryClient();
249
250
  const client = useClient();
251
+ const { address } = useAccount();
250
252
  const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
251
253
  const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
252
254
  const exerciseOption = async (option, liquidities) => {
253
- if (!client || !timelockLens || !vault || !marketAddr || !fee) throw new Error("Wallet not connected");
255
+ if (!client || !address) throw new Error("Wallet not connected");
256
+ if (!marketAddr) throw new Error("Market address not available");
257
+ if (!timelockLens) throw new Error("Timelock lens not available");
258
+ if (!vault) throw new Error("Vault not available");
259
+ if (!fee) throw new Error("Pool data not available");
254
260
  const refTick = await timelockLens.read.getRefTick([vault, option.startTick]);
255
261
  const hash$1 = await writeContractAsync({
256
262
  address: marketAddr,
@@ -266,6 +272,7 @@ const useExerciseOption = (marketAddr) => {
266
272
  ]
267
273
  });
268
274
  await waitForTransactionReceipt(client, { hash: hash$1 });
275
+ await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
269
276
  return hash$1;
270
277
  };
271
278
  return {
@@ -348,6 +355,7 @@ const useMintOption = (marketAddr) => {
348
355
  const { exact: currentTick } = useCurrentTick(pool);
349
356
  const client = useClient();
350
357
  const { address } = useAccount();
358
+ const queryClient = useQueryClient();
351
359
  const { writeContractAsync, data: hash, isPending, error } = useWriteContract();
352
360
  const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
353
361
  const askForApproval = async (premiumAmount) => {
@@ -361,7 +369,7 @@ const useMintOption = (marketAddr) => {
361
369
  }) });
362
370
  };
363
371
  const mintOption = async (optionType, amount, duration, strikeTick) => {
364
- if (!client) throw new Error("Wallet not connected");
372
+ if (!client || !address) throw new Error("Wallet not connected");
365
373
  if (!marketAddr) throw new Error("Market address not available");
366
374
  if (!timelockLens) throw new Error("Timelock lens not available");
367
375
  if (!vault) throw new Error("Vault not available");
@@ -390,6 +398,7 @@ const useMintOption = (marketAddr) => {
390
398
  ]
391
399
  });
392
400
  await waitForTransactionReceipt(client, { hash: hash$1 });
401
+ await queryClient.invalidateQueries({ queryKey: ["userOptions", address.toLowerCase()] });
393
402
  return hash$1;
394
403
  };
395
404
  return {
@@ -486,15 +495,16 @@ const useOptionPremium = (marketAddr, optionType, optionAmount, duration, strike
486
495
  //#region src/hooks/market/useUserOptions.ts
487
496
  const useUserOptions = (user, active = false) => {
488
497
  const { graphqlClient } = useTimelockConfig();
498
+ user = user === null || user === void 0 ? void 0 : user.toLowerCase();
489
499
  const { data,...rest } = useQuery({
490
500
  queryKey: [
491
- "userTrades",
501
+ "userOptions",
492
502
  user || "--",
493
503
  active
494
504
  ],
495
505
  queryFn: async () => {
496
- if (!graphqlClient) return [];
497
- return (active ? await graphqlClient.GetActiveUserOptions({ user: user.toLowerCase() }) : await graphqlClient.GetClosedUserOptions({ user: user.toLowerCase() })).UserOption.map((option) => ({
506
+ if (!graphqlClient || !user) return [];
507
+ return (active ? await graphqlClient.GetActiveUserOptions({ user }) : await graphqlClient.GetClosedUserOptions({ user })).UserOption.map((option) => ({
498
508
  ...option,
499
509
  optionId: BigInt(option.optionId),
500
510
  marketAddr: option.marketAddr,