@interchain-kit/react 0.3.28 → 0.3.30
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/modal/modal.js +14 -11
- package/esm/store/stateful-wallet.js +5 -1
- package/esm/store/store.js +13 -0
- package/modal/modal.js +14 -11
- package/package.json +3 -3
- package/store/stateful-wallet.d.ts +2 -1
- package/store/stateful-wallet.js +5 -1
- package/store/store.js +13 -0
- package/utils/wallet.d.ts +0 -1
package/esm/modal/modal.js
CHANGED
|
@@ -8,16 +8,18 @@ import { transferToWalletUISchema } from "../utils";
|
|
|
8
8
|
export const InterchainWalletModal = () => {
|
|
9
9
|
const [shouldShowList, setShouldShowList] = useState(false);
|
|
10
10
|
const { modalIsOpen: isOpen, walletConnectQRCodeUri, wallets: statefulWallets, getChainWalletState, currentWalletName, currentChainName, openModal: open, closeModal: close, chains, setCurrentWalletName, getDownloadLink, getEnv, } = useWalletManager();
|
|
11
|
+
const [selectedWallet, setSelectedWallet] = useState(null);
|
|
11
12
|
const walletsForUI = statefulWallets.map((w) => transferToWalletUISchema(w));
|
|
12
13
|
const chainNameToConnect = currentChainName || chains[0].chainName;
|
|
13
14
|
const chainToConnect = chains.find((chain) => chain.chainName === chainNameToConnect);
|
|
14
15
|
const currentWallet = statefulWallets.find((w) => w.info.name === currentWalletName);
|
|
15
|
-
const
|
|
16
|
-
|
|
16
|
+
const walletToShow = selectedWallet || currentWallet;
|
|
17
|
+
const { account, errorMessage } = getChainWalletState(selectedWallet?.info?.name || currentWalletName, currentChainName) || {};
|
|
17
18
|
const disconnect = () => {
|
|
18
|
-
|
|
19
|
+
walletToShow.disconnect(chainToConnect.chainId);
|
|
19
20
|
};
|
|
20
21
|
const onSelectWallet = (wallet) => {
|
|
22
|
+
setSelectedWallet(wallet);
|
|
21
23
|
setShouldShowList(false);
|
|
22
24
|
return wallet.connect(chainToConnect.chainId);
|
|
23
25
|
};
|
|
@@ -29,7 +31,7 @@ export const InterchainWalletModal = () => {
|
|
|
29
31
|
const onReconnect = () => {
|
|
30
32
|
currentWallet.connect(chainToConnect.chainId);
|
|
31
33
|
};
|
|
32
|
-
return (_jsx(WalletModal, { shouldShowList: shouldShowList, username: account?.username, address: account?.address, disconnect: disconnect, isOpen: isOpen, open: open, close: handleCloseModal, wallets: walletsForUI, walletConnectQRCodeUri: walletConnectQRCodeUri, currentWallet:
|
|
34
|
+
return (_jsx(WalletModal, { shouldShowList: shouldShowList, username: account?.username, address: account?.address, disconnect: disconnect, isOpen: isOpen, open: open, close: handleCloseModal, wallets: walletsForUI, walletConnectQRCodeUri: walletConnectQRCodeUri, currentWallet: walletToShow, isConnecting: walletToShow?.walletState === WalletState.Connecting, isConnected: walletToShow?.walletState === WalletState.Connected, isRejected: walletToShow?.walletState === WalletState.Rejected, isDisconnected: walletToShow?.walletState === WalletState.Disconnected, isNotExist: walletToShow?.walletState === WalletState.NotExist, errorMessage: errorMessage, onSelectWallet: (w) => onSelectWallet(w), onBack: () => setShouldShowList(true), onReconnect: () => onSelectWallet(walletToShow), getDownloadLink: () => getDownloadLink(walletToShow?.info.name), getEnv: getEnv }));
|
|
33
35
|
};
|
|
34
36
|
export const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wallets, username, address, currentWallet, isConnecting, isConnected, isRejected, isDisconnected, isNotExist, errorMessage, open, close, disconnect, onSelectWallet, onBack, onReconnect, getDownloadLink, getEnv, }) => {
|
|
35
37
|
const { header, content } = useMemo(() => {
|
|
@@ -40,12 +42,6 @@ export const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wa
|
|
|
40
42
|
content: (_jsx(WalletListContent, { onSelectWallet: onSelectWallet, wallets: wallets })),
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
|
-
if (currentWallet && currentWallet.errorMessage) {
|
|
44
|
-
return {
|
|
45
|
-
header: (_jsx(ErrorHeader, { wallet: currentWallet, close: close, onBack: onBack })),
|
|
46
|
-
content: _jsx(ErrorContent, { wallet: currentWallet, onBack: onBack }),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
45
|
if (currentWallet &&
|
|
50
46
|
walletConnectQRCodeUri &&
|
|
51
47
|
currentWallet.info.name === "WalletConnect") {
|
|
@@ -66,6 +62,12 @@ export const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wa
|
|
|
66
62
|
content: (_jsx(RejectContent, { wallet: currentWallet, onReconnect: onReconnect })),
|
|
67
63
|
};
|
|
68
64
|
}
|
|
65
|
+
if (currentWallet && currentWallet.errorMessage) {
|
|
66
|
+
return {
|
|
67
|
+
header: (_jsx(ErrorHeader, { wallet: currentWallet, close: close, onBack: onBack })),
|
|
68
|
+
content: _jsx(ErrorContent, { wallet: currentWallet, onBack: onBack }),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
69
71
|
if (currentWallet && isConnected) {
|
|
70
72
|
return {
|
|
71
73
|
header: (_jsx(ConnectedHeader, { wallet: currentWallet, onBack: onBack, close: close })),
|
|
@@ -83,13 +85,14 @@ export const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wa
|
|
|
83
85
|
content: (_jsx(WalletListContent, { onSelectWallet: onSelectWallet, wallets: wallets })),
|
|
84
86
|
};
|
|
85
87
|
}, [
|
|
86
|
-
currentWallet,
|
|
88
|
+
currentWallet?.info?.name,
|
|
87
89
|
isConnected,
|
|
88
90
|
isConnecting,
|
|
89
91
|
address,
|
|
90
92
|
shouldShowList,
|
|
91
93
|
walletConnectQRCodeUri,
|
|
92
94
|
wallets,
|
|
95
|
+
isOpen,
|
|
93
96
|
]);
|
|
94
97
|
return (_jsx(ConnectModal, { isOpen: isOpen, header: header, onOpen: open, onClose: close, children: content }));
|
|
95
98
|
};
|
|
@@ -2,6 +2,7 @@ import { BaseWallet, WalletState, WCWallet } from "@interchain-kit/core";
|
|
|
2
2
|
export class StatefulWallet extends BaseWallet {
|
|
3
3
|
originalWallet;
|
|
4
4
|
walletName;
|
|
5
|
+
walletState;
|
|
5
6
|
walletSet;
|
|
6
7
|
walletGet;
|
|
7
8
|
set;
|
|
@@ -43,6 +44,7 @@ export class StatefulWallet extends BaseWallet {
|
|
|
43
44
|
});
|
|
44
45
|
walletSet(draft => {
|
|
45
46
|
draft.walletState = WalletState.Connecting;
|
|
47
|
+
draft.errorMessage = '';
|
|
46
48
|
});
|
|
47
49
|
get().updateChainWalletState(walletName, chainToConnect.chainName, { walletState: WalletState.Connecting, errorMessage: '' });
|
|
48
50
|
try {
|
|
@@ -80,7 +82,9 @@ export class StatefulWallet extends BaseWallet {
|
|
|
80
82
|
const { get, walletName, walletSet, originalWallet } = this;
|
|
81
83
|
const chainToConnect = this.getChainToConnect(chainId);
|
|
82
84
|
try {
|
|
83
|
-
|
|
85
|
+
if (this.walletGet().walletState === WalletState.Connected) {
|
|
86
|
+
await originalWallet.disconnect(chainToConnect.chainId);
|
|
87
|
+
}
|
|
84
88
|
get().updateChainWalletState(walletName, chainToConnect.chainName, { walletState: WalletState.Disconnected, account: null });
|
|
85
89
|
walletSet(draft => {
|
|
86
90
|
draft.walletState = WalletState.Disconnected;
|
package/esm/store/store.js
CHANGED
|
@@ -129,6 +129,15 @@ export const createInterchainStore = (walletManager) => {
|
|
|
129
129
|
}
|
|
130
130
|
return cws;
|
|
131
131
|
});
|
|
132
|
+
draft.chainWalletState.forEach(cws => {
|
|
133
|
+
const lastExistWallet = draft.wallets.find(w => w.info.name === cws.walletName);
|
|
134
|
+
if (cws.walletState === WalletState.Connected && lastExistWallet.walletState !== WalletState.Connected) {
|
|
135
|
+
lastExistWallet.walletState = WalletState.Connected;
|
|
136
|
+
}
|
|
137
|
+
if (cws.walletState === WalletState.NotExist) {
|
|
138
|
+
lastExistWallet.walletState = WalletState.NotExist;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
132
141
|
draft.isReady = true;
|
|
133
142
|
});
|
|
134
143
|
},
|
|
@@ -224,6 +233,10 @@ export const createInterchainStore = (walletManager) => {
|
|
|
224
233
|
if (!chain) {
|
|
225
234
|
throw new Error(`Chain ${chainName} not found`);
|
|
226
235
|
}
|
|
236
|
+
const existedAccount = get().chainWalletState.find(cws => cws.walletName === walletName && cws.chainName === chainName)?.account;
|
|
237
|
+
if (existedAccount) {
|
|
238
|
+
return existedAccount;
|
|
239
|
+
}
|
|
227
240
|
return wallet.getAccount(chain.chainId);
|
|
228
241
|
},
|
|
229
242
|
getRpcEndpoint: async (walletName, chainName) => {
|
package/modal/modal.js
CHANGED
|
@@ -11,16 +11,18 @@ const utils_1 = require("../utils");
|
|
|
11
11
|
const InterchainWalletModal = () => {
|
|
12
12
|
const [shouldShowList, setShouldShowList] = (0, react_1.useState)(false);
|
|
13
13
|
const { modalIsOpen: isOpen, walletConnectQRCodeUri, wallets: statefulWallets, getChainWalletState, currentWalletName, currentChainName, openModal: open, closeModal: close, chains, setCurrentWalletName, getDownloadLink, getEnv, } = (0, hooks_1.useWalletManager)();
|
|
14
|
+
const [selectedWallet, setSelectedWallet] = (0, react_1.useState)(null);
|
|
14
15
|
const walletsForUI = statefulWallets.map((w) => (0, utils_1.transferToWalletUISchema)(w));
|
|
15
16
|
const chainNameToConnect = currentChainName || chains[0].chainName;
|
|
16
17
|
const chainToConnect = chains.find((chain) => chain.chainName === chainNameToConnect);
|
|
17
18
|
const currentWallet = statefulWallets.find((w) => w.info.name === currentWalletName);
|
|
18
|
-
const
|
|
19
|
-
|
|
19
|
+
const walletToShow = selectedWallet || currentWallet;
|
|
20
|
+
const { account, errorMessage } = getChainWalletState(selectedWallet?.info?.name || currentWalletName, currentChainName) || {};
|
|
20
21
|
const disconnect = () => {
|
|
21
|
-
|
|
22
|
+
walletToShow.disconnect(chainToConnect.chainId);
|
|
22
23
|
};
|
|
23
24
|
const onSelectWallet = (wallet) => {
|
|
25
|
+
setSelectedWallet(wallet);
|
|
24
26
|
setShouldShowList(false);
|
|
25
27
|
return wallet.connect(chainToConnect.chainId);
|
|
26
28
|
};
|
|
@@ -32,7 +34,7 @@ const InterchainWalletModal = () => {
|
|
|
32
34
|
const onReconnect = () => {
|
|
33
35
|
currentWallet.connect(chainToConnect.chainId);
|
|
34
36
|
};
|
|
35
|
-
return ((0, jsx_runtime_1.jsx)(exports.WalletModal, { shouldShowList: shouldShowList, username: account?.username, address: account?.address, disconnect: disconnect, isOpen: isOpen, open: open, close: handleCloseModal, wallets: walletsForUI, walletConnectQRCodeUri: walletConnectQRCodeUri, currentWallet:
|
|
37
|
+
return ((0, jsx_runtime_1.jsx)(exports.WalletModal, { shouldShowList: shouldShowList, username: account?.username, address: account?.address, disconnect: disconnect, isOpen: isOpen, open: open, close: handleCloseModal, wallets: walletsForUI, walletConnectQRCodeUri: walletConnectQRCodeUri, currentWallet: walletToShow, isConnecting: walletToShow?.walletState === core_1.WalletState.Connecting, isConnected: walletToShow?.walletState === core_1.WalletState.Connected, isRejected: walletToShow?.walletState === core_1.WalletState.Rejected, isDisconnected: walletToShow?.walletState === core_1.WalletState.Disconnected, isNotExist: walletToShow?.walletState === core_1.WalletState.NotExist, errorMessage: errorMessage, onSelectWallet: (w) => onSelectWallet(w), onBack: () => setShouldShowList(true), onReconnect: () => onSelectWallet(walletToShow), getDownloadLink: () => getDownloadLink(walletToShow?.info.name), getEnv: getEnv }));
|
|
36
38
|
};
|
|
37
39
|
exports.InterchainWalletModal = InterchainWalletModal;
|
|
38
40
|
const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wallets, username, address, currentWallet, isConnecting, isConnected, isRejected, isDisconnected, isNotExist, errorMessage, open, close, disconnect, onSelectWallet, onBack, onReconnect, getDownloadLink, getEnv, }) => {
|
|
@@ -44,12 +46,6 @@ const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wallets,
|
|
|
44
46
|
content: ((0, jsx_runtime_1.jsx)(views_1.WalletListContent, { onSelectWallet: onSelectWallet, wallets: wallets })),
|
|
45
47
|
};
|
|
46
48
|
}
|
|
47
|
-
if (currentWallet && currentWallet.errorMessage) {
|
|
48
|
-
return {
|
|
49
|
-
header: ((0, jsx_runtime_1.jsx)(views_1.ErrorHeader, { wallet: currentWallet, close: close, onBack: onBack })),
|
|
50
|
-
content: (0, jsx_runtime_1.jsx)(views_1.ErrorContent, { wallet: currentWallet, onBack: onBack }),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
49
|
if (currentWallet &&
|
|
54
50
|
walletConnectQRCodeUri &&
|
|
55
51
|
currentWallet.info.name === "WalletConnect") {
|
|
@@ -70,6 +66,12 @@ const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wallets,
|
|
|
70
66
|
content: ((0, jsx_runtime_1.jsx)(views_1.RejectContent, { wallet: currentWallet, onReconnect: onReconnect })),
|
|
71
67
|
};
|
|
72
68
|
}
|
|
69
|
+
if (currentWallet && currentWallet.errorMessage) {
|
|
70
|
+
return {
|
|
71
|
+
header: ((0, jsx_runtime_1.jsx)(views_1.ErrorHeader, { wallet: currentWallet, close: close, onBack: onBack })),
|
|
72
|
+
content: (0, jsx_runtime_1.jsx)(views_1.ErrorContent, { wallet: currentWallet, onBack: onBack }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
73
75
|
if (currentWallet && isConnected) {
|
|
74
76
|
return {
|
|
75
77
|
header: ((0, jsx_runtime_1.jsx)(views_1.ConnectedHeader, { wallet: currentWallet, onBack: onBack, close: close })),
|
|
@@ -87,13 +89,14 @@ const WalletModal = ({ shouldShowList, isOpen, walletConnectQRCodeUri, wallets,
|
|
|
87
89
|
content: ((0, jsx_runtime_1.jsx)(views_1.WalletListContent, { onSelectWallet: onSelectWallet, wallets: wallets })),
|
|
88
90
|
};
|
|
89
91
|
}, [
|
|
90
|
-
currentWallet,
|
|
92
|
+
currentWallet?.info?.name,
|
|
91
93
|
isConnected,
|
|
92
94
|
isConnecting,
|
|
93
95
|
address,
|
|
94
96
|
shouldShowList,
|
|
95
97
|
walletConnectQRCodeUri,
|
|
96
98
|
wallets,
|
|
99
|
+
isOpen,
|
|
97
100
|
]);
|
|
98
101
|
return ((0, jsx_runtime_1.jsx)(react_2.ConnectModal, { isOpen: isOpen, header: header, onOpen: open, onClose: close, children: content }));
|
|
99
102
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interchain-kit/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.30",
|
|
4
4
|
"author": "Hyperweb <developers@hyperweb.io>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"keywords": [],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@chain-registry/v2-types": "^0.53.40",
|
|
37
|
-
"@interchain-kit/core": "^0.3.
|
|
37
|
+
"@interchain-kit/core": "^0.3.30",
|
|
38
38
|
"@interchain-ui/react": "1.26.1",
|
|
39
39
|
"@interchainjs/cosmos": "1.11.9",
|
|
40
40
|
"@interchainjs/cosmos-types": "1.11.9",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"react": "^19.0.0",
|
|
65
65
|
"react-dom": "^19.0.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "82fcd0ffecf471e1ecb4c288b6752d04aa4f1777"
|
|
68
68
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BaseWallet, WalletAccount } from "@interchain-kit/core";
|
|
1
|
+
import { BaseWallet, WalletAccount, WalletState } from "@interchain-kit/core";
|
|
2
2
|
import { InterchainStore } from "./store";
|
|
3
3
|
import { Chain } from "@chain-registry/v2-types";
|
|
4
4
|
export declare class StatefulWallet extends BaseWallet {
|
|
5
5
|
originalWallet: BaseWallet;
|
|
6
6
|
walletName: string;
|
|
7
|
+
walletState: WalletState;
|
|
7
8
|
walletSet: (arg: (draft: StatefulWallet) => void) => void;
|
|
8
9
|
walletGet: () => StatefulWallet;
|
|
9
10
|
set: (arg: (draft: InterchainStore) => void) => void;
|
package/store/stateful-wallet.js
CHANGED
|
@@ -5,6 +5,7 @@ const core_1 = require("@interchain-kit/core");
|
|
|
5
5
|
class StatefulWallet extends core_1.BaseWallet {
|
|
6
6
|
originalWallet;
|
|
7
7
|
walletName;
|
|
8
|
+
walletState;
|
|
8
9
|
walletSet;
|
|
9
10
|
walletGet;
|
|
10
11
|
set;
|
|
@@ -46,6 +47,7 @@ class StatefulWallet extends core_1.BaseWallet {
|
|
|
46
47
|
});
|
|
47
48
|
walletSet(draft => {
|
|
48
49
|
draft.walletState = core_1.WalletState.Connecting;
|
|
50
|
+
draft.errorMessage = '';
|
|
49
51
|
});
|
|
50
52
|
get().updateChainWalletState(walletName, chainToConnect.chainName, { walletState: core_1.WalletState.Connecting, errorMessage: '' });
|
|
51
53
|
try {
|
|
@@ -83,7 +85,9 @@ class StatefulWallet extends core_1.BaseWallet {
|
|
|
83
85
|
const { get, walletName, walletSet, originalWallet } = this;
|
|
84
86
|
const chainToConnect = this.getChainToConnect(chainId);
|
|
85
87
|
try {
|
|
86
|
-
|
|
88
|
+
if (this.walletGet().walletState === core_1.WalletState.Connected) {
|
|
89
|
+
await originalWallet.disconnect(chainToConnect.chainId);
|
|
90
|
+
}
|
|
87
91
|
get().updateChainWalletState(walletName, chainToConnect.chainName, { walletState: core_1.WalletState.Disconnected, account: null });
|
|
88
92
|
walletSet(draft => {
|
|
89
93
|
draft.walletState = core_1.WalletState.Disconnected;
|
package/store/store.js
CHANGED
|
@@ -132,6 +132,15 @@ const createInterchainStore = (walletManager) => {
|
|
|
132
132
|
}
|
|
133
133
|
return cws;
|
|
134
134
|
});
|
|
135
|
+
draft.chainWalletState.forEach(cws => {
|
|
136
|
+
const lastExistWallet = draft.wallets.find(w => w.info.name === cws.walletName);
|
|
137
|
+
if (cws.walletState === core_1.WalletState.Connected && lastExistWallet.walletState !== core_1.WalletState.Connected) {
|
|
138
|
+
lastExistWallet.walletState = core_1.WalletState.Connected;
|
|
139
|
+
}
|
|
140
|
+
if (cws.walletState === core_1.WalletState.NotExist) {
|
|
141
|
+
lastExistWallet.walletState = core_1.WalletState.NotExist;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
135
144
|
draft.isReady = true;
|
|
136
145
|
});
|
|
137
146
|
},
|
|
@@ -227,6 +236,10 @@ const createInterchainStore = (walletManager) => {
|
|
|
227
236
|
if (!chain) {
|
|
228
237
|
throw new Error(`Chain ${chainName} not found`);
|
|
229
238
|
}
|
|
239
|
+
const existedAccount = get().chainWalletState.find(cws => cws.walletName === walletName && cws.chainName === chainName)?.account;
|
|
240
|
+
if (existedAccount) {
|
|
241
|
+
return existedAccount;
|
|
242
|
+
}
|
|
230
243
|
return wallet.getAccount(chain.chainId);
|
|
231
244
|
},
|
|
232
245
|
getRpcEndpoint: async (walletName, chainName) => {
|
package/utils/wallet.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export declare const transferToWalletUISchema: (w: BaseWallet) => {
|
|
|
15
15
|
session: import("@walletconnect/types").SessionTypes.Struct;
|
|
16
16
|
info: import("@interchain-kit/core").Wallet;
|
|
17
17
|
errorMessage: string;
|
|
18
|
-
walletState: import("@interchain-kit/core").WalletState;
|
|
19
18
|
events: import("events")<import("@interchain-kit/core").WalletEvents>;
|
|
20
19
|
chainMap: Map<import("@chain-registry/v2-types").Chain["chainId"], import("@chain-registry/v2-types").Chain>;
|
|
21
20
|
assetLists: import("@chain-registry/v2-types").AssetList[];
|