graz 0.1.0-alpha.1 → 0.1.0-alpha.2

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/index.d.ts CHANGED
@@ -479,8 +479,11 @@ interface UseAccountArgs {
479
479
  onDisconnect?: () => void;
480
480
  }
481
481
  /**
482
- * graz query hook to retrieve account data with optional arguments to invoke
483
- * given function on connect/disconnect.
482
+ * graz query hook to retrieve account data
483
+ *
484
+ * @param chainId - if provided, it will only return the data of the given chainId
485
+ * @param onConnect - callback function when the account is connected
486
+ * @param onDisconnect - callback function when the account is disconnected
484
487
  *
485
488
  * @example
486
489
  * ```tsx
@@ -502,6 +505,10 @@ type UseConnectChainArgs = MutationEventArgs<ConnectArgs, ConnectResult>;
502
505
  * graz mutation hook to execute wallet connection with optional arguments to
503
506
  * invoke given functions on error, loading, or success event.
504
507
  *
508
+ * @param onError - callback function when the connection is failed
509
+ * @param onLoading - callback function when the connection is loading
510
+ * @param onSuccess - callback function when the connection is successful
511
+ *
505
512
  * @example
506
513
  * ```ts
507
514
  * import { useConnect, mainnetChains } from "graz";
@@ -545,6 +552,10 @@ declare const useConnect: ({ onError, onLoading, onSuccess }?: UseConnectChainAr
545
552
  * graz mutation hook to execute wallet disconnection with optional arguments to
546
553
  * invoke given functions on error, loading, or success event.
547
554
  *
555
+ * @param onError - callback function when the disconnection is failed
556
+ * @param onLoading - callback function when the disconnection is loading
557
+ * @param onSuccess - callback function when the disconnection is successful
558
+ *
548
559
  * @example
549
560
  * ```ts
550
561
  * import { useDisconnect } from "graz";
@@ -559,8 +570,11 @@ declare const useConnect: ({ onError, onLoading, onSuccess }?: UseConnectChainAr
559
570
  * onSuccess: () => { ... },
560
571
  * });
561
572
  *
562
- * // pass `true` on disconnect to clear recent connected chain
563
- * disconnect(true);
573
+ * //disconnect all chains
574
+ * disconnect();
575
+ *
576
+ * //disconnect specific chains
577
+ * disconnect({ chainid: ["cosmoshub-4", "juno-1"] });
564
578
  * ```
565
579
  *
566
580
  * @see {@link disconnect}
@@ -580,12 +594,21 @@ declare const useDisconnect: ({ onError, onLoading, onSuccess }?: MutationEventA
580
594
  /**
581
595
  * graz hook to retrieve offline signer objects (default, amino enabled, and auto).
582
596
  *
583
- * Note: signer objects is initialized after connecting an account.
597
+ * @param chainId - chain id arguments
598
+ *
599
+ * @returns if chainId is string it will return an object, otherwise it will return a record of objects
584
600
  *
585
601
  * @example
586
602
  * ```ts
587
603
  * import { useOfflineSigners } from "graz";
588
- * const { signer, signerAmino, signerAuto } = useOfflineSigners();
604
+ *
605
+ * // single chain
606
+ * const { offlineSigner, offlineSignerAmino, offlineSignerAuto } = useOfflineSigners({ chainId: "cosmoshub-4" });
607
+ *
608
+ * // multi chain
609
+ * const offlineSigners = useOfflineSigners();
610
+ * offlineSigners["cosmoshub-4"].offlineSignerAuto;
611
+ *
589
612
  * ```
590
613
  */
591
614
  declare const useOfflineSigners: <T extends ChainIdArgs>(args?: T | undefined) => UseQueryResult<HookResultDataWithChainId<OfflineSigners, T> | undefined>;
@@ -619,8 +642,6 @@ declare const useActiveChainValidators: <T extends QueryClient & StakingExtensio
619
642
  * connect(recentChain);
620
643
  * }
621
644
  * ```
622
- *
623
- * @see {@link useActiveChain}
624
645
  */
625
646
  declare const useRecentChain: () => {
626
647
  data: string[] | null;
@@ -691,6 +712,16 @@ declare const useSuggestChainAndConnect: ({ onError, onLoading, onSuccess }?: Us
691
712
  suggestAndConnect: _tanstack_react_query.UseMutateFunction<ConnectResult, unknown, SuggestChainAndConnectArgs, unknown>;
692
713
  suggestAndConnectAsync: _tanstack_react_query.UseMutateAsyncFunction<ConnectResult, unknown, SuggestChainAndConnectArgs, unknown>;
693
714
  };
715
+ /**
716
+ * graz hook to retrieve chain data and usefull functions with given chainId
717
+ * @param chainId - Chain ID string
718
+ *
719
+ * @example
720
+ * ```ts
721
+ * import { useChain } from "graz";
722
+ * const { data: chain } = useChain("cosmoshub-4");
723
+ * ```
724
+ */
694
725
  declare const useChain: ({ chainId }: {
695
726
  chainId: string;
696
727
  }) => {
@@ -703,17 +734,25 @@ declare const useChain: ({ chainId }: {
703
734
  } | undefined;
704
735
 
705
736
  /**
706
- * graz query hook to retrieve a CosmWasmClient, StargateClient and Tendermint34Client. If there's no given arguments it will be using the current connected client
737
+ * graz query hook to retrieve a CosmWasmClient or StargateClient or Tendermint34Client.
738
+ *
739
+ * @param client - if provided, it will use the given client instead of the default client
740
+ * @param chainId - if provided, it will only return the data of the given chainId
741
+ * @param onlyConnectedChains - if true, it will only return the client of the current connected chains
742
+ * @param enabled - if false, it will not fetch the data
743
+ *
744
+ * @returns if chainId is string it will return an object, otherwise it will return a record of objects
707
745
  *
708
746
  * @example
709
747
  * ```ts
710
748
  * import { useClient } from "graz";
711
749
  *
712
- * // use connected client's cosmwasm client
713
- * const { data, isFetching, refetch, ... } = useClient();
750
+ * // single chain
751
+ * const { data, isLoading, ... } = useClient({ client: "stargate" chainId: "cosmoshub-4" });
752
+ *
753
+ * // all chains from GrazProvider example
754
+ * const { data, isLoading, ... } = useClient({ client: "stargate" });
714
755
  *
715
- * // initialize new custom client from given arguments
716
- * useClient({ rpc: "https://rpc.cosmoshub.strange.love", });
717
756
  * ```
718
757
  */
719
758
  declare const useConnectClient: <T extends Clients, U extends ChainIdArgs>(args?: ({
@@ -726,21 +765,24 @@ declare const useConnectClient: <T extends Clients, U extends ChainIdArgs>(args?
726
765
  enabled?: boolean | undefined;
727
766
  } & U) | undefined) => UseQueryResult<HookResultDataWithChainId<ConnectClient<T>, U> | undefined>;
728
767
  /**
729
- * graz query hook to retrieve a SigningCosmWasmClient. If there's no given args it will be using the current connected signer
768
+ * graz query hook to retrieve a SigningCosmWasmClient or SigningStargateClient.
769
+ *
770
+ * @param client - if provided, it will use the given client instead of the default client
771
+ * @param chainId - if provided, it will only return the data of the given chainId
772
+ * @param options - signing client options of given client
773
+ *
774
+ * @returns if chainId is string it will return an object, otherwise it will return a record of objects
730
775
  *
731
776
  * @example
732
777
  * ```ts
733
778
  * import { useSigningClient } from "graz";
734
779
  *
735
- * // get connected client's cosmwasm client
736
- * const { data, isFetching, refetch, ... } = useSigningClient();
780
+ * // single chain
781
+ * const { data, isLoading, ... } = useSigningClient({ client: "stargate" chainId: "cosmoshub-4" });
782
+ *
783
+ * // all chains from GrazProvider example
784
+ * const { data, isLoading, ... } = useSigningClient({ client: "stargate" });
737
785
  *
738
- * // initialize new custom client with given args
739
- * useSigningClient({
740
- * rpc: "https://rpc.cosmoshub.strange.love",
741
- * offlineSigner: customOfflineSigner,
742
- * ...
743
- * });
744
786
  * ```
745
787
  */
746
788
  declare const useConnectSigningClient: <T extends SigningClients, U extends ChainIdArgs>(args?: ({
@@ -781,6 +823,8 @@ declare const useBalance: <T extends "cosmWasm" | "stargate">(args: {
781
823
  * @param chainId - Optional chainId to retrieve the balances from given address and chainId, if not provided will return all balances currencies from all chains provided from GrazProvider
782
824
  * @param client - Optional client, if not provided will use the default client
783
825
  *
826
+ * @returns if chainId is string it will return an object, otherwise it will return a record of objects
827
+ *
784
828
  * @example
785
829
  * ```ts
786
830
  * import { useAllBalances } from "graz";
@@ -809,6 +853,8 @@ declare const useAllBalances: <U extends ChainIdArgs>(args: {
809
853
  * @param client - Optional client, if not provided will use the default client
810
854
  * @param chainId - Optional chainId to retrieve the balances from given address and chainId, if not provided will return all balances currencies from all chains provided from GrazProvider
811
855
  *
856
+ * @returns if chainId is string it will return an object, otherwise it will return a record of objects
857
+ *
812
858
  * @example
813
859
  * ```ts
814
860
  * import { useChainBalances } from "graz";
@@ -837,6 +883,8 @@ declare const useChainBalances: <T extends "cosmWasm" | "stargate", U extends Ch
837
883
  * @param bech32Address - Optional bech32 account address, if not provided will return undefined
838
884
  * @param chainId - Optional chainId to retrieve the balances from given address and chainId, if not provided will return all balances currencies from all chains provided from GrazProvider
839
885
  *
886
+ * @returns if chainId is string it will return an object, otherwise it will return a record of objects
887
+ *
840
888
  * @example
841
889
  * ```ts
842
890
  * import { useBalanceStaked } from "graz";
package/dist/index.js CHANGED
@@ -2507,39 +2507,18 @@ var useDisconnect = ({ onError, onLoading, onSuccess } = {}) => {
2507
2507
  };
2508
2508
  var useOfflineSigners = (args) => {
2509
2509
  const accounts = useAccount();
2510
- const { data } = (0, import_react_query2.useQuery)(
2511
- ["OFFLINE_SIGNERS", { accounts }],
2512
- async () => {
2513
- if (!accounts)
2514
- return void 0;
2515
- const connectedChainIds = Object.values(accounts).map((i) => i == null ? void 0 : i.chainId).filter(Boolean);
2516
- const res = {};
2517
- await Promise.all(
2518
- connectedChainIds.map(async (_chainId) => {
2519
- const signers = await getOfflineSigners({
2520
- chainId: _chainId
2521
- });
2522
- res[_chainId] = signers;
2523
- })
2524
- );
2525
- return res;
2526
- },
2527
- {
2528
- enabled: Boolean(accounts)
2529
- }
2530
- );
2531
2510
  const query = (0, import_react_query2.useQuery)(
2532
2511
  [
2533
2512
  "USE_OFFLINE_SIGNERS",
2534
2513
  {
2535
2514
  args,
2536
- offlineSigners: data
2515
+ accounts
2537
2516
  }
2538
2517
  ],
2539
2518
  async () => {
2540
- if (!data)
2519
+ if (!accounts)
2541
2520
  return void 0;
2542
- const connectedChainIds = Object.keys(data).map(([chainId]) => chainId).filter((i) => i);
2521
+ const connectedChainIds = Object.keys(accounts).map(([chainId]) => chainId).filter(Boolean);
2543
2522
  if (args == null ? void 0 : args.chainId) {
2544
2523
  const offlineSigners = await getOfflineSigners({
2545
2524
  chainId: args.chainId
@@ -2557,7 +2536,7 @@ var useOfflineSigners = (args) => {
2557
2536
  );
2558
2537
  return res;
2559
2538
  },
2560
- { enabled: Boolean(data), refetchOnMount: false, refetchOnWindowFocus: false }
2539
+ { enabled: Boolean(accounts), refetchOnMount: false, refetchOnWindowFocus: false }
2561
2540
  );
2562
2541
  return query;
2563
2542
  };
@@ -2650,7 +2629,7 @@ var useConnectClient = (args) => {
2650
2629
  const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
2651
2630
  const query = (0, import_react_query4.useQuery)(
2652
2631
  [
2653
- "USE_CLIENTS",
2632
+ "USE_CONNECT_CLIENT",
2654
2633
  {
2655
2634
  client: _client,
2656
2635
  chainId: args == null ? void 0 : args.chainId,
@@ -2697,7 +2676,7 @@ var useConnectSigningClient = (args) => {
2697
2676
  const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
2698
2677
  const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
2699
2678
  const queryKey = [
2700
- "USE_SIGNING_CLIENTS",
2679
+ "USE_CONNECT_SIGNING_CLIENT",
2701
2680
  { client: _client, chainId: args == null ? void 0 : args.chainId, options: args == null ? void 0 : args.options }
2702
2681
  ];
2703
2682
  const query = (0, import_react_query4.useQuery)(
@@ -2769,7 +2748,7 @@ var useBalance = (args) => {
2769
2748
  });
2770
2749
  const query = (0, import_react_query5.useQuery)(
2771
2750
  [
2772
- "USE_BALANCES",
2751
+ "USE_BALANCE",
2773
2752
  {
2774
2753
  client,
2775
2754
  ...args,
@@ -2809,7 +2788,7 @@ var useAllBalances = (args) => {
2809
2788
  });
2810
2789
  const query = (0, import_react_query5.useQuery)(
2811
2790
  [
2812
- "USE_BALANCES",
2791
+ "USE_ALL_BALANCES",
2813
2792
  {
2814
2793
  singleClient,
2815
2794
  multiClient,
@@ -2868,7 +2847,7 @@ var useChainBalances = (args) => {
2868
2847
  });
2869
2848
  const query = (0, import_react_query5.useQuery)(
2870
2849
  [
2871
- "USE_BALANCES",
2850
+ "USE_CHAIN_BALANCES",
2872
2851
  {
2873
2852
  singleClient,
2874
2853
  multiClient,
@@ -2942,7 +2921,7 @@ var useBalanceStaked = (args) => {
2942
2921
  });
2943
2922
  const query = (0, import_react_query5.useQuery)(
2944
2923
  [
2945
- "USE_BALANCE_STAKED",
2924
+ "useBalanceStaked",
2946
2925
  {
2947
2926
  singleClient,
2948
2927
  multiClient,
package/dist/index.mjs CHANGED
@@ -2399,39 +2399,18 @@ var useDisconnect = ({ onError, onLoading, onSuccess } = {}) => {
2399
2399
  };
2400
2400
  var useOfflineSigners = (args) => {
2401
2401
  const accounts = useAccount();
2402
- const { data } = useQuery2(
2403
- ["OFFLINE_SIGNERS", { accounts }],
2404
- async () => {
2405
- if (!accounts)
2406
- return void 0;
2407
- const connectedChainIds = Object.values(accounts).map((i) => i == null ? void 0 : i.chainId).filter(Boolean);
2408
- const res = {};
2409
- await Promise.all(
2410
- connectedChainIds.map(async (_chainId) => {
2411
- const signers = await getOfflineSigners({
2412
- chainId: _chainId
2413
- });
2414
- res[_chainId] = signers;
2415
- })
2416
- );
2417
- return res;
2418
- },
2419
- {
2420
- enabled: Boolean(accounts)
2421
- }
2422
- );
2423
2402
  const query = useQuery2(
2424
2403
  [
2425
2404
  "USE_OFFLINE_SIGNERS",
2426
2405
  {
2427
2406
  args,
2428
- offlineSigners: data
2407
+ accounts
2429
2408
  }
2430
2409
  ],
2431
2410
  async () => {
2432
- if (!data)
2411
+ if (!accounts)
2433
2412
  return void 0;
2434
- const connectedChainIds = Object.keys(data).map(([chainId]) => chainId).filter((i) => i);
2413
+ const connectedChainIds = Object.keys(accounts).map(([chainId]) => chainId).filter(Boolean);
2435
2414
  if (args == null ? void 0 : args.chainId) {
2436
2415
  const offlineSigners = await getOfflineSigners({
2437
2416
  chainId: args.chainId
@@ -2449,7 +2428,7 @@ var useOfflineSigners = (args) => {
2449
2428
  );
2450
2429
  return res;
2451
2430
  },
2452
- { enabled: Boolean(data), refetchOnMount: false, refetchOnWindowFocus: false }
2431
+ { enabled: Boolean(accounts), refetchOnMount: false, refetchOnWindowFocus: false }
2453
2432
  );
2454
2433
  return query;
2455
2434
  };
@@ -2542,7 +2521,7 @@ var useConnectClient = (args) => {
2542
2521
  const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
2543
2522
  const query = useQuery4(
2544
2523
  [
2545
- "USE_CLIENTS",
2524
+ "USE_CONNECT_CLIENT",
2546
2525
  {
2547
2526
  client: _client,
2548
2527
  chainId: args == null ? void 0 : args.chainId,
@@ -2589,7 +2568,7 @@ var useConnectSigningClient = (args) => {
2589
2568
  const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
2590
2569
  const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
2591
2570
  const queryKey = [
2592
- "USE_SIGNING_CLIENTS",
2571
+ "USE_CONNECT_SIGNING_CLIENT",
2593
2572
  { client: _client, chainId: args == null ? void 0 : args.chainId, options: args == null ? void 0 : args.options }
2594
2573
  ];
2595
2574
  const query = useQuery4(
@@ -2661,7 +2640,7 @@ var useBalance = (args) => {
2661
2640
  });
2662
2641
  const query = useQuery5(
2663
2642
  [
2664
- "USE_BALANCES",
2643
+ "USE_BALANCE",
2665
2644
  {
2666
2645
  client,
2667
2646
  ...args,
@@ -2701,7 +2680,7 @@ var useAllBalances = (args) => {
2701
2680
  });
2702
2681
  const query = useQuery5(
2703
2682
  [
2704
- "USE_BALANCES",
2683
+ "USE_ALL_BALANCES",
2705
2684
  {
2706
2685
  singleClient,
2707
2686
  multiClient,
@@ -2760,7 +2739,7 @@ var useChainBalances = (args) => {
2760
2739
  });
2761
2740
  const query = useQuery5(
2762
2741
  [
2763
- "USE_BALANCES",
2742
+ "USE_CHAIN_BALANCES",
2764
2743
  {
2765
2744
  singleClient,
2766
2745
  multiClient,
@@ -2834,7 +2813,7 @@ var useBalanceStaked = (args) => {
2834
2813
  });
2835
2814
  const query = useQuery5(
2836
2815
  [
2837
- "USE_BALANCE_STAKED",
2816
+ "useBalanceStaked",
2838
2817
  {
2839
2818
  singleClient,
2840
2819
  multiClient,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "graz",
3
3
  "description": "React hooks for Cosmos",
4
- "version": "0.1.0-alpha.1",
4
+ "version": "0.1.0-alpha.2",
5
5
  "author": "Griko Nibras <griko@strange.love>",
6
6
  "repository": "https://github.com/strangelove-ventures/graz.git",
7
7
  "homepage": "https://github.com/strangelove-ventures/graz",