@interchain-kit/react 0.3.28 → 0.3.31
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/useSigningClient.js +2 -2
- package/esm/modal/modal.js +14 -11
- package/esm/store/stateful-wallet.js +5 -1
- package/esm/store/store.js +50 -5
- package/hooks/useSigningClient.js +2 -2
- package/modal/modal.js +14 -11
- package/package.json +7 -7
- package/store/stateful-wallet.d.ts +2 -1
- package/store/stateful-wallet.js +5 -1
- package/store/store.js +50 -5
- package/utils/wallet.d.ts +0 -1
|
@@ -2,7 +2,7 @@ import { useWalletManager } from "./useWalletManager";
|
|
|
2
2
|
import { useAsync } from "./useAsync";
|
|
3
3
|
import { WalletState } from "@interchain-kit/core";
|
|
4
4
|
export const useSigningClient = (chainName, walletName) => {
|
|
5
|
-
const { getSigningClient, getChainWalletState, getRpcEndpoint } = useWalletManager();
|
|
5
|
+
const { getSigningClient, getChainWalletState, getRpcEndpoint, isReady } = useWalletManager();
|
|
6
6
|
const chainWalletState = getChainWalletState(walletName, chainName);
|
|
7
7
|
const { data, isLoading, error } = useAsync({
|
|
8
8
|
queryKey: `signing-client-${chainName}-${walletName}`,
|
|
@@ -13,7 +13,7 @@ export const useSigningClient = (chainName, walletName) => {
|
|
|
13
13
|
return getSigningClient(walletName, chainName);
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
enabled: chainWalletState?.walletState === WalletState.Connected,
|
|
16
|
+
enabled: chainWalletState?.walletState === WalletState.Connected && isReady,
|
|
17
17
|
disableCache: true,
|
|
18
18
|
});
|
|
19
19
|
return {
|
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
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { SigningClient } from '@interchainjs/cosmos/signing-client';
|
|
1
2
|
import { clientNotExistError, WalletState } from "@interchain-kit/core";
|
|
2
3
|
import { createStore } from "zustand";
|
|
3
4
|
import { immer } from "zustand/middleware/immer";
|
|
4
5
|
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
5
6
|
import { dedupeAsync } from '../utils';
|
|
6
7
|
import { StatefulWallet } from './stateful-wallet';
|
|
8
|
+
import { AminoGenericOfflineSigner, DirectGenericOfflineSigner } from '@interchainjs/cosmos/types/wallet';
|
|
7
9
|
const immerSyncUp = (newWalletManager) => {
|
|
8
10
|
return (draft) => {
|
|
9
11
|
draft.chains = newWalletManager.chains;
|
|
@@ -129,6 +131,15 @@ export const createInterchainStore = (walletManager) => {
|
|
|
129
131
|
}
|
|
130
132
|
return cws;
|
|
131
133
|
});
|
|
134
|
+
draft.chainWalletState.forEach(cws => {
|
|
135
|
+
const lastExistWallet = draft.wallets.find(w => w.info.name === cws.walletName);
|
|
136
|
+
if (cws.walletState === WalletState.Connected && lastExistWallet.walletState !== WalletState.Connected) {
|
|
137
|
+
lastExistWallet.walletState = WalletState.Connected;
|
|
138
|
+
}
|
|
139
|
+
if (cws.walletState === WalletState.NotExist) {
|
|
140
|
+
lastExistWallet.walletState = WalletState.NotExist;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
132
143
|
draft.isReady = true;
|
|
133
144
|
});
|
|
134
145
|
},
|
|
@@ -224,6 +235,14 @@ export const createInterchainStore = (walletManager) => {
|
|
|
224
235
|
if (!chain) {
|
|
225
236
|
throw new Error(`Chain ${chainName} not found`);
|
|
226
237
|
}
|
|
238
|
+
const existedAccount = get().chainWalletState.find(cws => cws.walletName === walletName && cws.chainName === chainName)?.account;
|
|
239
|
+
if (existedAccount) {
|
|
240
|
+
if (typeof existedAccount.pubkey === 'object') {
|
|
241
|
+
// return from localstorage need to restructure to uinit8Array
|
|
242
|
+
return { ...existedAccount, pubkey: Uint8Array.from({ ...existedAccount.pubkey, length: Object.keys(existedAccount.pubkey).length }) };
|
|
243
|
+
}
|
|
244
|
+
return existedAccount;
|
|
245
|
+
}
|
|
227
246
|
return wallet.getAccount(chain.chainId);
|
|
228
247
|
},
|
|
229
248
|
getRpcEndpoint: async (walletName, chainName) => {
|
|
@@ -247,17 +266,39 @@ export const createInterchainStore = (walletManager) => {
|
|
|
247
266
|
getDownloadLink(walletName) {
|
|
248
267
|
return walletManager.getDownloadLink(walletName);
|
|
249
268
|
},
|
|
250
|
-
getOfflineSigner(walletName, chainName) {
|
|
251
|
-
|
|
269
|
+
async getOfflineSigner(walletName, chainName) {
|
|
270
|
+
const chain = get().chains.find(c => c.chainName === chainName);
|
|
271
|
+
const wallet = get().getStatefulWalletByName(walletName);
|
|
272
|
+
const walletToUse = wallet.originalWallet;
|
|
273
|
+
console.log(await get().getAccount(walletName, chainName));
|
|
274
|
+
const preferSignType = get().getPreferSignType(chainName);
|
|
275
|
+
let offlineSigner;
|
|
276
|
+
if (preferSignType === 'amino') {
|
|
277
|
+
offlineSigner = new AminoGenericOfflineSigner({
|
|
278
|
+
getAccounts: async () => [await get().getAccount(walletName, chainName)],
|
|
279
|
+
signAmino(signerAddress, signDoc) {
|
|
280
|
+
return walletToUse.signAmino(chain.chainId, signerAddress, signDoc, walletToUse.defaultSignOptions);
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
else if (preferSignType === 'direct') {
|
|
285
|
+
offlineSigner = new DirectGenericOfflineSigner({
|
|
286
|
+
getAccounts: async () => [await get().getAccount(walletName, chainName)],
|
|
287
|
+
signDirect(signerAddress, signDoc) {
|
|
288
|
+
return walletToUse.signDirect(chain.chainId, signerAddress, signDoc, walletToUse.defaultSignOptions);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return offlineSigner;
|
|
252
293
|
},
|
|
253
294
|
getPreferSignType(chainName) {
|
|
254
295
|
const result = walletManager.getPreferSignType(chainName);
|
|
255
|
-
set(immerSyncUp(walletManager))
|
|
296
|
+
// set(immerSyncUp(walletManager))
|
|
256
297
|
return result;
|
|
257
298
|
},
|
|
258
299
|
getSignerOptions(chainName) {
|
|
259
300
|
const result = walletManager.getSignerOptions(chainName);
|
|
260
|
-
set(immerSyncUp(walletManager))
|
|
301
|
+
// set(immerSyncUp(walletManager))
|
|
261
302
|
return result;
|
|
262
303
|
},
|
|
263
304
|
getWalletByName(walletName) {
|
|
@@ -267,7 +308,11 @@ export const createInterchainStore = (walletManager) => {
|
|
|
267
308
|
return get().wallets.find(w => w.info.name === walletName);
|
|
268
309
|
},
|
|
269
310
|
async getSigningClient(walletName, chainName) {
|
|
270
|
-
|
|
311
|
+
const chainWalletState = get().getChainWalletState(walletName, chainName);
|
|
312
|
+
const signerOptions = await get().getSignerOptions(chainName);
|
|
313
|
+
const offlineSigner = await get().getOfflineSigner(walletName, chainName);
|
|
314
|
+
const signingClient = await SigningClient.connectWithSigner(chainWalletState.rpcEndpoint, offlineSigner, signerOptions);
|
|
315
|
+
return signingClient;
|
|
271
316
|
},
|
|
272
317
|
getEnv() {
|
|
273
318
|
return walletManager.getEnv();
|
|
@@ -5,7 +5,7 @@ const useWalletManager_1 = require("./useWalletManager");
|
|
|
5
5
|
const useAsync_1 = require("./useAsync");
|
|
6
6
|
const core_1 = require("@interchain-kit/core");
|
|
7
7
|
const useSigningClient = (chainName, walletName) => {
|
|
8
|
-
const { getSigningClient, getChainWalletState, getRpcEndpoint } = (0, useWalletManager_1.useWalletManager)();
|
|
8
|
+
const { getSigningClient, getChainWalletState, getRpcEndpoint, isReady } = (0, useWalletManager_1.useWalletManager)();
|
|
9
9
|
const chainWalletState = getChainWalletState(walletName, chainName);
|
|
10
10
|
const { data, isLoading, error } = (0, useAsync_1.useAsync)({
|
|
11
11
|
queryKey: `signing-client-${chainName}-${walletName}`,
|
|
@@ -16,7 +16,7 @@ const useSigningClient = (chainName, walletName) => {
|
|
|
16
16
|
return getSigningClient(walletName, chainName);
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
-
enabled: chainWalletState?.walletState === core_1.WalletState.Connected,
|
|
19
|
+
enabled: chainWalletState?.walletState === core_1.WalletState.Connected && isReady,
|
|
20
20
|
disableCache: true,
|
|
21
21
|
});
|
|
22
22
|
return {
|
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.31",
|
|
4
4
|
"author": "Hyperweb <developers@hyperweb.io>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -34,14 +34,14 @@
|
|
|
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.31",
|
|
38
38
|
"@interchain-ui/react": "1.26.1",
|
|
39
|
-
"@interchainjs/cosmos": "1.11.
|
|
40
|
-
"@interchainjs/cosmos-types": "1.11.
|
|
41
|
-
"@interchainjs/types": "1.11.
|
|
39
|
+
"@interchainjs/cosmos": "1.11.11",
|
|
40
|
+
"@interchainjs/cosmos-types": "1.11.11",
|
|
41
|
+
"@interchainjs/types": "1.11.11",
|
|
42
42
|
"@react-icons/all-files": "^4.1.0",
|
|
43
43
|
"@walletconnect/types": "^2.17.3",
|
|
44
|
-
"interchainjs": "1.11.
|
|
44
|
+
"interchainjs": "1.11.11",
|
|
45
45
|
"zustand": "^5.0.3"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"react": "^19.0.0",
|
|
65
65
|
"react-dom": "^19.0.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "ec8719da721263a2b3f1474aa106ce0da2425bf6"
|
|
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
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createInterchainStore = void 0;
|
|
4
|
+
const signing_client_1 = require("@interchainjs/cosmos/signing-client");
|
|
4
5
|
const core_1 = require("@interchain-kit/core");
|
|
5
6
|
const zustand_1 = require("zustand");
|
|
6
7
|
const immer_1 = require("zustand/middleware/immer");
|
|
7
8
|
const middleware_1 = require("zustand/middleware");
|
|
8
9
|
const utils_1 = require("../utils");
|
|
9
10
|
const stateful_wallet_1 = require("./stateful-wallet");
|
|
11
|
+
const wallet_1 = require("@interchainjs/cosmos/types/wallet");
|
|
10
12
|
const immerSyncUp = (newWalletManager) => {
|
|
11
13
|
return (draft) => {
|
|
12
14
|
draft.chains = newWalletManager.chains;
|
|
@@ -132,6 +134,15 @@ const createInterchainStore = (walletManager) => {
|
|
|
132
134
|
}
|
|
133
135
|
return cws;
|
|
134
136
|
});
|
|
137
|
+
draft.chainWalletState.forEach(cws => {
|
|
138
|
+
const lastExistWallet = draft.wallets.find(w => w.info.name === cws.walletName);
|
|
139
|
+
if (cws.walletState === core_1.WalletState.Connected && lastExistWallet.walletState !== core_1.WalletState.Connected) {
|
|
140
|
+
lastExistWallet.walletState = core_1.WalletState.Connected;
|
|
141
|
+
}
|
|
142
|
+
if (cws.walletState === core_1.WalletState.NotExist) {
|
|
143
|
+
lastExistWallet.walletState = core_1.WalletState.NotExist;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
135
146
|
draft.isReady = true;
|
|
136
147
|
});
|
|
137
148
|
},
|
|
@@ -227,6 +238,14 @@ const createInterchainStore = (walletManager) => {
|
|
|
227
238
|
if (!chain) {
|
|
228
239
|
throw new Error(`Chain ${chainName} not found`);
|
|
229
240
|
}
|
|
241
|
+
const existedAccount = get().chainWalletState.find(cws => cws.walletName === walletName && cws.chainName === chainName)?.account;
|
|
242
|
+
if (existedAccount) {
|
|
243
|
+
if (typeof existedAccount.pubkey === 'object') {
|
|
244
|
+
// return from localstorage need to restructure to uinit8Array
|
|
245
|
+
return { ...existedAccount, pubkey: Uint8Array.from({ ...existedAccount.pubkey, length: Object.keys(existedAccount.pubkey).length }) };
|
|
246
|
+
}
|
|
247
|
+
return existedAccount;
|
|
248
|
+
}
|
|
230
249
|
return wallet.getAccount(chain.chainId);
|
|
231
250
|
},
|
|
232
251
|
getRpcEndpoint: async (walletName, chainName) => {
|
|
@@ -250,17 +269,39 @@ const createInterchainStore = (walletManager) => {
|
|
|
250
269
|
getDownloadLink(walletName) {
|
|
251
270
|
return walletManager.getDownloadLink(walletName);
|
|
252
271
|
},
|
|
253
|
-
getOfflineSigner(walletName, chainName) {
|
|
254
|
-
|
|
272
|
+
async getOfflineSigner(walletName, chainName) {
|
|
273
|
+
const chain = get().chains.find(c => c.chainName === chainName);
|
|
274
|
+
const wallet = get().getStatefulWalletByName(walletName);
|
|
275
|
+
const walletToUse = wallet.originalWallet;
|
|
276
|
+
console.log(await get().getAccount(walletName, chainName));
|
|
277
|
+
const preferSignType = get().getPreferSignType(chainName);
|
|
278
|
+
let offlineSigner;
|
|
279
|
+
if (preferSignType === 'amino') {
|
|
280
|
+
offlineSigner = new wallet_1.AminoGenericOfflineSigner({
|
|
281
|
+
getAccounts: async () => [await get().getAccount(walletName, chainName)],
|
|
282
|
+
signAmino(signerAddress, signDoc) {
|
|
283
|
+
return walletToUse.signAmino(chain.chainId, signerAddress, signDoc, walletToUse.defaultSignOptions);
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
else if (preferSignType === 'direct') {
|
|
288
|
+
offlineSigner = new wallet_1.DirectGenericOfflineSigner({
|
|
289
|
+
getAccounts: async () => [await get().getAccount(walletName, chainName)],
|
|
290
|
+
signDirect(signerAddress, signDoc) {
|
|
291
|
+
return walletToUse.signDirect(chain.chainId, signerAddress, signDoc, walletToUse.defaultSignOptions);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return offlineSigner;
|
|
255
296
|
},
|
|
256
297
|
getPreferSignType(chainName) {
|
|
257
298
|
const result = walletManager.getPreferSignType(chainName);
|
|
258
|
-
set(immerSyncUp(walletManager))
|
|
299
|
+
// set(immerSyncUp(walletManager))
|
|
259
300
|
return result;
|
|
260
301
|
},
|
|
261
302
|
getSignerOptions(chainName) {
|
|
262
303
|
const result = walletManager.getSignerOptions(chainName);
|
|
263
|
-
set(immerSyncUp(walletManager))
|
|
304
|
+
// set(immerSyncUp(walletManager))
|
|
264
305
|
return result;
|
|
265
306
|
},
|
|
266
307
|
getWalletByName(walletName) {
|
|
@@ -270,7 +311,11 @@ const createInterchainStore = (walletManager) => {
|
|
|
270
311
|
return get().wallets.find(w => w.info.name === walletName);
|
|
271
312
|
},
|
|
272
313
|
async getSigningClient(walletName, chainName) {
|
|
273
|
-
|
|
314
|
+
const chainWalletState = get().getChainWalletState(walletName, chainName);
|
|
315
|
+
const signerOptions = await get().getSignerOptions(chainName);
|
|
316
|
+
const offlineSigner = await get().getOfflineSigner(walletName, chainName);
|
|
317
|
+
const signingClient = await signing_client_1.SigningClient.connectWithSigner(chainWalletState.rpcEndpoint, offlineSigner, signerOptions);
|
|
318
|
+
return signingClient;
|
|
274
319
|
},
|
|
275
320
|
getEnv() {
|
|
276
321
|
return walletManager.getEnv();
|
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[];
|