@interchain-kit/react 0.0.1-beta.43 → 0.0.1-beta.45
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/useAccount.js +12 -33
- package/esm/hooks/useChain.js +22 -28
- package/esm/hooks/useChainWallet.js +25 -41
- package/esm/hooks/useCurrentWallet.js +6 -1
- package/esm/hooks/useInterchainClient.js +10 -34
- package/esm/hooks/useOfflineSigner.js +10 -7
- package/esm/hooks/useRpcEndpoint.js +18 -0
- package/esm/hooks/useWalletManager.js +2 -1
- package/esm/modal/views/Connected.js +1 -1
- package/esm/modal/views/QRCode.js +2 -1
- package/esm/provider.js +8 -2
- package/esm/utils/helpers.js +11 -0
- package/hooks/useAccount.d.ts +6 -2
- package/hooks/useAccount.js +11 -32
- package/hooks/useChain.js +22 -28
- package/hooks/useChainWallet.js +25 -41
- package/hooks/useConfig.d.ts +0 -1
- package/hooks/useCurrentWallet.d.ts +1 -1
- package/hooks/useCurrentWallet.js +6 -1
- package/hooks/useInterchainClient.d.ts +6 -2
- package/hooks/useInterchainClient.js +9 -33
- package/hooks/useOfflineSigner.d.ts +4 -2
- package/hooks/useOfflineSigner.js +9 -6
- package/hooks/useRpcEndpoint.d.ts +6 -0
- package/hooks/useRpcEndpoint.js +22 -0
- package/hooks/useWalletManager.d.ts +0 -1
- package/hooks/useWalletManager.js +2 -1
- package/modal/views/Connected.js +1 -1
- package/modal/views/QRCode.js +2 -1
- package/package.json +10 -7
- package/provider.js +7 -1
- package/types/chain.d.ts +6 -2
- package/utils/helpers.d.ts +1 -0
- package/utils/helpers.js +15 -0
- package/utils/wallet.d.ts +2 -3
package/esm/hooks/useAccount.js
CHANGED
|
@@ -1,39 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WalletManagerState, WalletState } from "@interchain-kit/core";
|
|
1
|
+
import { WalletState } from "@interchain-kit/core";
|
|
3
2
|
import { useWalletManager } from './useWalletManager';
|
|
3
|
+
import { useEffect } from "react";
|
|
4
4
|
export const useAccount = (chainName, walletName) => {
|
|
5
5
|
const walletManager = useWalletManager();
|
|
6
|
-
const
|
|
7
|
-
const wallet = useMemo(() => {
|
|
8
|
-
return walletManager.wallets.find(w => w.info.name === walletName);
|
|
9
|
-
}, [walletManager, walletName]);
|
|
10
|
-
const [account, setAccount] = useState(null);
|
|
11
|
-
const chain = useMemo(() => {
|
|
12
|
-
return walletManager.chains.find(c => c.chainName === chainName);
|
|
13
|
-
}, [walletManager, chainName]);
|
|
14
|
-
const getAccount = async () => {
|
|
15
|
-
if (wallet && chain) {
|
|
16
|
-
if (wallet.walletState === WalletState.Connected && !isFetching) {
|
|
17
|
-
setIsFetching(true);
|
|
18
|
-
const account = await walletManager.getAccount(walletName, chainName);
|
|
19
|
-
setAccount(account);
|
|
20
|
-
setIsFetching(false);
|
|
21
|
-
}
|
|
22
|
-
if (wallet.walletState === WalletState.Disconnected) {
|
|
23
|
-
setAccount(null);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (!wallet) {
|
|
27
|
-
setAccount(null);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
6
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
30
7
|
useEffect(() => {
|
|
31
|
-
if (
|
|
32
|
-
|
|
8
|
+
if (chainAccount?.walletState === WalletState.Connected && !chainAccount?.account && chainName && walletName) {
|
|
9
|
+
chainAccount.getAccount();
|
|
33
10
|
}
|
|
34
|
-
}, [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
}, [chainAccount?.walletState, chainName, walletName]);
|
|
12
|
+
return {
|
|
13
|
+
account: chainAccount?.account || undefined,
|
|
14
|
+
isLoading: chainAccount?.getAccountState().loading || false,
|
|
15
|
+
error: chainAccount?.getAccountState().error || undefined,
|
|
16
|
+
getAccount: chainAccount?.getAccount
|
|
17
|
+
};
|
|
39
18
|
};
|
package/esm/hooks/useChain.js
CHANGED
|
@@ -3,47 +3,41 @@ import { useAccount } from "./useAccount";
|
|
|
3
3
|
import { useCurrentWallet } from './useCurrentWallet';
|
|
4
4
|
import { useInterchainClient } from './useInterchainClient';
|
|
5
5
|
import { useWalletModal } from "../modal";
|
|
6
|
-
import {
|
|
7
|
-
import { useCallback } from "react";
|
|
6
|
+
import { useRpcEndpoint } from "./useRpcEndpoint";
|
|
8
7
|
export const useChain = (chainName) => {
|
|
9
8
|
const walletManager = useWalletManager();
|
|
10
|
-
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
11
|
-
const assetList = walletManager.assetLists.find((a) => a.chainName === chainName);
|
|
12
9
|
const currentWallet = useCurrentWallet();
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const chainAccount = currentWallet?.getChainAccountByName?.(chainName);
|
|
11
|
+
const walletName = currentWallet?.info?.name;
|
|
12
|
+
const rpcEndpointHook = useRpcEndpoint(chainName, walletName);
|
|
13
|
+
const accountHook = useAccount(chainName, walletName);
|
|
14
|
+
const signingClientHook = useInterchainClient(chainName, walletName);
|
|
18
15
|
const { open, close } = useWalletModal();
|
|
19
|
-
const getRpcEndpoint = useCallback(async () => {
|
|
20
|
-
return await walletManager.getRpcEndpoint(currentWallet, chainName);
|
|
21
|
-
}, [walletManager, currentWallet, chainName]);
|
|
22
|
-
const disconnect = useCallback(() => {
|
|
23
|
-
walletManager.disconnect(currentWallet?.info?.name);
|
|
24
|
-
}, [walletManager, currentWallet]);
|
|
25
16
|
const cosmosKitUserChainReturnType = {
|
|
26
|
-
connect: () =>
|
|
27
|
-
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
open();
|
|
31
|
-
},
|
|
32
|
-
disconnect,
|
|
17
|
+
connect: () => chainAccount.connect(),
|
|
18
|
+
disconnect: () => chainAccount.disconnect(),
|
|
33
19
|
openView: open,
|
|
34
20
|
closeView: close,
|
|
35
|
-
getRpcEndpoint,
|
|
21
|
+
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
36
22
|
status: currentWallet?.walletState,
|
|
37
|
-
username: account?.username,
|
|
23
|
+
username: accountHook.account?.username,
|
|
38
24
|
message: currentWallet?.errorMessage
|
|
39
25
|
};
|
|
40
26
|
return {
|
|
41
27
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
42
|
-
chain:
|
|
43
|
-
assetList,
|
|
44
|
-
address: account?.address,
|
|
28
|
+
chain: chainAccount?.chain,
|
|
29
|
+
assetList: chainAccount?.assetList,
|
|
30
|
+
address: accountHook.account?.address,
|
|
45
31
|
wallet: currentWallet,
|
|
32
|
+
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
46
33
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
47
|
-
|
|
34
|
+
signingClient: signingClientHook.signingClient,
|
|
35
|
+
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
36
|
+
isAccountLoading: accountHook.isLoading,
|
|
37
|
+
isSigningClientLoading: signingClientHook.isLoading,
|
|
38
|
+
isLoading: rpcEndpointHook.isLoading || accountHook.isLoading || signingClientHook.isLoading,
|
|
39
|
+
getRpcEndpointError: rpcEndpointHook.error,
|
|
40
|
+
getSigningClientError: signingClientHook.error,
|
|
41
|
+
getAccountError: accountHook.error
|
|
48
42
|
};
|
|
49
43
|
};
|
|
@@ -1,50 +1,34 @@
|
|
|
1
1
|
import { useWalletManager } from "./useWalletManager";
|
|
2
2
|
import { useAccount } from "./useAccount";
|
|
3
|
-
import { ChainNotExist, WalletNotExist, WalletState } from "@interchain-kit/core";
|
|
4
3
|
import { useInterchainClient } from "./useInterchainClient";
|
|
5
|
-
import {
|
|
4
|
+
import { useRpcEndpoint } from "./useRpcEndpoint";
|
|
6
5
|
export const useChainWallet = (chainName, walletName) => {
|
|
7
6
|
const walletManager = useWalletManager();
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const connect = useCallback(() => {
|
|
14
|
-
if (!wallet) {
|
|
15
|
-
const error = new WalletNotExist(walletName);
|
|
16
|
-
console.error(error.message);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (!chainToShow) {
|
|
20
|
-
const error = new ChainNotExist(chainName);
|
|
21
|
-
console.error(error.message);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (wallet.walletState !== WalletState.Connected) {
|
|
25
|
-
walletManager.connect(wallet.info.name);
|
|
26
|
-
}
|
|
27
|
-
}, [chainName, walletName]);
|
|
28
|
-
const disconnect = useCallback(() => {
|
|
29
|
-
if (wallet.walletState === WalletState.Connected) {
|
|
30
|
-
walletManager.disconnect(wallet.info.name);
|
|
31
|
-
}
|
|
32
|
-
}, [chainName, walletName]);
|
|
33
|
-
const getRpcEndpoint = useCallback(async () => {
|
|
34
|
-
return walletManager.getRpcEndpoint(wallet, chainName);
|
|
35
|
-
}, []);
|
|
7
|
+
const walletRepository = walletManager.getWalletRepositoryByName(walletName);
|
|
8
|
+
const chainAccount = walletRepository.getChainAccountByName(chainName);
|
|
9
|
+
const rpcEndpointHook = useRpcEndpoint(chainName, walletName);
|
|
10
|
+
const accountHook = useAccount(chainName, walletName);
|
|
11
|
+
const signingClientHook = useInterchainClient(chainName, walletName);
|
|
36
12
|
return {
|
|
37
|
-
connect,
|
|
38
|
-
disconnect,
|
|
39
|
-
getRpcEndpoint,
|
|
40
|
-
status:
|
|
41
|
-
username: account?.username,
|
|
42
|
-
message:
|
|
13
|
+
connect: () => chainAccount.connect(),
|
|
14
|
+
disconnect: () => chainAccount.disconnect(),
|
|
15
|
+
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
16
|
+
status: chainAccount.walletState,
|
|
17
|
+
username: accountHook.account?.username,
|
|
18
|
+
message: chainAccount.errorMessage,
|
|
43
19
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
20
|
+
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
21
|
+
chain: chainAccount.chain,
|
|
22
|
+
assetList: chainAccount.assetList,
|
|
23
|
+
address: accountHook.account?.address,
|
|
24
|
+
wallet: walletRepository,
|
|
25
|
+
signingClient: signingClientHook.signingClient,
|
|
26
|
+
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
27
|
+
isAccountLoading: accountHook.isLoading,
|
|
28
|
+
isSigningClientLoading: signingClientHook.isLoading,
|
|
29
|
+
isLoading: rpcEndpointHook.isLoading || accountHook.isLoading || signingClientHook.isLoading,
|
|
30
|
+
getRpcEndpointError: rpcEndpointHook.error,
|
|
31
|
+
getSigningClientError: signingClientHook.error,
|
|
32
|
+
getAccountError: accountHook.error
|
|
49
33
|
};
|
|
50
34
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useWalletManager } from "./useWalletManager";
|
|
2
2
|
import { useWalletModal } from "../modal";
|
|
3
|
+
import { bindAllMethodsToContext } from "../utils/helpers";
|
|
3
4
|
export const useCurrentWallet = () => {
|
|
4
5
|
const walletManager = useWalletManager();
|
|
5
6
|
const { open } = useWalletModal();
|
|
@@ -8,5 +9,9 @@ export const useCurrentWallet = () => {
|
|
|
8
9
|
// open()
|
|
9
10
|
// }
|
|
10
11
|
// }, [walletManager.currentWalletName, walletManager.state])
|
|
11
|
-
|
|
12
|
+
const wallet = walletManager.getCurrentWallet();
|
|
13
|
+
if (wallet) {
|
|
14
|
+
return bindAllMethodsToContext(wallet);
|
|
15
|
+
}
|
|
16
|
+
return {};
|
|
12
17
|
};
|
|
@@ -1,42 +1,18 @@
|
|
|
1
|
-
import { useEffect
|
|
1
|
+
import { useEffect } from "react";
|
|
2
2
|
import { useWalletManager } from './useWalletManager';
|
|
3
|
-
import { useAccount } from './useAccount';
|
|
4
3
|
import { WalletState } from '@interchain-kit/core';
|
|
5
4
|
export const useInterchainClient = (chainName, walletName) => {
|
|
6
|
-
const [rpcEndpoint, setRpcEndpoint] = useState();
|
|
7
|
-
//signing
|
|
8
|
-
const [signingClient, setSigningClient] = useState(null);
|
|
9
|
-
const [error, setError] = useState(null);
|
|
10
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
11
5
|
const walletManager = useWalletManager();
|
|
12
|
-
const
|
|
13
|
-
const wallet = walletManager.wallets.find((w) => w.info.name === walletName);
|
|
14
|
-
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
15
|
-
const initialize = async () => {
|
|
16
|
-
if (wallet && chainToShow && wallet?.walletState === WalletState.Connected) {
|
|
17
|
-
try {
|
|
18
|
-
setIsLoading(true);
|
|
19
|
-
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
20
|
-
setRpcEndpoint(rpcEndpoint);
|
|
21
|
-
const signingClient = await walletManager.getSigningClient(walletName, chainName);
|
|
22
|
-
setSigningClient(signingClient);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
setError(error);
|
|
26
|
-
console.log("create client error", error);
|
|
27
|
-
}
|
|
28
|
-
finally {
|
|
29
|
-
setIsLoading(false);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
6
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
33
7
|
useEffect(() => {
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
if (chainAccount?.walletState === WalletState.Connected && !chainAccount.signingClient && chainName && walletName) {
|
|
9
|
+
chainAccount.getSigningClient();
|
|
10
|
+
}
|
|
11
|
+
}, [chainAccount?.walletState, chainName, walletName]);
|
|
36
12
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
error,
|
|
40
|
-
|
|
13
|
+
signingClient: chainAccount?.signingClient,
|
|
14
|
+
isLoading: chainAccount?.getSigningClientState().loading,
|
|
15
|
+
error: chainAccount?.getSigningClientState().error,
|
|
16
|
+
getSigningClient: chainAccount?.getSigningClient
|
|
41
17
|
};
|
|
42
18
|
};
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { useEffect
|
|
1
|
+
import { useEffect } from "react";
|
|
2
2
|
import { useWalletManager } from "./useWalletManager";
|
|
3
|
+
import { WalletState } from "@interchain-kit/core";
|
|
3
4
|
export const useOfflineSigner = (chainName, walletName) => {
|
|
4
5
|
const walletManager = useWalletManager();
|
|
5
|
-
const
|
|
6
|
-
const [offlineSigner, setOfflineSigner] = useState(null);
|
|
6
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
7
7
|
useEffect(() => {
|
|
8
|
-
if (
|
|
9
|
-
|
|
8
|
+
if (chainAccount?.walletState === WalletState.Connected && !chainAccount.offlineSigner && chainName && walletName) {
|
|
9
|
+
chainAccount.getOfflineSigner();
|
|
10
10
|
}
|
|
11
|
-
}, [
|
|
11
|
+
}, [chainAccount?.walletState, chainName, walletName]);
|
|
12
12
|
return {
|
|
13
|
-
offlineSigner
|
|
13
|
+
offlineSigner: chainAccount?.offlineSigner,
|
|
14
|
+
isLoading: chainAccount?.getOfflineSignerState().loading,
|
|
15
|
+
error: chainAccount?.getOfflineSignerState().error,
|
|
16
|
+
getOfflineSigner: chainAccount?.getOfflineSigner
|
|
14
17
|
};
|
|
15
18
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useWalletManager } from "./useWalletManager";
|
|
3
|
+
import { WalletState } from "@interchain-kit/core";
|
|
4
|
+
export const useRpcEndpoint = (chainName, walletName) => {
|
|
5
|
+
const walletManager = useWalletManager();
|
|
6
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (chainAccount?.walletState === WalletState.Connected && !chainAccount.rpcEndpoint && chainName && walletName) {
|
|
9
|
+
chainAccount.getRpcEndpoint();
|
|
10
|
+
}
|
|
11
|
+
}, [chainAccount?.walletState, walletName, chainName]);
|
|
12
|
+
return {
|
|
13
|
+
rpcEndpoint: chainAccount?.rpcEndpoint,
|
|
14
|
+
isLoading: chainAccount?.getRpcEndpointState().loading,
|
|
15
|
+
error: chainAccount?.getRpcEndpointState().error,
|
|
16
|
+
getRpcEndpoint: chainAccount?.getRpcEndpoint
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useInterchainWalletContext } from "../provider";
|
|
2
|
+
import { bindAllMethodsToContext } from '../utils/helpers';
|
|
2
3
|
export const useWalletManager = () => {
|
|
3
4
|
const { walletManager } = useInterchainWalletContext();
|
|
4
|
-
return walletManager;
|
|
5
|
+
return bindAllMethodsToContext(walletManager);
|
|
5
6
|
};
|
|
@@ -12,7 +12,7 @@ export const ConnectedHeader = ({ onBack }) => {
|
|
|
12
12
|
export const ConnectedContent = () => {
|
|
13
13
|
const currentWallet = useCurrentWallet();
|
|
14
14
|
const walletManager = useWalletManager();
|
|
15
|
-
const account = useAccount(
|
|
15
|
+
const { account } = useAccount(currentWallet.currentChainName, currentWallet?.info?.name);
|
|
16
16
|
const { close } = useWalletModal();
|
|
17
17
|
if (!currentWallet) {
|
|
18
18
|
return null;
|
|
@@ -12,7 +12,8 @@ export const QRCodeHeader = ({ onBack }) => {
|
|
|
12
12
|
}, closeButtonProps: { onClick: close } }));
|
|
13
13
|
};
|
|
14
14
|
export const QRCodeContent = () => {
|
|
15
|
-
const
|
|
15
|
+
const currentWalletRepository = useCurrentWallet();
|
|
16
|
+
const currentWallet = currentWalletRepository.wallet;
|
|
16
17
|
const walletManager = useWalletManager();
|
|
17
18
|
const data = currentWallet.pairingUri;
|
|
18
19
|
return (_jsx(ConnectModalQRCode, { status: data ? "Done" : "Pending", link: data, description: "Open App to connect", errorTitle: "errorTitle", errorDesc: currentWallet.errorMessage || "", onRefresh: () => walletManager.connect(currentWallet?.info?.name || "") }));
|
package/esm/provider.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
|
-
import { WalletManager, } from "@interchain-kit/core";
|
|
4
|
+
import { WalletManager, WalletManagerState, } from "@interchain-kit/core";
|
|
5
5
|
import { WalletModalProvider } from "./modal";
|
|
6
6
|
const InterchainWalletContext = createContext(null);
|
|
7
7
|
export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
|
|
8
8
|
const [_, forceRender] = useState({});
|
|
9
9
|
const walletManager = useMemo(() => {
|
|
10
|
-
|
|
10
|
+
const wm = new WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions);
|
|
11
|
+
return wm.getObservableObj(() => {
|
|
12
|
+
forceRender({});
|
|
13
|
+
});
|
|
11
14
|
}, []);
|
|
12
15
|
useEffect(() => {
|
|
13
16
|
walletManager.init();
|
|
14
17
|
}, []);
|
|
18
|
+
if (walletManager.state === WalletManagerState.Initializing) {
|
|
19
|
+
return _jsx("div", { children: "Interchain Kit Initializing..." });
|
|
20
|
+
}
|
|
15
21
|
return (_jsx(InterchainWalletContext.Provider, { value: { walletManager }, children: _jsx(WalletModalProvider, { children: children }) }));
|
|
16
22
|
};
|
|
17
23
|
export const useInterchainWalletContext = () => {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function bindAllMethodsToContext(context) {
|
|
2
|
+
return new Proxy(context, {
|
|
3
|
+
get(target, prop, receiver) {
|
|
4
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5
|
+
if (typeof value === 'function') {
|
|
6
|
+
return value.bind(context);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
package/hooks/useAccount.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare const useAccount: (chainName: string, walletName: string) => {
|
|
2
|
+
account: any;
|
|
3
|
+
isLoading: any;
|
|
4
|
+
error: any;
|
|
5
|
+
getAccount: any;
|
|
6
|
+
};
|
package/hooks/useAccount.js
CHANGED
|
@@ -1,43 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAccount = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
4
|
const core_1 = require("@interchain-kit/core");
|
|
6
5
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
|
+
const react_1 = require("react");
|
|
7
7
|
const useAccount = (chainName, walletName) => {
|
|
8
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
9
|
-
const
|
|
10
|
-
const wallet = (0, react_1.useMemo)(() => {
|
|
11
|
-
return walletManager.wallets.find(w => w.info.name === walletName);
|
|
12
|
-
}, [walletManager, walletName]);
|
|
13
|
-
const [account, setAccount] = (0, react_1.useState)(null);
|
|
14
|
-
const chain = (0, react_1.useMemo)(() => {
|
|
15
|
-
return walletManager.chains.find(c => c.chainName === chainName);
|
|
16
|
-
}, [walletManager, chainName]);
|
|
17
|
-
const getAccount = async () => {
|
|
18
|
-
if (wallet && chain) {
|
|
19
|
-
if (wallet.walletState === core_1.WalletState.Connected && !isFetching) {
|
|
20
|
-
setIsFetching(true);
|
|
21
|
-
const account = await walletManager.getAccount(walletName, chainName);
|
|
22
|
-
setAccount(account);
|
|
23
|
-
setIsFetching(false);
|
|
24
|
-
}
|
|
25
|
-
if (wallet.walletState === core_1.WalletState.Disconnected) {
|
|
26
|
-
setAccount(null);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (!wallet) {
|
|
30
|
-
setAccount(null);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
9
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
33
10
|
(0, react_1.useEffect)(() => {
|
|
34
|
-
if (
|
|
35
|
-
|
|
11
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected && !chainAccount?.account && chainName && walletName) {
|
|
12
|
+
chainAccount.getAccount();
|
|
36
13
|
}
|
|
37
|
-
}, [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
}, [chainAccount?.walletState, chainName, walletName]);
|
|
15
|
+
return {
|
|
16
|
+
account: chainAccount?.account || undefined,
|
|
17
|
+
isLoading: chainAccount?.getAccountState().loading || false,
|
|
18
|
+
error: chainAccount?.getAccountState().error || undefined,
|
|
19
|
+
getAccount: chainAccount?.getAccount
|
|
20
|
+
};
|
|
42
21
|
};
|
|
43
22
|
exports.useAccount = useAccount;
|
package/hooks/useChain.js
CHANGED
|
@@ -6,48 +6,42 @@ const useAccount_1 = require("./useAccount");
|
|
|
6
6
|
const useCurrentWallet_1 = require("./useCurrentWallet");
|
|
7
7
|
const useInterchainClient_1 = require("./useInterchainClient");
|
|
8
8
|
const modal_1 = require("../modal");
|
|
9
|
-
const
|
|
10
|
-
const react_1 = require("react");
|
|
9
|
+
const useRpcEndpoint_1 = require("./useRpcEndpoint");
|
|
11
10
|
const useChain = (chainName) => {
|
|
12
11
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
13
|
-
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
14
|
-
const assetList = walletManager.assetLists.find((a) => a.chainName === chainName);
|
|
15
12
|
const currentWallet = (0, useCurrentWallet_1.useCurrentWallet)();
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
const chainAccount = currentWallet?.getChainAccountByName?.(chainName);
|
|
14
|
+
const walletName = currentWallet?.info?.name;
|
|
15
|
+
const rpcEndpointHook = (0, useRpcEndpoint_1.useRpcEndpoint)(chainName, walletName);
|
|
16
|
+
const accountHook = (0, useAccount_1.useAccount)(chainName, walletName);
|
|
17
|
+
const signingClientHook = (0, useInterchainClient_1.useInterchainClient)(chainName, walletName);
|
|
21
18
|
const { open, close } = (0, modal_1.useWalletModal)();
|
|
22
|
-
const getRpcEndpoint = (0, react_1.useCallback)(async () => {
|
|
23
|
-
return await walletManager.getRpcEndpoint(currentWallet, chainName);
|
|
24
|
-
}, [walletManager, currentWallet, chainName]);
|
|
25
|
-
const disconnect = (0, react_1.useCallback)(() => {
|
|
26
|
-
walletManager.disconnect(currentWallet?.info?.name);
|
|
27
|
-
}, [walletManager, currentWallet]);
|
|
28
19
|
const cosmosKitUserChainReturnType = {
|
|
29
|
-
connect: () =>
|
|
30
|
-
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
open();
|
|
34
|
-
},
|
|
35
|
-
disconnect,
|
|
20
|
+
connect: () => chainAccount.connect(),
|
|
21
|
+
disconnect: () => chainAccount.disconnect(),
|
|
36
22
|
openView: open,
|
|
37
23
|
closeView: close,
|
|
38
|
-
getRpcEndpoint,
|
|
24
|
+
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
39
25
|
status: currentWallet?.walletState,
|
|
40
|
-
username: account?.username,
|
|
26
|
+
username: accountHook.account?.username,
|
|
41
27
|
message: currentWallet?.errorMessage
|
|
42
28
|
};
|
|
43
29
|
return {
|
|
44
30
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
45
|
-
chain:
|
|
46
|
-
assetList,
|
|
47
|
-
address: account?.address,
|
|
31
|
+
chain: chainAccount?.chain,
|
|
32
|
+
assetList: chainAccount?.assetList,
|
|
33
|
+
address: accountHook.account?.address,
|
|
48
34
|
wallet: currentWallet,
|
|
35
|
+
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
49
36
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
50
|
-
|
|
37
|
+
signingClient: signingClientHook.signingClient,
|
|
38
|
+
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
39
|
+
isAccountLoading: accountHook.isLoading,
|
|
40
|
+
isSigningClientLoading: signingClientHook.isLoading,
|
|
41
|
+
isLoading: rpcEndpointHook.isLoading || accountHook.isLoading || signingClientHook.isLoading,
|
|
42
|
+
getRpcEndpointError: rpcEndpointHook.error,
|
|
43
|
+
getSigningClientError: signingClientHook.error,
|
|
44
|
+
getAccountError: accountHook.error
|
|
51
45
|
};
|
|
52
46
|
};
|
|
53
47
|
exports.useChain = useChain;
|
package/hooks/useChainWallet.js
CHANGED
|
@@ -3,52 +3,36 @@ 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 core_1 = require("@interchain-kit/core");
|
|
7
6
|
const useInterchainClient_1 = require("./useInterchainClient");
|
|
8
|
-
const
|
|
7
|
+
const useRpcEndpoint_1 = require("./useRpcEndpoint");
|
|
9
8
|
const useChainWallet = (chainName, walletName) => {
|
|
10
9
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const connect = (0, react_1.useCallback)(() => {
|
|
17
|
-
if (!wallet) {
|
|
18
|
-
const error = new core_1.WalletNotExist(walletName);
|
|
19
|
-
console.error(error.message);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (!chainToShow) {
|
|
23
|
-
const error = new core_1.ChainNotExist(chainName);
|
|
24
|
-
console.error(error.message);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (wallet.walletState !== core_1.WalletState.Connected) {
|
|
28
|
-
walletManager.connect(wallet.info.name);
|
|
29
|
-
}
|
|
30
|
-
}, [chainName, walletName]);
|
|
31
|
-
const disconnect = (0, react_1.useCallback)(() => {
|
|
32
|
-
if (wallet.walletState === core_1.WalletState.Connected) {
|
|
33
|
-
walletManager.disconnect(wallet.info.name);
|
|
34
|
-
}
|
|
35
|
-
}, [chainName, walletName]);
|
|
36
|
-
const getRpcEndpoint = (0, react_1.useCallback)(async () => {
|
|
37
|
-
return walletManager.getRpcEndpoint(wallet, chainName);
|
|
38
|
-
}, []);
|
|
10
|
+
const walletRepository = walletManager.getWalletRepositoryByName(walletName);
|
|
11
|
+
const chainAccount = walletRepository.getChainAccountByName(chainName);
|
|
12
|
+
const rpcEndpointHook = (0, useRpcEndpoint_1.useRpcEndpoint)(chainName, walletName);
|
|
13
|
+
const accountHook = (0, useAccount_1.useAccount)(chainName, walletName);
|
|
14
|
+
const signingClientHook = (0, useInterchainClient_1.useInterchainClient)(chainName, walletName);
|
|
39
15
|
return {
|
|
40
|
-
connect,
|
|
41
|
-
disconnect,
|
|
42
|
-
getRpcEndpoint,
|
|
43
|
-
status:
|
|
44
|
-
username: account?.username,
|
|
45
|
-
message:
|
|
16
|
+
connect: () => chainAccount.connect(),
|
|
17
|
+
disconnect: () => chainAccount.disconnect(),
|
|
18
|
+
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
19
|
+
status: chainAccount.walletState,
|
|
20
|
+
username: accountHook.account?.username,
|
|
21
|
+
message: chainAccount.errorMessage,
|
|
46
22
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
23
|
+
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
24
|
+
chain: chainAccount.chain,
|
|
25
|
+
assetList: chainAccount.assetList,
|
|
26
|
+
address: accountHook.account?.address,
|
|
27
|
+
wallet: walletRepository,
|
|
28
|
+
signingClient: signingClientHook.signingClient,
|
|
29
|
+
isRpcEndpointLoading: rpcEndpointHook.isLoading,
|
|
30
|
+
isAccountLoading: accountHook.isLoading,
|
|
31
|
+
isSigningClientLoading: signingClientHook.isLoading,
|
|
32
|
+
isLoading: rpcEndpointHook.isLoading || accountHook.isLoading || signingClientHook.isLoading,
|
|
33
|
+
getRpcEndpointError: rpcEndpointHook.error,
|
|
34
|
+
getSigningClientError: signingClientHook.error,
|
|
35
|
+
getAccountError: accountHook.error
|
|
52
36
|
};
|
|
53
37
|
};
|
|
54
38
|
exports.useChainWallet = useChainWallet;
|
package/hooks/useConfig.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AssetList, Chain } from "@chain-registry/v2-types";
|
|
2
|
-
import { EndpointOptions, SignerOptions } from "@interchain-kit/core";
|
|
3
2
|
export declare const useConfig: () => {
|
|
4
3
|
updateChains: (chains: Chain[]) => Chain[];
|
|
5
4
|
updateAssetLists: (assetLists: AssetList[]) => AssetList[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useCurrentWallet: () =>
|
|
1
|
+
export declare const useCurrentWallet: () => WalletRepository;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useCurrentWallet = void 0;
|
|
4
4
|
const useWalletManager_1 = require("./useWalletManager");
|
|
5
5
|
const modal_1 = require("../modal");
|
|
6
|
+
const helpers_1 = require("../utils/helpers");
|
|
6
7
|
const useCurrentWallet = () => {
|
|
7
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
8
9
|
const { open } = (0, modal_1.useWalletModal)();
|
|
@@ -11,6 +12,10 @@ const useCurrentWallet = () => {
|
|
|
11
12
|
// open()
|
|
12
13
|
// }
|
|
13
14
|
// }, [walletManager.currentWalletName, walletManager.state])
|
|
14
|
-
|
|
15
|
+
const wallet = walletManager.getCurrentWallet();
|
|
16
|
+
if (wallet) {
|
|
17
|
+
return (0, helpers_1.bindAllMethodsToContext)(wallet);
|
|
18
|
+
}
|
|
19
|
+
return {};
|
|
15
20
|
};
|
|
16
21
|
exports.useCurrentWallet = useCurrentWallet;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export declare const useInterchainClient: (chainName: string, walletName: string) => {
|
|
2
|
+
signingClient: any;
|
|
3
|
+
isLoading: any;
|
|
4
|
+
error: any;
|
|
5
|
+
getSigningClient: any;
|
|
6
|
+
};
|
|
@@ -3,44 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useInterchainClient = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
|
-
const useAccount_1 = require("./useAccount");
|
|
7
6
|
const core_1 = require("@interchain-kit/core");
|
|
8
7
|
const useInterchainClient = (chainName, walletName) => {
|
|
9
|
-
const [rpcEndpoint, setRpcEndpoint] = (0, react_1.useState)();
|
|
10
|
-
//signing
|
|
11
|
-
const [signingClient, setSigningClient] = (0, react_1.useState)(null);
|
|
12
|
-
const [error, setError] = (0, react_1.useState)(null);
|
|
13
|
-
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
14
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
15
|
-
const
|
|
16
|
-
const wallet = walletManager.wallets.find((w) => w.info.name === walletName);
|
|
17
|
-
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
18
|
-
const initialize = async () => {
|
|
19
|
-
if (wallet && chainToShow && wallet?.walletState === core_1.WalletState.Connected) {
|
|
20
|
-
try {
|
|
21
|
-
setIsLoading(true);
|
|
22
|
-
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
23
|
-
setRpcEndpoint(rpcEndpoint);
|
|
24
|
-
const signingClient = await walletManager.getSigningClient(walletName, chainName);
|
|
25
|
-
setSigningClient(signingClient);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
setError(error);
|
|
29
|
-
console.log("create client error", error);
|
|
30
|
-
}
|
|
31
|
-
finally {
|
|
32
|
-
setIsLoading(false);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
9
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
36
10
|
(0, react_1.useEffect)(() => {
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected && !chainAccount.signingClient && chainName && walletName) {
|
|
12
|
+
chainAccount.getSigningClient();
|
|
13
|
+
}
|
|
14
|
+
}, [chainAccount?.walletState, chainName, walletName]);
|
|
39
15
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
error,
|
|
43
|
-
|
|
16
|
+
signingClient: chainAccount?.signingClient,
|
|
17
|
+
isLoading: chainAccount?.getSigningClientState().loading,
|
|
18
|
+
error: chainAccount?.getSigningClientState().error,
|
|
19
|
+
getSigningClient: chainAccount?.getSigningClient
|
|
44
20
|
};
|
|
45
21
|
};
|
|
46
22
|
exports.useInterchainClient = useInterchainClient;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ICosmosGenericOfflineSigner } from '@interchainjs/cosmos/types/wallet';
|
|
2
1
|
export declare const useOfflineSigner: (chainName: string, walletName: string) => {
|
|
3
|
-
offlineSigner:
|
|
2
|
+
offlineSigner: any;
|
|
3
|
+
isLoading: any;
|
|
4
|
+
error: any;
|
|
5
|
+
getOfflineSigner: any;
|
|
4
6
|
};
|
|
@@ -3,17 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useOfflineSigner = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
|
+
const core_1 = require("@interchain-kit/core");
|
|
6
7
|
const useOfflineSigner = (chainName, walletName) => {
|
|
7
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
8
|
-
const
|
|
9
|
-
const [offlineSigner, setOfflineSigner] = (0, react_1.useState)(null);
|
|
9
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
10
10
|
(0, react_1.useEffect)(() => {
|
|
11
|
-
if (
|
|
12
|
-
|
|
11
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected && !chainAccount.offlineSigner && chainName && walletName) {
|
|
12
|
+
chainAccount.getOfflineSigner();
|
|
13
13
|
}
|
|
14
|
-
}, [
|
|
14
|
+
}, [chainAccount?.walletState, chainName, walletName]);
|
|
15
15
|
return {
|
|
16
|
-
offlineSigner
|
|
16
|
+
offlineSigner: chainAccount?.offlineSigner,
|
|
17
|
+
isLoading: chainAccount?.getOfflineSignerState().loading,
|
|
18
|
+
error: chainAccount?.getOfflineSignerState().error,
|
|
19
|
+
getOfflineSigner: chainAccount?.getOfflineSigner
|
|
17
20
|
};
|
|
18
21
|
};
|
|
19
22
|
exports.useOfflineSigner = useOfflineSigner;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRpcEndpoint = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useWalletManager_1 = require("./useWalletManager");
|
|
6
|
+
const core_1 = require("@interchain-kit/core");
|
|
7
|
+
const useRpcEndpoint = (chainName, walletName) => {
|
|
8
|
+
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
9
|
+
const chainAccount = walletManager.getWalletRepositoryByName(walletName)?.getChainAccountByName(chainName);
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected && !chainAccount.rpcEndpoint && chainName && walletName) {
|
|
12
|
+
chainAccount.getRpcEndpoint();
|
|
13
|
+
}
|
|
14
|
+
}, [chainAccount?.walletState, walletName, chainName]);
|
|
15
|
+
return {
|
|
16
|
+
rpcEndpoint: chainAccount?.rpcEndpoint,
|
|
17
|
+
isLoading: chainAccount?.getRpcEndpointState().loading,
|
|
18
|
+
error: chainAccount?.getRpcEndpointState().error,
|
|
19
|
+
getRpcEndpoint: chainAccount?.getRpcEndpoint
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.useRpcEndpoint = useRpcEndpoint;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useWalletManager = void 0;
|
|
4
4
|
const provider_1 = require("../provider");
|
|
5
|
+
const helpers_1 = require("../utils/helpers");
|
|
5
6
|
const useWalletManager = () => {
|
|
6
7
|
const { walletManager } = (0, provider_1.useInterchainWalletContext)();
|
|
7
|
-
return walletManager;
|
|
8
|
+
return (0, helpers_1.bindAllMethodsToContext)(walletManager);
|
|
8
9
|
};
|
|
9
10
|
exports.useWalletManager = useWalletManager;
|
package/modal/views/Connected.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.ConnectedHeader = ConnectedHeader;
|
|
|
16
16
|
const ConnectedContent = () => {
|
|
17
17
|
const currentWallet = (0, hooks_1.useCurrentWallet)();
|
|
18
18
|
const walletManager = (0, hooks_1.useWalletManager)();
|
|
19
|
-
const account = (0, hooks_1.useAccount)(
|
|
19
|
+
const { account } = (0, hooks_1.useAccount)(currentWallet.currentChainName, currentWallet?.info?.name);
|
|
20
20
|
const { close } = (0, provider_1.useWalletModal)();
|
|
21
21
|
if (!currentWallet) {
|
|
22
22
|
return null;
|
package/modal/views/QRCode.js
CHANGED
|
@@ -16,7 +16,8 @@ const QRCodeHeader = ({ onBack }) => {
|
|
|
16
16
|
};
|
|
17
17
|
exports.QRCodeHeader = QRCodeHeader;
|
|
18
18
|
const QRCodeContent = () => {
|
|
19
|
-
const
|
|
19
|
+
const currentWalletRepository = (0, hooks_1.useCurrentWallet)();
|
|
20
|
+
const currentWallet = currentWalletRepository.wallet;
|
|
20
21
|
const walletManager = (0, hooks_1.useWalletManager)();
|
|
21
22
|
const data = currentWallet.pairingUri;
|
|
22
23
|
return ((0, jsx_runtime_1.jsx)(react_1.ConnectModalQRCode, { status: data ? "Done" : "Pending", link: data, description: "Open App to connect", errorTitle: "errorTitle", errorDesc: currentWallet.errorMessage || "", onRefresh: () => walletManager.connect(currentWallet?.info?.name || "") }));
|
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.45",
|
|
4
4
|
"author": "cosmology-tech <developers@cosmology.zone>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -33,17 +33,20 @@
|
|
|
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.45",
|
|
37
37
|
"@interchain-ui/react": "1.26.1",
|
|
38
38
|
"@interchainjs/cosmos": "1.6.3",
|
|
39
39
|
"@interchainjs/cosmos-types": "1.6.3",
|
|
40
|
+
"@nx-js/observer-util": "^4.2.2",
|
|
40
41
|
"@react-icons/all-files": "^4.1.0",
|
|
41
|
-
"@types/react": "^
|
|
42
|
-
"@types/react-dom": "^
|
|
42
|
+
"@types/react": "^18.3.3",
|
|
43
|
+
"@types/react-dom": "^18.3.0",
|
|
44
|
+
"@vue/reactivity": "^3.5.13",
|
|
43
45
|
"@walletconnect/types": "^2.17.3",
|
|
44
46
|
"interchainjs": "1.6.3",
|
|
45
|
-
"
|
|
46
|
-
"react
|
|
47
|
+
"observable-slim": "^0.1.6",
|
|
48
|
+
"react": "^18.3.1",
|
|
49
|
+
"react-dom": "^18.3.1"
|
|
47
50
|
},
|
|
48
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "1d52b0d7c0616c204434fb6a10e8d5a2fca62d92"
|
|
49
52
|
}
|
package/provider.js
CHANGED
|
@@ -10,11 +10,17 @@ const InterchainWalletContext = (0, react_2.createContext)(null);
|
|
|
10
10
|
const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
|
|
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
|
+
return wm.getObservableObj(() => {
|
|
15
|
+
forceRender({});
|
|
16
|
+
});
|
|
14
17
|
}, []);
|
|
15
18
|
(0, react_1.useEffect)(() => {
|
|
16
19
|
walletManager.init();
|
|
17
20
|
}, []);
|
|
21
|
+
if (walletManager.state === core_1.WalletManagerState.Initializing) {
|
|
22
|
+
return (0, jsx_runtime_1.jsx)("div", { children: "Interchain Kit Initializing..." });
|
|
23
|
+
}
|
|
18
24
|
return ((0, jsx_runtime_1.jsx)(InterchainWalletContext.Provider, { value: { walletManager }, children: (0, jsx_runtime_1.jsx)(modal_1.WalletModalProvider, { children: children }) }));
|
|
19
25
|
};
|
|
20
26
|
exports.ChainProvider = ChainProvider;
|
package/types/chain.d.ts
CHANGED
|
@@ -20,12 +20,16 @@ export type UseChainReturnType = {
|
|
|
20
20
|
wallet: BaseWallet;
|
|
21
21
|
rpcEndpoint: string | HttpEndpoint;
|
|
22
22
|
signingClient: SigningClient;
|
|
23
|
+
isRpcEndpointLoading: boolean;
|
|
24
|
+
isAccountLoading: boolean;
|
|
25
|
+
isSigningClientLoading: boolean;
|
|
23
26
|
isLoading: boolean;
|
|
24
|
-
|
|
27
|
+
getRpcEndpointError: Error | null;
|
|
28
|
+
getSigningClientError: Error | null;
|
|
29
|
+
getAccountError: Error | null;
|
|
25
30
|
} & CosmosKitUseChainReturnType;
|
|
26
31
|
export type UseChainWalletReturnType = Omit<UseChainReturnType, 'openView' | 'closeView'>;
|
|
27
32
|
export type UseInterchainClientReturnType = {
|
|
28
|
-
rpcEndpoint: string | HttpEndpoint | undefined;
|
|
29
33
|
signingClient: SigningClient | null;
|
|
30
34
|
error: string | unknown | null;
|
|
31
35
|
isLoading: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function bindAllMethodsToContext<T extends object>(context: T): T;
|
package/utils/helpers.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bindAllMethodsToContext = void 0;
|
|
4
|
+
function bindAllMethodsToContext(context) {
|
|
5
|
+
return new Proxy(context, {
|
|
6
|
+
get(target, prop, receiver) {
|
|
7
|
+
const value = Reflect.get(target, prop, receiver);
|
|
8
|
+
if (typeof value === 'function') {
|
|
9
|
+
return value.bind(context);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
exports.bindAllMethodsToContext = bindAllMethodsToContext;
|
package/utils/wallet.d.ts
CHANGED