@getpara/cosmos-wallet-connectors 3.26.0 → 3.27.0

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.
@@ -32,6 +32,7 @@ const CosmosExternalWalletContext = createContext(
32
32
  defaultCosmosExternalWallet
33
33
  );
34
34
  const normalizeWalletIdentifier = (identifier) => identifier == null ? void 0 : identifier.toLowerCase();
35
+ const isActiveGrazWallet = (wallet, activeWalletType) => !!wallet && !!activeWalletType && [wallet.grazType, wallet.grazMobileType].includes(activeWalletType);
35
36
  function CosmosExternalWalletProvider({
36
37
  children,
37
38
  onSwitchWallet,
@@ -64,6 +65,7 @@ function CosmosExternalWalletProvider({
64
65
  const { walletType } = useActiveWalletType();
65
66
  const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
66
67
  const disconnectTypeRef = useRef();
68
+ const activeWalletTypeRef = useRef(walletType);
67
69
  const ethAddressRef = useRef((_b = (_a = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _a.ethereumHexAddress) == null ? void 0 : _b.toLowerCase());
68
70
  const bech32AddressRef = useRef((_c = account == null ? void 0 : account[selectedChainId]) == null ? void 0 : _c.bech32Address);
69
71
  const wasConnectedRef = useRef(isConnected);
@@ -135,6 +137,9 @@ function CosmosExternalWalletProvider({
135
137
  }
136
138
  }
137
139
  }, [account, selectedChainId, walletType]);
140
+ useEffect(() => {
141
+ activeWalletTypeRef.current = walletType;
142
+ }, [walletType]);
138
143
  useEffect(() => {
139
144
  if (wasConnectedRef.current && isDisconnected) {
140
145
  ethAddressRef.current = void 0;
@@ -197,6 +202,7 @@ function CosmosExternalWalletProvider({
197
202
  connectParaConnector: () => __async(null, null, function* () {
198
203
  const chainId = multiChain ? chains.map((c) => c.chainId) : selectedChainId;
199
204
  yield connectAsync({ walletType: GrazWalletType.PARA, chainId });
205
+ activeWalletTypeRef.current = GrazWalletType.PARA;
200
206
  })
201
207
  }
202
208
  });
@@ -263,10 +269,12 @@ function CosmosExternalWalletProvider({
263
269
  const switchAccount = useCallback(
264
270
  (connectorName) => __async(null, null, function* () {
265
271
  const chainId = multiChain ? chains.map((c) => c.chainId) : selectedChainId;
272
+ const connectedWalletType = connectorName.toLowerCase();
266
273
  yield connectAsync({
267
- walletType: connectorName.toLowerCase(),
274
+ walletType: connectedWalletType,
268
275
  chainId
269
276
  });
277
+ activeWalletTypeRef.current = connectedWalletType;
270
278
  }),
271
279
  [chains, connectAsync, multiChain, selectedChainId]
272
280
  );
@@ -363,6 +371,7 @@ function CosmosExternalWalletProvider({
363
371
  }
364
372
  }
365
373
  const connectedWallet = yield shouldUseSuggestChainAndConnect ? suggestAndConnectAsync({ walletType: walletType2, chainInfo }) : connectAsync({ walletType: walletType2, chainId: _chainId });
374
+ activeWalletTypeRef.current = walletType2;
366
375
  const firstChain = !chainId ? selectedChainId : typeof _chainId === "string" ? _chainId : _chainId[0];
367
376
  const addressBech32 = connectedWallet.accounts[firstChain].bech32Address;
368
377
  let rawAddress;
@@ -481,6 +490,7 @@ function CosmosExternalWalletProvider({
481
490
  try {
482
491
  const chainId = multiChain ? chains.map((c) => c.chainId) : selectedChainId;
483
492
  const result = yield connectAsync({ walletType: GrazWalletType.PARA, chainId });
493
+ activeWalletTypeRef.current = GrazWalletType.PARA;
484
494
  return { result };
485
495
  } catch (err) {
486
496
  const error = err instanceof Error ? err.message : "Unknown error";
@@ -500,6 +510,8 @@ function CosmosExternalWalletProvider({
500
510
  wallet.grazType,
501
511
  multiChain ? (_a2 = chains[0]) == null ? void 0 : _a2.chainId : selectedChainId
502
512
  );
513
+ ethAddressRef.current = externalWallet.address;
514
+ bech32AddressRef.current = externalWallet.addressBech32;
503
515
  return externalWallet;
504
516
  } catch (e) {
505
517
  console.error("Error linking account:", e);
@@ -509,8 +521,11 @@ function CosmosExternalWalletProvider({
509
521
  [chains, connectBase, multiChain, selectedChainId, wallets]
510
522
  );
511
523
  const disconnectBase = useCallback(
512
- (_0, ..._1) => __async(null, [_0, ..._1], function* (_, { disconnectType } = {}) {
524
+ (_0, ..._1) => __async(null, [_0, ..._1], function* (providerId, { disconnectType } = {}) {
513
525
  var _a2;
526
+ if (providerId !== void 0 && !isActiveGrazWallet(getExternalWalletMetadata({ providerId }), activeWalletTypeRef.current)) {
527
+ return;
528
+ }
514
529
  if (disconnectType) {
515
530
  disconnectTypeRef.current = disconnectType;
516
531
  }
@@ -523,7 +538,7 @@ function CosmosExternalWalletProvider({
523
538
  disconnectTypeRef.current = void 0;
524
539
  }
525
540
  }),
526
- [disconnectAsync]
541
+ [disconnectAsync, getExternalWalletMetadata]
527
542
  );
528
543
  const contextValue = useMemo(
529
544
  () => __spreadValues({
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@getpara/cosmos-wallet-connectors",
3
- "version": "3.26.0",
3
+ "version": "3.27.0",
4
4
  "dependencies": {
5
- "@getpara/graz-connector": "3.26.0",
6
- "@getpara/react-common": "3.26.0",
7
- "@getpara/web-sdk": "3.26.0",
5
+ "@getpara/graz-connector": "3.27.0",
6
+ "@getpara/react-common": "3.27.0",
7
+ "@getpara/web-sdk": "3.27.0",
8
8
  "zustand": "^4.5.2",
9
9
  "zustand-sync-tabs": "^0.2.2"
10
10
  },
@@ -30,7 +30,7 @@
30
30
  "dist",
31
31
  "package.json"
32
32
  ],
33
- "gitHead": "3da03ae598e47dddcad44773264bcba424537e9d",
33
+ "gitHead": "6f1dd93f4508c6da9256b76bcc306ec995002754",
34
34
  "main": "dist/index.js",
35
35
  "peerDependencies": {
36
36
  "@cosmjs/amino": ">=0.32.4",