@gluwa/connect-kit 0.1.0-next.3 → 0.2.0-next.1

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,4 +1,4 @@
1
- import { useState, type FC } from 'react';
1
+ import { useEffect, useRef, useState, type FC } from 'react';
2
2
  import { useSwitchChain } from 'wagmi';
3
3
 
4
4
  interface SwitchChainViewProps {
@@ -18,6 +18,13 @@ export const SwitchChainView: FC<SwitchChainViewProps> = ({
18
18
  }) => {
19
19
  const { switchChainAsync, isPending } = useSwitchChain();
20
20
  const [error, setError] = useState<Error | null>(null);
21
+ const isMountedRef = useRef(true);
22
+ useEffect(() => {
23
+ isMountedRef.current = true;
24
+ return () => {
25
+ isMountedRef.current = false;
26
+ };
27
+ }, []);
21
28
 
22
29
  const targetLabel = requiredChainName ?? `chain ${requiredChainId}`;
23
30
 
@@ -25,8 +32,6 @@ export const SwitchChainView: FC<SwitchChainViewProps> = ({
25
32
  setError(null);
26
33
  switchChainAsync({ chainId: requiredChainId }).catch((err: unknown) => {
27
34
  const normalized = err instanceof Error ? err : new Error(String(err));
28
- // wagmi's MetaMask connector handles 4902 (chain not added) via wallet_addEthereumChain
29
- // automatically when chain metadata is configured. We only surface what reaches us.
30
35
  const code =
31
36
  typeof err === 'object' && err !== null && 'code' in err
32
37
  ? (err as { code: unknown }).code
@@ -36,7 +41,7 @@ export const SwitchChainView: FC<SwitchChainViewProps> = ({
36
41
  } else {
37
42
  onLog?.(`[connect-kit] switch chain failed: ${normalized.message}`, normalized);
38
43
  }
39
- setError(normalized);
44
+ if (isMountedRef.current) setError(normalized);
40
45
  });
41
46
  };
42
47
 
package/tsup.config.ts CHANGED
@@ -26,7 +26,7 @@ export default defineConfig({
26
26
  banner: {
27
27
  js: 'import React from "react";',
28
28
  },
29
- esbuildPlugins: [sassPlugin({ type: 'style' })],
29
+ esbuildPlugins: [sassPlugin({ type: 'css' })],
30
30
  esbuildOptions(options) {
31
31
  options.loader = { ...options.loader, '.png': 'dataurl' };
32
32
  },