@gluwa/connect-kit 0.2.0-next.3 → 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,23 @@
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
+
9
+ ## 0.2.0-next.5
10
+
11
+ ### Patch Changes
12
+
13
+ - d3d52e9: fix: react version paths
14
+
15
+ ## 0.2.0-next.4
16
+
17
+ ### Patch Changes
18
+
19
+ - ed8effc: add watchAsset
20
+
3
21
  ## 0.2.0-next.3
4
22
 
5
23
  ### 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[];
@@ -100,6 +101,7 @@ declare const connectKit: {
100
101
  readonly getAccount: () => _wagmi_core.GetAccountReturnType;
101
102
  readonly signMessage: (params: _wagmi_core.SignMessageParameters) => Promise<`0x${string}`>;
102
103
  readonly signTypedData: (params: _wagmi_core.SignTypedDataParameters) => Promise<`0x${string}`>;
104
+ readonly watchAsset: (params: _wagmi_core.WatchAssetParameters) => Promise<_wagmi_core.WatchAssetReturnType>;
103
105
  };
104
106
  readonly events: {
105
107
  readonly watchAccount: (params: _wagmi_core.WatchAccountParameters) => (() => void);
package/dist/index.js CHANGED
@@ -131,16 +131,44 @@ var signTypedData = /* @__PURE__ */ __name((params) => {
131
131
  return wagmiSignTypedData(getConfig(), params);
132
132
  }, "signTypedData");
133
133
 
134
+ // src/api/asset.ts
135
+ import { watchAsset as wagmiWatchAsset } from "@wagmi/core";
136
+ var watchAsset = /* @__PURE__ */ __name((params) => {
137
+ return wagmiWatchAsset(getConfig(), params);
138
+ }, "watchAsset");
139
+
134
140
  // src/events/account.ts
135
- 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";
136
142
  var watchAccount = /* @__PURE__ */ __name((params) => {
137
143
  return wagmiWatchAccount(getConfig(), params);
138
144
  }, "watchAccount");
139
145
  var watchConnections = /* @__PURE__ */ __name((params) => {
140
146
  return wagmiWatchConnections(getConfig(), params);
141
147
  }, "watchConnections");
142
- var reconnect = /* @__PURE__ */ __name(() => {
143
- 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);
144
172
  }, "reconnect");
145
173
  var disconnectAll = /* @__PURE__ */ __name(async (onLog) => {
146
174
  const config = getConfig();
@@ -1654,7 +1682,8 @@ var connectKit = {
1654
1682
  waitForTransactionReceipt,
1655
1683
  getAccount,
1656
1684
  signMessage,
1657
- signTypedData
1685
+ signTypedData,
1686
+ watchAsset
1658
1687
  },
1659
1688
  events: {
1660
1689
  watchAccount,
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gluwa/connect-kit",
3
- "version": "0.2.0-next.3",
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.3",
3
+ "version": "0.2.0-next.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -26,8 +26,8 @@
26
26
  "qrcode.react": "^4.2.0",
27
27
  "wagmi": "^2.15.6",
28
28
  "@wagmi/core": "^2.16.7",
29
- "@gluwa/credit-connect-sdk": "0.2.0-next.3",
30
29
  "@gluwa/credit-connect-storage-local": "0.2.0-next.3",
30
+ "@gluwa/credit-connect-sdk": "0.2.0-next.3",
31
31
  "@gluwa/credit-connect-e2ee-tweetnacl": "0.2.0-next.3",
32
32
  "@gluwa/credit-connect-hub-node-ws": "0.1.0-next.3"
33
33
  },
@@ -0,0 +1,10 @@
1
+ import {
2
+ watchAsset as wagmiWatchAsset,
3
+ type WatchAssetParameters,
4
+ type WatchAssetReturnType,
5
+ } from '@wagmi/core';
6
+ import { getConfig } from '../core/config';
7
+
8
+ export const watchAsset = (params: WatchAssetParameters): Promise<WatchAssetReturnType> => {
9
+ return wagmiWatchAsset(getConfig(), params);
10
+ };
@@ -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/index.ts CHANGED
@@ -3,6 +3,7 @@ import { getBalance } from './api/balance';
3
3
  import { switchChain, getPublicClient } from './api/chain';
4
4
  import { waitForTransactionReceipt } from './api/transaction';
5
5
  import { getAccount, signMessage, signTypedData } from './api/account';
6
+ import { watchAsset } from './api/asset';
6
7
  import { watchAccount, watchConnections, reconnect, disconnectAll } from './events/account';
7
8
 
8
9
  export { ConnectKitProvider, useConnectKit } from './ConnectKitProvider';
@@ -35,6 +36,7 @@ export const connectKit = {
35
36
  getAccount,
36
37
  signMessage,
37
38
  signTypedData,
39
+ watchAsset,
38
40
  },
39
41
  events: {
40
42
  watchAccount,
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 표시 순서를 결정.
package/tsconfig.json CHANGED
@@ -2,7 +2,11 @@
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "noEmit": true,
5
- "baseUrl": "./"
5
+ "baseUrl": "./",
6
+ "paths": {
7
+ "react": ["./node_modules/@types/react"],
8
+ "react/*": ["./node_modules/@types/react/*"]
9
+ }
6
10
  },
7
11
  "include": ["src/**/*"]
8
12
  }