graz 0.0.45-alpha.2 → 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 +361 -47
- package/dist/index.js +417 -54
- package/dist/index.mjs +399 -52
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -907,14 +907,20 @@ __export(src_exports, {
|
|
|
907
907
|
connect: () => connect,
|
|
908
908
|
connectClient: () => connectClient,
|
|
909
909
|
connectSigningClient: () => connectSigningClient,
|
|
910
|
+
convertDenomToMicroDenom: () => convertDenomToMicroDenom,
|
|
911
|
+
convertFromMicroDenom: () => convertFromMicroDenom,
|
|
912
|
+
convertMicroDenomToDenom: () => convertMicroDenomToDenom,
|
|
913
|
+
convertToFixedDecimals: () => convertToFixedDecimals,
|
|
910
914
|
defineChain: () => defineChain,
|
|
911
915
|
defineChainInfo: () => defineChainInfo,
|
|
912
916
|
defineChains: () => defineChains,
|
|
913
917
|
disconnect: () => disconnect,
|
|
914
918
|
executeContract: () => executeContract,
|
|
919
|
+
formatTokenName: () => formatTokenName,
|
|
920
|
+
getAllBalance: () => getAllBalance,
|
|
915
921
|
getAvailableWallets: () => getAvailableWallets,
|
|
922
|
+
getBalance: () => getBalance,
|
|
916
923
|
getBalanceStaked: () => getBalanceStaked,
|
|
917
|
-
getBalances: () => getBalances,
|
|
918
924
|
getCosmostation: () => getCosmostation,
|
|
919
925
|
getKeplr: () => getKeplr,
|
|
920
926
|
getLeap: () => getLeap,
|
|
@@ -928,6 +934,7 @@ __export(src_exports, {
|
|
|
928
934
|
getWCLeap: () => getWCLeap,
|
|
929
935
|
getWallet: () => getWallet,
|
|
930
936
|
getWalletConnect: () => getWalletConnect,
|
|
937
|
+
handleNaN: () => handleNaN,
|
|
931
938
|
instantiateContract: () => instantiateContract,
|
|
932
939
|
mainnetChains: () => mainnetChains,
|
|
933
940
|
mainnetChainsArray: () => mainnetChainsArray,
|
|
@@ -938,19 +945,28 @@ __export(src_exports, {
|
|
|
938
945
|
suggestChainAndConnect: () => suggestChainAndConnect,
|
|
939
946
|
testnetChains: () => testnetChains,
|
|
940
947
|
testnetChainsArray: () => testnetChainsArray,
|
|
948
|
+
truncate: () => truncate,
|
|
941
949
|
useAccount: () => useAccount,
|
|
942
950
|
useActiveChainValidators: () => useActiveChainValidators,
|
|
943
951
|
useActiveWalletType: () => useActiveWalletType,
|
|
952
|
+
useAllBalances: () => useAllBalances,
|
|
953
|
+
useBalance: () => useBalance,
|
|
944
954
|
useBalanceStaked: () => useBalanceStaked,
|
|
945
|
-
|
|
955
|
+
useChain: () => useChain,
|
|
956
|
+
useChainBalances: () => useChainBalances,
|
|
946
957
|
useCheckWallet: () => useCheckWallet,
|
|
947
958
|
useConnect: () => useConnect,
|
|
948
959
|
useConnectClient: () => useConnectClient,
|
|
949
960
|
useConnectSigningClient: () => useConnectSigningClient,
|
|
950
961
|
useDisconnect: () => useDisconnect,
|
|
962
|
+
useExecuteContract: () => useExecuteContract,
|
|
951
963
|
useGrazEvents: () => useGrazEvents,
|
|
964
|
+
useInstantiateContract: () => useInstantiateContract,
|
|
952
965
|
useOfflineSigners: () => useOfflineSigners,
|
|
966
|
+
useQueryRaw: () => useQueryRaw,
|
|
967
|
+
useQuerySmart: () => useQuerySmart,
|
|
953
968
|
useRecentChain: () => useRecentChain,
|
|
969
|
+
useSendIbcTokens: () => useSendIbcTokens,
|
|
954
970
|
useSendTokens: () => useSendTokens,
|
|
955
971
|
useSuggestChain: () => useSuggestChain,
|
|
956
972
|
useSuggestChainAndConnect: () => useSuggestChainAndConnect
|
|
@@ -1963,16 +1979,19 @@ var configureGraz = (args) => {
|
|
|
1963
1979
|
};
|
|
1964
1980
|
|
|
1965
1981
|
// src/actions/methods.ts
|
|
1966
|
-
var
|
|
1982
|
+
var getAllBalance = async ({
|
|
1983
|
+
bech32Address,
|
|
1984
|
+
client
|
|
1985
|
+
}) => {
|
|
1986
|
+
const balances = await client.getAllBalances(bech32Address);
|
|
1987
|
+
return balances;
|
|
1988
|
+
};
|
|
1989
|
+
var getBalance = async ({
|
|
1967
1990
|
bech32Address,
|
|
1968
1991
|
client,
|
|
1969
|
-
|
|
1992
|
+
searchDenom
|
|
1970
1993
|
}) => {
|
|
1971
|
-
const balances = await
|
|
1972
|
-
currencies9.filter((i) => !i.coinMinimalDenom.startsWith("cw20:")).map(async (item) => {
|
|
1973
|
-
return client.getBalance(bech32Address, item.coinMinimalDenom);
|
|
1974
|
-
})
|
|
1975
|
-
);
|
|
1994
|
+
const balances = await client.getBalance(bech32Address, searchDenom);
|
|
1976
1995
|
return balances;
|
|
1977
1996
|
};
|
|
1978
1997
|
var getBalanceStaked = async ({
|
|
@@ -2488,39 +2507,18 @@ var useDisconnect = ({ onError, onLoading, onSuccess } = {}) => {
|
|
|
2488
2507
|
};
|
|
2489
2508
|
var useOfflineSigners = (args) => {
|
|
2490
2509
|
const accounts = useAccount();
|
|
2491
|
-
const { data } = (0, import_react_query2.useQuery)(
|
|
2492
|
-
["OFFLINE_SIGNERS", { accounts }],
|
|
2493
|
-
async () => {
|
|
2494
|
-
if (!accounts)
|
|
2495
|
-
return void 0;
|
|
2496
|
-
const connectedChainIds = Object.values(accounts).map((i) => i == null ? void 0 : i.chainId).filter(Boolean);
|
|
2497
|
-
const res = {};
|
|
2498
|
-
await Promise.all(
|
|
2499
|
-
connectedChainIds.map(async (_chainId) => {
|
|
2500
|
-
const signers = await getOfflineSigners({
|
|
2501
|
-
chainId: _chainId
|
|
2502
|
-
});
|
|
2503
|
-
res[_chainId] = signers;
|
|
2504
|
-
})
|
|
2505
|
-
);
|
|
2506
|
-
return res;
|
|
2507
|
-
},
|
|
2508
|
-
{
|
|
2509
|
-
enabled: Boolean(accounts)
|
|
2510
|
-
}
|
|
2511
|
-
);
|
|
2512
2510
|
const query = (0, import_react_query2.useQuery)(
|
|
2513
2511
|
[
|
|
2514
2512
|
"USE_OFFLINE_SIGNERS",
|
|
2515
2513
|
{
|
|
2516
2514
|
args,
|
|
2517
|
-
|
|
2515
|
+
accounts
|
|
2518
2516
|
}
|
|
2519
2517
|
],
|
|
2520
2518
|
async () => {
|
|
2521
|
-
if (!
|
|
2519
|
+
if (!accounts)
|
|
2522
2520
|
return void 0;
|
|
2523
|
-
const connectedChainIds = Object.keys(
|
|
2521
|
+
const connectedChainIds = Object.keys(accounts).map(([chainId]) => chainId).filter(Boolean);
|
|
2524
2522
|
if (args == null ? void 0 : args.chainId) {
|
|
2525
2523
|
const offlineSigners = await getOfflineSigners({
|
|
2526
2524
|
chainId: args.chainId
|
|
@@ -2538,7 +2536,7 @@ var useOfflineSigners = (args) => {
|
|
|
2538
2536
|
);
|
|
2539
2537
|
return res;
|
|
2540
2538
|
},
|
|
2541
|
-
{ enabled: Boolean(
|
|
2539
|
+
{ enabled: Boolean(accounts), refetchOnMount: false, refetchOnWindowFocus: false }
|
|
2542
2540
|
);
|
|
2543
2541
|
return query;
|
|
2544
2542
|
};
|
|
@@ -2596,6 +2594,27 @@ var useSuggestChainAndConnect = ({ onError, onLoading, onSuccess } = {}) => {
|
|
|
2596
2594
|
suggestAndConnectAsync: mutation.mutateAsync
|
|
2597
2595
|
};
|
|
2598
2596
|
};
|
|
2597
|
+
var useChain = ({ chainId }) => {
|
|
2598
|
+
const chains = useGrazInternalStore((x) => x.chains);
|
|
2599
|
+
const chain = chains == null ? void 0 : chains.find((x) => x.chainId === chainId);
|
|
2600
|
+
if (!chain)
|
|
2601
|
+
return;
|
|
2602
|
+
const currencies9 = chain.currencies;
|
|
2603
|
+
const convertMinimalDenomToDenom = (searchMinimalDenom, value) => {
|
|
2604
|
+
const currency = chain.currencies.find((x) => x.coinMinimalDenom === searchMinimalDenom);
|
|
2605
|
+
if (!currency)
|
|
2606
|
+
return;
|
|
2607
|
+
return {
|
|
2608
|
+
denom: currency.coinDenom,
|
|
2609
|
+
value: Number(value) * Math.pow(10, currency.coinDecimals)
|
|
2610
|
+
};
|
|
2611
|
+
};
|
|
2612
|
+
return {
|
|
2613
|
+
convertMinimalDenomToDenom,
|
|
2614
|
+
currencies: currencies9,
|
|
2615
|
+
data: chain
|
|
2616
|
+
};
|
|
2617
|
+
};
|
|
2599
2618
|
|
|
2600
2619
|
// src/hooks/clients.ts
|
|
2601
2620
|
var import_stargate2 = require("@cosmjs/stargate");
|
|
@@ -2610,7 +2629,7 @@ var useConnectClient = (args) => {
|
|
|
2610
2629
|
const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
|
|
2611
2630
|
const query = (0, import_react_query4.useQuery)(
|
|
2612
2631
|
[
|
|
2613
|
-
"
|
|
2632
|
+
"USE_CONNECT_CLIENT",
|
|
2614
2633
|
{
|
|
2615
2634
|
client: _client,
|
|
2616
2635
|
chainId: args == null ? void 0 : args.chainId,
|
|
@@ -2657,7 +2676,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2657
2676
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
|
|
2658
2677
|
const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
|
|
2659
2678
|
const queryKey = [
|
|
2660
|
-
"
|
|
2679
|
+
"USE_CONNECT_SIGNING_CLIENT",
|
|
2661
2680
|
{ client: _client, chainId: args == null ? void 0 : args.chainId, options: args == null ? void 0 : args.options }
|
|
2662
2681
|
];
|
|
2663
2682
|
const query = (0, import_react_query4.useQuery)(
|
|
@@ -2719,21 +2738,57 @@ var useConnectSigningClient = (args) => {
|
|
|
2719
2738
|
// src/hooks/methods.ts
|
|
2720
2739
|
var import_encoding2 = require("@cosmjs/encoding");
|
|
2721
2740
|
var import_react_query5 = require("@tanstack/react-query");
|
|
2722
|
-
var
|
|
2723
|
-
const
|
|
2741
|
+
var useBalance = (args) => {
|
|
2742
|
+
const _chains = useGrazInternalStore.getState().chains;
|
|
2743
|
+
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2744
|
+
const { data: client } = useConnectClient({
|
|
2745
|
+
client: "stargate",
|
|
2746
|
+
chainId: args.chainId,
|
|
2747
|
+
enabled: Boolean(chain) && Boolean(args.bech32Address)
|
|
2748
|
+
});
|
|
2749
|
+
const query = (0, import_react_query5.useQuery)(
|
|
2750
|
+
[
|
|
2751
|
+
"USE_BALANCE",
|
|
2752
|
+
{
|
|
2753
|
+
client,
|
|
2754
|
+
...args,
|
|
2755
|
+
_chains
|
|
2756
|
+
}
|
|
2757
|
+
],
|
|
2758
|
+
async () => {
|
|
2759
|
+
if (client) {
|
|
2760
|
+
const res = await getBalance({
|
|
2761
|
+
client,
|
|
2762
|
+
bech32Address: (0, import_encoding2.toBech32)(chain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data),
|
|
2763
|
+
searchDenom: args.searchDenom
|
|
2764
|
+
});
|
|
2765
|
+
return res;
|
|
2766
|
+
}
|
|
2767
|
+
return void 0;
|
|
2768
|
+
},
|
|
2769
|
+
{
|
|
2770
|
+
enabled: Boolean(args.bech32Address) && Boolean(chain) && (Boolean(client) || Boolean(args.searchDenom)),
|
|
2771
|
+
refetchOnMount: false,
|
|
2772
|
+
refetchOnReconnect: true,
|
|
2773
|
+
refetchOnWindowFocus: false
|
|
2774
|
+
}
|
|
2775
|
+
);
|
|
2776
|
+
return query;
|
|
2777
|
+
};
|
|
2778
|
+
var useAllBalances = (args) => {
|
|
2724
2779
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2725
2780
|
const { data: singleClient } = useConnectClient({
|
|
2726
|
-
client:
|
|
2781
|
+
client: "stargate",
|
|
2727
2782
|
chainId: args.chainId,
|
|
2728
|
-
enabled: Boolean(args.chainId)
|
|
2783
|
+
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2729
2784
|
});
|
|
2730
2785
|
const { data: multiClient } = useConnectClient({
|
|
2731
|
-
client:
|
|
2732
|
-
enabled: !args.chainId
|
|
2786
|
+
client: "stargate",
|
|
2787
|
+
enabled: !args.chainId && Boolean(args.bech32Address)
|
|
2733
2788
|
});
|
|
2734
2789
|
const query = (0, import_react_query5.useQuery)(
|
|
2735
2790
|
[
|
|
2736
|
-
"
|
|
2791
|
+
"USE_ALL_BALANCES",
|
|
2737
2792
|
{
|
|
2738
2793
|
singleClient,
|
|
2739
2794
|
multiClient,
|
|
@@ -2744,10 +2799,9 @@ var useBalances = (args) => {
|
|
|
2744
2799
|
async () => {
|
|
2745
2800
|
if (args.chainId && singleClient) {
|
|
2746
2801
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2747
|
-
const res = await
|
|
2802
|
+
const res = await getAllBalance({
|
|
2748
2803
|
client: singleClient,
|
|
2749
|
-
bech32Address: (0, import_encoding2.toBech32)(singleChain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data)
|
|
2750
|
-
currencies: singleChain.currencies
|
|
2804
|
+
bech32Address: (0, import_encoding2.toBech32)(singleChain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data)
|
|
2751
2805
|
});
|
|
2752
2806
|
return res;
|
|
2753
2807
|
}
|
|
@@ -2759,10 +2813,9 @@ var useBalances = (args) => {
|
|
|
2759
2813
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2760
2814
|
if (!chain)
|
|
2761
2815
|
return;
|
|
2762
|
-
const _res = await
|
|
2816
|
+
const _res = await getAllBalance({
|
|
2763
2817
|
client,
|
|
2764
|
-
bech32Address: (0, import_encoding2.toBech32)(chain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data)
|
|
2765
|
-
currencies: chain.currencies
|
|
2818
|
+
bech32Address: (0, import_encoding2.toBech32)(chain.bech32Config.bech32PrefixAccAddr, (0, import_encoding2.fromBech32)(args.bech32Address).data)
|
|
2766
2819
|
});
|
|
2767
2820
|
res[chainId] = _res;
|
|
2768
2821
|
})
|
|
@@ -2780,20 +2833,95 @@ var useBalances = (args) => {
|
|
|
2780
2833
|
);
|
|
2781
2834
|
return query;
|
|
2782
2835
|
};
|
|
2836
|
+
var useChainBalances = (args) => {
|
|
2837
|
+
const _client = args.client ?? useGrazInternalStore.getState().defaultClient;
|
|
2838
|
+
const _chains = useGrazInternalStore.getState().chains;
|
|
2839
|
+
const { data: singleClient } = useConnectClient({
|
|
2840
|
+
client: _client,
|
|
2841
|
+
chainId: args.chainId,
|
|
2842
|
+
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2843
|
+
});
|
|
2844
|
+
const { data: multiClient } = useConnectClient({
|
|
2845
|
+
client: _client,
|
|
2846
|
+
enabled: !args.chainId && Boolean(args.bech32Address)
|
|
2847
|
+
});
|
|
2848
|
+
const query = (0, import_react_query5.useQuery)(
|
|
2849
|
+
[
|
|
2850
|
+
"USE_CHAIN_BALANCES",
|
|
2851
|
+
{
|
|
2852
|
+
singleClient,
|
|
2853
|
+
multiClient,
|
|
2854
|
+
...args,
|
|
2855
|
+
_chains
|
|
2856
|
+
}
|
|
2857
|
+
],
|
|
2858
|
+
async () => {
|
|
2859
|
+
if (args.chainId && singleClient) {
|
|
2860
|
+
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2861
|
+
const res = await Promise.all(
|
|
2862
|
+
singleChain.currencies.map(
|
|
2863
|
+
(currency) => getBalance({
|
|
2864
|
+
client: singleClient,
|
|
2865
|
+
bech32Address: (0, import_encoding2.toBech32)(
|
|
2866
|
+
singleChain.bech32Config.bech32PrefixAccAddr,
|
|
2867
|
+
(0, import_encoding2.fromBech32)(args.bech32Address).data
|
|
2868
|
+
),
|
|
2869
|
+
searchDenom: currency.coinMinimalDenom
|
|
2870
|
+
})
|
|
2871
|
+
)
|
|
2872
|
+
);
|
|
2873
|
+
return res;
|
|
2874
|
+
}
|
|
2875
|
+
if (!args.chainId && multiClient) {
|
|
2876
|
+
const multiChain = Object.entries(multiClient);
|
|
2877
|
+
const res = {};
|
|
2878
|
+
await Promise.all(
|
|
2879
|
+
multiChain.map(async ([chainId, client]) => {
|
|
2880
|
+
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2881
|
+
if (!chain)
|
|
2882
|
+
return;
|
|
2883
|
+
const _res = await Promise.all(
|
|
2884
|
+
chain.currencies.filter((i) => !i.coinMinimalDenom.startsWith("cw20:")).map(
|
|
2885
|
+
(currency) => getBalance({
|
|
2886
|
+
client,
|
|
2887
|
+
bech32Address: (0, import_encoding2.toBech32)(
|
|
2888
|
+
chain.bech32Config.bech32PrefixAccAddr,
|
|
2889
|
+
(0, import_encoding2.fromBech32)(args.bech32Address).data
|
|
2890
|
+
),
|
|
2891
|
+
searchDenom: currency.coinMinimalDenom
|
|
2892
|
+
})
|
|
2893
|
+
)
|
|
2894
|
+
);
|
|
2895
|
+
res[chainId] = _res;
|
|
2896
|
+
})
|
|
2897
|
+
);
|
|
2898
|
+
return res;
|
|
2899
|
+
}
|
|
2900
|
+
return void 0;
|
|
2901
|
+
},
|
|
2902
|
+
{
|
|
2903
|
+
enabled: Boolean(args.bech32Address) && Boolean(_chains) && (Boolean(singleClient) || Boolean(multiClient)),
|
|
2904
|
+
refetchOnMount: false,
|
|
2905
|
+
refetchOnReconnect: true,
|
|
2906
|
+
refetchOnWindowFocus: false
|
|
2907
|
+
}
|
|
2908
|
+
);
|
|
2909
|
+
return query;
|
|
2910
|
+
};
|
|
2783
2911
|
var useBalanceStaked = (args) => {
|
|
2784
2912
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2785
2913
|
const { data: singleClient } = useConnectClient({
|
|
2786
2914
|
client: "stargate",
|
|
2787
2915
|
chainId: args.chainId,
|
|
2788
|
-
enabled: Boolean(args.chainId)
|
|
2916
|
+
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2789
2917
|
});
|
|
2790
2918
|
const { data: multiClient } = useConnectClient({
|
|
2791
2919
|
client: "stargate",
|
|
2792
|
-
enabled: !args.chainId
|
|
2920
|
+
enabled: !args.chainId && Boolean(args.bech32Address)
|
|
2793
2921
|
});
|
|
2794
2922
|
const query = (0, import_react_query5.useQuery)(
|
|
2795
2923
|
[
|
|
2796
|
-
"
|
|
2924
|
+
"useBalanceStaked",
|
|
2797
2925
|
{
|
|
2798
2926
|
singleClient,
|
|
2799
2927
|
multiClient,
|
|
@@ -2878,6 +3006,188 @@ var useSendTokens = ({
|
|
|
2878
3006
|
status: mutation.status
|
|
2879
3007
|
};
|
|
2880
3008
|
};
|
|
3009
|
+
var useSendIbcTokens = ({
|
|
3010
|
+
chainId,
|
|
3011
|
+
signingClientOptions,
|
|
3012
|
+
onError,
|
|
3013
|
+
onLoading,
|
|
3014
|
+
onSuccess
|
|
3015
|
+
}) => {
|
|
3016
|
+
const { data: _signingClient } = useConnectSigningClient({
|
|
3017
|
+
chainId,
|
|
3018
|
+
client: "stargate",
|
|
3019
|
+
options: signingClientOptions
|
|
3020
|
+
});
|
|
3021
|
+
const queryKey = [
|
|
3022
|
+
"USE_SEND_IBC_TOKENS",
|
|
3023
|
+
{ onError, onLoading, onSuccess, _signingClient, chainId, signingClientOptions }
|
|
3024
|
+
];
|
|
3025
|
+
const mutation = (0, import_react_query5.useMutation)(
|
|
3026
|
+
queryKey,
|
|
3027
|
+
async (args) => {
|
|
3028
|
+
if (!_signingClient)
|
|
3029
|
+
throw new Error("Signing client is not available");
|
|
3030
|
+
const res = await sendIbcTokens({ signingClient: _signingClient, ...args });
|
|
3031
|
+
return res;
|
|
3032
|
+
},
|
|
3033
|
+
{
|
|
3034
|
+
onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
|
|
3035
|
+
onMutate: onLoading,
|
|
3036
|
+
onSuccess: (txResponse) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(txResponse))
|
|
3037
|
+
}
|
|
3038
|
+
);
|
|
3039
|
+
return {
|
|
3040
|
+
error: mutation.error,
|
|
3041
|
+
isLoading: mutation.isLoading,
|
|
3042
|
+
isSuccess: mutation.isSuccess,
|
|
3043
|
+
sendIbcTokens: mutation.mutate,
|
|
3044
|
+
sendIbcTokensAsync: mutation.mutateAsync,
|
|
3045
|
+
status: mutation.status
|
|
3046
|
+
};
|
|
3047
|
+
};
|
|
3048
|
+
var useInstantiateContract = ({
|
|
3049
|
+
chainId,
|
|
3050
|
+
codeId,
|
|
3051
|
+
signingClientOptions,
|
|
3052
|
+
onError,
|
|
3053
|
+
onLoading,
|
|
3054
|
+
onSuccess
|
|
3055
|
+
}) => {
|
|
3056
|
+
var _a;
|
|
3057
|
+
const account = useAccount({
|
|
3058
|
+
chainId
|
|
3059
|
+
});
|
|
3060
|
+
const accountAddress = (_a = account == null ? void 0 : account.account) == null ? void 0 : _a.bech32Address;
|
|
3061
|
+
const { data: _signingClient } = useConnectSigningClient({
|
|
3062
|
+
chainId,
|
|
3063
|
+
client: "cosmWasm",
|
|
3064
|
+
options: signingClientOptions
|
|
3065
|
+
});
|
|
3066
|
+
const mutationFn = (args) => {
|
|
3067
|
+
if (!accountAddress)
|
|
3068
|
+
throw new Error("senderAddress is undefined");
|
|
3069
|
+
if (!_signingClient)
|
|
3070
|
+
throw new Error("Signing client is not available");
|
|
3071
|
+
return instantiateContract({
|
|
3072
|
+
...args,
|
|
3073
|
+
signingClient: _signingClient,
|
|
3074
|
+
fee: args.fee ?? "auto",
|
|
3075
|
+
senderAddress: accountAddress,
|
|
3076
|
+
codeId
|
|
3077
|
+
});
|
|
3078
|
+
};
|
|
3079
|
+
const queryKey = ["USE_INSTANTIATE_CONTRACT", onError, onLoading, onSuccess, codeId, accountAddress];
|
|
3080
|
+
const mutation = (0, import_react_query5.useMutation)(queryKey, mutationFn, {
|
|
3081
|
+
onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
|
|
3082
|
+
onMutate: onLoading,
|
|
3083
|
+
onSuccess: (instantiateResult) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(instantiateResult))
|
|
3084
|
+
});
|
|
3085
|
+
return {
|
|
3086
|
+
error: mutation.error,
|
|
3087
|
+
isLoading: mutation.isLoading,
|
|
3088
|
+
isSuccess: mutation.isSuccess,
|
|
3089
|
+
instantiateContract: mutation.mutate,
|
|
3090
|
+
instantiateContractAsync: mutation.mutateAsync,
|
|
3091
|
+
status: mutation.status
|
|
3092
|
+
};
|
|
3093
|
+
};
|
|
3094
|
+
var useExecuteContract = ({
|
|
3095
|
+
chainId,
|
|
3096
|
+
contractAddress,
|
|
3097
|
+
signingClientOptions,
|
|
3098
|
+
onError,
|
|
3099
|
+
onLoading,
|
|
3100
|
+
onSuccess
|
|
3101
|
+
}) => {
|
|
3102
|
+
var _a;
|
|
3103
|
+
const account = useAccount({
|
|
3104
|
+
chainId
|
|
3105
|
+
});
|
|
3106
|
+
const accountAddress = (_a = account == null ? void 0 : account.account) == null ? void 0 : _a.bech32Address;
|
|
3107
|
+
const { data: _signingClient } = useConnectSigningClient({
|
|
3108
|
+
chainId,
|
|
3109
|
+
client: "cosmWasm",
|
|
3110
|
+
options: signingClientOptions
|
|
3111
|
+
});
|
|
3112
|
+
const mutationFn = (args) => {
|
|
3113
|
+
if (!accountAddress)
|
|
3114
|
+
throw new Error("senderAddress is undefined");
|
|
3115
|
+
if (!_signingClient)
|
|
3116
|
+
throw new Error("Signing client is not available");
|
|
3117
|
+
return executeContract({
|
|
3118
|
+
...args,
|
|
3119
|
+
signingClient: _signingClient,
|
|
3120
|
+
fee: args.fee ?? "auto",
|
|
3121
|
+
senderAddress: accountAddress,
|
|
3122
|
+
contractAddress,
|
|
3123
|
+
memo: args.memo ?? "",
|
|
3124
|
+
funds: args.funds ?? []
|
|
3125
|
+
});
|
|
3126
|
+
};
|
|
3127
|
+
const queryKey = ["USE_EXECUTE_CONTRACT", onError, onLoading, onSuccess, contractAddress, accountAddress];
|
|
3128
|
+
const mutation = (0, import_react_query5.useMutation)(queryKey, mutationFn, {
|
|
3129
|
+
onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
|
|
3130
|
+
onMutate: onLoading,
|
|
3131
|
+
onSuccess: (executeResult) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(executeResult))
|
|
3132
|
+
});
|
|
3133
|
+
return {
|
|
3134
|
+
error: mutation.error,
|
|
3135
|
+
isLoading: mutation.isLoading,
|
|
3136
|
+
isSuccess: mutation.isSuccess,
|
|
3137
|
+
executeContract: mutation.mutate,
|
|
3138
|
+
executeContractAsync: mutation.mutateAsync,
|
|
3139
|
+
status: mutation.status
|
|
3140
|
+
};
|
|
3141
|
+
};
|
|
3142
|
+
var useQuerySmart = ({
|
|
3143
|
+
address,
|
|
3144
|
+
queryMsg,
|
|
3145
|
+
chainId
|
|
3146
|
+
}) => {
|
|
3147
|
+
const { data: client } = useConnectClient({
|
|
3148
|
+
client: "cosmWasm",
|
|
3149
|
+
chainId
|
|
3150
|
+
});
|
|
3151
|
+
const query = (0, import_react_query5.useQuery)(
|
|
3152
|
+
["USE_QUERY_SMART", { address, queryMsg, chainId }],
|
|
3153
|
+
() => {
|
|
3154
|
+
if (!address || !queryMsg)
|
|
3155
|
+
throw new Error("address or queryMsg undefined");
|
|
3156
|
+
if (!client)
|
|
3157
|
+
throw new Error("Client is not available");
|
|
3158
|
+
return getQuerySmart({ address, queryMsg, client });
|
|
3159
|
+
},
|
|
3160
|
+
{
|
|
3161
|
+
enabled: Boolean(address) && Boolean(queryMsg)
|
|
3162
|
+
}
|
|
3163
|
+
);
|
|
3164
|
+
return query;
|
|
3165
|
+
};
|
|
3166
|
+
var useQueryRaw = ({
|
|
3167
|
+
address,
|
|
3168
|
+
key,
|
|
3169
|
+
chainId
|
|
3170
|
+
}) => {
|
|
3171
|
+
const { data: client } = useConnectClient({
|
|
3172
|
+
client: "cosmWasm",
|
|
3173
|
+
chainId
|
|
3174
|
+
});
|
|
3175
|
+
const queryKey = ["USE_QUERY_RAW", key, address];
|
|
3176
|
+
const query = (0, import_react_query5.useQuery)(
|
|
3177
|
+
queryKey,
|
|
3178
|
+
({ queryKey: [, _address] }) => {
|
|
3179
|
+
if (!address || !key)
|
|
3180
|
+
throw new Error("address or key undefined");
|
|
3181
|
+
if (!client)
|
|
3182
|
+
throw new Error("Client is not available");
|
|
3183
|
+
return getQueryRaw({ address, keyStr: key, client });
|
|
3184
|
+
},
|
|
3185
|
+
{
|
|
3186
|
+
enabled: Boolean(address) && Boolean(key)
|
|
3187
|
+
}
|
|
3188
|
+
);
|
|
3189
|
+
return query;
|
|
3190
|
+
};
|
|
2881
3191
|
|
|
2882
3192
|
// src/provider/events.tsx
|
|
2883
3193
|
var import_react2 = require("react");
|
|
@@ -2965,6 +3275,43 @@ var GrazProvider = ({ children, grazConfig, ...props }) => {
|
|
|
2965
3275
|
children
|
|
2966
3276
|
] }) }, "graz-provider");
|
|
2967
3277
|
};
|
|
3278
|
+
|
|
3279
|
+
// src/utils/conversion.ts
|
|
3280
|
+
var convertMicroDenomToDenom = (value, decimals) => {
|
|
3281
|
+
if (decimals === 0) {
|
|
3282
|
+
return Number(value);
|
|
3283
|
+
}
|
|
3284
|
+
return handleNaN(Number(value) / Math.pow(10, decimals));
|
|
3285
|
+
};
|
|
3286
|
+
var convertDenomToMicroDenom = (value, decimals) => {
|
|
3287
|
+
if (decimals === 0) {
|
|
3288
|
+
return Number(value);
|
|
3289
|
+
}
|
|
3290
|
+
return handleNaN(parseInt(String(Number(value) * Math.pow(10, decimals)), 10));
|
|
3291
|
+
};
|
|
3292
|
+
var convertFromMicroDenom = (denom) => {
|
|
3293
|
+
return denom.substring(1).toUpperCase();
|
|
3294
|
+
};
|
|
3295
|
+
var convertToFixedDecimals = (value, fractionDigits = 2) => {
|
|
3296
|
+
const amount = Number(value);
|
|
3297
|
+
return amount > 0.01 ? amount.toFixed(fractionDigits) : String(amount);
|
|
3298
|
+
};
|
|
3299
|
+
var formatTokenName = (name) => {
|
|
3300
|
+
if (name) {
|
|
3301
|
+
return name.slice(0, 1).toUpperCase() + name.slice(1).toLowerCase();
|
|
3302
|
+
}
|
|
3303
|
+
return "";
|
|
3304
|
+
};
|
|
3305
|
+
var handleNaN = (value) => {
|
|
3306
|
+
return isNaN(value) ? 0 : value;
|
|
3307
|
+
};
|
|
3308
|
+
var truncate = (string, slice) => {
|
|
3309
|
+
if (string && slice && string.length <= slice)
|
|
3310
|
+
return string;
|
|
3311
|
+
const pre = string == null ? void 0 : string.slice(0, slice || 8);
|
|
3312
|
+
const post = string == null ? void 0 : string.slice((slice || 8) * -1);
|
|
3313
|
+
return `${pre}...${post}`;
|
|
3314
|
+
};
|
|
2968
3315
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2969
3316
|
0 && (module.exports = {
|
|
2970
3317
|
GrazEvents,
|
|
@@ -2977,14 +3324,20 @@ var GrazProvider = ({ children, grazConfig, ...props }) => {
|
|
|
2977
3324
|
connect,
|
|
2978
3325
|
connectClient,
|
|
2979
3326
|
connectSigningClient,
|
|
3327
|
+
convertDenomToMicroDenom,
|
|
3328
|
+
convertFromMicroDenom,
|
|
3329
|
+
convertMicroDenomToDenom,
|
|
3330
|
+
convertToFixedDecimals,
|
|
2980
3331
|
defineChain,
|
|
2981
3332
|
defineChainInfo,
|
|
2982
3333
|
defineChains,
|
|
2983
3334
|
disconnect,
|
|
2984
3335
|
executeContract,
|
|
3336
|
+
formatTokenName,
|
|
3337
|
+
getAllBalance,
|
|
2985
3338
|
getAvailableWallets,
|
|
3339
|
+
getBalance,
|
|
2986
3340
|
getBalanceStaked,
|
|
2987
|
-
getBalances,
|
|
2988
3341
|
getCosmostation,
|
|
2989
3342
|
getKeplr,
|
|
2990
3343
|
getLeap,
|
|
@@ -2998,6 +3351,7 @@ var GrazProvider = ({ children, grazConfig, ...props }) => {
|
|
|
2998
3351
|
getWCLeap,
|
|
2999
3352
|
getWallet,
|
|
3000
3353
|
getWalletConnect,
|
|
3354
|
+
handleNaN,
|
|
3001
3355
|
instantiateContract,
|
|
3002
3356
|
mainnetChains,
|
|
3003
3357
|
mainnetChainsArray,
|
|
@@ -3008,19 +3362,28 @@ var GrazProvider = ({ children, grazConfig, ...props }) => {
|
|
|
3008
3362
|
suggestChainAndConnect,
|
|
3009
3363
|
testnetChains,
|
|
3010
3364
|
testnetChainsArray,
|
|
3365
|
+
truncate,
|
|
3011
3366
|
useAccount,
|
|
3012
3367
|
useActiveChainValidators,
|
|
3013
3368
|
useActiveWalletType,
|
|
3369
|
+
useAllBalances,
|
|
3370
|
+
useBalance,
|
|
3014
3371
|
useBalanceStaked,
|
|
3015
|
-
|
|
3372
|
+
useChain,
|
|
3373
|
+
useChainBalances,
|
|
3016
3374
|
useCheckWallet,
|
|
3017
3375
|
useConnect,
|
|
3018
3376
|
useConnectClient,
|
|
3019
3377
|
useConnectSigningClient,
|
|
3020
3378
|
useDisconnect,
|
|
3379
|
+
useExecuteContract,
|
|
3021
3380
|
useGrazEvents,
|
|
3381
|
+
useInstantiateContract,
|
|
3022
3382
|
useOfflineSigners,
|
|
3383
|
+
useQueryRaw,
|
|
3384
|
+
useQuerySmart,
|
|
3023
3385
|
useRecentChain,
|
|
3386
|
+
useSendIbcTokens,
|
|
3024
3387
|
useSendTokens,
|
|
3025
3388
|
useSuggestChain,
|
|
3026
3389
|
useSuggestChainAndConnect
|