@interchain-kit/react 0.0.1-beta.45 → 0.0.1-beta.47
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/useAccount.js +14 -6
- package/esm/hooks/useChain.js +30 -1
- package/esm/hooks/useChainWallet.js +8 -1
- package/esm/hooks/useInterchainClient.js +12 -10
- package/esm/hooks/useOfflineSigner.js +12 -10
- package/esm/hooks/useRpcEndpoint.js +14 -6
- package/esm/modal/modal.js +3 -1
- package/esm/modal/views/Connected.js +3 -3
- package/esm/provider.js +3 -3
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useAccount.d.ts +4 -4
- package/hooks/useAccount.js +14 -6
- package/hooks/useChain.js +30 -1
- package/hooks/useChainWallet.js +8 -1
- package/hooks/useConfig.d.ts +1 -0
- package/hooks/useCurrentWallet.d.ts +1 -0
- package/hooks/useInterchainClient.d.ts +4 -4
- package/hooks/useInterchainClient.js +12 -10
- package/hooks/useOfflineSigner.d.ts +4 -4
- package/hooks/useOfflineSigner.js +12 -10
- package/hooks/useRpcEndpoint.d.ts +4 -4
- package/hooks/useRpcEndpoint.js +14 -6
- package/hooks/useWalletManager.d.ts +1 -0
- package/modal/modal.js +3 -1
- package/modal/views/Connected.js +2 -2
- package/package.json +3 -3
- package/provider.js +3 -3
- package/types/chain.d.ts +1 -0
- package/utils/wallet.d.ts +3 -2
package/esm/hooks/index.js
CHANGED
package/esm/hooks/useAccount.js
CHANGED
|
@@ -5,14 +5,22 @@ export const useAccount = (chainName, walletName) => {
|
|
|
5
5
|
const walletManager = useWalletManager();
|
|
6
6
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
7
7
|
useEffect(() => {
|
|
8
|
-
if (chainAccount?.walletState === WalletState.Connected
|
|
8
|
+
if (chainAccount?.walletState === WalletState.Connected) {
|
|
9
9
|
chainAccount.getAccount();
|
|
10
10
|
}
|
|
11
|
-
}, [
|
|
11
|
+
}, [chainName, walletName, chainAccount?.walletState]);
|
|
12
|
+
if (chainAccount?.walletState === WalletState.Connected) {
|
|
13
|
+
return {
|
|
14
|
+
account: chainAccount?.account,
|
|
15
|
+
isLoading: chainAccount.getAccountState().loading,
|
|
16
|
+
error: chainAccount.getAccountState().error,
|
|
17
|
+
getAccount: () => chainAccount?.getAccount()
|
|
18
|
+
};
|
|
19
|
+
}
|
|
12
20
|
return {
|
|
13
|
-
account:
|
|
14
|
-
isLoading:
|
|
15
|
-
error:
|
|
16
|
-
getAccount: chainAccount?.getAccount
|
|
21
|
+
account: undefined,
|
|
22
|
+
isLoading: false,
|
|
23
|
+
error: null,
|
|
24
|
+
getAccount: () => chainAccount?.getAccount()
|
|
17
25
|
};
|
|
18
26
|
};
|
package/esm/hooks/useChain.js
CHANGED
|
@@ -4,6 +4,7 @@ import { useCurrentWallet } from './useCurrentWallet';
|
|
|
4
4
|
import { useInterchainClient } from './useInterchainClient';
|
|
5
5
|
import { useWalletModal } from "../modal";
|
|
6
6
|
import { useRpcEndpoint } from "./useRpcEndpoint";
|
|
7
|
+
import { WalletState } from "@interchain-kit/core";
|
|
7
8
|
export const useChain = (chainName) => {
|
|
8
9
|
const walletManager = useWalletManager();
|
|
9
10
|
const currentWallet = useCurrentWallet();
|
|
@@ -14,7 +15,14 @@ export const useChain = (chainName) => {
|
|
|
14
15
|
const signingClientHook = useInterchainClient(chainName, walletName);
|
|
15
16
|
const { open, close } = useWalletModal();
|
|
16
17
|
const cosmosKitUserChainReturnType = {
|
|
17
|
-
connect: () =>
|
|
18
|
+
connect: () => {
|
|
19
|
+
if (chainAccount?.walletState === WalletState.Connected) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
open();
|
|
24
|
+
}
|
|
25
|
+
},
|
|
18
26
|
disconnect: () => chainAccount.disconnect(),
|
|
19
27
|
openView: open,
|
|
20
28
|
closeView: close,
|
|
@@ -23,6 +31,26 @@ export const useChain = (chainName) => {
|
|
|
23
31
|
username: accountHook.account?.username,
|
|
24
32
|
message: currentWallet?.errorMessage
|
|
25
33
|
};
|
|
34
|
+
if (currentWallet && chainAccount?.walletState === WalletState.Connected) {
|
|
35
|
+
return {
|
|
36
|
+
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
37
|
+
chain: chainAccount?.chain,
|
|
38
|
+
assetList: chainAccount?.assetList,
|
|
39
|
+
address: accountHook.account?.address,
|
|
40
|
+
wallet: currentWallet,
|
|
41
|
+
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
42
|
+
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
43
|
+
signingClient: signingClientHook.signingClient,
|
|
44
|
+
getSigningClient: () => signingClientHook.getSigningClient(),
|
|
45
|
+
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
46
|
+
isAccountLoading: accountHook.isLoading,
|
|
47
|
+
isSigningClientLoading: signingClientHook.isLoading,
|
|
48
|
+
isLoading: rpcEndpointHook.isLoading || accountHook.isLoading || signingClientHook.isLoading,
|
|
49
|
+
getRpcEndpointError: rpcEndpointHook.error,
|
|
50
|
+
getSigningClientError: signingClientHook.error,
|
|
51
|
+
getAccountError: accountHook.error
|
|
52
|
+
};
|
|
53
|
+
}
|
|
26
54
|
return {
|
|
27
55
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
28
56
|
chain: chainAccount?.chain,
|
|
@@ -32,6 +60,7 @@ export const useChain = (chainName) => {
|
|
|
32
60
|
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
33
61
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
34
62
|
signingClient: signingClientHook.signingClient,
|
|
63
|
+
getSigningClient: () => signingClientHook.getSigningClient(),
|
|
35
64
|
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
36
65
|
isAccountLoading: accountHook.isLoading,
|
|
37
66
|
isSigningClientLoading: signingClientHook.isLoading,
|
|
@@ -2,6 +2,7 @@ import { useWalletManager } from "./useWalletManager";
|
|
|
2
2
|
import { useAccount } from "./useAccount";
|
|
3
3
|
import { useInterchainClient } from "./useInterchainClient";
|
|
4
4
|
import { useRpcEndpoint } from "./useRpcEndpoint";
|
|
5
|
+
import { WalletState } from "@interchain-kit/core";
|
|
5
6
|
export const useChainWallet = (chainName, walletName) => {
|
|
6
7
|
const walletManager = useWalletManager();
|
|
7
8
|
const walletRepository = walletManager.getWalletRepositoryByName(walletName);
|
|
@@ -10,7 +11,12 @@ export const useChainWallet = (chainName, walletName) => {
|
|
|
10
11
|
const accountHook = useAccount(chainName, walletName);
|
|
11
12
|
const signingClientHook = useInterchainClient(chainName, walletName);
|
|
12
13
|
return {
|
|
13
|
-
connect: () =>
|
|
14
|
+
connect: () => {
|
|
15
|
+
if (!chainAccount && chainAccount.walletState === WalletState.Connected) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
chainAccount.connect();
|
|
19
|
+
},
|
|
14
20
|
disconnect: () => chainAccount.disconnect(),
|
|
15
21
|
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
16
22
|
status: chainAccount.walletState,
|
|
@@ -23,6 +29,7 @@ export const useChainWallet = (chainName, walletName) => {
|
|
|
23
29
|
address: accountHook.account?.address,
|
|
24
30
|
wallet: walletRepository,
|
|
25
31
|
signingClient: signingClientHook.signingClient,
|
|
32
|
+
getSigningClient: () => signingClientHook.getSigningClient(),
|
|
26
33
|
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
27
34
|
isAccountLoading: accountHook.isLoading,
|
|
28
35
|
isSigningClientLoading: signingClientHook.isLoading,
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
1
|
import { useWalletManager } from './useWalletManager';
|
|
3
2
|
import { WalletState } from '@interchain-kit/core';
|
|
4
3
|
export const useInterchainClient = (chainName, walletName) => {
|
|
5
4
|
const walletManager = useWalletManager();
|
|
6
5
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
chainAccount
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
if (chainAccount && chainAccount.walletState === WalletState.Connected) {
|
|
7
|
+
return {
|
|
8
|
+
signingClient: chainAccount?.signingClient,
|
|
9
|
+
isLoading: chainAccount?.getSigningClientState().loading,
|
|
10
|
+
error: chainAccount?.getSigningClientState().error,
|
|
11
|
+
getSigningClient: () => chainAccount?.getSigningClient()
|
|
12
|
+
};
|
|
13
|
+
}
|
|
12
14
|
return {
|
|
13
|
-
signingClient:
|
|
14
|
-
isLoading:
|
|
15
|
-
error:
|
|
16
|
-
getSigningClient: chainAccount?.getSigningClient
|
|
15
|
+
signingClient: undefined,
|
|
16
|
+
isLoading: false,
|
|
17
|
+
error: undefined,
|
|
18
|
+
getSigningClient: () => chainAccount?.getSigningClient()
|
|
17
19
|
};
|
|
18
20
|
};
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
1
|
import { useWalletManager } from "./useWalletManager";
|
|
3
2
|
import { WalletState } from "@interchain-kit/core";
|
|
4
3
|
export const useOfflineSigner = (chainName, walletName) => {
|
|
5
4
|
const walletManager = useWalletManager();
|
|
6
5
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
chainAccount
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
if (chainAccount && chainAccount.walletState === WalletState.Connected) {
|
|
7
|
+
return {
|
|
8
|
+
offlineSigner: chainAccount?.offlineSigner,
|
|
9
|
+
isLoading: chainAccount?.getOfflineSignerState().loading,
|
|
10
|
+
error: chainAccount?.getOfflineSignerState().error,
|
|
11
|
+
getOfflineSigner: () => chainAccount?.getOfflineSigner()
|
|
12
|
+
};
|
|
13
|
+
}
|
|
12
14
|
return {
|
|
13
|
-
offlineSigner:
|
|
14
|
-
isLoading:
|
|
15
|
-
error:
|
|
16
|
-
getOfflineSigner: chainAccount?.getOfflineSigner
|
|
15
|
+
offlineSigner: undefined,
|
|
16
|
+
isLoading: false,
|
|
17
|
+
error: undefined,
|
|
18
|
+
getOfflineSigner: () => chainAccount?.getOfflineSigner()
|
|
17
19
|
};
|
|
18
20
|
};
|
|
@@ -5,14 +5,22 @@ export const useRpcEndpoint = (chainName, walletName) => {
|
|
|
5
5
|
const walletManager = useWalletManager();
|
|
6
6
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
7
7
|
useEffect(() => {
|
|
8
|
-
if (chainAccount?.walletState === WalletState.Connected
|
|
8
|
+
if (chainAccount?.walletState === WalletState.Connected) {
|
|
9
9
|
chainAccount.getRpcEndpoint();
|
|
10
10
|
}
|
|
11
|
-
}, [
|
|
11
|
+
}, [chainName, walletName, chainAccount?.walletState]);
|
|
12
|
+
if (chainAccount && chainAccount.walletState === WalletState.Connected) {
|
|
13
|
+
return {
|
|
14
|
+
rpcEndpoint: chainAccount?.rpcEndpoint,
|
|
15
|
+
isLoading: chainAccount?.getRpcEndpointState().loading,
|
|
16
|
+
error: chainAccount?.getRpcEndpointState().error,
|
|
17
|
+
getRpcEndpoint: () => chainAccount?.getRpcEndpoint()
|
|
18
|
+
};
|
|
19
|
+
}
|
|
12
20
|
return {
|
|
13
|
-
rpcEndpoint:
|
|
14
|
-
isLoading:
|
|
15
|
-
error:
|
|
16
|
-
getRpcEndpoint: chainAccount?.getRpcEndpoint
|
|
21
|
+
rpcEndpoint: undefined,
|
|
22
|
+
isLoading: false,
|
|
23
|
+
error: undefined,
|
|
24
|
+
getRpcEndpoint: () => chainAccount?.getRpcEndpoint()
|
|
17
25
|
};
|
|
18
26
|
};
|
package/esm/modal/modal.js
CHANGED
|
@@ -8,6 +8,7 @@ import { ConnectModal } from "@interchain-ui/react";
|
|
|
8
8
|
export const WalletModal = () => {
|
|
9
9
|
const { modalIsOpen, open, close } = useWalletModal();
|
|
10
10
|
const currentWallet = useCurrentWallet();
|
|
11
|
+
const currentChainAccount = currentWallet?.getChainAccountByName?.(currentWallet.currentChainName);
|
|
11
12
|
const walletManager = useWalletManager();
|
|
12
13
|
const handleSelectWallet = async (wallet) => {
|
|
13
14
|
const selectedWallet = walletManager.getWalletByName(wallet.info.name);
|
|
@@ -55,7 +56,8 @@ export const WalletModal = () => {
|
|
|
55
56
|
const [modalView, setModalView] = useState(defaultModalView);
|
|
56
57
|
const gotoWalletList = () => setModalView(defaultModalView);
|
|
57
58
|
useEffect(() => {
|
|
58
|
-
if (modalIsOpen &&
|
|
59
|
+
if (modalIsOpen &&
|
|
60
|
+
currentChainAccount?.walletState === WalletState.Connected) {
|
|
59
61
|
setModalView({
|
|
60
62
|
header: _jsx(ConnectedHeader, { onBack: gotoWalletList }),
|
|
61
63
|
content: _jsx(ConnectedContent, {}),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ConnectModalHead, ConnectModalStatus } from "@interchain-ui/react";
|
|
3
|
-
import { useAccount, useCurrentWallet
|
|
3
|
+
import { useAccount, useCurrentWallet } from "../../hooks";
|
|
4
4
|
import { useWalletModal } from "../provider";
|
|
5
5
|
import { getWalletInfo } from "../../utils";
|
|
6
6
|
import { AstronautSvg } from "./Astronaut";
|
|
@@ -11,7 +11,7 @@ export const ConnectedHeader = ({ onBack }) => {
|
|
|
11
11
|
};
|
|
12
12
|
export const ConnectedContent = () => {
|
|
13
13
|
const currentWallet = useCurrentWallet();
|
|
14
|
-
const
|
|
14
|
+
const chainAccount = currentWallet?.getChainAccountByName?.(currentWallet.currentChainName);
|
|
15
15
|
const { account } = useAccount(currentWallet.currentChainName, currentWallet?.info?.name);
|
|
16
16
|
const { close } = useWalletModal();
|
|
17
17
|
if (!currentWallet) {
|
|
@@ -26,7 +26,7 @@ export const ConnectedContent = () => {
|
|
|
26
26
|
} })),
|
|
27
27
|
address: account?.address,
|
|
28
28
|
}, onDisconnect: async () => {
|
|
29
|
-
await
|
|
29
|
+
await chainAccount.disconnect();
|
|
30
30
|
close();
|
|
31
31
|
} }));
|
|
32
32
|
};
|
package/esm/provider.js
CHANGED
|
@@ -8,9 +8,9 @@ export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endp
|
|
|
8
8
|
const [_, forceRender] = useState({});
|
|
9
9
|
const walletManager = useMemo(() => {
|
|
10
10
|
const wm = new WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const observable = wm.getObservableObj();
|
|
12
|
+
observable.subscribe(() => forceRender({}));
|
|
13
|
+
return observable;
|
|
14
14
|
}, []);
|
|
15
15
|
useEffect(() => {
|
|
16
16
|
walletManager.init();
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.js
CHANGED
package/hooks/useAccount.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const useAccount: (chainName: string, walletName: string) => {
|
|
2
|
-
account:
|
|
3
|
-
isLoading:
|
|
4
|
-
error:
|
|
5
|
-
getAccount:
|
|
2
|
+
account: import("@interchain-kit/core").WalletAccount;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
error: Error;
|
|
5
|
+
getAccount: () => Promise<import("@interchain-kit/core").WalletAccount>;
|
|
6
6
|
};
|
package/hooks/useAccount.js
CHANGED
|
@@ -8,15 +8,23 @@ const useAccount = (chainName, walletName) => {
|
|
|
8
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
9
9
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
10
10
|
(0, react_1.useEffect)(() => {
|
|
11
|
-
if (chainAccount?.walletState === core_1.WalletState.Connected
|
|
11
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
12
12
|
chainAccount.getAccount();
|
|
13
13
|
}
|
|
14
|
-
}, [
|
|
14
|
+
}, [chainName, walletName, chainAccount?.walletState]);
|
|
15
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
16
|
+
return {
|
|
17
|
+
account: chainAccount?.account,
|
|
18
|
+
isLoading: chainAccount.getAccountState().loading,
|
|
19
|
+
error: chainAccount.getAccountState().error,
|
|
20
|
+
getAccount: () => chainAccount?.getAccount()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
15
23
|
return {
|
|
16
|
-
account:
|
|
17
|
-
isLoading:
|
|
18
|
-
error:
|
|
19
|
-
getAccount: chainAccount?.getAccount
|
|
24
|
+
account: undefined,
|
|
25
|
+
isLoading: false,
|
|
26
|
+
error: null,
|
|
27
|
+
getAccount: () => chainAccount?.getAccount()
|
|
20
28
|
};
|
|
21
29
|
};
|
|
22
30
|
exports.useAccount = useAccount;
|
package/hooks/useChain.js
CHANGED
|
@@ -7,6 +7,7 @@ const useCurrentWallet_1 = require("./useCurrentWallet");
|
|
|
7
7
|
const useInterchainClient_1 = require("./useInterchainClient");
|
|
8
8
|
const modal_1 = require("../modal");
|
|
9
9
|
const useRpcEndpoint_1 = require("./useRpcEndpoint");
|
|
10
|
+
const core_1 = require("@interchain-kit/core");
|
|
10
11
|
const useChain = (chainName) => {
|
|
11
12
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
12
13
|
const currentWallet = (0, useCurrentWallet_1.useCurrentWallet)();
|
|
@@ -17,7 +18,14 @@ const useChain = (chainName) => {
|
|
|
17
18
|
const signingClientHook = (0, useInterchainClient_1.useInterchainClient)(chainName, walletName);
|
|
18
19
|
const { open, close } = (0, modal_1.useWalletModal)();
|
|
19
20
|
const cosmosKitUserChainReturnType = {
|
|
20
|
-
connect: () =>
|
|
21
|
+
connect: () => {
|
|
22
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
open();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
21
29
|
disconnect: () => chainAccount.disconnect(),
|
|
22
30
|
openView: open,
|
|
23
31
|
closeView: close,
|
|
@@ -26,6 +34,26 @@ const useChain = (chainName) => {
|
|
|
26
34
|
username: accountHook.account?.username,
|
|
27
35
|
message: currentWallet?.errorMessage
|
|
28
36
|
};
|
|
37
|
+
if (currentWallet && chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
38
|
+
return {
|
|
39
|
+
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
40
|
+
chain: chainAccount?.chain,
|
|
41
|
+
assetList: chainAccount?.assetList,
|
|
42
|
+
address: accountHook.account?.address,
|
|
43
|
+
wallet: currentWallet,
|
|
44
|
+
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
45
|
+
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
46
|
+
signingClient: signingClientHook.signingClient,
|
|
47
|
+
getSigningClient: () => signingClientHook.getSigningClient(),
|
|
48
|
+
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
49
|
+
isAccountLoading: accountHook.isLoading,
|
|
50
|
+
isSigningClientLoading: signingClientHook.isLoading,
|
|
51
|
+
isLoading: rpcEndpointHook.isLoading || accountHook.isLoading || signingClientHook.isLoading,
|
|
52
|
+
getRpcEndpointError: rpcEndpointHook.error,
|
|
53
|
+
getSigningClientError: signingClientHook.error,
|
|
54
|
+
getAccountError: accountHook.error
|
|
55
|
+
};
|
|
56
|
+
}
|
|
29
57
|
return {
|
|
30
58
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
31
59
|
chain: chainAccount?.chain,
|
|
@@ -35,6 +63,7 @@ const useChain = (chainName) => {
|
|
|
35
63
|
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
36
64
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
37
65
|
signingClient: signingClientHook.signingClient,
|
|
66
|
+
getSigningClient: () => signingClientHook.getSigningClient(),
|
|
38
67
|
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
39
68
|
isAccountLoading: accountHook.isLoading,
|
|
40
69
|
isSigningClientLoading: signingClientHook.isLoading,
|
package/hooks/useChainWallet.js
CHANGED
|
@@ -5,6 +5,7 @@ const useWalletManager_1 = require("./useWalletManager");
|
|
|
5
5
|
const useAccount_1 = require("./useAccount");
|
|
6
6
|
const useInterchainClient_1 = require("./useInterchainClient");
|
|
7
7
|
const useRpcEndpoint_1 = require("./useRpcEndpoint");
|
|
8
|
+
const core_1 = require("@interchain-kit/core");
|
|
8
9
|
const useChainWallet = (chainName, walletName) => {
|
|
9
10
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
10
11
|
const walletRepository = walletManager.getWalletRepositoryByName(walletName);
|
|
@@ -13,7 +14,12 @@ const useChainWallet = (chainName, walletName) => {
|
|
|
13
14
|
const accountHook = (0, useAccount_1.useAccount)(chainName, walletName);
|
|
14
15
|
const signingClientHook = (0, useInterchainClient_1.useInterchainClient)(chainName, walletName);
|
|
15
16
|
return {
|
|
16
|
-
connect: () =>
|
|
17
|
+
connect: () => {
|
|
18
|
+
if (!chainAccount && chainAccount.walletState === core_1.WalletState.Connected) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
chainAccount.connect();
|
|
22
|
+
},
|
|
17
23
|
disconnect: () => chainAccount.disconnect(),
|
|
18
24
|
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
19
25
|
status: chainAccount.walletState,
|
|
@@ -26,6 +32,7 @@ const useChainWallet = (chainName, walletName) => {
|
|
|
26
32
|
address: accountHook.account?.address,
|
|
27
33
|
wallet: walletRepository,
|
|
28
34
|
signingClient: signingClientHook.signingClient,
|
|
35
|
+
getSigningClient: () => signingClientHook.getSigningClient(),
|
|
29
36
|
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
30
37
|
isAccountLoading: accountHook.isLoading,
|
|
31
38
|
isSigningClientLoading: signingClientHook.isLoading,
|
package/hooks/useConfig.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AssetList, Chain } from "@chain-registry/v2-types";
|
|
2
|
+
import { EndpointOptions, SignerOptions } from "@interchain-kit/core";
|
|
2
3
|
export declare const useConfig: () => {
|
|
3
4
|
updateChains: (chains: Chain[]) => Chain[];
|
|
4
5
|
updateAssetLists: (assetLists: AssetList[]) => AssetList[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const useInterchainClient: (chainName: string, walletName: string) => {
|
|
2
|
-
signingClient:
|
|
3
|
-
isLoading:
|
|
4
|
-
error:
|
|
5
|
-
getSigningClient:
|
|
2
|
+
signingClient: import("@interchainjs/cosmos/signing-client").SigningClient;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
error: Error;
|
|
5
|
+
getSigningClient: () => Promise<import("@interchainjs/cosmos/signing-client").SigningClient>;
|
|
6
6
|
};
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useInterchainClient = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
4
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
5
|
const core_1 = require("@interchain-kit/core");
|
|
7
6
|
const useInterchainClient = (chainName, walletName) => {
|
|
8
7
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
9
8
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
chainAccount
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (chainAccount && chainAccount.walletState === core_1.WalletState.Connected) {
|
|
10
|
+
return {
|
|
11
|
+
signingClient: chainAccount?.signingClient,
|
|
12
|
+
isLoading: chainAccount?.getSigningClientState().loading,
|
|
13
|
+
error: chainAccount?.getSigningClientState().error,
|
|
14
|
+
getSigningClient: () => chainAccount?.getSigningClient()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
15
17
|
return {
|
|
16
|
-
signingClient:
|
|
17
|
-
isLoading:
|
|
18
|
-
error:
|
|
19
|
-
getSigningClient: chainAccount?.getSigningClient
|
|
18
|
+
signingClient: undefined,
|
|
19
|
+
isLoading: false,
|
|
20
|
+
error: undefined,
|
|
21
|
+
getSigningClient: () => chainAccount?.getSigningClient()
|
|
20
22
|
};
|
|
21
23
|
};
|
|
22
24
|
exports.useInterchainClient = useInterchainClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const useOfflineSigner: (chainName: string, walletName: string) => {
|
|
2
|
-
offlineSigner:
|
|
3
|
-
isLoading:
|
|
4
|
-
error:
|
|
5
|
-
getOfflineSigner:
|
|
2
|
+
offlineSigner: import("@interchainjs/cosmos/types/wallet").OfflineSigner;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
error: Error;
|
|
5
|
+
getOfflineSigner: () => import("@interchainjs/cosmos/types/wallet").ICosmosGenericOfflineSigner;
|
|
6
6
|
};
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useOfflineSigner = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
4
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
5
|
const core_1 = require("@interchain-kit/core");
|
|
7
6
|
const useOfflineSigner = (chainName, walletName) => {
|
|
8
7
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
9
8
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
chainAccount
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (chainAccount && chainAccount.walletState === core_1.WalletState.Connected) {
|
|
10
|
+
return {
|
|
11
|
+
offlineSigner: chainAccount?.offlineSigner,
|
|
12
|
+
isLoading: chainAccount?.getOfflineSignerState().loading,
|
|
13
|
+
error: chainAccount?.getOfflineSignerState().error,
|
|
14
|
+
getOfflineSigner: () => chainAccount?.getOfflineSigner()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
15
17
|
return {
|
|
16
|
-
offlineSigner:
|
|
17
|
-
isLoading:
|
|
18
|
-
error:
|
|
19
|
-
getOfflineSigner: chainAccount?.getOfflineSigner
|
|
18
|
+
offlineSigner: undefined,
|
|
19
|
+
isLoading: false,
|
|
20
|
+
error: undefined,
|
|
21
|
+
getOfflineSigner: () => chainAccount?.getOfflineSigner()
|
|
20
22
|
};
|
|
21
23
|
};
|
|
22
24
|
exports.useOfflineSigner = useOfflineSigner;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const useRpcEndpoint: (chainName: string, walletName: string) => {
|
|
2
|
-
rpcEndpoint:
|
|
3
|
-
isLoading:
|
|
4
|
-
error:
|
|
5
|
-
getRpcEndpoint:
|
|
2
|
+
rpcEndpoint: string | import("@interchainjs/types").HttpEndpoint;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
error: Error;
|
|
5
|
+
getRpcEndpoint: () => Promise<string | import("@interchainjs/types").HttpEndpoint>;
|
|
6
6
|
};
|
package/hooks/useRpcEndpoint.js
CHANGED
|
@@ -8,15 +8,23 @@ const useRpcEndpoint = (chainName, walletName) => {
|
|
|
8
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
9
9
|
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
10
10
|
(0, react_1.useEffect)(() => {
|
|
11
|
-
if (chainAccount?.walletState === core_1.WalletState.Connected
|
|
11
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
12
12
|
chainAccount.getRpcEndpoint();
|
|
13
13
|
}
|
|
14
|
-
}, [
|
|
14
|
+
}, [chainName, walletName, chainAccount?.walletState]);
|
|
15
|
+
if (chainAccount && chainAccount.walletState === core_1.WalletState.Connected) {
|
|
16
|
+
return {
|
|
17
|
+
rpcEndpoint: chainAccount?.rpcEndpoint,
|
|
18
|
+
isLoading: chainAccount?.getRpcEndpointState().loading,
|
|
19
|
+
error: chainAccount?.getRpcEndpointState().error,
|
|
20
|
+
getRpcEndpoint: () => chainAccount?.getRpcEndpoint()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
15
23
|
return {
|
|
16
|
-
rpcEndpoint:
|
|
17
|
-
isLoading:
|
|
18
|
-
error:
|
|
19
|
-
getRpcEndpoint: chainAccount?.getRpcEndpoint
|
|
24
|
+
rpcEndpoint: undefined,
|
|
25
|
+
isLoading: false,
|
|
26
|
+
error: undefined,
|
|
27
|
+
getRpcEndpoint: () => chainAccount?.getRpcEndpoint()
|
|
20
28
|
};
|
|
21
29
|
};
|
|
22
30
|
exports.useRpcEndpoint = useRpcEndpoint;
|
package/modal/modal.js
CHANGED
|
@@ -11,6 +11,7 @@ const react_2 = require("@interchain-ui/react");
|
|
|
11
11
|
const WalletModal = () => {
|
|
12
12
|
const { modalIsOpen, open, close } = (0, provider_1.useWalletModal)();
|
|
13
13
|
const currentWallet = (0, hooks_1.useCurrentWallet)();
|
|
14
|
+
const currentChainAccount = currentWallet?.getChainAccountByName?.(currentWallet.currentChainName);
|
|
14
15
|
const walletManager = (0, hooks_1.useWalletManager)();
|
|
15
16
|
const handleSelectWallet = async (wallet) => {
|
|
16
17
|
const selectedWallet = walletManager.getWalletByName(wallet.info.name);
|
|
@@ -58,7 +59,8 @@ const WalletModal = () => {
|
|
|
58
59
|
const [modalView, setModalView] = (0, react_1.useState)(defaultModalView);
|
|
59
60
|
const gotoWalletList = () => setModalView(defaultModalView);
|
|
60
61
|
(0, react_1.useEffect)(() => {
|
|
61
|
-
if (modalIsOpen &&
|
|
62
|
+
if (modalIsOpen &&
|
|
63
|
+
currentChainAccount?.walletState === core_1.WalletState.Connected) {
|
|
62
64
|
setModalView({
|
|
63
65
|
header: (0, jsx_runtime_1.jsx)(views_1.ConnectedHeader, { onBack: gotoWalletList }),
|
|
64
66
|
content: (0, jsx_runtime_1.jsx)(views_1.ConnectedContent, {}),
|
package/modal/views/Connected.js
CHANGED
|
@@ -15,7 +15,7 @@ const ConnectedHeader = ({ onBack }) => {
|
|
|
15
15
|
exports.ConnectedHeader = ConnectedHeader;
|
|
16
16
|
const ConnectedContent = () => {
|
|
17
17
|
const currentWallet = (0, hooks_1.useCurrentWallet)();
|
|
18
|
-
const
|
|
18
|
+
const chainAccount = currentWallet?.getChainAccountByName?.(currentWallet.currentChainName);
|
|
19
19
|
const { account } = (0, hooks_1.useAccount)(currentWallet.currentChainName, currentWallet?.info?.name);
|
|
20
20
|
const { close } = (0, provider_1.useWalletModal)();
|
|
21
21
|
if (!currentWallet) {
|
|
@@ -30,7 +30,7 @@ const ConnectedContent = () => {
|
|
|
30
30
|
} })),
|
|
31
31
|
address: account?.address,
|
|
32
32
|
}, onDisconnect: async () => {
|
|
33
|
-
await
|
|
33
|
+
await chainAccount.disconnect();
|
|
34
34
|
close();
|
|
35
35
|
} }));
|
|
36
36
|
};
|
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.47",
|
|
4
4
|
"author": "cosmology-tech <developers@cosmology.zone>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"keywords": [],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@chain-registry/v2-types": "^0.53.40",
|
|
36
|
-
"@interchain-kit/core": "0.0.1-beta.
|
|
36
|
+
"@interchain-kit/core": "0.0.1-beta.47",
|
|
37
37
|
"@interchain-ui/react": "1.26.1",
|
|
38
38
|
"@interchainjs/cosmos": "1.6.3",
|
|
39
39
|
"@interchainjs/cosmos-types": "1.6.3",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react": "^18.3.1",
|
|
49
49
|
"react-dom": "^18.3.1"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ecd10d66d0c74955a26c75659d998f31663fcb93"
|
|
52
52
|
}
|
package/provider.js
CHANGED
|
@@ -11,9 +11,9 @@ const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOpt
|
|
|
11
11
|
const [_, forceRender] = (0, react_1.useState)({});
|
|
12
12
|
const walletManager = (0, react_1.useMemo)(() => {
|
|
13
13
|
const wm = new core_1.WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const observable = wm.getObservableObj();
|
|
15
|
+
observable.subscribe(() => forceRender({}));
|
|
16
|
+
return observable;
|
|
17
17
|
}, []);
|
|
18
18
|
(0, react_1.useEffect)(() => {
|
|
19
19
|
walletManager.init();
|
package/types/chain.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export type UseChainReturnType = {
|
|
|
20
20
|
wallet: BaseWallet;
|
|
21
21
|
rpcEndpoint: string | HttpEndpoint;
|
|
22
22
|
signingClient: SigningClient;
|
|
23
|
+
getSigningClient: () => Promise<SigningClient>;
|
|
23
24
|
isRpcEndpointLoading: boolean;
|
|
24
25
|
isAccountLoading: boolean;
|
|
25
26
|
isSigningClientLoading: boolean;
|
package/utils/wallet.d.ts
CHANGED