@gluwa/connect-kit 0.2.0-next.5 → 0.2.0-next.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @gluwa/wallet-kit
2
2
 
3
+ ## 0.2.0-next.6
4
+
5
+ ### Patch Changes
6
+
7
+ - a9bbec9: enhance reconnect logic with auto-connect for injected connectors
8
+
3
9
  ## 0.2.0-next.5
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ interface ConnectKitConfig {
19
19
  serverUrl: string;
20
20
  };
21
21
  extraConnectors?: CreateConnectorFn[];
22
+ autoConnectInjected?: boolean;
22
23
  }
23
24
  type ConnectorKey = 'creditWallet' | 'metamask' | 'walletConnect';
24
25
  type Connectors = readonly ConnectorKey[];
package/dist/index.js CHANGED
@@ -138,15 +138,37 @@ var watchAsset = /* @__PURE__ */ __name((params) => {
138
138
  }, "watchAsset");
139
139
 
140
140
  // src/events/account.ts
141
- import { watchAccount as wagmiWatchAccount, watchConnections as wagmiWatchConnections, reconnect as wagmiReconnect, disconnect as wagmiDisconnect } from "@wagmi/core";
141
+ import { watchAccount as wagmiWatchAccount, watchConnections as wagmiWatchConnections, reconnect as wagmiReconnect, connect as wagmiConnect, getAccount as wagmiGetAccount2, disconnect as wagmiDisconnect } from "@wagmi/core";
142
142
  var watchAccount = /* @__PURE__ */ __name((params) => {
143
143
  return wagmiWatchAccount(getConfig(), params);
144
144
  }, "watchAccount");
145
145
  var watchConnections = /* @__PURE__ */ __name((params) => {
146
146
  return wagmiWatchConnections(getConfig(), params);
147
147
  }, "watchConnections");
148
- var reconnect = /* @__PURE__ */ __name(() => {
149
- return wagmiReconnect(getConfig());
148
+ var reconnect = /* @__PURE__ */ __name(async () => {
149
+ const config = getConfig();
150
+ if (getKitConfig().autoConnectInjected !== false) {
151
+ try {
152
+ const injected2 = config.connectors.find((connector) => connector.type === "injected");
153
+ if (injected2) {
154
+ const provider = await injected2.getProvider();
155
+ const accounts = (provider == null ? void 0 : provider.request) ? await provider.request({
156
+ method: "eth_accounts"
157
+ }) : [];
158
+ if (Array.isArray(accounts) && accounts.length > 0) {
159
+ await wagmiConnect(config, {
160
+ connector: injected2
161
+ });
162
+ }
163
+ }
164
+ } catch (error) {
165
+ console.warn("injected auto-connect skipped (non-fatal):", error);
166
+ }
167
+ }
168
+ if (wagmiGetAccount2(config).status === "connected") {
169
+ return [];
170
+ }
171
+ return wagmiReconnect(config);
150
172
  }, "reconnect");
151
173
  var disconnectAll = /* @__PURE__ */ __name(async (onLog) => {
152
174
  const config = getConfig();
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gluwa/connect-kit",
3
- "version": "0.2.0-next.5",
3
+ "version": "0.2.0-next.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gluwa/connect-kit",
3
- "version": "0.2.0-next.5",
3
+ "version": "0.2.0-next.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -26,10 +26,10 @@
26
26
  "qrcode.react": "^4.2.0",
27
27
  "wagmi": "^2.15.6",
28
28
  "@wagmi/core": "^2.16.7",
29
+ "@gluwa/credit-connect-storage-local": "0.2.0-next.3",
29
30
  "@gluwa/credit-connect-sdk": "0.2.0-next.3",
30
31
  "@gluwa/credit-connect-e2ee-tweetnacl": "0.2.0-next.3",
31
- "@gluwa/credit-connect-hub-node-ws": "0.1.0-next.3",
32
- "@gluwa/credit-connect-storage-local": "0.2.0-next.3"
32
+ "@gluwa/credit-connect-hub-node-ws": "0.1.0-next.3"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@tanstack/react-query": "^5.62.0",
@@ -2,12 +2,14 @@ import {
2
2
  watchAccount as wagmiWatchAccount,
3
3
  watchConnections as wagmiWatchConnections,
4
4
  reconnect as wagmiReconnect,
5
+ connect as wagmiConnect,
6
+ getAccount as wagmiGetAccount,
5
7
  disconnect as wagmiDisconnect,
6
8
  type WatchAccountParameters,
7
9
  type WatchConnectionsParameters,
8
10
  type ReconnectReturnType,
9
11
  } from '@wagmi/core';
10
- import { getConfig } from '../core/config';
12
+ import { getConfig, getKitConfig } from '../core/config';
11
13
 
12
14
  export const watchAccount = (params: WatchAccountParameters): (() => void) => {
13
15
  return wagmiWatchAccount(getConfig(), params);
@@ -17,8 +19,33 @@ export const watchConnections = (params: WatchConnectionsParameters): (() => voi
17
19
  return wagmiWatchConnections(getConfig(), params);
18
20
  };
19
21
 
20
- export const reconnect = (): Promise<ReconnectReturnType> => {
21
- return wagmiReconnect(getConfig());
22
+ export const reconnect = async (): Promise<ReconnectReturnType> => {
23
+ const config = getConfig();
24
+
25
+ if (getKitConfig().autoConnectInjected !== false) {
26
+ try {
27
+ const injected = config.connectors.find((connector) => connector.type === 'injected');
28
+ if (injected) {
29
+ const provider = (await injected.getProvider()) as
30
+ | { request?: (args: { method: string }) => Promise<unknown> }
31
+ | undefined;
32
+ const accounts = provider?.request
33
+ ? await provider.request({ method: 'eth_accounts' })
34
+ : [];
35
+ if (Array.isArray(accounts) && accounts.length > 0) {
36
+ await wagmiConnect(config, { connector: injected });
37
+ }
38
+ }
39
+ } catch (error) {
40
+ // eslint-disable-next-line no-console
41
+ console.warn('injected auto-connect skipped (non-fatal):', error);
42
+ }
43
+ }
44
+
45
+ if (wagmiGetAccount(config).status === 'connected') {
46
+ return [];
47
+ }
48
+ return wagmiReconnect(config);
22
49
  };
23
50
 
24
51
  export const disconnectAll = async (
package/src/types.ts CHANGED
@@ -13,6 +13,7 @@ export interface ConnectKitConfig {
13
13
  serverUrl: string;
14
14
  };
15
15
  extraConnectors?: CreateConnectorFn[];
16
+ autoConnectInjected?: boolean;
16
17
  }
17
18
 
18
19
  // 활성화할 connector key 배열. 빠진 key 는 비활성. 순서가 selector 표시 순서를 결정.