@interchain-kit/react 0.0.1-beta.1 → 0.0.1-beta.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/esm/hooks/useChain.js +3 -14
- package/esm/hooks/useChainWallet.js +3 -21
- package/esm/hooks/useInterchainClient.js +60 -0
- package/hooks/useChain.js +3 -14
- package/hooks/useChainWallet.d.ts +2 -15
- package/hooks/useChainWallet.js +3 -21
- package/hooks/useInterchainClient.d.ts +15 -0
- package/hooks/useInterchainClient.js +64 -0
- package/package.json +3 -3
- package/types/chain.d.ts +15 -3
package/esm/hooks/useChain.js
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
import { useWalletManager } from "./useWalletManager";
|
|
2
2
|
import { useAccount } from "./useAccount";
|
|
3
3
|
import { useActiveWallet } from './useActiveWallet';
|
|
4
|
-
import {
|
|
4
|
+
import { useInterchainClient } from './useInterchainClient';
|
|
5
5
|
export const useChain = (chainName) => {
|
|
6
6
|
const walletManager = useWalletManager();
|
|
7
7
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
8
8
|
const assetList = walletManager.assetLists.find((a) => a.chainName === chainName);
|
|
9
9
|
const activeWallet = useActiveWallet();
|
|
10
10
|
const account = useAccount(chainName, activeWallet.option.name);
|
|
11
|
-
const
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
walletManager.createClientFactory(activeWallet, chainName).then(clientFactory => {
|
|
14
|
-
setClientFactory(clientFactory);
|
|
15
|
-
});
|
|
16
|
-
}, [chainName, activeWallet, account?.address]);
|
|
11
|
+
const interchainClient = useInterchainClient(chainName, activeWallet.option.name);
|
|
17
12
|
return {
|
|
18
13
|
chain: chainToShow,
|
|
19
14
|
assetList,
|
|
20
15
|
address: account?.address,
|
|
21
16
|
wallet: activeWallet,
|
|
22
|
-
|
|
23
|
-
getClient: () => clientFactory.getClient(),
|
|
24
|
-
getSigningClient: () => clientFactory.getSigningClient(),
|
|
25
|
-
getCosmwasmClient: () => clientFactory.getCosmwasmClient(),
|
|
26
|
-
getSigningCosmwasmClient: () => clientFactory.getSigningCosmwasmClient(),
|
|
27
|
-
getSigningStargateClient: () => clientFactory.getSigningStargateClient(),
|
|
28
|
-
getStargateClient: () => clientFactory.getStargateClient(),
|
|
17
|
+
...interchainClient
|
|
29
18
|
};
|
|
30
19
|
};
|
|
@@ -1,36 +1,18 @@
|
|
|
1
1
|
import { useWalletManager } from "./useWalletManager";
|
|
2
2
|
import { useAccount } from "./useAccount";
|
|
3
|
-
import {
|
|
4
|
-
import { ChainNotExist, WalletNotExist } from "@interChain-kit/core";
|
|
3
|
+
import { useInterchainClient } from "./useInterchainClient";
|
|
5
4
|
export const useChainWallet = (chainName, walletName) => {
|
|
6
5
|
const walletManager = useWalletManager();
|
|
7
6
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
8
7
|
const assetList = walletManager.assetLists.find((a) => a.chainName === chainName);
|
|
9
8
|
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
10
9
|
const account = useAccount(chainName, walletName);
|
|
11
|
-
const
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
if (!wallet) {
|
|
14
|
-
throw new WalletNotExist(walletName);
|
|
15
|
-
}
|
|
16
|
-
if (!chainToShow) {
|
|
17
|
-
throw new ChainNotExist(chainName);
|
|
18
|
-
}
|
|
19
|
-
walletManager.createClientFactory(wallet, chainName).then(clientFactory => {
|
|
20
|
-
setClientFactory(clientFactory);
|
|
21
|
-
});
|
|
22
|
-
}, [chainName, walletName, account?.address]);
|
|
10
|
+
const interchainClient = useInterchainClient(chainName, walletName);
|
|
23
11
|
return {
|
|
24
12
|
chain: chainToShow,
|
|
25
13
|
assetList,
|
|
26
14
|
address: account?.address,
|
|
27
15
|
wallet,
|
|
28
|
-
|
|
29
|
-
getClient: () => clientFactory.getClient(),
|
|
30
|
-
getSigningClient: async () => clientFactory.getSigningClient(),
|
|
31
|
-
getCosmwasmClient: () => clientFactory.getCosmwasmClient(),
|
|
32
|
-
getSigningCosmwasmClient: () => clientFactory.getSigningCosmwasmClient(),
|
|
33
|
-
getSigningStargateClient: () => clientFactory.getSigningStargateClient(),
|
|
34
|
-
getStargateClient: () => clientFactory.getStargateClient(),
|
|
16
|
+
...interchainClient
|
|
35
17
|
};
|
|
36
18
|
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useWalletManager } from './useWalletManager';
|
|
3
|
+
import { useAccount } from './useAccount';
|
|
4
|
+
export const useInterchainClient = (chainName, walletName) => {
|
|
5
|
+
const [rpcEndpoint, setRpcEndpoint] = useState();
|
|
6
|
+
const [signingClient, setSigningClient] = useState(null);
|
|
7
|
+
const [client, setClient] = useState(null);
|
|
8
|
+
const [stargateSigningClient, setStargateSigningClient] = useState(null);
|
|
9
|
+
const [stargateClient, setStargateClient] = useState();
|
|
10
|
+
const [cosmWasmSigningClient, setCosmWasmSigningClient] = useState(null);
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
13
|
+
const walletManager = useWalletManager();
|
|
14
|
+
const account = useAccount(chainName, walletName);
|
|
15
|
+
const initialize = async () => {
|
|
16
|
+
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
17
|
+
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
18
|
+
if (!wallet) {
|
|
19
|
+
throw new Error('Wallet not found');
|
|
20
|
+
}
|
|
21
|
+
if (!chainToShow) {
|
|
22
|
+
throw new Error('Chain not found');
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
setIsLoading(true);
|
|
26
|
+
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
27
|
+
setRpcEndpoint(rpcEndpoint);
|
|
28
|
+
const clientFactory = await walletManager.createClientFactory(wallet, chainName);
|
|
29
|
+
const client = await clientFactory.getClient();
|
|
30
|
+
setClient(client);
|
|
31
|
+
const signingClient = await clientFactory.getSigningClient();
|
|
32
|
+
setSigningClient(signingClient);
|
|
33
|
+
const stargateClient = await clientFactory.getStargateClient();
|
|
34
|
+
setStargateClient(stargateClient);
|
|
35
|
+
const signingStargateClient = await clientFactory.getSigningStargateClient(chainToShow.bech32Prefix);
|
|
36
|
+
setStargateSigningClient(signingStargateClient);
|
|
37
|
+
const signingCosmwasmClient = await clientFactory.getSigningCosmwasmClient();
|
|
38
|
+
setCosmWasmSigningClient(signingCosmwasmClient);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
setError(error);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
setIsLoading(false);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
initialize();
|
|
49
|
+
}, [chainName, walletName, account?.address]);
|
|
50
|
+
return {
|
|
51
|
+
rpcEndpoint,
|
|
52
|
+
signingClient,
|
|
53
|
+
client,
|
|
54
|
+
stargateSigningClient,
|
|
55
|
+
stargateClient,
|
|
56
|
+
cosmWasmSigningClient,
|
|
57
|
+
error,
|
|
58
|
+
isLoading
|
|
59
|
+
};
|
|
60
|
+
};
|
package/hooks/useChain.js
CHANGED
|
@@ -4,31 +4,20 @@ exports.useChain = void 0;
|
|
|
4
4
|
const useWalletManager_1 = require("./useWalletManager");
|
|
5
5
|
const useAccount_1 = require("./useAccount");
|
|
6
6
|
const useActiveWallet_1 = require("./useActiveWallet");
|
|
7
|
-
const
|
|
7
|
+
const useInterchainClient_1 = require("./useInterchainClient");
|
|
8
8
|
const useChain = (chainName) => {
|
|
9
9
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
10
10
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
11
11
|
const assetList = walletManager.assetLists.find((a) => a.chainName === chainName);
|
|
12
12
|
const activeWallet = (0, useActiveWallet_1.useActiveWallet)();
|
|
13
13
|
const account = (0, useAccount_1.useAccount)(chainName, activeWallet.option.name);
|
|
14
|
-
const
|
|
15
|
-
(0, react_1.useEffect)(() => {
|
|
16
|
-
walletManager.createClientFactory(activeWallet, chainName).then(clientFactory => {
|
|
17
|
-
setClientFactory(clientFactory);
|
|
18
|
-
});
|
|
19
|
-
}, [chainName, activeWallet, account?.address]);
|
|
14
|
+
const interchainClient = (0, useInterchainClient_1.useInterchainClient)(chainName, activeWallet.option.name);
|
|
20
15
|
return {
|
|
21
16
|
chain: chainToShow,
|
|
22
17
|
assetList,
|
|
23
18
|
address: account?.address,
|
|
24
19
|
wallet: activeWallet,
|
|
25
|
-
|
|
26
|
-
getClient: () => clientFactory.getClient(),
|
|
27
|
-
getSigningClient: () => clientFactory.getSigningClient(),
|
|
28
|
-
getCosmwasmClient: () => clientFactory.getCosmwasmClient(),
|
|
29
|
-
getSigningCosmwasmClient: () => clientFactory.getSigningCosmwasmClient(),
|
|
30
|
-
getSigningStargateClient: () => clientFactory.getSigningStargateClient(),
|
|
31
|
-
getStargateClient: () => clientFactory.getStargateClient(),
|
|
20
|
+
...interchainClient
|
|
32
21
|
};
|
|
33
22
|
};
|
|
34
23
|
exports.useChain = useChain;
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const useChainWallet: (chainName: string, walletName: string) => {
|
|
4
|
-
chain: Chain;
|
|
5
|
-
assetList: AssetList;
|
|
6
|
-
address: string;
|
|
7
|
-
wallet: BaseWallet;
|
|
8
|
-
getRpcEndpoint: () => Promise<string | import("@cosmjs/tendermint-rpc").HttpEndpoint>;
|
|
9
|
-
getClient: () => Promise<import("@cosmjs/stargate").StargateClient | import("@cosmjs/cosmwasm-stargate").CosmWasmClient>;
|
|
10
|
-
getSigningClient: () => Promise<import("@cosmjs/stargate").SigningStargateClient | import("@cosmjs/cosmwasm-stargate").SigningCosmWasmClient>;
|
|
11
|
-
getCosmwasmClient: () => Promise<import("@cosmjs/cosmwasm-stargate").CosmWasmClient>;
|
|
12
|
-
getSigningCosmwasmClient: () => Promise<import("@cosmjs/cosmwasm-stargate").SigningCosmWasmClient>;
|
|
13
|
-
getSigningStargateClient: () => Promise<import("@cosmjs/stargate").SigningStargateClient>;
|
|
14
|
-
getStargateClient: () => Promise<import("@cosmjs/stargate").StargateClient>;
|
|
15
|
-
};
|
|
1
|
+
import { UseChainReturnType } from "../types/chain";
|
|
2
|
+
export declare const useChainWallet: (chainName: string, walletName: string) => UseChainReturnType;
|
package/hooks/useChainWallet.js
CHANGED
|
@@ -3,38 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useChainWallet = void 0;
|
|
4
4
|
const useWalletManager_1 = require("./useWalletManager");
|
|
5
5
|
const useAccount_1 = require("./useAccount");
|
|
6
|
-
const
|
|
7
|
-
const core_1 = require("@interChain-kit/core");
|
|
6
|
+
const useInterchainClient_1 = require("./useInterchainClient");
|
|
8
7
|
const useChainWallet = (chainName, walletName) => {
|
|
9
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
10
9
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
11
10
|
const assetList = walletManager.assetLists.find((a) => a.chainName === chainName);
|
|
12
11
|
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
13
12
|
const account = (0, useAccount_1.useAccount)(chainName, walletName);
|
|
14
|
-
const
|
|
15
|
-
(0, react_1.useEffect)(() => {
|
|
16
|
-
if (!wallet) {
|
|
17
|
-
throw new core_1.WalletNotExist(walletName);
|
|
18
|
-
}
|
|
19
|
-
if (!chainToShow) {
|
|
20
|
-
throw new core_1.ChainNotExist(chainName);
|
|
21
|
-
}
|
|
22
|
-
walletManager.createClientFactory(wallet, chainName).then(clientFactory => {
|
|
23
|
-
setClientFactory(clientFactory);
|
|
24
|
-
});
|
|
25
|
-
}, [chainName, walletName, account?.address]);
|
|
13
|
+
const interchainClient = (0, useInterchainClient_1.useInterchainClient)(chainName, walletName);
|
|
26
14
|
return {
|
|
27
15
|
chain: chainToShow,
|
|
28
16
|
assetList,
|
|
29
17
|
address: account?.address,
|
|
30
18
|
wallet,
|
|
31
|
-
|
|
32
|
-
getClient: () => clientFactory.getClient(),
|
|
33
|
-
getSigningClient: async () => clientFactory.getSigningClient(),
|
|
34
|
-
getCosmwasmClient: () => clientFactory.getCosmwasmClient(),
|
|
35
|
-
getSigningCosmwasmClient: () => clientFactory.getSigningCosmwasmClient(),
|
|
36
|
-
getSigningStargateClient: () => clientFactory.getSigningStargateClient(),
|
|
37
|
-
getStargateClient: () => clientFactory.getStargateClient(),
|
|
19
|
+
...interchainClient
|
|
38
20
|
};
|
|
39
21
|
};
|
|
40
22
|
exports.useChainWallet = useChainWallet;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CosmWasmSigningClient } from 'interchainjs/cosmwasm-stargate';
|
|
2
|
+
import { StargateSigningClient } from 'interchainjs/stargate';
|
|
3
|
+
import { StargateClient, HttpEndpoint } from '@cosmjs/stargate';
|
|
4
|
+
import { SigningClient } from 'interchainjs/signing-client';
|
|
5
|
+
import { RpcQuery } from 'interchainjs/query/rpc';
|
|
6
|
+
export declare const useInterchainClient: (chainName: string, walletName: string) => {
|
|
7
|
+
rpcEndpoint: string | HttpEndpoint;
|
|
8
|
+
signingClient: SigningClient;
|
|
9
|
+
client: RpcQuery;
|
|
10
|
+
stargateSigningClient: StargateSigningClient;
|
|
11
|
+
stargateClient: StargateClient;
|
|
12
|
+
cosmWasmSigningClient: CosmWasmSigningClient;
|
|
13
|
+
error: unknown;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInterchainClient = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useWalletManager_1 = require("./useWalletManager");
|
|
6
|
+
const useAccount_1 = require("./useAccount");
|
|
7
|
+
const useInterchainClient = (chainName, walletName) => {
|
|
8
|
+
const [rpcEndpoint, setRpcEndpoint] = (0, react_1.useState)();
|
|
9
|
+
const [signingClient, setSigningClient] = (0, react_1.useState)(null);
|
|
10
|
+
const [client, setClient] = (0, react_1.useState)(null);
|
|
11
|
+
const [stargateSigningClient, setStargateSigningClient] = (0, react_1.useState)(null);
|
|
12
|
+
const [stargateClient, setStargateClient] = (0, react_1.useState)();
|
|
13
|
+
const [cosmWasmSigningClient, setCosmWasmSigningClient] = (0, react_1.useState)(null);
|
|
14
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
15
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
16
|
+
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
17
|
+
const account = (0, useAccount_1.useAccount)(chainName, walletName);
|
|
18
|
+
const initialize = async () => {
|
|
19
|
+
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
20
|
+
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
21
|
+
if (!wallet) {
|
|
22
|
+
throw new Error('Wallet not found');
|
|
23
|
+
}
|
|
24
|
+
if (!chainToShow) {
|
|
25
|
+
throw new Error('Chain not found');
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
setIsLoading(true);
|
|
29
|
+
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
30
|
+
setRpcEndpoint(rpcEndpoint);
|
|
31
|
+
const clientFactory = await walletManager.createClientFactory(wallet, chainName);
|
|
32
|
+
const client = await clientFactory.getClient();
|
|
33
|
+
setClient(client);
|
|
34
|
+
const signingClient = await clientFactory.getSigningClient();
|
|
35
|
+
setSigningClient(signingClient);
|
|
36
|
+
const stargateClient = await clientFactory.getStargateClient();
|
|
37
|
+
setStargateClient(stargateClient);
|
|
38
|
+
const signingStargateClient = await clientFactory.getSigningStargateClient(chainToShow.bech32Prefix);
|
|
39
|
+
setStargateSigningClient(signingStargateClient);
|
|
40
|
+
const signingCosmwasmClient = await clientFactory.getSigningCosmwasmClient();
|
|
41
|
+
setCosmWasmSigningClient(signingCosmwasmClient);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
setError(error);
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
setIsLoading(false);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
initialize();
|
|
52
|
+
}, [chainName, walletName, account?.address]);
|
|
53
|
+
return {
|
|
54
|
+
rpcEndpoint,
|
|
55
|
+
signingClient,
|
|
56
|
+
client,
|
|
57
|
+
stargateSigningClient,
|
|
58
|
+
stargateClient,
|
|
59
|
+
cosmWasmSigningClient,
|
|
60
|
+
error,
|
|
61
|
+
isLoading
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.useInterchainClient = useInterchainClient;
|
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.2",
|
|
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.2",
|
|
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": "c501ca36b82d71763b563290dd71a3adec50c31f"
|
|
42
42
|
}
|
package/types/chain.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
import { CosmWasmSigningClient } from 'interchainjs/cosmwasm-stargate';
|
|
2
|
+
import { StargateClient } from '@cosmjs/stargate';
|
|
3
|
+
import { SigningClient } from 'interchainjs/signing-client';
|
|
4
|
+
import { RpcQuery } from 'interchainjs/query/rpc';
|
|
5
|
+
import { StargateSigningClient } from 'interchainjs/stargate';
|
|
1
6
|
import { HttpEndpoint } from '@cosmjs/stargate';
|
|
2
7
|
import { Chain, AssetList } from '@chain-registry/v2-types';
|
|
3
|
-
import { BaseWallet
|
|
8
|
+
import { BaseWallet } from '@interChain-kit/core';
|
|
4
9
|
export type UseChainReturnType = {
|
|
5
10
|
chain: Chain;
|
|
6
11
|
assetList: AssetList;
|
|
7
12
|
address: string;
|
|
8
13
|
wallet: BaseWallet;
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
rpcEndpoint: string | HttpEndpoint;
|
|
15
|
+
client: RpcQuery;
|
|
16
|
+
signingClient: SigningClient;
|
|
17
|
+
stargateClient: StargateClient;
|
|
18
|
+
stargateSigningClient: StargateSigningClient;
|
|
19
|
+
cosmWasmSigningClient: CosmWasmSigningClient;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
error: unknown;
|
|
22
|
+
};
|