graz 0.1.0-alpha.2 → 0.1.0-alpha.3
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 +23 -18
- package/dist/index.js +37 -27
- package/dist/index.mjs +35 -26
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -248,6 +248,9 @@ interface SuggestChainAndConnectArgs {
|
|
|
248
248
|
walletType?: WalletType;
|
|
249
249
|
}
|
|
250
250
|
declare const suggestChainAndConnect: (args: SuggestChainAndConnectArgs) => Promise<ConnectResult>;
|
|
251
|
+
declare const getChain: ({ chainId }: {
|
|
252
|
+
chainId: string;
|
|
253
|
+
}) => GrazChain | undefined;
|
|
251
254
|
|
|
252
255
|
interface ConfigureGrazArgs {
|
|
253
256
|
chains?: GrazChain[];
|
|
@@ -461,7 +464,7 @@ interface ChainIdArgs {
|
|
|
461
464
|
/**
|
|
462
465
|
* if provided, it will only return the data of the given chainId
|
|
463
466
|
*/
|
|
464
|
-
chainId?: string | undefined;
|
|
467
|
+
chainId?: string | string[] | undefined;
|
|
465
468
|
}
|
|
466
469
|
type HookResultDataWithChainId<T, U extends ChainIdArgs> = U["chainId"] extends string ? T : Record<string, T>;
|
|
467
470
|
|
|
@@ -489,8 +492,19 @@ interface UseAccountArgs {
|
|
|
489
492
|
* ```tsx
|
|
490
493
|
* import { useAccount } from "graz";
|
|
491
494
|
*
|
|
492
|
-
* //
|
|
493
|
-
* const
|
|
495
|
+
* // single chain
|
|
496
|
+
* const account = useAccount({
|
|
497
|
+
* chainId: "cosmoshub-4",
|
|
498
|
+
* })
|
|
499
|
+
*
|
|
500
|
+
* return <div>{account?.account.bech32Address}</div>
|
|
501
|
+
*
|
|
502
|
+
* // multi chain
|
|
503
|
+
* const accounts = useAccount();
|
|
504
|
+
*
|
|
505
|
+
* Object.entries(accounts).map(([chainId, account]) => {
|
|
506
|
+
* return <div key={chainId}>{account?.account.bech32Address}</div>
|
|
507
|
+
* })
|
|
494
508
|
*
|
|
495
509
|
* // with event arguments
|
|
496
510
|
* useAccount({
|
|
@@ -523,17 +537,8 @@ type UseConnectChainArgs = MutationEventArgs<ConnectArgs, ConnectResult>;
|
|
|
523
537
|
* onSuccess: (account) => { ... },
|
|
524
538
|
* });
|
|
525
539
|
*
|
|
526
|
-
* // use graz provided chain information
|
|
527
|
-
* connect(mainnetChains.cosmos);
|
|
528
|
-
*
|
|
529
|
-
* // use custom chain information
|
|
530
540
|
* connect({
|
|
531
|
-
*
|
|
532
|
-
* rpc: "https://rpc.juno.strange.love",
|
|
533
|
-
* rest: "https://api.juno.strange.love",
|
|
534
|
-
* chainId: "juno-1",
|
|
535
|
-
* ...
|
|
536
|
-
* }
|
|
541
|
+
* chainId: ["cosmoshub-4"],
|
|
537
542
|
* });
|
|
538
543
|
* ```
|
|
539
544
|
*
|
|
@@ -630,20 +635,20 @@ declare const useOfflineSigners: <T extends ChainIdArgs>(args?: T | undefined) =
|
|
|
630
635
|
*/
|
|
631
636
|
declare const useActiveChainValidators: <T extends QueryClient & StakingExtension>(queryClient: T | undefined, status?: BondStatusString) => UseQueryResult<QueryValidatorsResponse>;
|
|
632
637
|
/**
|
|
633
|
-
* graz hook to retrieve last connected chain
|
|
638
|
+
* graz hook to retrieve last connected chain ids
|
|
634
639
|
*
|
|
635
640
|
* @example
|
|
636
641
|
* ```ts
|
|
637
642
|
* import { useRecentChain, connect, mainnetChains } from "graz";
|
|
638
643
|
* const { data: recentChain, clear } = useRecentChain();
|
|
639
644
|
* try {
|
|
640
|
-
* connect(mainnetChains.cosmos);
|
|
645
|
+
* connect({chainId: [mainnetChains.cosmos]});
|
|
641
646
|
* } catch {
|
|
642
|
-
* connect(recentChain);
|
|
647
|
+
* connect({chainId: recentChain});
|
|
643
648
|
* }
|
|
644
649
|
* ```
|
|
645
650
|
*/
|
|
646
|
-
declare const
|
|
651
|
+
declare const useRecentChains: () => {
|
|
647
652
|
data: string[] | null;
|
|
648
653
|
clear: () => void;
|
|
649
654
|
};
|
|
@@ -1172,4 +1177,4 @@ declare const formatTokenName: (name: string) => string;
|
|
|
1172
1177
|
declare const handleNaN: (value: number) => number;
|
|
1173
1178
|
declare const truncate: (string?: string, slice?: number) => string;
|
|
1174
1179
|
|
|
1175
|
-
export { AccountData, ChainInfoWithPath, Clients, ConfigureGrazArgs, ConnectArgs, ConnectClient, ConnectClientArgs, ConnectResult, ConnectSigningClient, ConnectSigningClientArgs, Connector, Dictionary, ExecuteContractArgs, ExecuteContractMutationArgs, GetWalletConnectParams, GrazAdapter, GrazChain, GrazConfig, GrazEvents, GrazProvider, GrazProviderProps, InstantiateContractArgs, InstantiateContractMutationArgs, Maybe, OfflineSigners, ReconnectArgs, SendIbcTokensArgs, SendTokensArgs, SigningClients, SuggestChainAndConnectArgs, UseAccountArgs, UseConnectChainArgs, UseExecuteContractArgs, UseInstantiateContractArgs, UseSendIbcTokens, UseSuggestChainAndConnectArgs, UseSuggestChainArgs, WALLET_TYPES, Wallet, WalletType, checkWallet, clearRecentChain, configureGraz, connect, connectClient, connectSigningClient, convertDenomToMicroDenom, convertFromMicroDenom, convertMicroDenomToDenom, convertToFixedDecimals, defineChain, defineChainInfo, defineChains, disconnect, executeContract, formatTokenName, getAllBalance, getAvailableWallets, getBalance, getBalanceStaked, getCosmostation, getKeplr, getLeap, getOfflineSigners, getQueryRaw, getQuerySmart, getRecentChains, getVectis, getWCCosmostation, getWCKeplr, getWCLeap, getWallet, getWalletConnect, handleNaN, instantiateContract, mainnetChains, mainnetChainsArray, reconnect, sendIbcTokens, sendTokens, suggestChain, suggestChainAndConnect, testnetChains, testnetChainsArray, truncate, useAccount, useActiveChainValidators, useActiveWalletType, useAllBalances, useBalance, useBalanceStaked, useChain, useChainBalances, useCheckWallet, useConnect, useConnectClient, useConnectSigningClient, useDisconnect, useExecuteContract, useGrazEvents, useInstantiateContract, useOfflineSigners, useQueryRaw, useQuerySmart,
|
|
1180
|
+
export { AccountData, ChainInfoWithPath, Clients, ConfigureGrazArgs, ConnectArgs, ConnectClient, ConnectClientArgs, ConnectResult, ConnectSigningClient, ConnectSigningClientArgs, Connector, Dictionary, ExecuteContractArgs, ExecuteContractMutationArgs, GetWalletConnectParams, GrazAdapter, GrazChain, GrazConfig, GrazEvents, GrazProvider, GrazProviderProps, InstantiateContractArgs, InstantiateContractMutationArgs, Maybe, OfflineSigners, ReconnectArgs, SendIbcTokensArgs, SendTokensArgs, SigningClients, SuggestChainAndConnectArgs, UseAccountArgs, UseConnectChainArgs, UseExecuteContractArgs, UseInstantiateContractArgs, UseSendIbcTokens, UseSuggestChainAndConnectArgs, UseSuggestChainArgs, WALLET_TYPES, Wallet, WalletType, checkWallet, clearRecentChain, configureGraz, connect, connectClient, connectSigningClient, convertDenomToMicroDenom, convertFromMicroDenom, convertMicroDenomToDenom, convertToFixedDecimals, defineChain, defineChainInfo, defineChains, disconnect, executeContract, formatTokenName, getAllBalance, getAvailableWallets, getBalance, getBalanceStaked, getChain, getCosmostation, getKeplr, getLeap, getOfflineSigners, getQueryRaw, getQuerySmart, getRecentChains, getVectis, getWCCosmostation, getWCKeplr, getWCLeap, getWallet, getWalletConnect, handleNaN, instantiateContract, mainnetChains, mainnetChainsArray, reconnect, sendIbcTokens, sendTokens, suggestChain, suggestChainAndConnect, testnetChains, testnetChainsArray, truncate, useAccount, useActiveChainValidators, useActiveWalletType, useAllBalances, useBalance, useBalanceStaked, useChain, useChainBalances, useCheckWallet, useConnect, useConnectClient, useConnectSigningClient, useDisconnect, useExecuteContract, useGrazEvents, useInstantiateContract, useOfflineSigners, useQueryRaw, useQuerySmart, useRecentChains, useSendIbcTokens, useSendTokens, useSuggestChain, useSuggestChainAndConnect };
|
package/dist/index.js
CHANGED
|
@@ -921,6 +921,7 @@ __export(src_exports, {
|
|
|
921
921
|
getAvailableWallets: () => getAvailableWallets,
|
|
922
922
|
getBalance: () => getBalance,
|
|
923
923
|
getBalanceStaked: () => getBalanceStaked,
|
|
924
|
+
getChain: () => getChain,
|
|
924
925
|
getCosmostation: () => getCosmostation,
|
|
925
926
|
getKeplr: () => getKeplr,
|
|
926
927
|
getLeap: () => getLeap,
|
|
@@ -965,7 +966,7 @@ __export(src_exports, {
|
|
|
965
966
|
useOfflineSigners: () => useOfflineSigners,
|
|
966
967
|
useQueryRaw: () => useQueryRaw,
|
|
967
968
|
useQuerySmart: () => useQuerySmart,
|
|
968
|
-
|
|
969
|
+
useRecentChains: () => useRecentChains,
|
|
969
970
|
useSendIbcTokens: () => useSendIbcTokens,
|
|
970
971
|
useSendTokens: () => useSendTokens,
|
|
971
972
|
useSuggestChain: () => useSuggestChain,
|
|
@@ -1922,6 +1923,11 @@ var suggestChainAndConnect = async (args) => {
|
|
|
1922
1923
|
});
|
|
1923
1924
|
return result;
|
|
1924
1925
|
};
|
|
1926
|
+
var getChain = ({ chainId }) => {
|
|
1927
|
+
var _a;
|
|
1928
|
+
const chain = (_a = useGrazInternalStore.getState().chains) == null ? void 0 : _a.find((x) => x.chainId === chainId);
|
|
1929
|
+
return chain;
|
|
1930
|
+
};
|
|
1925
1931
|
|
|
1926
1932
|
// src/actions/clients.ts
|
|
1927
1933
|
var import_cosmwasm_stargate = require("@cosmjs/cosmwasm-stargate");
|
|
@@ -2457,12 +2463,12 @@ var useAccount = (args) => {
|
|
|
2457
2463
|
const res = (0, import_react.useMemo)(() => {
|
|
2458
2464
|
if (!sessions)
|
|
2459
2465
|
return void 0;
|
|
2460
|
-
if (args == null ? void 0 : args.chainId) {
|
|
2466
|
+
if (typeof (args == null ? void 0 : args.chainId) === "string" && args.chainId) {
|
|
2461
2467
|
const singleChainRes = sessions.find((i) => i.chainId === args.chainId);
|
|
2462
2468
|
return singleChainRes;
|
|
2463
2469
|
}
|
|
2464
2470
|
const multiChainRes = {};
|
|
2465
|
-
sessions.forEach((i) => {
|
|
2471
|
+
sessions.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x.chainId) : true).forEach((i) => {
|
|
2466
2472
|
multiChainRes[i.chainId] = i;
|
|
2467
2473
|
});
|
|
2468
2474
|
return multiChainRes;
|
|
@@ -2519,7 +2525,7 @@ var useOfflineSigners = (args) => {
|
|
|
2519
2525
|
if (!accounts)
|
|
2520
2526
|
return void 0;
|
|
2521
2527
|
const connectedChainIds = Object.keys(accounts).map(([chainId]) => chainId).filter(Boolean);
|
|
2522
|
-
if (args == null ? void 0 : args.chainId) {
|
|
2528
|
+
if (typeof (args == null ? void 0 : args.chainId) === "string" && args.chainId) {
|
|
2523
2529
|
const offlineSigners = await getOfflineSigners({
|
|
2524
2530
|
chainId: args.chainId
|
|
2525
2531
|
});
|
|
@@ -2527,7 +2533,7 @@ var useOfflineSigners = (args) => {
|
|
|
2527
2533
|
}
|
|
2528
2534
|
const res = {};
|
|
2529
2535
|
await Promise.all(
|
|
2530
|
-
connectedChainIds.map(async (_chainId) => {
|
|
2536
|
+
connectedChainIds.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x) : true).map(async (_chainId) => {
|
|
2531
2537
|
const signers = await getOfflineSigners({
|
|
2532
2538
|
chainId: _chainId
|
|
2533
2539
|
});
|
|
@@ -2556,7 +2562,7 @@ var useActiveChainValidators = (queryClient2, status = "BOND_STATUS_BONDED") =>
|
|
|
2556
2562
|
);
|
|
2557
2563
|
return query;
|
|
2558
2564
|
};
|
|
2559
|
-
var
|
|
2565
|
+
var useRecentChains = () => {
|
|
2560
2566
|
const recentChains = useGrazInternalStore((x) => x.recentChains);
|
|
2561
2567
|
return { data: recentChains, clear: clearRecentChain };
|
|
2562
2568
|
};
|
|
@@ -2624,7 +2630,7 @@ var useConnectClient = (args) => {
|
|
|
2624
2630
|
const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
|
|
2625
2631
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2626
2632
|
const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
|
|
2627
|
-
const singleChain =
|
|
2633
|
+
const singleChain = typeof (args == null ? void 0 : args.chainId) === "string" && (_chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId));
|
|
2628
2634
|
const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
|
|
2629
2635
|
const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
|
|
2630
2636
|
const query = (0, import_react_query4.useQuery)(
|
|
@@ -2649,7 +2655,7 @@ var useConnectClient = (args) => {
|
|
|
2649
2655
|
if (!chains)
|
|
2650
2656
|
return void 0;
|
|
2651
2657
|
await Promise.all(
|
|
2652
|
-
chains.map(async (chain) => {
|
|
2658
|
+
chains.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x.chainId) : true).map(async (chain) => {
|
|
2653
2659
|
const client = await connectClient({
|
|
2654
2660
|
client: _client,
|
|
2655
2661
|
rpc: chain.rpc,
|
|
@@ -2673,7 +2679,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2673
2679
|
const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
|
|
2674
2680
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2675
2681
|
const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
|
|
2676
|
-
const singleChain =
|
|
2682
|
+
const singleChain = typeof (args == null ? void 0 : args.chainId) === "string" && (_chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId));
|
|
2677
2683
|
const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
|
|
2678
2684
|
const queryKey = [
|
|
2679
2685
|
"USE_CONNECT_SIGNING_CLIENT",
|
|
@@ -2687,7 +2693,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2687
2693
|
chainId: singleChain.chainId
|
|
2688
2694
|
});
|
|
2689
2695
|
const gasPrice = singleChain.gas ? import_stargate2.GasPrice.fromString(`${singleChain.gas.price}${singleChain.gas.denom}`) : void 0;
|
|
2690
|
-
const options = _client === "cosmWasm" ? { gasPrice, ...
|
|
2696
|
+
const options = _client === "cosmWasm" ? { gasPrice, ...args.options || {} } : args.options;
|
|
2691
2697
|
const client = await connectSigningClient({
|
|
2692
2698
|
client: _client,
|
|
2693
2699
|
rpc: singleChain.rpc,
|
|
@@ -2701,7 +2707,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2701
2707
|
if (!sessionChains)
|
|
2702
2708
|
return void 0;
|
|
2703
2709
|
await Promise.all(
|
|
2704
|
-
sessionChains.map(async (chain) => {
|
|
2710
|
+
sessionChains.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x.chainId) : true).map(async (chain) => {
|
|
2705
2711
|
var _a2, _b;
|
|
2706
2712
|
const { offlineSignerAuto } = await getOfflineSigners({ chainId: chain.chainId });
|
|
2707
2713
|
const gasPrice = chain.gas ? import_stargate2.GasPrice.fromString(`${chain.gas.price}${chain.gas.denom}`) : void 0;
|
|
@@ -2780,11 +2786,12 @@ var useAllBalances = (args) => {
|
|
|
2780
2786
|
const { data: singleClient } = useConnectClient({
|
|
2781
2787
|
client: "stargate",
|
|
2782
2788
|
chainId: args.chainId,
|
|
2783
|
-
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2789
|
+
enabled: Boolean(args.chainId) && typeof args.chainId === "string" && Boolean(args.bech32Address)
|
|
2784
2790
|
});
|
|
2785
2791
|
const { data: multiClient } = useConnectClient({
|
|
2786
2792
|
client: "stargate",
|
|
2787
|
-
|
|
2793
|
+
chainId: args.chainId,
|
|
2794
|
+
enabled: (!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && Boolean(args.bech32Address)
|
|
2788
2795
|
});
|
|
2789
2796
|
const query = (0, import_react_query5.useQuery)(
|
|
2790
2797
|
[
|
|
@@ -2797,7 +2804,7 @@ var useAllBalances = (args) => {
|
|
|
2797
2804
|
}
|
|
2798
2805
|
],
|
|
2799
2806
|
async () => {
|
|
2800
|
-
if (args.chainId && singleClient) {
|
|
2807
|
+
if (args.chainId && typeof args.chainId === "string" && singleClient) {
|
|
2801
2808
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2802
2809
|
const res = await getAllBalance({
|
|
2803
2810
|
client: singleClient,
|
|
@@ -2805,11 +2812,11 @@ var useAllBalances = (args) => {
|
|
|
2805
2812
|
});
|
|
2806
2813
|
return res;
|
|
2807
2814
|
}
|
|
2808
|
-
if (!args.chainId && multiClient) {
|
|
2815
|
+
if ((!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && multiClient) {
|
|
2809
2816
|
const multiChain = Object.entries(multiClient);
|
|
2810
2817
|
const res = {};
|
|
2811
2818
|
await Promise.all(
|
|
2812
|
-
multiChain.map(async ([chainId, client]) => {
|
|
2819
|
+
multiChain.filter((x) => args.chainId ? args.chainId.includes(x[0]) : true).map(async ([chainId, client]) => {
|
|
2813
2820
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2814
2821
|
if (!chain)
|
|
2815
2822
|
return;
|
|
@@ -2839,11 +2846,12 @@ var useChainBalances = (args) => {
|
|
|
2839
2846
|
const { data: singleClient } = useConnectClient({
|
|
2840
2847
|
client: _client,
|
|
2841
2848
|
chainId: args.chainId,
|
|
2842
|
-
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2849
|
+
enabled: Boolean(args.chainId) && typeof args.chainId === "string" && Boolean(args.bech32Address)
|
|
2843
2850
|
});
|
|
2844
2851
|
const { data: multiClient } = useConnectClient({
|
|
2845
2852
|
client: _client,
|
|
2846
|
-
|
|
2853
|
+
chainId: args.chainId,
|
|
2854
|
+
enabled: (!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && Boolean(args.bech32Address)
|
|
2847
2855
|
});
|
|
2848
2856
|
const query = (0, import_react_query5.useQuery)(
|
|
2849
2857
|
[
|
|
@@ -2856,7 +2864,7 @@ var useChainBalances = (args) => {
|
|
|
2856
2864
|
}
|
|
2857
2865
|
],
|
|
2858
2866
|
async () => {
|
|
2859
|
-
if (args.chainId && singleClient) {
|
|
2867
|
+
if (typeof args.chainId === "string" && args.chainId && singleClient) {
|
|
2860
2868
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2861
2869
|
const res = await Promise.all(
|
|
2862
2870
|
singleChain.currencies.map(
|
|
@@ -2872,11 +2880,11 @@ var useChainBalances = (args) => {
|
|
|
2872
2880
|
);
|
|
2873
2881
|
return res;
|
|
2874
2882
|
}
|
|
2875
|
-
if (!args.chainId && multiClient) {
|
|
2883
|
+
if ((!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && multiClient) {
|
|
2876
2884
|
const multiChain = Object.entries(multiClient);
|
|
2877
2885
|
const res = {};
|
|
2878
2886
|
await Promise.all(
|
|
2879
|
-
multiChain.map(async ([chainId, client]) => {
|
|
2887
|
+
multiChain.filter((x) => args.chainId ? args.chainId.includes(x[0]) : true).map(async ([chainId, client]) => {
|
|
2880
2888
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2881
2889
|
if (!chain)
|
|
2882
2890
|
return;
|
|
@@ -2913,11 +2921,12 @@ var useBalanceStaked = (args) => {
|
|
|
2913
2921
|
const { data: singleClient } = useConnectClient({
|
|
2914
2922
|
client: "stargate",
|
|
2915
2923
|
chainId: args.chainId,
|
|
2916
|
-
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2924
|
+
enabled: Boolean(args.chainId) && typeof args.chainId === "string" && Boolean(args.bech32Address)
|
|
2917
2925
|
});
|
|
2918
2926
|
const { data: multiClient } = useConnectClient({
|
|
2919
2927
|
client: "stargate",
|
|
2920
|
-
|
|
2928
|
+
chainId: args.chainId,
|
|
2929
|
+
enabled: (!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && Boolean(args.bech32Address)
|
|
2921
2930
|
});
|
|
2922
2931
|
const query = (0, import_react_query5.useQuery)(
|
|
2923
2932
|
[
|
|
@@ -2930,7 +2939,7 @@ var useBalanceStaked = (args) => {
|
|
|
2930
2939
|
}
|
|
2931
2940
|
],
|
|
2932
2941
|
async () => {
|
|
2933
|
-
if (args.chainId && singleClient) {
|
|
2942
|
+
if (args.chainId && typeof args.chainId === "string" && singleClient) {
|
|
2934
2943
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2935
2944
|
if (!singleChain)
|
|
2936
2945
|
throw new Error(`${args.chainId} Chain not found`);
|
|
@@ -2940,11 +2949,11 @@ var useBalanceStaked = (args) => {
|
|
|
2940
2949
|
});
|
|
2941
2950
|
return res;
|
|
2942
2951
|
}
|
|
2943
|
-
if (!args.chainId && multiClient) {
|
|
2952
|
+
if ((!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && multiClient) {
|
|
2944
2953
|
const multiChain = Object.entries(multiClient);
|
|
2945
2954
|
const res = {};
|
|
2946
2955
|
await Promise.all(
|
|
2947
|
-
multiChain.map(async ([chainId, client]) => {
|
|
2956
|
+
multiChain.filter((x) => args.chainId ? args.chainId.includes(x[0]) : true).map(async ([chainId, client]) => {
|
|
2948
2957
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2949
2958
|
if (!chain)
|
|
2950
2959
|
return;
|
|
@@ -3338,6 +3347,7 @@ var truncate = (string, slice) => {
|
|
|
3338
3347
|
getAvailableWallets,
|
|
3339
3348
|
getBalance,
|
|
3340
3349
|
getBalanceStaked,
|
|
3350
|
+
getChain,
|
|
3341
3351
|
getCosmostation,
|
|
3342
3352
|
getKeplr,
|
|
3343
3353
|
getLeap,
|
|
@@ -3382,7 +3392,7 @@ var truncate = (string, slice) => {
|
|
|
3382
3392
|
useOfflineSigners,
|
|
3383
3393
|
useQueryRaw,
|
|
3384
3394
|
useQuerySmart,
|
|
3385
|
-
|
|
3395
|
+
useRecentChains,
|
|
3386
3396
|
useSendIbcTokens,
|
|
3387
3397
|
useSendTokens,
|
|
3388
3398
|
useSuggestChain,
|
package/dist/index.mjs
CHANGED
|
@@ -1814,6 +1814,11 @@ var suggestChainAndConnect = async (args) => {
|
|
|
1814
1814
|
});
|
|
1815
1815
|
return result;
|
|
1816
1816
|
};
|
|
1817
|
+
var getChain = ({ chainId }) => {
|
|
1818
|
+
var _a;
|
|
1819
|
+
const chain = (_a = useGrazInternalStore.getState().chains) == null ? void 0 : _a.find((x) => x.chainId === chainId);
|
|
1820
|
+
return chain;
|
|
1821
|
+
};
|
|
1817
1822
|
|
|
1818
1823
|
// src/actions/clients.ts
|
|
1819
1824
|
import { CosmWasmClient, SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
|
|
@@ -2349,12 +2354,12 @@ var useAccount = (args) => {
|
|
|
2349
2354
|
const res = useMemo(() => {
|
|
2350
2355
|
if (!sessions)
|
|
2351
2356
|
return void 0;
|
|
2352
|
-
if (args == null ? void 0 : args.chainId) {
|
|
2357
|
+
if (typeof (args == null ? void 0 : args.chainId) === "string" && args.chainId) {
|
|
2353
2358
|
const singleChainRes = sessions.find((i) => i.chainId === args.chainId);
|
|
2354
2359
|
return singleChainRes;
|
|
2355
2360
|
}
|
|
2356
2361
|
const multiChainRes = {};
|
|
2357
|
-
sessions.forEach((i) => {
|
|
2362
|
+
sessions.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x.chainId) : true).forEach((i) => {
|
|
2358
2363
|
multiChainRes[i.chainId] = i;
|
|
2359
2364
|
});
|
|
2360
2365
|
return multiChainRes;
|
|
@@ -2411,7 +2416,7 @@ var useOfflineSigners = (args) => {
|
|
|
2411
2416
|
if (!accounts)
|
|
2412
2417
|
return void 0;
|
|
2413
2418
|
const connectedChainIds = Object.keys(accounts).map(([chainId]) => chainId).filter(Boolean);
|
|
2414
|
-
if (args == null ? void 0 : args.chainId) {
|
|
2419
|
+
if (typeof (args == null ? void 0 : args.chainId) === "string" && args.chainId) {
|
|
2415
2420
|
const offlineSigners = await getOfflineSigners({
|
|
2416
2421
|
chainId: args.chainId
|
|
2417
2422
|
});
|
|
@@ -2419,7 +2424,7 @@ var useOfflineSigners = (args) => {
|
|
|
2419
2424
|
}
|
|
2420
2425
|
const res = {};
|
|
2421
2426
|
await Promise.all(
|
|
2422
|
-
connectedChainIds.map(async (_chainId) => {
|
|
2427
|
+
connectedChainIds.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x) : true).map(async (_chainId) => {
|
|
2423
2428
|
const signers = await getOfflineSigners({
|
|
2424
2429
|
chainId: _chainId
|
|
2425
2430
|
});
|
|
@@ -2448,7 +2453,7 @@ var useActiveChainValidators = (queryClient2, status = "BOND_STATUS_BONDED") =>
|
|
|
2448
2453
|
);
|
|
2449
2454
|
return query;
|
|
2450
2455
|
};
|
|
2451
|
-
var
|
|
2456
|
+
var useRecentChains = () => {
|
|
2452
2457
|
const recentChains = useGrazInternalStore((x) => x.recentChains);
|
|
2453
2458
|
return { data: recentChains, clear: clearRecentChain };
|
|
2454
2459
|
};
|
|
@@ -2516,7 +2521,7 @@ var useConnectClient = (args) => {
|
|
|
2516
2521
|
const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
|
|
2517
2522
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2518
2523
|
const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
|
|
2519
|
-
const singleChain =
|
|
2524
|
+
const singleChain = typeof (args == null ? void 0 : args.chainId) === "string" && (_chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId));
|
|
2520
2525
|
const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
|
|
2521
2526
|
const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
|
|
2522
2527
|
const query = useQuery4(
|
|
@@ -2541,7 +2546,7 @@ var useConnectClient = (args) => {
|
|
|
2541
2546
|
if (!chains)
|
|
2542
2547
|
return void 0;
|
|
2543
2548
|
await Promise.all(
|
|
2544
|
-
chains.map(async (chain) => {
|
|
2549
|
+
chains.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x.chainId) : true).map(async (chain) => {
|
|
2545
2550
|
const client = await connectClient({
|
|
2546
2551
|
client: _client,
|
|
2547
2552
|
rpc: chain.rpc,
|
|
@@ -2565,7 +2570,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2565
2570
|
const _client = (args == null ? void 0 : args.client) ?? useGrazInternalStore.getState().defaultClient;
|
|
2566
2571
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2567
2572
|
const sessionChainIds = (_a = useGrazSessionStore.getState().sessions) == null ? void 0 : _a.map((i) => i.chainId);
|
|
2568
|
-
const singleChain =
|
|
2573
|
+
const singleChain = typeof (args == null ? void 0 : args.chainId) === "string" && (_chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId));
|
|
2569
2574
|
const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
|
|
2570
2575
|
const queryKey = [
|
|
2571
2576
|
"USE_CONNECT_SIGNING_CLIENT",
|
|
@@ -2579,7 +2584,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2579
2584
|
chainId: singleChain.chainId
|
|
2580
2585
|
});
|
|
2581
2586
|
const gasPrice = singleChain.gas ? GasPrice.fromString(`${singleChain.gas.price}${singleChain.gas.denom}`) : void 0;
|
|
2582
|
-
const options = _client === "cosmWasm" ? { gasPrice, ...
|
|
2587
|
+
const options = _client === "cosmWasm" ? { gasPrice, ...args.options || {} } : args.options;
|
|
2583
2588
|
const client = await connectSigningClient({
|
|
2584
2589
|
client: _client,
|
|
2585
2590
|
rpc: singleChain.rpc,
|
|
@@ -2593,7 +2598,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2593
2598
|
if (!sessionChains)
|
|
2594
2599
|
return void 0;
|
|
2595
2600
|
await Promise.all(
|
|
2596
|
-
sessionChains.map(async (chain) => {
|
|
2601
|
+
sessionChains.filter((x) => (args == null ? void 0 : args.chainId) ? args.chainId.includes(x.chainId) : true).map(async (chain) => {
|
|
2597
2602
|
var _a2, _b;
|
|
2598
2603
|
const { offlineSignerAuto } = await getOfflineSigners({ chainId: chain.chainId });
|
|
2599
2604
|
const gasPrice = chain.gas ? GasPrice.fromString(`${chain.gas.price}${chain.gas.denom}`) : void 0;
|
|
@@ -2672,11 +2677,12 @@ var useAllBalances = (args) => {
|
|
|
2672
2677
|
const { data: singleClient } = useConnectClient({
|
|
2673
2678
|
client: "stargate",
|
|
2674
2679
|
chainId: args.chainId,
|
|
2675
|
-
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2680
|
+
enabled: Boolean(args.chainId) && typeof args.chainId === "string" && Boolean(args.bech32Address)
|
|
2676
2681
|
});
|
|
2677
2682
|
const { data: multiClient } = useConnectClient({
|
|
2678
2683
|
client: "stargate",
|
|
2679
|
-
|
|
2684
|
+
chainId: args.chainId,
|
|
2685
|
+
enabled: (!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && Boolean(args.bech32Address)
|
|
2680
2686
|
});
|
|
2681
2687
|
const query = useQuery5(
|
|
2682
2688
|
[
|
|
@@ -2689,7 +2695,7 @@ var useAllBalances = (args) => {
|
|
|
2689
2695
|
}
|
|
2690
2696
|
],
|
|
2691
2697
|
async () => {
|
|
2692
|
-
if (args.chainId && singleClient) {
|
|
2698
|
+
if (args.chainId && typeof args.chainId === "string" && singleClient) {
|
|
2693
2699
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2694
2700
|
const res = await getAllBalance({
|
|
2695
2701
|
client: singleClient,
|
|
@@ -2697,11 +2703,11 @@ var useAllBalances = (args) => {
|
|
|
2697
2703
|
});
|
|
2698
2704
|
return res;
|
|
2699
2705
|
}
|
|
2700
|
-
if (!args.chainId && multiClient) {
|
|
2706
|
+
if ((!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && multiClient) {
|
|
2701
2707
|
const multiChain = Object.entries(multiClient);
|
|
2702
2708
|
const res = {};
|
|
2703
2709
|
await Promise.all(
|
|
2704
|
-
multiChain.map(async ([chainId, client]) => {
|
|
2710
|
+
multiChain.filter((x) => args.chainId ? args.chainId.includes(x[0]) : true).map(async ([chainId, client]) => {
|
|
2705
2711
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2706
2712
|
if (!chain)
|
|
2707
2713
|
return;
|
|
@@ -2731,11 +2737,12 @@ var useChainBalances = (args) => {
|
|
|
2731
2737
|
const { data: singleClient } = useConnectClient({
|
|
2732
2738
|
client: _client,
|
|
2733
2739
|
chainId: args.chainId,
|
|
2734
|
-
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2740
|
+
enabled: Boolean(args.chainId) && typeof args.chainId === "string" && Boolean(args.bech32Address)
|
|
2735
2741
|
});
|
|
2736
2742
|
const { data: multiClient } = useConnectClient({
|
|
2737
2743
|
client: _client,
|
|
2738
|
-
|
|
2744
|
+
chainId: args.chainId,
|
|
2745
|
+
enabled: (!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && Boolean(args.bech32Address)
|
|
2739
2746
|
});
|
|
2740
2747
|
const query = useQuery5(
|
|
2741
2748
|
[
|
|
@@ -2748,7 +2755,7 @@ var useChainBalances = (args) => {
|
|
|
2748
2755
|
}
|
|
2749
2756
|
],
|
|
2750
2757
|
async () => {
|
|
2751
|
-
if (args.chainId && singleClient) {
|
|
2758
|
+
if (typeof args.chainId === "string" && args.chainId && singleClient) {
|
|
2752
2759
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2753
2760
|
const res = await Promise.all(
|
|
2754
2761
|
singleChain.currencies.map(
|
|
@@ -2764,11 +2771,11 @@ var useChainBalances = (args) => {
|
|
|
2764
2771
|
);
|
|
2765
2772
|
return res;
|
|
2766
2773
|
}
|
|
2767
|
-
if (!args.chainId && multiClient) {
|
|
2774
|
+
if ((!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && multiClient) {
|
|
2768
2775
|
const multiChain = Object.entries(multiClient);
|
|
2769
2776
|
const res = {};
|
|
2770
2777
|
await Promise.all(
|
|
2771
|
-
multiChain.map(async ([chainId, client]) => {
|
|
2778
|
+
multiChain.filter((x) => args.chainId ? args.chainId.includes(x[0]) : true).map(async ([chainId, client]) => {
|
|
2772
2779
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2773
2780
|
if (!chain)
|
|
2774
2781
|
return;
|
|
@@ -2805,11 +2812,12 @@ var useBalanceStaked = (args) => {
|
|
|
2805
2812
|
const { data: singleClient } = useConnectClient({
|
|
2806
2813
|
client: "stargate",
|
|
2807
2814
|
chainId: args.chainId,
|
|
2808
|
-
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2815
|
+
enabled: Boolean(args.chainId) && typeof args.chainId === "string" && Boolean(args.bech32Address)
|
|
2809
2816
|
});
|
|
2810
2817
|
const { data: multiClient } = useConnectClient({
|
|
2811
2818
|
client: "stargate",
|
|
2812
|
-
|
|
2819
|
+
chainId: args.chainId,
|
|
2820
|
+
enabled: (!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && Boolean(args.bech32Address)
|
|
2813
2821
|
});
|
|
2814
2822
|
const query = useQuery5(
|
|
2815
2823
|
[
|
|
@@ -2822,7 +2830,7 @@ var useBalanceStaked = (args) => {
|
|
|
2822
2830
|
}
|
|
2823
2831
|
],
|
|
2824
2832
|
async () => {
|
|
2825
|
-
if (args.chainId && singleClient) {
|
|
2833
|
+
if (args.chainId && typeof args.chainId === "string" && singleClient) {
|
|
2826
2834
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2827
2835
|
if (!singleChain)
|
|
2828
2836
|
throw new Error(`${args.chainId} Chain not found`);
|
|
@@ -2832,11 +2840,11 @@ var useBalanceStaked = (args) => {
|
|
|
2832
2840
|
});
|
|
2833
2841
|
return res;
|
|
2834
2842
|
}
|
|
2835
|
-
if (!args.chainId && multiClient) {
|
|
2843
|
+
if ((!args.chainId || Boolean(args.chainId) && Array.isArray(args.chainId)) && multiClient) {
|
|
2836
2844
|
const multiChain = Object.entries(multiClient);
|
|
2837
2845
|
const res = {};
|
|
2838
2846
|
await Promise.all(
|
|
2839
|
-
multiChain.map(async ([chainId, client]) => {
|
|
2847
|
+
multiChain.filter((x) => args.chainId ? args.chainId.includes(x[0]) : true).map(async ([chainId, client]) => {
|
|
2840
2848
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2841
2849
|
if (!chain)
|
|
2842
2850
|
return;
|
|
@@ -3229,6 +3237,7 @@ export {
|
|
|
3229
3237
|
getAvailableWallets,
|
|
3230
3238
|
getBalance,
|
|
3231
3239
|
getBalanceStaked,
|
|
3240
|
+
getChain,
|
|
3232
3241
|
getCosmostation,
|
|
3233
3242
|
getKeplr,
|
|
3234
3243
|
getLeap,
|
|
@@ -3273,7 +3282,7 @@ export {
|
|
|
3273
3282
|
useOfflineSigners,
|
|
3274
3283
|
useQueryRaw,
|
|
3275
3284
|
useQuerySmart,
|
|
3276
|
-
|
|
3285
|
+
useRecentChains,
|
|
3277
3286
|
useSendIbcTokens,
|
|
3278
3287
|
useSendTokens,
|
|
3279
3288
|
useSuggestChain,
|
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.
|
|
4
|
+
"version": "0.1.0-alpha.3",
|
|
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",
|