@interchain-kit/react 0.2.201 → 0.2.203
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/useWalletManager.js +14 -3
- package/esm/modal/modal.js +13 -8
- package/esm/modal/views/Connected.js +0 -1
- package/esm/provider.js +2 -4
- package/esm/store/index.js +24 -2
- package/hooks/useWalletManager.d.ts +1 -1
- package/hooks/useWalletManager.js +14 -3
- package/modal/modal.js +13 -8
- package/modal/views/Connected.js +0 -1
- package/package.json +6 -6
- package/provider.d.ts +2 -5
- package/provider.js +1 -3
- package/store/index.js +23 -1
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import { useStore } from "zustand";
|
|
1
2
|
import { useInterchainWalletContext } from "../provider";
|
|
2
|
-
|
|
3
|
+
function bindMethodsToContext(context) {
|
|
4
|
+
for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(context))) {
|
|
5
|
+
const value = context[key];
|
|
6
|
+
if (typeof value === 'function') {
|
|
7
|
+
context[key] = value.bind(context);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
3
11
|
export const useWalletManager = () => {
|
|
4
|
-
const
|
|
5
|
-
|
|
12
|
+
const object = useInterchainWalletContext();
|
|
13
|
+
// put useStore here to update the hook
|
|
14
|
+
const store = useStore(object.store);
|
|
15
|
+
bindMethodsToContext(object);
|
|
16
|
+
return object;
|
|
6
17
|
};
|
package/esm/modal/modal.js
CHANGED
|
@@ -13,14 +13,19 @@ export const WalletModal = () => {
|
|
|
13
13
|
const [selectedWallet, setSelectedWallet] = useState(null);
|
|
14
14
|
const { chain, status, wallet } = useChainWallet(currentChainName, currentWalletName);
|
|
15
15
|
const handleConnect = async () => {
|
|
16
|
-
|
|
17
|
-
wallet.originalWallet
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
try {
|
|
17
|
+
if (wallet.originalWallet instanceof WCWallet) {
|
|
18
|
+
wallet.originalWallet.setOnPairingUriCreatedCallback((uri) => {
|
|
19
|
+
setQRCode(uri);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
await connect(selectedWallet?.info?.name, chain.chainName);
|
|
23
|
+
await getAccount(selectedWallet?.info?.name, chain.chainName);
|
|
24
|
+
setSelectedWallet(null);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error("Failed to connect wallet:", error);
|
|
20
28
|
}
|
|
21
|
-
await connect(selectedWallet?.info?.name, chain.chainName);
|
|
22
|
-
await getAccount(selectedWallet?.info?.name, chain.chainName);
|
|
23
|
-
setSelectedWallet(null);
|
|
24
29
|
};
|
|
25
30
|
useEffect(() => {
|
|
26
31
|
if (selectedWallet && currentWalletName && currentChainName) {
|
|
@@ -58,7 +63,7 @@ export const WalletModal = () => {
|
|
|
58
63
|
status,
|
|
59
64
|
modalIsOpen,
|
|
60
65
|
selectedWallet,
|
|
61
|
-
qrCode
|
|
66
|
+
qrCode,
|
|
62
67
|
]);
|
|
63
68
|
const goBackList = () => setModalType("wallet-list");
|
|
64
69
|
const { header, content } = useMemo(() => {
|
|
@@ -10,7 +10,6 @@ export const ConnectedHeader = ({ wallet, onBack, }) => {
|
|
|
10
10
|
};
|
|
11
11
|
export const ConnectedContent = ({ afterDisconnect, }) => {
|
|
12
12
|
const { currentChainName, currentWalletName } = useWalletManager();
|
|
13
|
-
console.log({ currentChainName, currentWalletName });
|
|
14
13
|
const { address, username, wallet } = useChainWallet(currentChainName, currentWalletName);
|
|
15
14
|
const { close } = useWalletModal();
|
|
16
15
|
if (!wallet) {
|
package/esm/provider.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
4
|
import { WalletManager, } from "@interchain-kit/core";
|
|
5
5
|
import { WalletModalProvider } from "./modal";
|
|
6
|
-
import { createInterchainStore } from "./store";
|
|
7
6
|
const InterchainWalletContext = createContext(null);
|
|
8
7
|
export const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
|
|
9
8
|
// const [_, forceRender] = useState({});
|
|
10
9
|
const walletManager = new WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions);
|
|
11
|
-
const store = useRef(createInterchainStore(walletManager));
|
|
12
10
|
useEffect(() => {
|
|
13
11
|
walletManager.init();
|
|
14
12
|
}, []);
|
|
15
|
-
return (_jsx(InterchainWalletContext.Provider, { value:
|
|
13
|
+
return (_jsx(InterchainWalletContext.Provider, { value: walletManager, children: _jsx(WalletModalProvider, { children: children }) }));
|
|
16
14
|
};
|
|
17
15
|
export const useInterchainWalletContext = () => {
|
|
18
16
|
const context = useContext(InterchainWalletContext);
|
package/esm/store/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletState } from "@interchain-kit/core";
|
|
1
|
+
import { clientNotExistError, WalletState } from "@interchain-kit/core";
|
|
2
2
|
import { createStore } from "zustand";
|
|
3
3
|
import { immer } from "zustand/middleware/immer";
|
|
4
4
|
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
@@ -32,6 +32,7 @@ export const createInterchainStore = (walletManager) => {
|
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
return createStore(persist(immer((set, get) => ({
|
|
35
|
+
store: walletManager.store,
|
|
35
36
|
chainWalletState,
|
|
36
37
|
currentWalletName: '',
|
|
37
38
|
currentChainName: '',
|
|
@@ -49,7 +50,28 @@ export const createInterchainStore = (walletManager) => {
|
|
|
49
50
|
draft.chainWalletState[targetIndex] = { ...draft.chainWalletState[targetIndex], ...data };
|
|
50
51
|
});
|
|
51
52
|
},
|
|
52
|
-
init: () =>
|
|
53
|
+
init: async () => {
|
|
54
|
+
const NotExistWallets = [];
|
|
55
|
+
await Promise.all(get().wallets.map(async (wallet) => {
|
|
56
|
+
try {
|
|
57
|
+
await wallet.init();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error === clientNotExistError.message) {
|
|
61
|
+
NotExistWallets.push(wallet.info.name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
set(draft => {
|
|
66
|
+
draft.chainWalletState = draft.chainWalletState.map(cws => {
|
|
67
|
+
if (NotExistWallets.includes(cws.walletName)) {
|
|
68
|
+
return { ...cws, walletState: WalletState.NotExist };
|
|
69
|
+
}
|
|
70
|
+
return cws;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
// return walletManager.init()
|
|
74
|
+
},
|
|
53
75
|
setCurrentChainName: (chainName) => {
|
|
54
76
|
set(draft => { draft.currentChainName = chainName; });
|
|
55
77
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useWalletManager: () => import("
|
|
1
|
+
export declare const useWalletManager: () => import("@interchain-kit/core").WalletManager;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useWalletManager = void 0;
|
|
4
|
-
const provider_1 = require("../provider");
|
|
5
4
|
const zustand_1 = require("zustand");
|
|
5
|
+
const provider_1 = require("../provider");
|
|
6
|
+
function bindMethodsToContext(context) {
|
|
7
|
+
for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(context))) {
|
|
8
|
+
const value = context[key];
|
|
9
|
+
if (typeof value === 'function') {
|
|
10
|
+
context[key] = value.bind(context);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
6
14
|
const useWalletManager = () => {
|
|
7
|
-
const
|
|
8
|
-
|
|
15
|
+
const object = (0, provider_1.useInterchainWalletContext)();
|
|
16
|
+
// put useStore here to update the hook
|
|
17
|
+
const store = (0, zustand_1.useStore)(object.store);
|
|
18
|
+
bindMethodsToContext(object);
|
|
19
|
+
return object;
|
|
9
20
|
};
|
|
10
21
|
exports.useWalletManager = useWalletManager;
|
package/modal/modal.js
CHANGED
|
@@ -16,14 +16,19 @@ const WalletModal = () => {
|
|
|
16
16
|
const [selectedWallet, setSelectedWallet] = (0, react_1.useState)(null);
|
|
17
17
|
const { chain, status, wallet } = (0, hooks_1.useChainWallet)(currentChainName, currentWalletName);
|
|
18
18
|
const handleConnect = async () => {
|
|
19
|
-
|
|
20
|
-
wallet.originalWallet.
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
try {
|
|
20
|
+
if (wallet.originalWallet instanceof core_1.WCWallet) {
|
|
21
|
+
wallet.originalWallet.setOnPairingUriCreatedCallback((uri) => {
|
|
22
|
+
setQRCode(uri);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
await connect(selectedWallet?.info?.name, chain.chainName);
|
|
26
|
+
await getAccount(selectedWallet?.info?.name, chain.chainName);
|
|
27
|
+
setSelectedWallet(null);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error("Failed to connect wallet:", error);
|
|
23
31
|
}
|
|
24
|
-
await connect(selectedWallet?.info?.name, chain.chainName);
|
|
25
|
-
await getAccount(selectedWallet?.info?.name, chain.chainName);
|
|
26
|
-
setSelectedWallet(null);
|
|
27
32
|
};
|
|
28
33
|
(0, react_1.useEffect)(() => {
|
|
29
34
|
if (selectedWallet && currentWalletName && currentChainName) {
|
|
@@ -61,7 +66,7 @@ const WalletModal = () => {
|
|
|
61
66
|
status,
|
|
62
67
|
modalIsOpen,
|
|
63
68
|
selectedWallet,
|
|
64
|
-
qrCode
|
|
69
|
+
qrCode,
|
|
65
70
|
]);
|
|
66
71
|
const goBackList = () => setModalType("wallet-list");
|
|
67
72
|
const { header, content } = (0, react_1.useMemo)(() => {
|
package/modal/views/Connected.js
CHANGED
|
@@ -14,7 +14,6 @@ const ConnectedHeader = ({ wallet, onBack, }) => {
|
|
|
14
14
|
exports.ConnectedHeader = ConnectedHeader;
|
|
15
15
|
const ConnectedContent = ({ afterDisconnect, }) => {
|
|
16
16
|
const { currentChainName, currentWalletName } = (0, hooks_1.useWalletManager)();
|
|
17
|
-
console.log({ currentChainName, currentWalletName });
|
|
18
17
|
const { address, username, wallet } = (0, hooks_1.useChainWallet)(currentChainName, currentWalletName);
|
|
19
18
|
const { close } = (0, provider_1.useWalletModal)();
|
|
20
19
|
if (!wallet) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interchain-kit/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.203",
|
|
4
4
|
"author": "Hyperweb <developers@hyperweb.io>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -33,18 +33,18 @@
|
|
|
33
33
|
"keywords": [],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@chain-registry/v2-types": "^0.53.40",
|
|
36
|
-
"@interchain-kit/core": "0.2.
|
|
36
|
+
"@interchain-kit/core": "0.2.203",
|
|
37
37
|
"@interchain-ui/react": "1.26.1",
|
|
38
|
-
"@interchainjs/cosmos": "1.9.
|
|
39
|
-
"@interchainjs/cosmos-types": "1.9.
|
|
38
|
+
"@interchainjs/cosmos": "1.9.12",
|
|
39
|
+
"@interchainjs/cosmos-types": "1.9.12",
|
|
40
40
|
"@react-icons/all-files": "^4.1.0",
|
|
41
41
|
"@types/react": "^18.3.3",
|
|
42
42
|
"@types/react-dom": "^18.3.0",
|
|
43
43
|
"@walletconnect/types": "^2.17.3",
|
|
44
|
-
"interchainjs": "1.9.
|
|
44
|
+
"interchainjs": "1.9.12",
|
|
45
45
|
"react": "^18.3.1",
|
|
46
46
|
"react-dom": "^18.3.1",
|
|
47
47
|
"zustand": "^5.0.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "26df3f33b03181c1a067e6662835982cc235c376"
|
|
50
50
|
}
|
package/provider.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { BaseWallet, SignerOptions, EndpointOptions } from "@interchain-kit/core";
|
|
2
|
+
import { BaseWallet, SignerOptions, EndpointOptions, WalletManager } from "@interchain-kit/core";
|
|
3
3
|
import { AssetList, Chain } from "@chain-registry/v2-types";
|
|
4
|
-
import { InterchainStore } from "./store";
|
|
5
|
-
import { StoreApi } from "zustand";
|
|
6
|
-
type InterchainWalletContextType = StoreApi<InterchainStore>;
|
|
7
4
|
type InterchainWalletProviderProps = {
|
|
8
5
|
chains: Chain[];
|
|
9
6
|
assetLists: AssetList[];
|
|
@@ -13,5 +10,5 @@ type InterchainWalletProviderProps = {
|
|
|
13
10
|
children: React.ReactNode;
|
|
14
11
|
};
|
|
15
12
|
export declare const ChainProvider: ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }: InterchainWalletProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
export declare const useInterchainWalletContext: () =>
|
|
13
|
+
export declare const useInterchainWalletContext: () => WalletManager;
|
|
17
14
|
export {};
|
package/provider.js
CHANGED
|
@@ -6,16 +6,14 @@ 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 store_1 = require("./store");
|
|
10
9
|
const InterchainWalletContext = (0, react_2.createContext)(null);
|
|
11
10
|
const ChainProvider = ({ chains, assetLists, wallets, signerOptions, endpointOptions, children, }) => {
|
|
12
11
|
// const [_, forceRender] = useState({});
|
|
13
12
|
const walletManager = new core_1.WalletManager(chains, assetLists, wallets, signerOptions, endpointOptions);
|
|
14
|
-
const store = (0, react_1.useRef)((0, store_1.createInterchainStore)(walletManager));
|
|
15
13
|
(0, react_1.useEffect)(() => {
|
|
16
14
|
walletManager.init();
|
|
17
15
|
}, []);
|
|
18
|
-
return ((0, jsx_runtime_1.jsx)(InterchainWalletContext.Provider, { value:
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(InterchainWalletContext.Provider, { value: walletManager, children: (0, jsx_runtime_1.jsx)(modal_1.WalletModalProvider, { children: children }) }));
|
|
19
17
|
};
|
|
20
18
|
exports.ChainProvider = ChainProvider;
|
|
21
19
|
const useInterchainWalletContext = () => {
|
package/store/index.js
CHANGED
|
@@ -35,6 +35,7 @@ const createInterchainStore = (walletManager) => {
|
|
|
35
35
|
});
|
|
36
36
|
});
|
|
37
37
|
return (0, zustand_1.createStore)((0, middleware_1.persist)((0, immer_1.immer)((set, get) => ({
|
|
38
|
+
store: walletManager.store,
|
|
38
39
|
chainWalletState,
|
|
39
40
|
currentWalletName: '',
|
|
40
41
|
currentChainName: '',
|
|
@@ -52,7 +53,28 @@ const createInterchainStore = (walletManager) => {
|
|
|
52
53
|
draft.chainWalletState[targetIndex] = { ...draft.chainWalletState[targetIndex], ...data };
|
|
53
54
|
});
|
|
54
55
|
},
|
|
55
|
-
init: () =>
|
|
56
|
+
init: async () => {
|
|
57
|
+
const NotExistWallets = [];
|
|
58
|
+
await Promise.all(get().wallets.map(async (wallet) => {
|
|
59
|
+
try {
|
|
60
|
+
await wallet.init();
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error === core_1.clientNotExistError.message) {
|
|
64
|
+
NotExistWallets.push(wallet.info.name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
set(draft => {
|
|
69
|
+
draft.chainWalletState = draft.chainWalletState.map(cws => {
|
|
70
|
+
if (NotExistWallets.includes(cws.walletName)) {
|
|
71
|
+
return { ...cws, walletState: core_1.WalletState.NotExist };
|
|
72
|
+
}
|
|
73
|
+
return cws;
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// return walletManager.init()
|
|
77
|
+
},
|
|
56
78
|
setCurrentChainName: (chainName) => {
|
|
57
79
|
set(draft => { draft.currentChainName = chainName; });
|
|
58
80
|
},
|