@rango-dev/widget-embedded 0.44.2-next.7 → 0.44.2-next.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.44.2-next.7",
3
+ "version": "0.44.2-next.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -54,4 +54,4 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
57
- }
57
+ }
@@ -12,7 +12,7 @@ import {
12
12
  Typography,
13
13
  } from '@rango-dev/ui';
14
14
  import { useWallets } from '@rango-dev/wallets-react';
15
- import React, { useEffect, useLayoutEffect, useState } from 'react';
15
+ import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
16
16
 
17
17
  import { useAppStore } from '../../store/AppStore';
18
18
  import { getConciseAddress } from '../../utils/wallets';
@@ -46,10 +46,17 @@ export const NamespaceDetachedItem = function NamespaceDetachedItem(
46
46
 
47
47
  const supportedChains = namespace.getSupportedChains(blockchains);
48
48
 
49
+ /*
50
+ * Ref to track ongoing connection attempts.
51
+ * In React Strict Mode, effects run twice for safety checks.
52
+ * This prevents multiple connect requests by ensuring only one attempt is processed at a time.
53
+ */
54
+ const processingConnectAttempt = useRef(false);
55
+
49
56
  useEffect(() => setErrorIsExpanded(false), [error]);
50
57
 
51
58
  useLayoutEffect(() => {
52
- if (initialConnect) {
59
+ if (initialConnect && !processingConnectAttempt.current) {
53
60
  void handleConnectNamespace(walletType, namespace.value);
54
61
  }
55
62
  }, []);
@@ -59,6 +66,7 @@ export const NamespaceDetachedItem = function NamespaceDetachedItem(
59
66
  namespace: Namespace
60
67
  ) => {
61
68
  try {
69
+ processingConnectAttempt.current = true;
62
70
  await connect(walletType, [
63
71
  {
64
72
  namespace: namespace,
@@ -67,6 +75,8 @@ export const NamespaceDetachedItem = function NamespaceDetachedItem(
67
75
  ]);
68
76
  } catch (error) {
69
77
  setError(error as Error);
78
+ } finally {
79
+ processingConnectAttempt.current = false;
70
80
  }
71
81
  };
72
82