@interchain-kit/react 0.0.1-beta.15 → 0.0.1-beta.17
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/README.md +127 -12
- package/esm/hooks/useAccount.js +3 -2
- package/esm/hooks/useChain.js +2 -2
- package/esm/hooks/useInterchainClient.js +7 -7
- package/esm/hooks/useWalletManager.js +2 -2
- package/esm/modal/modal.js +4 -4
- package/esm/modal/views/QRCode.js +4 -3
- package/esm/provider.js +9 -9
- package/hooks/useAccount.js +3 -2
- package/hooks/useChain.js +2 -2
- package/hooks/useInterchainClient.js +7 -7
- package/hooks/useWalletManager.js +1 -1
- package/modal/modal.js +3 -3
- package/modal/views/QRCode.js +8 -7
- package/package.json +3 -3
- package/provider.d.ts +6 -6
- package/provider.js +8 -8
package/README.md
CHANGED
|
@@ -1,22 +1,137 @@
|
|
|
1
|
-
# react
|
|
2
|
-
|
|
3
1
|
<p align="center">
|
|
4
2
|
<img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"><br />
|
|
5
|
-
interchain-kit
|
|
3
|
+
@interchain-kit/react
|
|
6
4
|
</p>
|
|
7
5
|
|
|
8
|
-
##
|
|
9
|
-
|
|
6
|
+
## Install
|
|
7
|
+
Using npm:
|
|
8
|
+
```sh
|
|
9
|
+
npm install @interchain-kit/react
|
|
10
|
+
```
|
|
11
|
+
Using yarn:
|
|
10
12
|
```sh
|
|
11
|
-
|
|
13
|
+
yarn add @interchain-kit/react
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
### Setup
|
|
18
|
+
```js
|
|
19
|
+
import { ChainProvider, useChain } from "@interchain-kit/react";
|
|
20
|
+
import { assetLists, chains } from "@chain-registry/v2";
|
|
21
|
+
import { keplrWallet } from "@interchain-kit/keplr-extension";
|
|
22
|
+
import { ThemeProvider } from "@interchain-ui/react";
|
|
23
|
+
import "@interchain-ui/react/styles";
|
|
24
|
+
|
|
25
|
+
const chainName = 'cosmoshub'
|
|
26
|
+
|
|
27
|
+
const Show = () => {
|
|
28
|
+
const {address} = useChain(chainName);
|
|
29
|
+
// will show cosmoshub address from what you selected wallet in modal
|
|
30
|
+
return <div>{address}</div>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function App() {
|
|
34
|
+
return (
|
|
35
|
+
<ThemeProvider>
|
|
36
|
+
<ChainProvider
|
|
37
|
+
chains={chains.filter((c) => c.chainName === chainName)}
|
|
38
|
+
assetLists={assetLists.filter((c) => c.chainName === chainName)}
|
|
39
|
+
wallets={[keplrWallet]}
|
|
40
|
+
signerOptions={{}}
|
|
41
|
+
endpointOptions={{}}
|
|
42
|
+
>
|
|
43
|
+
<Show />
|
|
44
|
+
</ChainProvider>
|
|
45
|
+
</ThemeProvider>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default App;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### useChain
|
|
53
|
+
```js
|
|
54
|
+
|
|
55
|
+
const chainName = 'cosmoshub'
|
|
56
|
+
const { chain, assetList, address, wallet, queryClient, signingClient } = useChain(chainName)
|
|
57
|
+
|
|
58
|
+
console.log(wallet) //keprl extension wallet info
|
|
59
|
+
console.log(chain) // chain info for cosmoshub
|
|
60
|
+
console.log(assetList) // assets info for cosmoshub
|
|
61
|
+
console.log(address) // address for cosmoshub in keplr-extension wallet
|
|
62
|
+
|
|
63
|
+
//query
|
|
64
|
+
const { balance } = await queryClient.balance({
|
|
65
|
+
address,
|
|
66
|
+
denom: 'uosmo'
|
|
67
|
+
})
|
|
68
|
+
console.log(balance)
|
|
69
|
+
// { amount: 23423, denom: 'uosmos' }
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## useChainWallet
|
|
74
|
+
```js
|
|
75
|
+
import { keplrWallet } from "@interchain-kit/keplr-extension";
|
|
76
|
+
import { leapWallet } from "@interchain-kit/leap-extension";
|
|
77
|
+
|
|
78
|
+
const Show = () => {
|
|
79
|
+
const juno = useChainWallet('juno', 'keplr-extension')
|
|
80
|
+
const stargaze = useChainWallet('stargaze', 'leap-extension')
|
|
81
|
+
console.log(juno.address) // juno1xxxxxxx in keplr extension wallet
|
|
82
|
+
console.log(stargaze.addresss) // stargaze1xxxxxx in leap extension wallet
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const chainNames
|
|
86
|
+
|
|
87
|
+
function App() {
|
|
88
|
+
return (
|
|
89
|
+
<ThemeProvider>
|
|
90
|
+
<ChainProvider
|
|
91
|
+
chains={chains.filter((c) => c.chainName === chainName)}
|
|
92
|
+
assetLists={assetLists.filter((c) => c.chainName === chainName)}
|
|
93
|
+
wallets={[keplrWallet, leapWallet]}
|
|
94
|
+
signerOptions={{}}
|
|
95
|
+
endpointOptions={{}}
|
|
96
|
+
>
|
|
97
|
+
<Show />
|
|
98
|
+
</ChainProvider>
|
|
99
|
+
</ThemeProvider>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default App;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### useActiveWallet
|
|
107
|
+
```js
|
|
108
|
+
const wallet = useActiveWallet()
|
|
109
|
+
|
|
110
|
+
console.log(wallet) // current connected wallet
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### useAccount
|
|
115
|
+
```js
|
|
116
|
+
const account = useAccount('cosmoshub', 'keplr-extension')
|
|
117
|
+
|
|
118
|
+
console.log(account.address) // cosmoshub address in keplr-extension wallet
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### useOfflineSigner
|
|
123
|
+
```js
|
|
124
|
+
const offlineSigner = useOfflineSigner('cosmoshub', 'keplr-extension')
|
|
125
|
+
|
|
126
|
+
console.log(offlineSigner) // cosmoshub offlineSigner in keplr-extension wallet
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### useChains
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
WIP
|
|
12
133
|
```
|
|
13
|
-
## Table of contents
|
|
14
134
|
|
|
15
|
-
- [react](#react)
|
|
16
|
-
- [Install](#install)
|
|
17
|
-
- [Table of contents](#table-of-contents)
|
|
18
|
-
- [Developing](#developing)
|
|
19
|
-
- [Credits](#credits)
|
|
20
135
|
|
|
21
136
|
## Developing
|
|
22
137
|
|
package/esm/hooks/useAccount.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
+
import { WalletState } from "@interChain-kit/core";
|
|
2
3
|
import { useWalletManager } from './useWalletManager';
|
|
3
4
|
export const useAccount = (chainName, walletName) => {
|
|
4
5
|
const walletManager = useWalletManager();
|
|
@@ -7,11 +8,11 @@ export const useAccount = (chainName, walletName) => {
|
|
|
7
8
|
const chain = walletManager.chains.find(c => c.chainName === chainName);
|
|
8
9
|
const getAccount = async () => {
|
|
9
10
|
if (wallet && chain) {
|
|
10
|
-
if (wallet.walletState ===
|
|
11
|
+
if (wallet.walletState === WalletState.Connected) {
|
|
11
12
|
const account = await wallet.getAccount(chain.chainId);
|
|
12
13
|
setAccount(account);
|
|
13
14
|
}
|
|
14
|
-
if (wallet.walletState ===
|
|
15
|
+
if (wallet.walletState === WalletState.Disconnected) {
|
|
15
16
|
setAccount(null);
|
|
16
17
|
}
|
|
17
18
|
}
|
package/esm/hooks/useChain.js
CHANGED
|
@@ -28,8 +28,8 @@ export const useChain = (chainName) => {
|
|
|
28
28
|
status: activeWallet?.walletState,
|
|
29
29
|
username: account?.username,
|
|
30
30
|
message: activeWallet?.errorMessage,
|
|
31
|
-
getSigningCosmWasmClient: () => walletManager.
|
|
32
|
-
getSigningCosmosClient: () => walletManager.
|
|
31
|
+
getSigningCosmWasmClient: () => walletManager.getSigningCosmwasmClient(activeWallet.option.name, chainName),
|
|
32
|
+
getSigningCosmosClient: () => walletManager.getSigningCosmosClient(activeWallet.option.name, chainName),
|
|
33
33
|
};
|
|
34
34
|
return {
|
|
35
35
|
chain: chainToShow,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
import { useWalletManager } from './useWalletManager';
|
|
3
3
|
import { useAccount } from './useAccount';
|
|
4
|
+
import { WalletState } from '@interChain-kit/core';
|
|
4
5
|
export const useInterchainClient = (chainName, walletName) => {
|
|
5
6
|
const [rpcEndpoint, setRpcEndpoint] = useState();
|
|
6
7
|
//query
|
|
@@ -17,21 +18,20 @@ export const useInterchainClient = (chainName, walletName) => {
|
|
|
17
18
|
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
18
19
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
19
20
|
const initialize = async () => {
|
|
20
|
-
if (wallet && chainToShow && wallet?.walletState ===
|
|
21
|
+
if (wallet && chainToShow && wallet?.walletState === WalletState.Connected) {
|
|
21
22
|
try {
|
|
22
23
|
setIsLoading(true);
|
|
23
24
|
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
24
25
|
setRpcEndpoint(rpcEndpoint);
|
|
25
|
-
const
|
|
26
|
-
const queryClient = await clientFactory.getClient();
|
|
26
|
+
const queryClient = await walletManager.getQueryClient(walletName, chainName);
|
|
27
27
|
setQueryClient(queryClient);
|
|
28
|
-
const signingClient = await
|
|
28
|
+
const signingClient = await walletManager.getSigningClient(walletName, chainName);
|
|
29
29
|
setSigningClient(signingClient);
|
|
30
|
-
const signingStargateClient = await
|
|
30
|
+
const signingStargateClient = await walletManager.getSigningCosmosClient(walletName, chainName);
|
|
31
31
|
setSigningCosmosClient(signingStargateClient);
|
|
32
|
-
const signingCosmwasmClient = await
|
|
32
|
+
const signingCosmwasmClient = await walletManager.getSigningCosmwasmClient(walletName, chainName);
|
|
33
33
|
setSigningCosmWasmClient(signingCosmwasmClient);
|
|
34
|
-
const signingInjectiveClient = await
|
|
34
|
+
const signingInjectiveClient = await walletManager.getSigningInjectiveClient(walletName, chainName);
|
|
35
35
|
setSigningInjectiveClient(signingInjectiveClient);
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useInterchainWalletContext } from "../provider";
|
|
2
2
|
export const useWalletManager = () => {
|
|
3
|
-
const { walletManager } =
|
|
3
|
+
const { walletManager } = useInterchainWalletContext();
|
|
4
4
|
return walletManager;
|
|
5
5
|
};
|
package/esm/modal/modal.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ConnectedContent, ConnectedHeader, ConnectingContent, ConnectingHeader,
|
|
|
4
4
|
import { useWalletModal } from "./provider";
|
|
5
5
|
import { useActiveWallet } from "../hooks";
|
|
6
6
|
import { useEffect, useState } from "react";
|
|
7
|
-
import { WCWallet } from "@interChain-kit/core";
|
|
7
|
+
import { WalletState, WCWallet } from "@interChain-kit/core";
|
|
8
8
|
const defaultModalView = {
|
|
9
9
|
header: _jsx(WalletListHeader, {}), content: _jsx(WalletListContent, {})
|
|
10
10
|
};
|
|
@@ -18,13 +18,13 @@ export const WalletModal = () => {
|
|
|
18
18
|
case activeWallet instanceof WCWallet && !activeWallet.session:
|
|
19
19
|
setModalView({ header: _jsx(QRCodeHeader, {}), content: _jsx(QRCodeContent, {}) });
|
|
20
20
|
break;
|
|
21
|
-
case activeWallet?.walletState ===
|
|
21
|
+
case activeWallet?.walletState === WalletState.Connecting:
|
|
22
22
|
setModalView({ header: _jsx(ConnectingHeader, { onBack: gotoWalletList }), content: _jsx(ConnectingContent, {}) });
|
|
23
23
|
break;
|
|
24
|
-
case activeWallet?.walletState ===
|
|
24
|
+
case activeWallet?.walletState === WalletState.Connected:
|
|
25
25
|
setModalView({ header: _jsx(ConnectedHeader, { onBack: gotoWalletList }), content: _jsx(ConnectedContent, {}) });
|
|
26
26
|
break;
|
|
27
|
-
case activeWallet?.walletState ===
|
|
27
|
+
case activeWallet?.walletState === WalletState.Reject:
|
|
28
28
|
setModalView({ header: _jsx(RejectHeader, { onBack: gotoWalletList }), content: _jsx(RejectContent, {}) });
|
|
29
29
|
break;
|
|
30
30
|
default:
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ConnectModalHead, ConnectModalQRCode } from "@interchain-ui/react";
|
|
3
|
-
import { useActiveWallet, useWalletManager
|
|
3
|
+
import { useActiveWallet, useWalletManager } from "../../hooks";
|
|
4
|
+
import { useWalletModal } from "../provider";
|
|
4
5
|
export const QRCodeHeader = () => {
|
|
5
6
|
const activeWallet = useActiveWallet();
|
|
6
7
|
const { close } = useWalletModal();
|
|
7
|
-
return (_jsx(ConnectModalHead, { title: activeWallet?.option?.prettyName ||
|
|
8
|
+
return (_jsx(ConnectModalHead, { title: activeWallet?.option?.prettyName || "", hasBackButton: true, onClose: () => void 0, onBack: () => void 0, closeButtonProps: { onClick: close } }));
|
|
8
9
|
};
|
|
9
10
|
export const QRCodeContent = () => {
|
|
10
11
|
const activeWallet = useActiveWallet();
|
|
11
12
|
const walletManager = useWalletManager();
|
|
12
13
|
const data = activeWallet.pairingUri;
|
|
13
|
-
return (_jsx(ConnectModalQRCode, { status: data ? "Done" :
|
|
14
|
+
return (_jsx(ConnectModalQRCode, { status: data ? "Done" : "Pending", link: data, description: "Open App to connect", errorTitle: "errorTitle", errorDesc: activeWallet.errorMessage || "", onRefresh: () => walletManager.connect(activeWallet?.option?.name || "") }));
|
|
14
15
|
};
|
package/esm/provider.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useMemo, useState } from
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
|
-
import { WalletManager } from
|
|
5
|
-
import { WalletModalProvider } from
|
|
6
|
-
const
|
|
7
|
-
export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children }) => {
|
|
4
|
+
import { WalletManager, } from "@interChain-kit/core";
|
|
5
|
+
import { WalletModalProvider } from "./modal";
|
|
6
|
+
const InterchainWalletContext = createContext(null);
|
|
7
|
+
export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
|
|
8
8
|
const [_, forceRender] = useState({});
|
|
9
9
|
const walletManager = useMemo(() => {
|
|
10
10
|
return new WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions, () => forceRender({}));
|
|
@@ -12,12 +12,12 @@ export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endp
|
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
walletManager.init();
|
|
14
14
|
}, []);
|
|
15
|
-
return (_jsx(
|
|
15
|
+
return (_jsx(InterchainWalletContext.Provider, { value: { walletManager }, children: _jsx(WalletModalProvider, { children: children }) }));
|
|
16
16
|
};
|
|
17
|
-
export const
|
|
18
|
-
const context = useContext(
|
|
17
|
+
export const useInterchainWalletContext = () => {
|
|
18
|
+
const context = useContext(InterchainWalletContext);
|
|
19
19
|
if (!context) {
|
|
20
|
-
throw new Error(
|
|
20
|
+
throw new Error("useInterChainWalletContext must be used within a InterChainProvider");
|
|
21
21
|
}
|
|
22
22
|
return context;
|
|
23
23
|
};
|
package/hooks/useAccount.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAccount = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const core_1 = require("@interChain-kit/core");
|
|
5
6
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
7
|
const useAccount = (chainName, walletName) => {
|
|
7
8
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
@@ -10,11 +11,11 @@ const useAccount = (chainName, walletName) => {
|
|
|
10
11
|
const chain = walletManager.chains.find(c => c.chainName === chainName);
|
|
11
12
|
const getAccount = async () => {
|
|
12
13
|
if (wallet && chain) {
|
|
13
|
-
if (wallet.walletState ===
|
|
14
|
+
if (wallet.walletState === core_1.WalletState.Connected) {
|
|
14
15
|
const account = await wallet.getAccount(chain.chainId);
|
|
15
16
|
setAccount(account);
|
|
16
17
|
}
|
|
17
|
-
if (wallet.walletState ===
|
|
18
|
+
if (wallet.walletState === core_1.WalletState.Disconnected) {
|
|
18
19
|
setAccount(null);
|
|
19
20
|
}
|
|
20
21
|
}
|
package/hooks/useChain.js
CHANGED
|
@@ -31,8 +31,8 @@ const useChain = (chainName) => {
|
|
|
31
31
|
status: activeWallet?.walletState,
|
|
32
32
|
username: account?.username,
|
|
33
33
|
message: activeWallet?.errorMessage,
|
|
34
|
-
getSigningCosmWasmClient: () => walletManager.
|
|
35
|
-
getSigningCosmosClient: () => walletManager.
|
|
34
|
+
getSigningCosmWasmClient: () => walletManager.getSigningCosmwasmClient(activeWallet.option.name, chainName),
|
|
35
|
+
getSigningCosmosClient: () => walletManager.getSigningCosmosClient(activeWallet.option.name, chainName),
|
|
36
36
|
};
|
|
37
37
|
return {
|
|
38
38
|
chain: chainToShow,
|
|
@@ -4,6 +4,7 @@ exports.useInterchainClient = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
6
|
const useAccount_1 = require("./useAccount");
|
|
7
|
+
const core_1 = require("@interChain-kit/core");
|
|
7
8
|
const useInterchainClient = (chainName, walletName) => {
|
|
8
9
|
const [rpcEndpoint, setRpcEndpoint] = (0, react_1.useState)();
|
|
9
10
|
//query
|
|
@@ -20,21 +21,20 @@ const useInterchainClient = (chainName, walletName) => {
|
|
|
20
21
|
const wallet = walletManager.wallets.find((w) => w.option.name === walletName);
|
|
21
22
|
const chainToShow = walletManager.chains.find((c) => c.chainName === chainName);
|
|
22
23
|
const initialize = async () => {
|
|
23
|
-
if (wallet && chainToShow && wallet?.walletState ===
|
|
24
|
+
if (wallet && chainToShow && wallet?.walletState === core_1.WalletState.Connected) {
|
|
24
25
|
try {
|
|
25
26
|
setIsLoading(true);
|
|
26
27
|
const rpcEndpoint = await walletManager.getRpcEndpoint(wallet, chainName);
|
|
27
28
|
setRpcEndpoint(rpcEndpoint);
|
|
28
|
-
const
|
|
29
|
-
const queryClient = await clientFactory.getClient();
|
|
29
|
+
const queryClient = await walletManager.getQueryClient(walletName, chainName);
|
|
30
30
|
setQueryClient(queryClient);
|
|
31
|
-
const signingClient = await
|
|
31
|
+
const signingClient = await walletManager.getSigningClient(walletName, chainName);
|
|
32
32
|
setSigningClient(signingClient);
|
|
33
|
-
const signingStargateClient = await
|
|
33
|
+
const signingStargateClient = await walletManager.getSigningCosmosClient(walletName, chainName);
|
|
34
34
|
setSigningCosmosClient(signingStargateClient);
|
|
35
|
-
const signingCosmwasmClient = await
|
|
35
|
+
const signingCosmwasmClient = await walletManager.getSigningCosmwasmClient(walletName, chainName);
|
|
36
36
|
setSigningCosmWasmClient(signingCosmwasmClient);
|
|
37
|
-
const signingInjectiveClient = await
|
|
37
|
+
const signingInjectiveClient = await walletManager.getSigningInjectiveClient(walletName, chainName);
|
|
38
38
|
setSigningInjectiveClient(signingInjectiveClient);
|
|
39
39
|
}
|
|
40
40
|
catch (error) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useWalletManager = void 0;
|
|
4
4
|
const provider_1 = require("../provider");
|
|
5
5
|
const useWalletManager = () => {
|
|
6
|
-
const { walletManager } = (0, provider_1.
|
|
6
|
+
const { walletManager } = (0, provider_1.useInterchainWalletContext)();
|
|
7
7
|
return walletManager;
|
|
8
8
|
};
|
|
9
9
|
exports.useWalletManager = useWalletManager;
|
package/modal/modal.js
CHANGED
|
@@ -21,13 +21,13 @@ const WalletModal = () => {
|
|
|
21
21
|
case activeWallet instanceof core_1.WCWallet && !activeWallet.session:
|
|
22
22
|
setModalView({ header: (0, jsx_runtime_1.jsx)(views_1.QRCodeHeader, {}), content: (0, jsx_runtime_1.jsx)(views_1.QRCodeContent, {}) });
|
|
23
23
|
break;
|
|
24
|
-
case activeWallet?.walletState ===
|
|
24
|
+
case activeWallet?.walletState === core_1.WalletState.Connecting:
|
|
25
25
|
setModalView({ header: (0, jsx_runtime_1.jsx)(views_1.ConnectingHeader, { onBack: gotoWalletList }), content: (0, jsx_runtime_1.jsx)(views_1.ConnectingContent, {}) });
|
|
26
26
|
break;
|
|
27
|
-
case activeWallet?.walletState ===
|
|
27
|
+
case activeWallet?.walletState === core_1.WalletState.Connected:
|
|
28
28
|
setModalView({ header: (0, jsx_runtime_1.jsx)(views_1.ConnectedHeader, { onBack: gotoWalletList }), content: (0, jsx_runtime_1.jsx)(views_1.ConnectedContent, {}) });
|
|
29
29
|
break;
|
|
30
|
-
case activeWallet?.walletState ===
|
|
30
|
+
case activeWallet?.walletState === core_1.WalletState.Reject:
|
|
31
31
|
setModalView({ header: (0, jsx_runtime_1.jsx)(views_1.RejectHeader, { onBack: gotoWalletList }), content: (0, jsx_runtime_1.jsx)(views_1.RejectContent, {}) });
|
|
32
32
|
break;
|
|
33
33
|
default:
|
package/modal/views/QRCode.js
CHANGED
|
@@ -3,17 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.QRCodeContent = exports.QRCodeHeader = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("@interchain-ui/react");
|
|
6
|
-
const
|
|
6
|
+
const hooks_1 = require("../../hooks");
|
|
7
|
+
const provider_1 = require("../provider");
|
|
7
8
|
const QRCodeHeader = () => {
|
|
8
|
-
const activeWallet = (0,
|
|
9
|
-
const { close } = (0,
|
|
10
|
-
return ((0, jsx_runtime_1.jsx)(react_1.ConnectModalHead, { title: activeWallet?.option?.prettyName ||
|
|
9
|
+
const activeWallet = (0, hooks_1.useActiveWallet)();
|
|
10
|
+
const { close } = (0, provider_1.useWalletModal)();
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(react_1.ConnectModalHead, { title: activeWallet?.option?.prettyName || "", hasBackButton: true, onClose: () => void 0, onBack: () => void 0, closeButtonProps: { onClick: close } }));
|
|
11
12
|
};
|
|
12
13
|
exports.QRCodeHeader = QRCodeHeader;
|
|
13
14
|
const QRCodeContent = () => {
|
|
14
|
-
const activeWallet = (0,
|
|
15
|
-
const walletManager = (0,
|
|
15
|
+
const activeWallet = (0, hooks_1.useActiveWallet)();
|
|
16
|
+
const walletManager = (0, hooks_1.useWalletManager)();
|
|
16
17
|
const data = activeWallet.pairingUri;
|
|
17
|
-
return ((0, jsx_runtime_1.jsx)(react_1.ConnectModalQRCode, { status: data ? "Done" :
|
|
18
|
+
return ((0, jsx_runtime_1.jsx)(react_1.ConnectModalQRCode, { status: data ? "Done" : "Pending", link: data, description: "Open App to connect", errorTitle: "errorTitle", errorDesc: activeWallet.errorMessage || "", onRefresh: () => walletManager.connect(activeWallet?.option?.name || "") }));
|
|
18
19
|
};
|
|
19
20
|
exports.QRCodeContent = QRCodeContent;
|
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.17",
|
|
4
4
|
"author": "cosmology-tech <developers@cosmology.zone>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
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.17",
|
|
36
36
|
"@interchain-ui/react": "^1.23.31",
|
|
37
37
|
"@interchainjs/cosmos-types": "0.0.1-beta.9",
|
|
38
38
|
"@interchainjs/injective": "0.0.1-beta.13",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"react": "^18.3.1",
|
|
43
43
|
"react-dom": "^18.3.1"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "04f8185798e960bcaf9620ad47df4b68ef3263d9"
|
|
46
46
|
}
|
package/provider.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { BaseWallet, SignerOptions, WalletManager, EndpointOptions } from
|
|
3
|
-
import { AssetList, Chain } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BaseWallet, SignerOptions, WalletManager, EndpointOptions } from "@interChain-kit/core";
|
|
3
|
+
import { AssetList, Chain } from "@chain-registry/v2-types";
|
|
4
4
|
type InterchainWalletContextType = {
|
|
5
5
|
walletManager: WalletManager;
|
|
6
6
|
};
|
|
7
|
-
type
|
|
7
|
+
type InterchainWalletProviderProps = {
|
|
8
8
|
chains: Chain[];
|
|
9
9
|
assetLists: AssetList[];
|
|
10
10
|
wallets: BaseWallet[];
|
|
@@ -12,6 +12,6 @@ type InterchianWalletProviderProps = {
|
|
|
12
12
|
endpointOptions: EndpointOptions;
|
|
13
13
|
children: React.ReactNode;
|
|
14
14
|
};
|
|
15
|
-
export declare const ChainProvider: ({ chains, assetLists, wallets, signerOptions, endpointOptions, children }:
|
|
16
|
-
export declare const
|
|
15
|
+
export declare const ChainProvider: ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }: InterchainWalletProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare const useInterchainWalletContext: () => InterchainWalletContextType;
|
|
17
17
|
export {};
|
package/provider.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.useInterchainWalletContext = exports.ChainProvider = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_2 = require("react");
|
|
7
7
|
const core_1 = require("@interChain-kit/core");
|
|
8
8
|
const modal_1 = require("./modal");
|
|
9
|
-
const
|
|
10
|
-
const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children }) => {
|
|
9
|
+
const InterchainWalletContext = (0, react_2.createContext)(null);
|
|
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
|
return new core_1.WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions, () => forceRender({}));
|
|
@@ -15,14 +15,14 @@ const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOpt
|
|
|
15
15
|
(0, react_1.useEffect)(() => {
|
|
16
16
|
walletManager.init();
|
|
17
17
|
}, []);
|
|
18
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
18
|
+
return ((0, jsx_runtime_1.jsx)(InterchainWalletContext.Provider, { value: { walletManager }, children: (0, jsx_runtime_1.jsx)(modal_1.WalletModalProvider, { children: children }) }));
|
|
19
19
|
};
|
|
20
20
|
exports.ChainProvider = ChainProvider;
|
|
21
|
-
const
|
|
22
|
-
const context = (0, react_2.useContext)(
|
|
21
|
+
const useInterchainWalletContext = () => {
|
|
22
|
+
const context = (0, react_2.useContext)(InterchainWalletContext);
|
|
23
23
|
if (!context) {
|
|
24
|
-
throw new Error(
|
|
24
|
+
throw new Error("useInterChainWalletContext must be used within a InterChainProvider");
|
|
25
25
|
}
|
|
26
26
|
return context;
|
|
27
27
|
};
|
|
28
|
-
exports.
|
|
28
|
+
exports.useInterchainWalletContext = useInterchainWalletContext;
|