@interchain-kit/react 0.0.1-beta.3 → 0.0.1-beta.5
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/esm/hooks/index.js +1 -0
- package/esm/hooks/useChain.js +20 -0
- package/esm/hooks/useConfig.js +10 -0
- package/esm/hooks/useInterchainClient.js +11 -15
- package/esm/hooks/useOfflineSigner.js +8 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useChain.d.ts +2 -2
- package/hooks/useChain.js +20 -0
- package/hooks/useConfig.d.ts +8 -0
- package/hooks/useConfig.js +14 -0
- package/hooks/useInterchainClient.d.ts +4 -5
- package/hooks/useInterchainClient.js +11 -15
- package/hooks/useOfflineSigner.d.ts +3 -0
- package/hooks/useOfflineSigner.js +12 -0
- package/package.json +3 -3
- package/types/chain.d.ts +16 -7
package/esm/hooks/index.js
CHANGED
package/esm/hooks/useChain.js
CHANGED
|
@@ -2,6 +2,7 @@ import { useWalletManager } from "./useWalletManager";
|
|
|
2
2
|
import { useAccount } from "./useAccount";
|
|
3
3
|
import { useActiveWallet } from './useActiveWallet';
|
|
4
4
|
import { useInterchainClient } from './useInterchainClient';
|
|
5
|
+
import { useWalletModal } from "../modal";
|
|
5
6
|
export const useChain = (chainName) => {
|
|
6
7
|
const walletManager = useWalletManager();
|
|
7
8
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
@@ -9,11 +10,30 @@ export const useChain = (chainName) => {
|
|
|
9
10
|
const activeWallet = useActiveWallet();
|
|
10
11
|
const account = useAccount(chainName, activeWallet.option.name);
|
|
11
12
|
const interchainClient = useInterchainClient(chainName, activeWallet.option.name);
|
|
13
|
+
const { open, close } = useWalletModal();
|
|
14
|
+
const clientFactory = walletManager.createClientFactory(activeWallet, chainName);
|
|
15
|
+
const cosmosKitUserChainReturnType = {
|
|
16
|
+
connect: () => {
|
|
17
|
+
if (activeWallet) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
open();
|
|
21
|
+
},
|
|
22
|
+
openView: open,
|
|
23
|
+
closeView: close,
|
|
24
|
+
getRpcEndpoint: () => walletManager.getRpcEndpoint(activeWallet, chainName),
|
|
25
|
+
status: activeWallet.walletState,
|
|
26
|
+
username: account?.username,
|
|
27
|
+
message: activeWallet.errorMessage,
|
|
28
|
+
getSigningCosmWasmClient: () => clientFactory.then((c) => c.getSigningCosmwasmClient()),
|
|
29
|
+
getSigningStargateClient: () => clientFactory.then((c) => c.getSigningStargateClient())
|
|
30
|
+
};
|
|
12
31
|
return {
|
|
13
32
|
chain: chainToShow,
|
|
14
33
|
assetList,
|
|
15
34
|
address: account?.address,
|
|
16
35
|
wallet: activeWallet,
|
|
36
|
+
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
17
37
|
...interchainClient
|
|
18
38
|
};
|
|
19
39
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useWalletManager } from "./useWalletManager";
|
|
2
|
+
export const useConfig = () => {
|
|
3
|
+
const walletManager = useWalletManager();
|
|
4
|
+
return {
|
|
5
|
+
updateChains: (chains) => walletManager.chains = chains,
|
|
6
|
+
updateAssetLists: (assetLists) => walletManager.assetLists = assetLists,
|
|
7
|
+
updateSignerOptions: (signerOptions) => walletManager.signerOptions = signerOptions,
|
|
8
|
+
updateEndpoints: (endpointOptions) => walletManager.endpointOptions = endpointOptions,
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -4,10 +4,9 @@ import { useAccount } from './useAccount';
|
|
|
4
4
|
export const useInterchainClient = (chainName, walletName) => {
|
|
5
5
|
const [rpcEndpoint, setRpcEndpoint] = useState();
|
|
6
6
|
const [signingClient, setSigningClient] = useState(null);
|
|
7
|
-
const [
|
|
8
|
-
const [
|
|
9
|
-
const [
|
|
10
|
-
const [cosmWasmSigningClient, setCosmWasmSigningClient] = useState(null);
|
|
7
|
+
const [queryClient, setQueryClient] = useState(null);
|
|
8
|
+
const [signingStargateClient, setSigningStargateClient] = useState(null);
|
|
9
|
+
const [signingCosmWasmClient, setSigningCosmWasmClient] = useState(null);
|
|
11
10
|
const [error, setError] = useState(null);
|
|
12
11
|
const [isLoading, setIsLoading] = useState(false);
|
|
13
12
|
const walletManager = useWalletManager();
|
|
@@ -26,16 +25,14 @@ export const useInterchainClient = (chainName, walletName) => {
|
|
|
26
25
|
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
27
26
|
setRpcEndpoint(rpcEndpoint);
|
|
28
27
|
const clientFactory = await walletManager.createClientFactory(wallet, chainName);
|
|
29
|
-
const
|
|
30
|
-
|
|
28
|
+
const queryClient = await clientFactory.getClient();
|
|
29
|
+
setQueryClient(queryClient);
|
|
31
30
|
const signingClient = await clientFactory.getSigningClient();
|
|
32
31
|
setSigningClient(signingClient);
|
|
33
|
-
const stargateClient = await clientFactory.getStargateClient();
|
|
34
|
-
setStargateClient(stargateClient);
|
|
35
32
|
const signingStargateClient = await clientFactory.getSigningStargateClient(chainToShow.bech32Prefix);
|
|
36
|
-
|
|
33
|
+
setSigningStargateClient(signingStargateClient);
|
|
37
34
|
const signingCosmwasmClient = await clientFactory.getSigningCosmwasmClient();
|
|
38
|
-
|
|
35
|
+
setSigningCosmWasmClient(signingCosmwasmClient);
|
|
39
36
|
}
|
|
40
37
|
catch (error) {
|
|
41
38
|
setError(error);
|
|
@@ -46,14 +43,13 @@ export const useInterchainClient = (chainName, walletName) => {
|
|
|
46
43
|
};
|
|
47
44
|
useEffect(() => {
|
|
48
45
|
initialize();
|
|
49
|
-
}, [chainName, walletName, account
|
|
46
|
+
}, [chainName, walletName, account]);
|
|
50
47
|
return {
|
|
51
48
|
rpcEndpoint,
|
|
52
49
|
signingClient,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
cosmWasmSigningClient,
|
|
50
|
+
queryClient,
|
|
51
|
+
signingStargateClient,
|
|
52
|
+
signingCosmWasmClient,
|
|
57
53
|
error,
|
|
58
54
|
isLoading
|
|
59
55
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useWalletManager } from "./useWalletManager";
|
|
2
|
+
export const useOfflineSigner = (chainName, walletName) => {
|
|
3
|
+
const walletManager = useWalletManager();
|
|
4
|
+
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
5
|
+
return {
|
|
6
|
+
offlineSigner: walletManager.getOfflineSigner(wallet, chainName),
|
|
7
|
+
};
|
|
8
|
+
};
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.js
CHANGED
package/hooks/useChain.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { UseChainReturnType } from '../types/chain';
|
|
2
|
-
export declare const useChain: (chainName: string) => UseChainReturnType;
|
|
1
|
+
import { CosmosKitUseChainReturnType, UseChainReturnType } from '../types/chain';
|
|
2
|
+
export declare const useChain: (chainName: string) => UseChainReturnType & CosmosKitUseChainReturnType;
|
package/hooks/useChain.js
CHANGED
|
@@ -5,6 +5,7 @@ const useWalletManager_1 = require("./useWalletManager");
|
|
|
5
5
|
const useAccount_1 = require("./useAccount");
|
|
6
6
|
const useActiveWallet_1 = require("./useActiveWallet");
|
|
7
7
|
const useInterchainClient_1 = require("./useInterchainClient");
|
|
8
|
+
const modal_1 = require("../modal");
|
|
8
9
|
const useChain = (chainName) => {
|
|
9
10
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
10
11
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
@@ -12,11 +13,30 @@ const useChain = (chainName) => {
|
|
|
12
13
|
const activeWallet = (0, useActiveWallet_1.useActiveWallet)();
|
|
13
14
|
const account = (0, useAccount_1.useAccount)(chainName, activeWallet.option.name);
|
|
14
15
|
const interchainClient = (0, useInterchainClient_1.useInterchainClient)(chainName, activeWallet.option.name);
|
|
16
|
+
const { open, close } = (0, modal_1.useWalletModal)();
|
|
17
|
+
const clientFactory = walletManager.createClientFactory(activeWallet, chainName);
|
|
18
|
+
const cosmosKitUserChainReturnType = {
|
|
19
|
+
connect: () => {
|
|
20
|
+
if (activeWallet) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
open();
|
|
24
|
+
},
|
|
25
|
+
openView: open,
|
|
26
|
+
closeView: close,
|
|
27
|
+
getRpcEndpoint: () => walletManager.getRpcEndpoint(activeWallet, chainName),
|
|
28
|
+
status: activeWallet.walletState,
|
|
29
|
+
username: account?.username,
|
|
30
|
+
message: activeWallet.errorMessage,
|
|
31
|
+
getSigningCosmWasmClient: () => clientFactory.then((c) => c.getSigningCosmwasmClient()),
|
|
32
|
+
getSigningStargateClient: () => clientFactory.then((c) => c.getSigningStargateClient())
|
|
33
|
+
};
|
|
15
34
|
return {
|
|
16
35
|
chain: chainToShow,
|
|
17
36
|
assetList,
|
|
18
37
|
address: account?.address,
|
|
19
38
|
wallet: activeWallet,
|
|
39
|
+
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
20
40
|
...interchainClient
|
|
21
41
|
};
|
|
22
42
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AssetList, Chain } from "@chain-registry/v2-types";
|
|
2
|
+
import { EndpointOptions, SignerOptions } from "@interChain-kit/core";
|
|
3
|
+
export declare const useConfig: () => {
|
|
4
|
+
updateChains: (chains: Chain[]) => Chain[];
|
|
5
|
+
updateAssetLists: (assetLists: AssetList[]) => AssetList[];
|
|
6
|
+
updateSignerOptions: (signerOptions: SignerOptions) => SignerOptions;
|
|
7
|
+
updateEndpoints: (endpointOptions: EndpointOptions) => EndpointOptions;
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useConfig = void 0;
|
|
4
|
+
const useWalletManager_1 = require("./useWalletManager");
|
|
5
|
+
const useConfig = () => {
|
|
6
|
+
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
7
|
+
return {
|
|
8
|
+
updateChains: (chains) => walletManager.chains = chains,
|
|
9
|
+
updateAssetLists: (assetLists) => walletManager.assetLists = assetLists,
|
|
10
|
+
updateSignerOptions: (signerOptions) => walletManager.signerOptions = signerOptions,
|
|
11
|
+
updateEndpoints: (endpointOptions) => walletManager.endpointOptions = endpointOptions,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.useConfig = useConfig;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
import { HttpEndpoint } from '@interchainjs/types';
|
|
1
2
|
import { CosmWasmSigningClient } from 'interchainjs/cosmwasm-stargate';
|
|
2
3
|
import { StargateSigningClient } from 'interchainjs/stargate';
|
|
3
|
-
import { StargateClient, HttpEndpoint } from '@cosmjs/stargate';
|
|
4
4
|
import { SigningClient } from 'interchainjs/signing-client';
|
|
5
5
|
import { RpcQuery } from 'interchainjs/query/rpc';
|
|
6
6
|
export declare const useInterchainClient: (chainName: string, walletName: string) => {
|
|
7
7
|
rpcEndpoint: string | HttpEndpoint;
|
|
8
8
|
signingClient: SigningClient;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
cosmWasmSigningClient: CosmWasmSigningClient;
|
|
9
|
+
queryClient: RpcQuery;
|
|
10
|
+
signingStargateClient: StargateSigningClient;
|
|
11
|
+
signingCosmWasmClient: CosmWasmSigningClient;
|
|
13
12
|
error: unknown;
|
|
14
13
|
isLoading: boolean;
|
|
15
14
|
};
|
|
@@ -7,10 +7,9 @@ const useAccount_1 = require("./useAccount");
|
|
|
7
7
|
const useInterchainClient = (chainName, walletName) => {
|
|
8
8
|
const [rpcEndpoint, setRpcEndpoint] = (0, react_1.useState)();
|
|
9
9
|
const [signingClient, setSigningClient] = (0, react_1.useState)(null);
|
|
10
|
-
const [
|
|
11
|
-
const [
|
|
12
|
-
const [
|
|
13
|
-
const [cosmWasmSigningClient, setCosmWasmSigningClient] = (0, react_1.useState)(null);
|
|
10
|
+
const [queryClient, setQueryClient] = (0, react_1.useState)(null);
|
|
11
|
+
const [signingStargateClient, setSigningStargateClient] = (0, react_1.useState)(null);
|
|
12
|
+
const [signingCosmWasmClient, setSigningCosmWasmClient] = (0, react_1.useState)(null);
|
|
14
13
|
const [error, setError] = (0, react_1.useState)(null);
|
|
15
14
|
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
16
15
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
@@ -29,16 +28,14 @@ const useInterchainClient = (chainName, walletName) => {
|
|
|
29
28
|
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
30
29
|
setRpcEndpoint(rpcEndpoint);
|
|
31
30
|
const clientFactory = await walletManager.createClientFactory(wallet, chainName);
|
|
32
|
-
const
|
|
33
|
-
|
|
31
|
+
const queryClient = await clientFactory.getClient();
|
|
32
|
+
setQueryClient(queryClient);
|
|
34
33
|
const signingClient = await clientFactory.getSigningClient();
|
|
35
34
|
setSigningClient(signingClient);
|
|
36
|
-
const stargateClient = await clientFactory.getStargateClient();
|
|
37
|
-
setStargateClient(stargateClient);
|
|
38
35
|
const signingStargateClient = await clientFactory.getSigningStargateClient(chainToShow.bech32Prefix);
|
|
39
|
-
|
|
36
|
+
setSigningStargateClient(signingStargateClient);
|
|
40
37
|
const signingCosmwasmClient = await clientFactory.getSigningCosmwasmClient();
|
|
41
|
-
|
|
38
|
+
setSigningCosmWasmClient(signingCosmwasmClient);
|
|
42
39
|
}
|
|
43
40
|
catch (error) {
|
|
44
41
|
setError(error);
|
|
@@ -49,14 +46,13 @@ const useInterchainClient = (chainName, walletName) => {
|
|
|
49
46
|
};
|
|
50
47
|
(0, react_1.useEffect)(() => {
|
|
51
48
|
initialize();
|
|
52
|
-
}, [chainName, walletName, account
|
|
49
|
+
}, [chainName, walletName, account]);
|
|
53
50
|
return {
|
|
54
51
|
rpcEndpoint,
|
|
55
52
|
signingClient,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
cosmWasmSigningClient,
|
|
53
|
+
queryClient,
|
|
54
|
+
signingStargateClient,
|
|
55
|
+
signingCosmWasmClient,
|
|
60
56
|
error,
|
|
61
57
|
isLoading
|
|
62
58
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useOfflineSigner = void 0;
|
|
4
|
+
const useWalletManager_1 = require("./useWalletManager");
|
|
5
|
+
const useOfflineSigner = (chainName, walletName) => {
|
|
6
|
+
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
7
|
+
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
8
|
+
return {
|
|
9
|
+
offlineSigner: walletManager.getOfflineSigner(wallet, chainName),
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
exports.useOfflineSigner = useOfflineSigner;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interchain-kit/react",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.5",
|
|
4
4
|
"author": "cosmology-tech <developers@cosmology.zone>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"keywords": [],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@chain-registry/v2-types": "^0.49.6",
|
|
35
|
-
"@interchain-kit/core": "0.0.1-beta.
|
|
35
|
+
"@interchain-kit/core": "0.0.1-beta.5",
|
|
36
36
|
"@types/react": "^18.3.3",
|
|
37
37
|
"@types/react-dom": "^18.3.0",
|
|
38
38
|
"react": "^18.3.1",
|
|
39
39
|
"react-dom": "^18.3.1"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "84a7448891bef2688645da8009605786267de720"
|
|
42
42
|
}
|
package/types/chain.d.ts
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
+
import { HttpEndpoint } from '@interchainjs/types';
|
|
1
2
|
import { CosmWasmSigningClient } from 'interchainjs/cosmwasm-stargate';
|
|
2
|
-
import { StargateClient } from '@cosmjs/stargate';
|
|
3
3
|
import { SigningClient } from 'interchainjs/signing-client';
|
|
4
4
|
import { RpcQuery } from 'interchainjs/query/rpc';
|
|
5
5
|
import { StargateSigningClient } from 'interchainjs/stargate';
|
|
6
|
-
import { HttpEndpoint } from '@cosmjs/stargate';
|
|
7
6
|
import { Chain, AssetList } from '@chain-registry/v2-types';
|
|
8
|
-
import { BaseWallet } from '@
|
|
7
|
+
import { BaseWallet, WalletState } from '@interchain-kit/core';
|
|
8
|
+
export type CosmosKitUseChainReturnType = {
|
|
9
|
+
connect: () => void;
|
|
10
|
+
openView: () => void;
|
|
11
|
+
closeView: () => void;
|
|
12
|
+
getRpcEndpoint: () => Promise<string | HttpEndpoint>;
|
|
13
|
+
status: WalletState;
|
|
14
|
+
username: string;
|
|
15
|
+
message: string;
|
|
16
|
+
getSigningCosmWasmClient: () => Promise<CosmWasmSigningClient>;
|
|
17
|
+
getSigningStargateClient: () => Promise<StargateSigningClient>;
|
|
18
|
+
};
|
|
9
19
|
export type UseChainReturnType = {
|
|
10
20
|
chain: Chain;
|
|
11
21
|
assetList: AssetList;
|
|
12
22
|
address: string;
|
|
13
23
|
wallet: BaseWallet;
|
|
14
24
|
rpcEndpoint: string | HttpEndpoint;
|
|
15
|
-
|
|
25
|
+
queryClient: RpcQuery;
|
|
16
26
|
signingClient: SigningClient;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
cosmWasmSigningClient: CosmWasmSigningClient;
|
|
27
|
+
signingStargateClient: StargateSigningClient;
|
|
28
|
+
signingCosmWasmClient: CosmWasmSigningClient;
|
|
20
29
|
isLoading: boolean;
|
|
21
30
|
error: unknown;
|
|
22
31
|
};
|