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.mjs
CHANGED
|
@@ -1871,16 +1871,19 @@ var configureGraz = (args) => {
|
|
|
1871
1871
|
};
|
|
1872
1872
|
|
|
1873
1873
|
// src/actions/methods.ts
|
|
1874
|
-
var
|
|
1874
|
+
var getAllBalance = async ({
|
|
1875
|
+
bech32Address,
|
|
1876
|
+
client
|
|
1877
|
+
}) => {
|
|
1878
|
+
const balances = await client.getAllBalances(bech32Address);
|
|
1879
|
+
return balances;
|
|
1880
|
+
};
|
|
1881
|
+
var getBalance = async ({
|
|
1875
1882
|
bech32Address,
|
|
1876
1883
|
client,
|
|
1877
|
-
|
|
1884
|
+
searchDenom
|
|
1878
1885
|
}) => {
|
|
1879
|
-
const balances = await
|
|
1880
|
-
currencies9.filter((i) => !i.coinMinimalDenom.startsWith("cw20:")).map(async (item) => {
|
|
1881
|
-
return client.getBalance(bech32Address, item.coinMinimalDenom);
|
|
1882
|
-
})
|
|
1883
|
-
);
|
|
1886
|
+
const balances = await client.getBalance(bech32Address, searchDenom);
|
|
1884
1887
|
return balances;
|
|
1885
1888
|
};
|
|
1886
1889
|
var getBalanceStaked = async ({
|
|
@@ -2396,39 +2399,18 @@ var useDisconnect = ({ onError, onLoading, onSuccess } = {}) => {
|
|
|
2396
2399
|
};
|
|
2397
2400
|
var useOfflineSigners = (args) => {
|
|
2398
2401
|
const accounts = useAccount();
|
|
2399
|
-
const { data } = useQuery2(
|
|
2400
|
-
["OFFLINE_SIGNERS", { accounts }],
|
|
2401
|
-
async () => {
|
|
2402
|
-
if (!accounts)
|
|
2403
|
-
return void 0;
|
|
2404
|
-
const connectedChainIds = Object.values(accounts).map((i) => i == null ? void 0 : i.chainId).filter(Boolean);
|
|
2405
|
-
const res = {};
|
|
2406
|
-
await Promise.all(
|
|
2407
|
-
connectedChainIds.map(async (_chainId) => {
|
|
2408
|
-
const signers = await getOfflineSigners({
|
|
2409
|
-
chainId: _chainId
|
|
2410
|
-
});
|
|
2411
|
-
res[_chainId] = signers;
|
|
2412
|
-
})
|
|
2413
|
-
);
|
|
2414
|
-
return res;
|
|
2415
|
-
},
|
|
2416
|
-
{
|
|
2417
|
-
enabled: Boolean(accounts)
|
|
2418
|
-
}
|
|
2419
|
-
);
|
|
2420
2402
|
const query = useQuery2(
|
|
2421
2403
|
[
|
|
2422
2404
|
"USE_OFFLINE_SIGNERS",
|
|
2423
2405
|
{
|
|
2424
2406
|
args,
|
|
2425
|
-
|
|
2407
|
+
accounts
|
|
2426
2408
|
}
|
|
2427
2409
|
],
|
|
2428
2410
|
async () => {
|
|
2429
|
-
if (!
|
|
2411
|
+
if (!accounts)
|
|
2430
2412
|
return void 0;
|
|
2431
|
-
const connectedChainIds = Object.keys(
|
|
2413
|
+
const connectedChainIds = Object.keys(accounts).map(([chainId]) => chainId).filter(Boolean);
|
|
2432
2414
|
if (args == null ? void 0 : args.chainId) {
|
|
2433
2415
|
const offlineSigners = await getOfflineSigners({
|
|
2434
2416
|
chainId: args.chainId
|
|
@@ -2446,7 +2428,7 @@ var useOfflineSigners = (args) => {
|
|
|
2446
2428
|
);
|
|
2447
2429
|
return res;
|
|
2448
2430
|
},
|
|
2449
|
-
{ enabled: Boolean(
|
|
2431
|
+
{ enabled: Boolean(accounts), refetchOnMount: false, refetchOnWindowFocus: false }
|
|
2450
2432
|
);
|
|
2451
2433
|
return query;
|
|
2452
2434
|
};
|
|
@@ -2504,6 +2486,27 @@ var useSuggestChainAndConnect = ({ onError, onLoading, onSuccess } = {}) => {
|
|
|
2504
2486
|
suggestAndConnectAsync: mutation.mutateAsync
|
|
2505
2487
|
};
|
|
2506
2488
|
};
|
|
2489
|
+
var useChain = ({ chainId }) => {
|
|
2490
|
+
const chains = useGrazInternalStore((x) => x.chains);
|
|
2491
|
+
const chain = chains == null ? void 0 : chains.find((x) => x.chainId === chainId);
|
|
2492
|
+
if (!chain)
|
|
2493
|
+
return;
|
|
2494
|
+
const currencies9 = chain.currencies;
|
|
2495
|
+
const convertMinimalDenomToDenom = (searchMinimalDenom, value) => {
|
|
2496
|
+
const currency = chain.currencies.find((x) => x.coinMinimalDenom === searchMinimalDenom);
|
|
2497
|
+
if (!currency)
|
|
2498
|
+
return;
|
|
2499
|
+
return {
|
|
2500
|
+
denom: currency.coinDenom,
|
|
2501
|
+
value: Number(value) * Math.pow(10, currency.coinDecimals)
|
|
2502
|
+
};
|
|
2503
|
+
};
|
|
2504
|
+
return {
|
|
2505
|
+
convertMinimalDenomToDenom,
|
|
2506
|
+
currencies: currencies9,
|
|
2507
|
+
data: chain
|
|
2508
|
+
};
|
|
2509
|
+
};
|
|
2507
2510
|
|
|
2508
2511
|
// src/hooks/clients.ts
|
|
2509
2512
|
import { GasPrice } from "@cosmjs/stargate";
|
|
@@ -2518,7 +2521,7 @@ var useConnectClient = (args) => {
|
|
|
2518
2521
|
const chains = (args == null ? void 0 : args.onlyConnectedChains) ? sessionChains : _chains;
|
|
2519
2522
|
const query = useQuery4(
|
|
2520
2523
|
[
|
|
2521
|
-
"
|
|
2524
|
+
"USE_CONNECT_CLIENT",
|
|
2522
2525
|
{
|
|
2523
2526
|
client: _client,
|
|
2524
2527
|
chainId: args == null ? void 0 : args.chainId,
|
|
@@ -2565,7 +2568,7 @@ var useConnectSigningClient = (args) => {
|
|
|
2565
2568
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === (args == null ? void 0 : args.chainId));
|
|
2566
2569
|
const sessionChains = sessionChainIds == null ? void 0 : sessionChainIds.map((i) => _chains.find((x) => x.chainId === i));
|
|
2567
2570
|
const queryKey = [
|
|
2568
|
-
"
|
|
2571
|
+
"USE_CONNECT_SIGNING_CLIENT",
|
|
2569
2572
|
{ client: _client, chainId: args == null ? void 0 : args.chainId, options: args == null ? void 0 : args.options }
|
|
2570
2573
|
];
|
|
2571
2574
|
const query = useQuery4(
|
|
@@ -2627,21 +2630,57 @@ var useConnectSigningClient = (args) => {
|
|
|
2627
2630
|
// src/hooks/methods.ts
|
|
2628
2631
|
import { fromBech32 as fromBech322, toBech32 } from "@cosmjs/encoding";
|
|
2629
2632
|
import { useMutation as useMutation3, useQuery as useQuery5 } from "@tanstack/react-query";
|
|
2630
|
-
var
|
|
2631
|
-
const
|
|
2633
|
+
var useBalance = (args) => {
|
|
2634
|
+
const _chains = useGrazInternalStore.getState().chains;
|
|
2635
|
+
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2636
|
+
const { data: client } = useConnectClient({
|
|
2637
|
+
client: "stargate",
|
|
2638
|
+
chainId: args.chainId,
|
|
2639
|
+
enabled: Boolean(chain) && Boolean(args.bech32Address)
|
|
2640
|
+
});
|
|
2641
|
+
const query = useQuery5(
|
|
2642
|
+
[
|
|
2643
|
+
"USE_BALANCE",
|
|
2644
|
+
{
|
|
2645
|
+
client,
|
|
2646
|
+
...args,
|
|
2647
|
+
_chains
|
|
2648
|
+
}
|
|
2649
|
+
],
|
|
2650
|
+
async () => {
|
|
2651
|
+
if (client) {
|
|
2652
|
+
const res = await getBalance({
|
|
2653
|
+
client,
|
|
2654
|
+
bech32Address: toBech32(chain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data),
|
|
2655
|
+
searchDenom: args.searchDenom
|
|
2656
|
+
});
|
|
2657
|
+
return res;
|
|
2658
|
+
}
|
|
2659
|
+
return void 0;
|
|
2660
|
+
},
|
|
2661
|
+
{
|
|
2662
|
+
enabled: Boolean(args.bech32Address) && Boolean(chain) && (Boolean(client) || Boolean(args.searchDenom)),
|
|
2663
|
+
refetchOnMount: false,
|
|
2664
|
+
refetchOnReconnect: true,
|
|
2665
|
+
refetchOnWindowFocus: false
|
|
2666
|
+
}
|
|
2667
|
+
);
|
|
2668
|
+
return query;
|
|
2669
|
+
};
|
|
2670
|
+
var useAllBalances = (args) => {
|
|
2632
2671
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2633
2672
|
const { data: singleClient } = useConnectClient({
|
|
2634
|
-
client:
|
|
2673
|
+
client: "stargate",
|
|
2635
2674
|
chainId: args.chainId,
|
|
2636
|
-
enabled: Boolean(args.chainId)
|
|
2675
|
+
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2637
2676
|
});
|
|
2638
2677
|
const { data: multiClient } = useConnectClient({
|
|
2639
|
-
client:
|
|
2640
|
-
enabled: !args.chainId
|
|
2678
|
+
client: "stargate",
|
|
2679
|
+
enabled: !args.chainId && Boolean(args.bech32Address)
|
|
2641
2680
|
});
|
|
2642
2681
|
const query = useQuery5(
|
|
2643
2682
|
[
|
|
2644
|
-
"
|
|
2683
|
+
"USE_ALL_BALANCES",
|
|
2645
2684
|
{
|
|
2646
2685
|
singleClient,
|
|
2647
2686
|
multiClient,
|
|
@@ -2652,10 +2691,9 @@ var useBalances = (args) => {
|
|
|
2652
2691
|
async () => {
|
|
2653
2692
|
if (args.chainId && singleClient) {
|
|
2654
2693
|
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2655
|
-
const res = await
|
|
2694
|
+
const res = await getAllBalance({
|
|
2656
2695
|
client: singleClient,
|
|
2657
|
-
bech32Address: toBech32(singleChain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data)
|
|
2658
|
-
currencies: singleChain.currencies
|
|
2696
|
+
bech32Address: toBech32(singleChain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data)
|
|
2659
2697
|
});
|
|
2660
2698
|
return res;
|
|
2661
2699
|
}
|
|
@@ -2667,10 +2705,9 @@ var useBalances = (args) => {
|
|
|
2667
2705
|
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2668
2706
|
if (!chain)
|
|
2669
2707
|
return;
|
|
2670
|
-
const _res = await
|
|
2708
|
+
const _res = await getAllBalance({
|
|
2671
2709
|
client,
|
|
2672
|
-
bech32Address: toBech32(chain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data)
|
|
2673
|
-
currencies: chain.currencies
|
|
2710
|
+
bech32Address: toBech32(chain.bech32Config.bech32PrefixAccAddr, fromBech322(args.bech32Address).data)
|
|
2674
2711
|
});
|
|
2675
2712
|
res[chainId] = _res;
|
|
2676
2713
|
})
|
|
@@ -2688,20 +2725,95 @@ var useBalances = (args) => {
|
|
|
2688
2725
|
);
|
|
2689
2726
|
return query;
|
|
2690
2727
|
};
|
|
2728
|
+
var useChainBalances = (args) => {
|
|
2729
|
+
const _client = args.client ?? useGrazInternalStore.getState().defaultClient;
|
|
2730
|
+
const _chains = useGrazInternalStore.getState().chains;
|
|
2731
|
+
const { data: singleClient } = useConnectClient({
|
|
2732
|
+
client: _client,
|
|
2733
|
+
chainId: args.chainId,
|
|
2734
|
+
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2735
|
+
});
|
|
2736
|
+
const { data: multiClient } = useConnectClient({
|
|
2737
|
+
client: _client,
|
|
2738
|
+
enabled: !args.chainId && Boolean(args.bech32Address)
|
|
2739
|
+
});
|
|
2740
|
+
const query = useQuery5(
|
|
2741
|
+
[
|
|
2742
|
+
"USE_CHAIN_BALANCES",
|
|
2743
|
+
{
|
|
2744
|
+
singleClient,
|
|
2745
|
+
multiClient,
|
|
2746
|
+
...args,
|
|
2747
|
+
_chains
|
|
2748
|
+
}
|
|
2749
|
+
],
|
|
2750
|
+
async () => {
|
|
2751
|
+
if (args.chainId && singleClient) {
|
|
2752
|
+
const singleChain = _chains == null ? void 0 : _chains.find((i) => i.chainId === args.chainId);
|
|
2753
|
+
const res = await Promise.all(
|
|
2754
|
+
singleChain.currencies.map(
|
|
2755
|
+
(currency) => getBalance({
|
|
2756
|
+
client: singleClient,
|
|
2757
|
+
bech32Address: toBech32(
|
|
2758
|
+
singleChain.bech32Config.bech32PrefixAccAddr,
|
|
2759
|
+
fromBech322(args.bech32Address).data
|
|
2760
|
+
),
|
|
2761
|
+
searchDenom: currency.coinMinimalDenom
|
|
2762
|
+
})
|
|
2763
|
+
)
|
|
2764
|
+
);
|
|
2765
|
+
return res;
|
|
2766
|
+
}
|
|
2767
|
+
if (!args.chainId && multiClient) {
|
|
2768
|
+
const multiChain = Object.entries(multiClient);
|
|
2769
|
+
const res = {};
|
|
2770
|
+
await Promise.all(
|
|
2771
|
+
multiChain.map(async ([chainId, client]) => {
|
|
2772
|
+
const chain = _chains == null ? void 0 : _chains.find((i) => i.chainId === chainId);
|
|
2773
|
+
if (!chain)
|
|
2774
|
+
return;
|
|
2775
|
+
const _res = await Promise.all(
|
|
2776
|
+
chain.currencies.filter((i) => !i.coinMinimalDenom.startsWith("cw20:")).map(
|
|
2777
|
+
(currency) => getBalance({
|
|
2778
|
+
client,
|
|
2779
|
+
bech32Address: toBech32(
|
|
2780
|
+
chain.bech32Config.bech32PrefixAccAddr,
|
|
2781
|
+
fromBech322(args.bech32Address).data
|
|
2782
|
+
),
|
|
2783
|
+
searchDenom: currency.coinMinimalDenom
|
|
2784
|
+
})
|
|
2785
|
+
)
|
|
2786
|
+
);
|
|
2787
|
+
res[chainId] = _res;
|
|
2788
|
+
})
|
|
2789
|
+
);
|
|
2790
|
+
return res;
|
|
2791
|
+
}
|
|
2792
|
+
return void 0;
|
|
2793
|
+
},
|
|
2794
|
+
{
|
|
2795
|
+
enabled: Boolean(args.bech32Address) && Boolean(_chains) && (Boolean(singleClient) || Boolean(multiClient)),
|
|
2796
|
+
refetchOnMount: false,
|
|
2797
|
+
refetchOnReconnect: true,
|
|
2798
|
+
refetchOnWindowFocus: false
|
|
2799
|
+
}
|
|
2800
|
+
);
|
|
2801
|
+
return query;
|
|
2802
|
+
};
|
|
2691
2803
|
var useBalanceStaked = (args) => {
|
|
2692
2804
|
const _chains = useGrazInternalStore.getState().chains;
|
|
2693
2805
|
const { data: singleClient } = useConnectClient({
|
|
2694
2806
|
client: "stargate",
|
|
2695
2807
|
chainId: args.chainId,
|
|
2696
|
-
enabled: Boolean(args.chainId)
|
|
2808
|
+
enabled: Boolean(args.chainId) && Boolean(args.bech32Address)
|
|
2697
2809
|
});
|
|
2698
2810
|
const { data: multiClient } = useConnectClient({
|
|
2699
2811
|
client: "stargate",
|
|
2700
|
-
enabled: !args.chainId
|
|
2812
|
+
enabled: !args.chainId && Boolean(args.bech32Address)
|
|
2701
2813
|
});
|
|
2702
2814
|
const query = useQuery5(
|
|
2703
2815
|
[
|
|
2704
|
-
"
|
|
2816
|
+
"useBalanceStaked",
|
|
2705
2817
|
{
|
|
2706
2818
|
singleClient,
|
|
2707
2819
|
multiClient,
|
|
@@ -2786,6 +2898,188 @@ var useSendTokens = ({
|
|
|
2786
2898
|
status: mutation.status
|
|
2787
2899
|
};
|
|
2788
2900
|
};
|
|
2901
|
+
var useSendIbcTokens = ({
|
|
2902
|
+
chainId,
|
|
2903
|
+
signingClientOptions,
|
|
2904
|
+
onError,
|
|
2905
|
+
onLoading,
|
|
2906
|
+
onSuccess
|
|
2907
|
+
}) => {
|
|
2908
|
+
const { data: _signingClient } = useConnectSigningClient({
|
|
2909
|
+
chainId,
|
|
2910
|
+
client: "stargate",
|
|
2911
|
+
options: signingClientOptions
|
|
2912
|
+
});
|
|
2913
|
+
const queryKey = [
|
|
2914
|
+
"USE_SEND_IBC_TOKENS",
|
|
2915
|
+
{ onError, onLoading, onSuccess, _signingClient, chainId, signingClientOptions }
|
|
2916
|
+
];
|
|
2917
|
+
const mutation = useMutation3(
|
|
2918
|
+
queryKey,
|
|
2919
|
+
async (args) => {
|
|
2920
|
+
if (!_signingClient)
|
|
2921
|
+
throw new Error("Signing client is not available");
|
|
2922
|
+
const res = await sendIbcTokens({ signingClient: _signingClient, ...args });
|
|
2923
|
+
return res;
|
|
2924
|
+
},
|
|
2925
|
+
{
|
|
2926
|
+
onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
|
|
2927
|
+
onMutate: onLoading,
|
|
2928
|
+
onSuccess: (txResponse) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(txResponse))
|
|
2929
|
+
}
|
|
2930
|
+
);
|
|
2931
|
+
return {
|
|
2932
|
+
error: mutation.error,
|
|
2933
|
+
isLoading: mutation.isLoading,
|
|
2934
|
+
isSuccess: mutation.isSuccess,
|
|
2935
|
+
sendIbcTokens: mutation.mutate,
|
|
2936
|
+
sendIbcTokensAsync: mutation.mutateAsync,
|
|
2937
|
+
status: mutation.status
|
|
2938
|
+
};
|
|
2939
|
+
};
|
|
2940
|
+
var useInstantiateContract = ({
|
|
2941
|
+
chainId,
|
|
2942
|
+
codeId,
|
|
2943
|
+
signingClientOptions,
|
|
2944
|
+
onError,
|
|
2945
|
+
onLoading,
|
|
2946
|
+
onSuccess
|
|
2947
|
+
}) => {
|
|
2948
|
+
var _a;
|
|
2949
|
+
const account = useAccount({
|
|
2950
|
+
chainId
|
|
2951
|
+
});
|
|
2952
|
+
const accountAddress = (_a = account == null ? void 0 : account.account) == null ? void 0 : _a.bech32Address;
|
|
2953
|
+
const { data: _signingClient } = useConnectSigningClient({
|
|
2954
|
+
chainId,
|
|
2955
|
+
client: "cosmWasm",
|
|
2956
|
+
options: signingClientOptions
|
|
2957
|
+
});
|
|
2958
|
+
const mutationFn = (args) => {
|
|
2959
|
+
if (!accountAddress)
|
|
2960
|
+
throw new Error("senderAddress is undefined");
|
|
2961
|
+
if (!_signingClient)
|
|
2962
|
+
throw new Error("Signing client is not available");
|
|
2963
|
+
return instantiateContract({
|
|
2964
|
+
...args,
|
|
2965
|
+
signingClient: _signingClient,
|
|
2966
|
+
fee: args.fee ?? "auto",
|
|
2967
|
+
senderAddress: accountAddress,
|
|
2968
|
+
codeId
|
|
2969
|
+
});
|
|
2970
|
+
};
|
|
2971
|
+
const queryKey = ["USE_INSTANTIATE_CONTRACT", onError, onLoading, onSuccess, codeId, accountAddress];
|
|
2972
|
+
const mutation = useMutation3(queryKey, mutationFn, {
|
|
2973
|
+
onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
|
|
2974
|
+
onMutate: onLoading,
|
|
2975
|
+
onSuccess: (instantiateResult) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(instantiateResult))
|
|
2976
|
+
});
|
|
2977
|
+
return {
|
|
2978
|
+
error: mutation.error,
|
|
2979
|
+
isLoading: mutation.isLoading,
|
|
2980
|
+
isSuccess: mutation.isSuccess,
|
|
2981
|
+
instantiateContract: mutation.mutate,
|
|
2982
|
+
instantiateContractAsync: mutation.mutateAsync,
|
|
2983
|
+
status: mutation.status
|
|
2984
|
+
};
|
|
2985
|
+
};
|
|
2986
|
+
var useExecuteContract = ({
|
|
2987
|
+
chainId,
|
|
2988
|
+
contractAddress,
|
|
2989
|
+
signingClientOptions,
|
|
2990
|
+
onError,
|
|
2991
|
+
onLoading,
|
|
2992
|
+
onSuccess
|
|
2993
|
+
}) => {
|
|
2994
|
+
var _a;
|
|
2995
|
+
const account = useAccount({
|
|
2996
|
+
chainId
|
|
2997
|
+
});
|
|
2998
|
+
const accountAddress = (_a = account == null ? void 0 : account.account) == null ? void 0 : _a.bech32Address;
|
|
2999
|
+
const { data: _signingClient } = useConnectSigningClient({
|
|
3000
|
+
chainId,
|
|
3001
|
+
client: "cosmWasm",
|
|
3002
|
+
options: signingClientOptions
|
|
3003
|
+
});
|
|
3004
|
+
const mutationFn = (args) => {
|
|
3005
|
+
if (!accountAddress)
|
|
3006
|
+
throw new Error("senderAddress is undefined");
|
|
3007
|
+
if (!_signingClient)
|
|
3008
|
+
throw new Error("Signing client is not available");
|
|
3009
|
+
return executeContract({
|
|
3010
|
+
...args,
|
|
3011
|
+
signingClient: _signingClient,
|
|
3012
|
+
fee: args.fee ?? "auto",
|
|
3013
|
+
senderAddress: accountAddress,
|
|
3014
|
+
contractAddress,
|
|
3015
|
+
memo: args.memo ?? "",
|
|
3016
|
+
funds: args.funds ?? []
|
|
3017
|
+
});
|
|
3018
|
+
};
|
|
3019
|
+
const queryKey = ["USE_EXECUTE_CONTRACT", onError, onLoading, onSuccess, contractAddress, accountAddress];
|
|
3020
|
+
const mutation = useMutation3(queryKey, mutationFn, {
|
|
3021
|
+
onError: (err, data) => Promise.resolve(onError == null ? void 0 : onError(err, data)),
|
|
3022
|
+
onMutate: onLoading,
|
|
3023
|
+
onSuccess: (executeResult) => Promise.resolve(onSuccess == null ? void 0 : onSuccess(executeResult))
|
|
3024
|
+
});
|
|
3025
|
+
return {
|
|
3026
|
+
error: mutation.error,
|
|
3027
|
+
isLoading: mutation.isLoading,
|
|
3028
|
+
isSuccess: mutation.isSuccess,
|
|
3029
|
+
executeContract: mutation.mutate,
|
|
3030
|
+
executeContractAsync: mutation.mutateAsync,
|
|
3031
|
+
status: mutation.status
|
|
3032
|
+
};
|
|
3033
|
+
};
|
|
3034
|
+
var useQuerySmart = ({
|
|
3035
|
+
address,
|
|
3036
|
+
queryMsg,
|
|
3037
|
+
chainId
|
|
3038
|
+
}) => {
|
|
3039
|
+
const { data: client } = useConnectClient({
|
|
3040
|
+
client: "cosmWasm",
|
|
3041
|
+
chainId
|
|
3042
|
+
});
|
|
3043
|
+
const query = useQuery5(
|
|
3044
|
+
["USE_QUERY_SMART", { address, queryMsg, chainId }],
|
|
3045
|
+
() => {
|
|
3046
|
+
if (!address || !queryMsg)
|
|
3047
|
+
throw new Error("address or queryMsg undefined");
|
|
3048
|
+
if (!client)
|
|
3049
|
+
throw new Error("Client is not available");
|
|
3050
|
+
return getQuerySmart({ address, queryMsg, client });
|
|
3051
|
+
},
|
|
3052
|
+
{
|
|
3053
|
+
enabled: Boolean(address) && Boolean(queryMsg)
|
|
3054
|
+
}
|
|
3055
|
+
);
|
|
3056
|
+
return query;
|
|
3057
|
+
};
|
|
3058
|
+
var useQueryRaw = ({
|
|
3059
|
+
address,
|
|
3060
|
+
key,
|
|
3061
|
+
chainId
|
|
3062
|
+
}) => {
|
|
3063
|
+
const { data: client } = useConnectClient({
|
|
3064
|
+
client: "cosmWasm",
|
|
3065
|
+
chainId
|
|
3066
|
+
});
|
|
3067
|
+
const queryKey = ["USE_QUERY_RAW", key, address];
|
|
3068
|
+
const query = useQuery5(
|
|
3069
|
+
queryKey,
|
|
3070
|
+
({ queryKey: [, _address] }) => {
|
|
3071
|
+
if (!address || !key)
|
|
3072
|
+
throw new Error("address or key undefined");
|
|
3073
|
+
if (!client)
|
|
3074
|
+
throw new Error("Client is not available");
|
|
3075
|
+
return getQueryRaw({ address, keyStr: key, client });
|
|
3076
|
+
},
|
|
3077
|
+
{
|
|
3078
|
+
enabled: Boolean(address) && Boolean(key)
|
|
3079
|
+
}
|
|
3080
|
+
);
|
|
3081
|
+
return query;
|
|
3082
|
+
};
|
|
2789
3083
|
|
|
2790
3084
|
// src/provider/events.tsx
|
|
2791
3085
|
import { useEffect as useEffect2 } from "react";
|
|
@@ -2873,6 +3167,43 @@ var GrazProvider = ({ children, grazConfig, ...props }) => {
|
|
|
2873
3167
|
children
|
|
2874
3168
|
] }) }, "graz-provider");
|
|
2875
3169
|
};
|
|
3170
|
+
|
|
3171
|
+
// src/utils/conversion.ts
|
|
3172
|
+
var convertMicroDenomToDenom = (value, decimals) => {
|
|
3173
|
+
if (decimals === 0) {
|
|
3174
|
+
return Number(value);
|
|
3175
|
+
}
|
|
3176
|
+
return handleNaN(Number(value) / Math.pow(10, decimals));
|
|
3177
|
+
};
|
|
3178
|
+
var convertDenomToMicroDenom = (value, decimals) => {
|
|
3179
|
+
if (decimals === 0) {
|
|
3180
|
+
return Number(value);
|
|
3181
|
+
}
|
|
3182
|
+
return handleNaN(parseInt(String(Number(value) * Math.pow(10, decimals)), 10));
|
|
3183
|
+
};
|
|
3184
|
+
var convertFromMicroDenom = (denom) => {
|
|
3185
|
+
return denom.substring(1).toUpperCase();
|
|
3186
|
+
};
|
|
3187
|
+
var convertToFixedDecimals = (value, fractionDigits = 2) => {
|
|
3188
|
+
const amount = Number(value);
|
|
3189
|
+
return amount > 0.01 ? amount.toFixed(fractionDigits) : String(amount);
|
|
3190
|
+
};
|
|
3191
|
+
var formatTokenName = (name) => {
|
|
3192
|
+
if (name) {
|
|
3193
|
+
return name.slice(0, 1).toUpperCase() + name.slice(1).toLowerCase();
|
|
3194
|
+
}
|
|
3195
|
+
return "";
|
|
3196
|
+
};
|
|
3197
|
+
var handleNaN = (value) => {
|
|
3198
|
+
return isNaN(value) ? 0 : value;
|
|
3199
|
+
};
|
|
3200
|
+
var truncate = (string, slice) => {
|
|
3201
|
+
if (string && slice && string.length <= slice)
|
|
3202
|
+
return string;
|
|
3203
|
+
const pre = string == null ? void 0 : string.slice(0, slice || 8);
|
|
3204
|
+
const post = string == null ? void 0 : string.slice((slice || 8) * -1);
|
|
3205
|
+
return `${pre}...${post}`;
|
|
3206
|
+
};
|
|
2876
3207
|
export {
|
|
2877
3208
|
GrazEvents,
|
|
2878
3209
|
GrazProvider,
|
|
@@ -2884,14 +3215,20 @@ export {
|
|
|
2884
3215
|
connect,
|
|
2885
3216
|
connectClient,
|
|
2886
3217
|
connectSigningClient,
|
|
3218
|
+
convertDenomToMicroDenom,
|
|
3219
|
+
convertFromMicroDenom,
|
|
3220
|
+
convertMicroDenomToDenom,
|
|
3221
|
+
convertToFixedDecimals,
|
|
2887
3222
|
defineChain,
|
|
2888
3223
|
defineChainInfo,
|
|
2889
3224
|
defineChains,
|
|
2890
3225
|
disconnect,
|
|
2891
3226
|
executeContract,
|
|
3227
|
+
formatTokenName,
|
|
3228
|
+
getAllBalance,
|
|
2892
3229
|
getAvailableWallets,
|
|
3230
|
+
getBalance,
|
|
2893
3231
|
getBalanceStaked,
|
|
2894
|
-
getBalances,
|
|
2895
3232
|
getCosmostation,
|
|
2896
3233
|
getKeplr,
|
|
2897
3234
|
getLeap,
|
|
@@ -2905,6 +3242,7 @@ export {
|
|
|
2905
3242
|
getWCLeap,
|
|
2906
3243
|
getWallet,
|
|
2907
3244
|
getWalletConnect,
|
|
3245
|
+
handleNaN,
|
|
2908
3246
|
instantiateContract,
|
|
2909
3247
|
mainnetChains,
|
|
2910
3248
|
mainnetChainsArray,
|
|
@@ -2915,19 +3253,28 @@ export {
|
|
|
2915
3253
|
suggestChainAndConnect,
|
|
2916
3254
|
testnetChains,
|
|
2917
3255
|
testnetChainsArray,
|
|
3256
|
+
truncate,
|
|
2918
3257
|
useAccount,
|
|
2919
3258
|
useActiveChainValidators,
|
|
2920
3259
|
useActiveWalletType,
|
|
3260
|
+
useAllBalances,
|
|
3261
|
+
useBalance,
|
|
2921
3262
|
useBalanceStaked,
|
|
2922
|
-
|
|
3263
|
+
useChain,
|
|
3264
|
+
useChainBalances,
|
|
2923
3265
|
useCheckWallet,
|
|
2924
3266
|
useConnect,
|
|
2925
3267
|
useConnectClient,
|
|
2926
3268
|
useConnectSigningClient,
|
|
2927
3269
|
useDisconnect,
|
|
3270
|
+
useExecuteContract,
|
|
2928
3271
|
useGrazEvents,
|
|
3272
|
+
useInstantiateContract,
|
|
2929
3273
|
useOfflineSigners,
|
|
3274
|
+
useQueryRaw,
|
|
3275
|
+
useQuerySmart,
|
|
2930
3276
|
useRecentChain,
|
|
3277
|
+
useSendIbcTokens,
|
|
2931
3278
|
useSendTokens,
|
|
2932
3279
|
useSuggestChain,
|
|
2933
3280
|
useSuggestChainAndConnect
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graz",
|
|
3
3
|
"description": "React hooks for Cosmos",
|
|
4
|
-
"version": "0.0
|
|
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",
|