@interchain-kit/react 0.2.218 → 0.2.220

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.
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createContext, useContext, useState } from "react";
2
+ import { createContext, useContext, useEffect, useRef, useState } from "react";
3
3
  import { WalletModal } from "./modal";
4
4
  import { WalletState } from "@interchain-kit/core";
5
5
  import { useChainWallet, useWalletManager } from "../hooks";
@@ -17,8 +17,12 @@ export const WalletModalProvider = ({ children, }) => {
17
17
  close();
18
18
  setShouldShowList(false);
19
19
  };
20
+ const currentChainNameRef = useRef("");
21
+ useEffect(() => {
22
+ currentChainNameRef.current = currentChainName;
23
+ }, [currentChainName]);
20
24
  const handleConnectWallet = async (walletName) => {
21
- const chainToConnect = currentChainName || chains[0].chainName;
25
+ const chainToConnect = currentChainNameRef.current || chains[0].chainName;
22
26
  setShouldShowList(false);
23
27
  setCurrentWalletName(walletName);
24
28
  await connect(walletName, chainToConnect);
@@ -95,38 +95,48 @@ export const createInterchainStore = (walletManager) => {
95
95
  getChainWalletState: (walletName, chainName) => {
96
96
  return get().chainWalletState.find(cws => cws.walletName === walletName && cws.chainName === chainName);
97
97
  },
98
- addChains: (chains, assetLists, signerOptions, endpointOptions) => {
99
- walletManager.addChains(chains, assetLists, signerOptions, endpointOptions);
98
+ addChains: async (newChains, newAssetLists, newSignerOptions, newEndpointOptions) => {
99
+ await walletManager.addChains(newChains, newAssetLists, newSignerOptions, newEndpointOptions);
100
100
  // console.log(walletManager.chains, walletManager.assetLists)
101
101
  // set(immerSyncUp(walletManager))
102
102
  // set(draft => {
103
103
  // draft.chains = walletManager.chains
104
104
  // })
105
105
  set(draft => {
106
- chains.forEach(newChain => {
107
- const existChain = draft.chains.find(c => c.chainId === newChain.chainId);
108
- if (!existChain) {
106
+ const existedChainMap = new Map(get().chains.map(chain => [chain.chainName, chain]));
107
+ const newAssetListMap = new Map(newAssetLists.map(assetList => [assetList.chainName, assetList]));
108
+ newChains.forEach(newChain => {
109
+ if (!existedChainMap.has(newChain.chainName)) {
109
110
  draft.chains.push(newChain);
110
- const assetList = assetLists.find(a => a.chainName === newChain.chainName);
111
- draft.assetLists.push(assetList);
112
- draft.wallets.forEach(w => {
111
+ draft.assetLists.push(newAssetListMap.get(newChain.chainName));
112
+ }
113
+ draft.signerOptionMap[newChain.chainName] = newSignerOptions?.signing(newChain.chainName);
114
+ draft.endpointOptionsMap[newChain.chainName] = newEndpointOptions?.endpoints?.[newChain.chainName];
115
+ });
116
+ get().chains.forEach(chain => {
117
+ draft.signerOptionMap[chain.chainName] = {
118
+ ...get().signerOptionMap[chain.chainName],
119
+ ...newSignerOptions?.signing(chain.chainName)
120
+ };
121
+ draft.endpointOptionsMap[chain.chainName] = {
122
+ ...get().endpointOptionsMap[chain.chainName],
123
+ ...newEndpointOptions?.endpoints?.[chain.chainName]
124
+ };
125
+ });
126
+ const existedChainWalletStatesMap = new Map(get().chainWalletState.map(cws => [cws.walletName + cws.chainName, cws]));
127
+ get().wallets.forEach(wallet => {
128
+ newChains.forEach(newChain => {
129
+ if (!existedChainWalletStatesMap.has(wallet.info.name + newChain.chainName)) {
113
130
  draft.chainWalletState.push({
114
131
  chainName: newChain.chainName,
115
- walletName: w.info.name,
132
+ walletName: wallet.info.name,
116
133
  walletState: WalletState.Disconnected,
117
- rpcEndpoint: endpointOptions?.endpoints[newChain.chainName]?.rpc?.[0] || '',
134
+ rpcEndpoint: "",
118
135
  errorMessage: "",
119
136
  account: undefined
120
137
  });
121
- });
122
- }
123
- else {
124
- draft.updateChainWalletState(newChain.chainName, newChain.chainName, {
125
- rpcEndpoint: endpointOptions?.endpoints[newChain.chainName]?.rpc?.[0] || '',
126
- });
127
- }
128
- draft.signerOptionMap[newChain.chainName] = signerOptions?.signing?.(newChain.chainName);
129
- draft.endpointOptionsMap[newChain.chainName] = endpointOptions?.endpoints?.[newChain.chainName];
138
+ }
139
+ });
130
140
  });
131
141
  });
132
142
  },
@@ -175,11 +185,7 @@ export const createInterchainStore = (walletManager) => {
175
185
  return account;
176
186
  },
177
187
  getRpcEndpoint: async (walletName, chainName) => {
178
- const exist = get().getChainWalletState(walletName, chainName).rpcEndpoint;
179
- if (exist)
180
- return exist;
181
188
  const rpcEndpoint = await walletManager.getRpcEndpoint(walletName, chainName);
182
- get().updateChainWalletState(walletName, chainName, { rpcEndpoint });
183
189
  return rpcEndpoint;
184
190
  },
185
191
  getChainLogoUrl(chainName) {
package/modal/provider.js CHANGED
@@ -20,8 +20,12 @@ const WalletModalProvider = ({ children, }) => {
20
20
  close();
21
21
  setShouldShowList(false);
22
22
  };
23
+ const currentChainNameRef = (0, react_1.useRef)("");
24
+ (0, react_1.useEffect)(() => {
25
+ currentChainNameRef.current = currentChainName;
26
+ }, [currentChainName]);
23
27
  const handleConnectWallet = async (walletName) => {
24
- const chainToConnect = currentChainName || chains[0].chainName;
28
+ const chainToConnect = currentChainNameRef.current || chains[0].chainName;
25
29
  setShouldShowList(false);
26
30
  setCurrentWalletName(walletName);
27
31
  await connect(walletName, chainToConnect);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interchain-kit/react",
3
- "version": "0.2.218",
3
+ "version": "0.2.220",
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.2.218",
37
+ "@interchain-kit/core": "0.2.220",
38
38
  "@interchain-ui/react": "1.26.1",
39
39
  "@interchainjs/cosmos": "1.10.1",
40
40
  "@interchainjs/cosmos-types": "1.10.1",
@@ -61,5 +61,5 @@
61
61
  "jest-environment-jsdom": "^29.7.0",
62
62
  "ts-jest": "^29.3.0"
63
63
  },
64
- "gitHead": "f7c6e9d67ed0a788fb8b37359adfbc09df2f69a2"
64
+ "gitHead": "f3ba828eb8b2a4db46931a04b010a59aeec4cc4e"
65
65
  }
package/store/store.js CHANGED
@@ -98,38 +98,48 @@ const createInterchainStore = (walletManager) => {
98
98
  getChainWalletState: (walletName, chainName) => {
99
99
  return get().chainWalletState.find(cws => cws.walletName === walletName && cws.chainName === chainName);
100
100
  },
101
- addChains: (chains, assetLists, signerOptions, endpointOptions) => {
102
- walletManager.addChains(chains, assetLists, signerOptions, endpointOptions);
101
+ addChains: async (newChains, newAssetLists, newSignerOptions, newEndpointOptions) => {
102
+ await walletManager.addChains(newChains, newAssetLists, newSignerOptions, newEndpointOptions);
103
103
  // console.log(walletManager.chains, walletManager.assetLists)
104
104
  // set(immerSyncUp(walletManager))
105
105
  // set(draft => {
106
106
  // draft.chains = walletManager.chains
107
107
  // })
108
108
  set(draft => {
109
- chains.forEach(newChain => {
110
- const existChain = draft.chains.find(c => c.chainId === newChain.chainId);
111
- if (!existChain) {
109
+ const existedChainMap = new Map(get().chains.map(chain => [chain.chainName, chain]));
110
+ const newAssetListMap = new Map(newAssetLists.map(assetList => [assetList.chainName, assetList]));
111
+ newChains.forEach(newChain => {
112
+ if (!existedChainMap.has(newChain.chainName)) {
112
113
  draft.chains.push(newChain);
113
- const assetList = assetLists.find(a => a.chainName === newChain.chainName);
114
- draft.assetLists.push(assetList);
115
- draft.wallets.forEach(w => {
114
+ draft.assetLists.push(newAssetListMap.get(newChain.chainName));
115
+ }
116
+ draft.signerOptionMap[newChain.chainName] = newSignerOptions?.signing(newChain.chainName);
117
+ draft.endpointOptionsMap[newChain.chainName] = newEndpointOptions?.endpoints?.[newChain.chainName];
118
+ });
119
+ get().chains.forEach(chain => {
120
+ draft.signerOptionMap[chain.chainName] = {
121
+ ...get().signerOptionMap[chain.chainName],
122
+ ...newSignerOptions?.signing(chain.chainName)
123
+ };
124
+ draft.endpointOptionsMap[chain.chainName] = {
125
+ ...get().endpointOptionsMap[chain.chainName],
126
+ ...newEndpointOptions?.endpoints?.[chain.chainName]
127
+ };
128
+ });
129
+ const existedChainWalletStatesMap = new Map(get().chainWalletState.map(cws => [cws.walletName + cws.chainName, cws]));
130
+ get().wallets.forEach(wallet => {
131
+ newChains.forEach(newChain => {
132
+ if (!existedChainWalletStatesMap.has(wallet.info.name + newChain.chainName)) {
116
133
  draft.chainWalletState.push({
117
134
  chainName: newChain.chainName,
118
- walletName: w.info.name,
135
+ walletName: wallet.info.name,
119
136
  walletState: core_1.WalletState.Disconnected,
120
- rpcEndpoint: endpointOptions?.endpoints[newChain.chainName]?.rpc?.[0] || '',
137
+ rpcEndpoint: "",
121
138
  errorMessage: "",
122
139
  account: undefined
123
140
  });
124
- });
125
- }
126
- else {
127
- draft.updateChainWalletState(newChain.chainName, newChain.chainName, {
128
- rpcEndpoint: endpointOptions?.endpoints[newChain.chainName]?.rpc?.[0] || '',
129
- });
130
- }
131
- draft.signerOptionMap[newChain.chainName] = signerOptions?.signing?.(newChain.chainName);
132
- draft.endpointOptionsMap[newChain.chainName] = endpointOptions?.endpoints?.[newChain.chainName];
141
+ }
142
+ });
133
143
  });
134
144
  });
135
145
  },
@@ -178,11 +188,7 @@ const createInterchainStore = (walletManager) => {
178
188
  return account;
179
189
  },
180
190
  getRpcEndpoint: async (walletName, chainName) => {
181
- const exist = get().getChainWalletState(walletName, chainName).rpcEndpoint;
182
- if (exist)
183
- return exist;
184
191
  const rpcEndpoint = await walletManager.getRpcEndpoint(walletName, chainName);
185
- get().updateChainWalletState(walletName, chainName, { rpcEndpoint });
186
192
  return rpcEndpoint;
187
193
  },
188
194
  getChainLogoUrl(chainName) {