@interchain-kit/react 0.0.1-beta.46 → 0.0.1-beta.48
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 +2 -2
- package/esm/hooks/useChain.js +23 -12
- package/esm/hooks/useChainWallet.js +7 -1
- package/esm/hooks/useCurrentChainWallet.js +11 -0
- package/esm/hooks/useCurrentWallet.js +2 -1
- package/esm/modal/modal.js +17 -11
- package/esm/modal/views/Connected.js +6 -5
- package/hooks/useAccount.js +2 -2
- package/hooks/useChain.js +23 -12
- package/hooks/useChainWallet.js +7 -1
- package/hooks/useCurrentChainWallet.d.ts +2 -0
- package/hooks/useCurrentChainWallet.js +15 -0
- package/hooks/useCurrentWallet.d.ts +1 -1
- package/hooks/useCurrentWallet.js +2 -1
- package/modal/modal.js +16 -10
- package/modal/views/Connected.js +5 -4
- package/package.json +3 -3
package/esm/hooks/useAccount.js
CHANGED
|
@@ -5,11 +5,11 @@ 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 && chainName && walletName) {
|
|
9
9
|
chainAccount.getAccount();
|
|
10
10
|
}
|
|
11
11
|
}, [chainName, walletName, chainAccount?.walletState]);
|
|
12
|
-
if (chainAccount?.walletState === WalletState.Connected) {
|
|
12
|
+
if (chainAccount?.walletState === WalletState.Connected && chainName && walletName) {
|
|
13
13
|
return {
|
|
14
14
|
account: chainAccount?.account,
|
|
15
15
|
isLoading: chainAccount.getAccountState().loading,
|
package/esm/hooks/useChain.js
CHANGED
|
@@ -1,36 +1,47 @@
|
|
|
1
1
|
import { useWalletManager } from "./useWalletManager";
|
|
2
2
|
import { useAccount } from "./useAccount";
|
|
3
|
-
import { useCurrentWallet } from './useCurrentWallet';
|
|
4
3
|
import { useInterchainClient } from './useInterchainClient';
|
|
5
4
|
import { useWalletModal } from "../modal";
|
|
6
5
|
import { useRpcEndpoint } from "./useRpcEndpoint";
|
|
7
6
|
import { WalletState } from "@interchain-kit/core";
|
|
7
|
+
import { useCurrentChainWallet } from "./useCurrentChainWallet";
|
|
8
8
|
export const useChain = (chainName) => {
|
|
9
9
|
const walletManager = useWalletManager();
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const walletName = currentWallet?.info?.name;
|
|
10
|
+
const chainAccount = useCurrentChainWallet();
|
|
11
|
+
const walletName = chainAccount?.info?.name;
|
|
13
12
|
const rpcEndpointHook = useRpcEndpoint(chainName, walletName);
|
|
14
13
|
const accountHook = useAccount(chainName, walletName);
|
|
15
14
|
const signingClientHook = useInterchainClient(chainName, walletName);
|
|
16
15
|
const { open, close } = useWalletModal();
|
|
17
16
|
const cosmosKitUserChainReturnType = {
|
|
18
|
-
connect: () =>
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
connect: () => {
|
|
18
|
+
if (chainAccount?.walletState === WalletState.Connected) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
walletManager.currentChainName = chainName;
|
|
22
|
+
open();
|
|
23
|
+
},
|
|
24
|
+
disconnect: () => {
|
|
25
|
+
walletManager.currentChainName = chainName;
|
|
26
|
+
chainAccount ?? chainAccount.disconnect();
|
|
27
|
+
},
|
|
28
|
+
openView: () => {
|
|
29
|
+
walletManager.currentChainName = chainName;
|
|
30
|
+
open();
|
|
31
|
+
},
|
|
21
32
|
closeView: close,
|
|
22
33
|
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
23
|
-
status:
|
|
34
|
+
status: chainAccount?.walletState,
|
|
24
35
|
username: accountHook.account?.username,
|
|
25
|
-
message:
|
|
36
|
+
message: chainAccount?.errorMessage
|
|
26
37
|
};
|
|
27
|
-
if (
|
|
38
|
+
if (chainAccount && chainAccount?.walletState === WalletState.Connected) {
|
|
28
39
|
return {
|
|
29
40
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
30
41
|
chain: chainAccount?.chain,
|
|
31
42
|
assetList: chainAccount?.assetList,
|
|
32
43
|
address: accountHook.account?.address,
|
|
33
|
-
wallet:
|
|
44
|
+
wallet: chainAccount,
|
|
34
45
|
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
35
46
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
36
47
|
signingClient: signingClientHook.signingClient,
|
|
@@ -49,7 +60,7 @@ export const useChain = (chainName) => {
|
|
|
49
60
|
chain: chainAccount?.chain,
|
|
50
61
|
assetList: chainAccount?.assetList,
|
|
51
62
|
address: accountHook.account?.address,
|
|
52
|
-
wallet:
|
|
63
|
+
wallet: chainAccount,
|
|
53
64
|
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
54
65
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
55
66
|
signingClient: signingClientHook.signingClient,
|
|
@@ -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,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { bindAllMethodsToContext } from "../utils/helpers";
|
|
2
|
+
import { useWalletManager } from "./useWalletManager";
|
|
3
|
+
export const useCurrentChainWallet = () => {
|
|
4
|
+
const walletManager = useWalletManager();
|
|
5
|
+
const { currentChainName, currentWalletName } = walletManager;
|
|
6
|
+
const chainWallet = walletManager.getWalletRepositoryByName(currentWalletName)?.getChainAccountByName(currentChainName);
|
|
7
|
+
if (chainWallet) {
|
|
8
|
+
return bindAllMethodsToContext(chainWallet);
|
|
9
|
+
}
|
|
10
|
+
return {};
|
|
11
|
+
};
|
|
@@ -9,7 +9,8 @@ export const useCurrentWallet = () => {
|
|
|
9
9
|
// open()
|
|
10
10
|
// }
|
|
11
11
|
// }, [walletManager.currentWalletName, walletManager.state])
|
|
12
|
-
const
|
|
12
|
+
const { currentWalletName, currentChainName, getWalletRepositoryByName } = walletManager;
|
|
13
|
+
const wallet = getWalletRepositoryByName(currentWalletName);
|
|
13
14
|
if (wallet) {
|
|
14
15
|
return bindAllMethodsToContext(wallet);
|
|
15
16
|
}
|
package/esm/modal/modal.js
CHANGED
|
@@ -1,45 +1,50 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ConnectedContent, ConnectedHeader, ConnectingContent, ConnectingHeader, NotExistContent, NotExistHeader, QRCodeContent, QRCodeHeader, RejectContent, RejectHeader, WalletListContent, WalletListHeader, } from "./views";
|
|
3
3
|
import { useWalletModal } from "./provider";
|
|
4
|
-
import {
|
|
4
|
+
import { useWalletManager } from "../hooks";
|
|
5
5
|
import { useEffect, useMemo, useState } from "react";
|
|
6
6
|
import { WalletState, } from "@interchain-kit/core";
|
|
7
7
|
import { ConnectModal } from "@interchain-ui/react";
|
|
8
|
+
import { useCurrentChainWallet } from "../hooks/useCurrentChainWallet";
|
|
8
9
|
export const WalletModal = () => {
|
|
9
10
|
const { modalIsOpen, open, close } = useWalletModal();
|
|
10
|
-
const currentWallet = useCurrentWallet();
|
|
11
11
|
const walletManager = useWalletManager();
|
|
12
12
|
const handleSelectWallet = async (wallet) => {
|
|
13
|
-
|
|
13
|
+
walletManager.currentWalletName = wallet.info.name;
|
|
14
|
+
const currentWallet = walletManager
|
|
15
|
+
.getWalletRepositoryByName(wallet.info.name)
|
|
16
|
+
.getChainAccountByName(walletManager.currentChainName);
|
|
14
17
|
setModalView({
|
|
15
18
|
header: _jsx(ConnectingHeader, { wallet: wallet, onBack: gotoWalletList }),
|
|
16
19
|
content: _jsx(ConnectingContent, { wallet: wallet }),
|
|
17
20
|
});
|
|
18
|
-
if (
|
|
19
|
-
!
|
|
21
|
+
if (currentWallet.wallet.info.mode === "extension" &&
|
|
22
|
+
!currentWallet.wallet.isExtensionInstalled) {
|
|
20
23
|
setModalView({
|
|
21
|
-
header: (_jsx(NotExistHeader, { wallet:
|
|
22
|
-
content: _jsx(NotExistContent, { wallet:
|
|
24
|
+
header: (_jsx(NotExistHeader, { wallet: currentWallet, onBack: gotoWalletList })),
|
|
25
|
+
content: _jsx(NotExistContent, { wallet: currentWallet }),
|
|
23
26
|
});
|
|
24
27
|
return;
|
|
25
28
|
}
|
|
26
29
|
try {
|
|
27
|
-
if (
|
|
28
|
-
|
|
30
|
+
if (currentWallet.wallet.info.mode === "wallet-connect") {
|
|
31
|
+
currentWallet.wallet.setOnPairingUriCreatedCallback(() => {
|
|
29
32
|
setModalView({
|
|
30
33
|
header: _jsx(QRCodeHeader, { onBack: gotoWalletList }),
|
|
31
34
|
content: _jsx(QRCodeContent, {}),
|
|
32
35
|
});
|
|
33
36
|
});
|
|
34
|
-
|
|
37
|
+
currentWallet.wallet.setPairingToConnect(wallet.pairing);
|
|
35
38
|
}
|
|
36
|
-
await
|
|
39
|
+
await currentWallet.connect();
|
|
40
|
+
await currentWallet.getAccount();
|
|
37
41
|
setModalView({
|
|
38
42
|
header: _jsx(ConnectedHeader, { onBack: gotoWalletList }),
|
|
39
43
|
content: _jsx(ConnectedContent, {}),
|
|
40
44
|
});
|
|
41
45
|
}
|
|
42
46
|
catch (error) {
|
|
47
|
+
console.log(error);
|
|
43
48
|
setModalView({
|
|
44
49
|
header: _jsx(RejectHeader, { wallet: wallet, onBack: gotoWalletList }),
|
|
45
50
|
content: _jsx(RejectContent, { wallet: wallet }),
|
|
@@ -54,6 +59,7 @@ export const WalletModal = () => {
|
|
|
54
59
|
}, []);
|
|
55
60
|
const [modalView, setModalView] = useState(defaultModalView);
|
|
56
61
|
const gotoWalletList = () => setModalView(defaultModalView);
|
|
62
|
+
const currentWallet = useCurrentChainWallet();
|
|
57
63
|
useEffect(() => {
|
|
58
64
|
if (modalIsOpen && currentWallet?.walletState === WalletState.Connected) {
|
|
59
65
|
setModalView({
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ConnectModalHead, ConnectModalStatus } from "@interchain-ui/react";
|
|
3
|
-
import { useAccount,
|
|
3
|
+
import { useAccount, useWalletManager } from "../../hooks";
|
|
4
4
|
import { useWalletModal } from "../provider";
|
|
5
5
|
import { getWalletInfo } from "../../utils";
|
|
6
6
|
import { AstronautSvg } from "./Astronaut";
|
|
7
|
+
import { useCurrentChainWallet } from "../../hooks/useCurrentChainWallet";
|
|
7
8
|
export const ConnectedHeader = ({ onBack }) => {
|
|
8
|
-
const currentWallet =
|
|
9
|
+
const currentWallet = useCurrentChainWallet();
|
|
9
10
|
const { close } = useWalletModal();
|
|
10
11
|
return (_jsx(ConnectModalHead, { title: currentWallet?.info?.prettyName || "", hasBackButton: true, onClose: close, onBack: onBack, closeButtonProps: { onClick: close } }));
|
|
11
12
|
};
|
|
12
13
|
export const ConnectedContent = () => {
|
|
13
|
-
const currentWallet =
|
|
14
|
+
const currentWallet = useCurrentChainWallet();
|
|
14
15
|
const walletManager = useWalletManager();
|
|
15
|
-
const { account } = useAccount(
|
|
16
|
+
const { account } = useAccount(walletManager.currentChainName, currentWallet?.info?.name);
|
|
16
17
|
const { close } = useWalletModal();
|
|
17
18
|
if (!currentWallet) {
|
|
18
19
|
return null;
|
|
@@ -26,7 +27,7 @@ export const ConnectedContent = () => {
|
|
|
26
27
|
} })),
|
|
27
28
|
address: account?.address,
|
|
28
29
|
}, onDisconnect: async () => {
|
|
29
|
-
await
|
|
30
|
+
await currentWallet.disconnect();
|
|
30
31
|
close();
|
|
31
32
|
} }));
|
|
32
33
|
};
|
package/hooks/useAccount.js
CHANGED
|
@@ -8,11 +8,11 @@ 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 && chainName && walletName) {
|
|
12
12
|
chainAccount.getAccount();
|
|
13
13
|
}
|
|
14
14
|
}, [chainName, walletName, chainAccount?.walletState]);
|
|
15
|
-
if (chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
15
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected && chainName && walletName) {
|
|
16
16
|
return {
|
|
17
17
|
account: chainAccount?.account,
|
|
18
18
|
isLoading: chainAccount.getAccountState().loading,
|
package/hooks/useChain.js
CHANGED
|
@@ -3,37 +3,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useChain = void 0;
|
|
4
4
|
const useWalletManager_1 = require("./useWalletManager");
|
|
5
5
|
const useAccount_1 = require("./useAccount");
|
|
6
|
-
const useCurrentWallet_1 = require("./useCurrentWallet");
|
|
7
6
|
const useInterchainClient_1 = require("./useInterchainClient");
|
|
8
7
|
const modal_1 = require("../modal");
|
|
9
8
|
const useRpcEndpoint_1 = require("./useRpcEndpoint");
|
|
10
9
|
const core_1 = require("@interchain-kit/core");
|
|
10
|
+
const useCurrentChainWallet_1 = require("./useCurrentChainWallet");
|
|
11
11
|
const useChain = (chainName) => {
|
|
12
12
|
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const walletName = currentWallet?.info?.name;
|
|
13
|
+
const chainAccount = (0, useCurrentChainWallet_1.useCurrentChainWallet)();
|
|
14
|
+
const walletName = chainAccount?.info?.name;
|
|
16
15
|
const rpcEndpointHook = (0, useRpcEndpoint_1.useRpcEndpoint)(chainName, walletName);
|
|
17
16
|
const accountHook = (0, useAccount_1.useAccount)(chainName, walletName);
|
|
18
17
|
const signingClientHook = (0, useInterchainClient_1.useInterchainClient)(chainName, walletName);
|
|
19
18
|
const { open, close } = (0, modal_1.useWalletModal)();
|
|
20
19
|
const cosmosKitUserChainReturnType = {
|
|
21
|
-
connect: () =>
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
connect: () => {
|
|
21
|
+
if (chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
walletManager.currentChainName = chainName;
|
|
25
|
+
open();
|
|
26
|
+
},
|
|
27
|
+
disconnect: () => {
|
|
28
|
+
walletManager.currentChainName = chainName;
|
|
29
|
+
chainAccount ?? chainAccount.disconnect();
|
|
30
|
+
},
|
|
31
|
+
openView: () => {
|
|
32
|
+
walletManager.currentChainName = chainName;
|
|
33
|
+
open();
|
|
34
|
+
},
|
|
24
35
|
closeView: close,
|
|
25
36
|
getRpcEndpoint: () => chainAccount.getRpcEndpoint(),
|
|
26
|
-
status:
|
|
37
|
+
status: chainAccount?.walletState,
|
|
27
38
|
username: accountHook.account?.username,
|
|
28
|
-
message:
|
|
39
|
+
message: chainAccount?.errorMessage
|
|
29
40
|
};
|
|
30
|
-
if (
|
|
41
|
+
if (chainAccount && chainAccount?.walletState === core_1.WalletState.Connected) {
|
|
31
42
|
return {
|
|
32
43
|
logoUrl: walletManager.getChainLogoUrl(chainName),
|
|
33
44
|
chain: chainAccount?.chain,
|
|
34
45
|
assetList: chainAccount?.assetList,
|
|
35
46
|
address: accountHook.account?.address,
|
|
36
|
-
wallet:
|
|
47
|
+
wallet: chainAccount,
|
|
37
48
|
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
38
49
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
39
50
|
signingClient: signingClientHook.signingClient,
|
|
@@ -52,7 +63,7 @@ const useChain = (chainName) => {
|
|
|
52
63
|
chain: chainAccount?.chain,
|
|
53
64
|
assetList: chainAccount?.assetList,
|
|
54
65
|
address: accountHook.account?.address,
|
|
55
|
-
wallet:
|
|
66
|
+
wallet: chainAccount,
|
|
56
67
|
rpcEndpoint: rpcEndpointHook.rpcEndpoint,
|
|
57
68
|
...cosmosKitUserChainReturnType, //for migration cosmos kit
|
|
58
69
|
signingClient: signingClientHook.signingClient,
|
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,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCurrentChainWallet = void 0;
|
|
4
|
+
const helpers_1 = require("../utils/helpers");
|
|
5
|
+
const useWalletManager_1 = require("./useWalletManager");
|
|
6
|
+
const useCurrentChainWallet = () => {
|
|
7
|
+
const walletManager = (0, useWalletManager_1.useWalletManager)();
|
|
8
|
+
const { currentChainName, currentWalletName } = walletManager;
|
|
9
|
+
const chainWallet = walletManager.getWalletRepositoryByName(currentWalletName)?.getChainAccountByName(currentChainName);
|
|
10
|
+
if (chainWallet) {
|
|
11
|
+
return (0, helpers_1.bindAllMethodsToContext)(chainWallet);
|
|
12
|
+
}
|
|
13
|
+
return {};
|
|
14
|
+
};
|
|
15
|
+
exports.useCurrentChainWallet = useCurrentChainWallet;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { WalletRepository } from
|
|
1
|
+
import { WalletRepository } from "@interchain-kit/core/wallet-repository";
|
|
2
2
|
export declare const useCurrentWallet: () => WalletRepository;
|
|
@@ -12,7 +12,8 @@ const useCurrentWallet = () => {
|
|
|
12
12
|
// open()
|
|
13
13
|
// }
|
|
14
14
|
// }, [walletManager.currentWalletName, walletManager.state])
|
|
15
|
-
const
|
|
15
|
+
const { currentWalletName, currentChainName, getWalletRepositoryByName } = walletManager;
|
|
16
|
+
const wallet = getWalletRepositoryByName(currentWalletName);
|
|
16
17
|
if (wallet) {
|
|
17
18
|
return (0, helpers_1.bindAllMethodsToContext)(wallet);
|
|
18
19
|
}
|
package/modal/modal.js
CHANGED
|
@@ -8,41 +8,46 @@ const hooks_1 = require("../hooks");
|
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const core_1 = require("@interchain-kit/core");
|
|
10
10
|
const react_2 = require("@interchain-ui/react");
|
|
11
|
+
const useCurrentChainWallet_1 = require("../hooks/useCurrentChainWallet");
|
|
11
12
|
const WalletModal = () => {
|
|
12
13
|
const { modalIsOpen, open, close } = (0, provider_1.useWalletModal)();
|
|
13
|
-
const currentWallet = (0, hooks_1.useCurrentWallet)();
|
|
14
14
|
const walletManager = (0, hooks_1.useWalletManager)();
|
|
15
15
|
const handleSelectWallet = async (wallet) => {
|
|
16
|
-
|
|
16
|
+
walletManager.currentWalletName = wallet.info.name;
|
|
17
|
+
const currentWallet = walletManager
|
|
18
|
+
.getWalletRepositoryByName(wallet.info.name)
|
|
19
|
+
.getChainAccountByName(walletManager.currentChainName);
|
|
17
20
|
setModalView({
|
|
18
21
|
header: (0, jsx_runtime_1.jsx)(views_1.ConnectingHeader, { wallet: wallet, onBack: gotoWalletList }),
|
|
19
22
|
content: (0, jsx_runtime_1.jsx)(views_1.ConnectingContent, { wallet: wallet }),
|
|
20
23
|
});
|
|
21
|
-
if (
|
|
22
|
-
!
|
|
24
|
+
if (currentWallet.wallet.info.mode === "extension" &&
|
|
25
|
+
!currentWallet.wallet.isExtensionInstalled) {
|
|
23
26
|
setModalView({
|
|
24
|
-
header: ((0, jsx_runtime_1.jsx)(views_1.NotExistHeader, { wallet:
|
|
25
|
-
content: (0, jsx_runtime_1.jsx)(views_1.NotExistContent, { wallet:
|
|
27
|
+
header: ((0, jsx_runtime_1.jsx)(views_1.NotExistHeader, { wallet: currentWallet, onBack: gotoWalletList })),
|
|
28
|
+
content: (0, jsx_runtime_1.jsx)(views_1.NotExistContent, { wallet: currentWallet }),
|
|
26
29
|
});
|
|
27
30
|
return;
|
|
28
31
|
}
|
|
29
32
|
try {
|
|
30
|
-
if (
|
|
31
|
-
|
|
33
|
+
if (currentWallet.wallet.info.mode === "wallet-connect") {
|
|
34
|
+
currentWallet.wallet.setOnPairingUriCreatedCallback(() => {
|
|
32
35
|
setModalView({
|
|
33
36
|
header: (0, jsx_runtime_1.jsx)(views_1.QRCodeHeader, { onBack: gotoWalletList }),
|
|
34
37
|
content: (0, jsx_runtime_1.jsx)(views_1.QRCodeContent, {}),
|
|
35
38
|
});
|
|
36
39
|
});
|
|
37
|
-
|
|
40
|
+
currentWallet.wallet.setPairingToConnect(wallet.pairing);
|
|
38
41
|
}
|
|
39
|
-
await
|
|
42
|
+
await currentWallet.connect();
|
|
43
|
+
await currentWallet.getAccount();
|
|
40
44
|
setModalView({
|
|
41
45
|
header: (0, jsx_runtime_1.jsx)(views_1.ConnectedHeader, { onBack: gotoWalletList }),
|
|
42
46
|
content: (0, jsx_runtime_1.jsx)(views_1.ConnectedContent, {}),
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
catch (error) {
|
|
50
|
+
console.log(error);
|
|
46
51
|
setModalView({
|
|
47
52
|
header: (0, jsx_runtime_1.jsx)(views_1.RejectHeader, { wallet: wallet, onBack: gotoWalletList }),
|
|
48
53
|
content: (0, jsx_runtime_1.jsx)(views_1.RejectContent, { wallet: wallet }),
|
|
@@ -57,6 +62,7 @@ const WalletModal = () => {
|
|
|
57
62
|
}, []);
|
|
58
63
|
const [modalView, setModalView] = (0, react_1.useState)(defaultModalView);
|
|
59
64
|
const gotoWalletList = () => setModalView(defaultModalView);
|
|
65
|
+
const currentWallet = (0, useCurrentChainWallet_1.useCurrentChainWallet)();
|
|
60
66
|
(0, react_1.useEffect)(() => {
|
|
61
67
|
if (modalIsOpen && currentWallet?.walletState === core_1.WalletState.Connected) {
|
|
62
68
|
setModalView({
|
package/modal/views/Connected.js
CHANGED
|
@@ -7,16 +7,17 @@ const hooks_1 = require("../../hooks");
|
|
|
7
7
|
const provider_1 = require("../provider");
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
const Astronaut_1 = require("./Astronaut");
|
|
10
|
+
const useCurrentChainWallet_1 = require("../../hooks/useCurrentChainWallet");
|
|
10
11
|
const ConnectedHeader = ({ onBack }) => {
|
|
11
|
-
const currentWallet = (0,
|
|
12
|
+
const currentWallet = (0, useCurrentChainWallet_1.useCurrentChainWallet)();
|
|
12
13
|
const { close } = (0, provider_1.useWalletModal)();
|
|
13
14
|
return ((0, jsx_runtime_1.jsx)(react_1.ConnectModalHead, { title: currentWallet?.info?.prettyName || "", hasBackButton: true, onClose: close, onBack: onBack, closeButtonProps: { onClick: close } }));
|
|
14
15
|
};
|
|
15
16
|
exports.ConnectedHeader = ConnectedHeader;
|
|
16
17
|
const ConnectedContent = () => {
|
|
17
|
-
const currentWallet = (0,
|
|
18
|
+
const currentWallet = (0, useCurrentChainWallet_1.useCurrentChainWallet)();
|
|
18
19
|
const walletManager = (0, hooks_1.useWalletManager)();
|
|
19
|
-
const { account } = (0, hooks_1.useAccount)(
|
|
20
|
+
const { account } = (0, hooks_1.useAccount)(walletManager.currentChainName, currentWallet?.info?.name);
|
|
20
21
|
const { close } = (0, provider_1.useWalletModal)();
|
|
21
22
|
if (!currentWallet) {
|
|
22
23
|
return null;
|
|
@@ -30,7 +31,7 @@ const ConnectedContent = () => {
|
|
|
30
31
|
} })),
|
|
31
32
|
address: account?.address,
|
|
32
33
|
}, onDisconnect: async () => {
|
|
33
|
-
await
|
|
34
|
+
await currentWallet.disconnect();
|
|
34
35
|
close();
|
|
35
36
|
} }));
|
|
36
37
|
};
|
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.48",
|
|
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.48",
|
|
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": "b78c7ffdf4e93298add4400bbc85148996ae5545"
|
|
52
52
|
}
|