@qinzhehan/rainbow-wallet-kit 0.1.0 → 0.1.2

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/dist/index.mjs CHANGED
@@ -1,231 +1,252 @@
1
- var J = Object.defineProperty;
2
- var K = (t, e, n) => e in t ? J(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var y = (t, e, n) => K(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { jsx as m, jsxs as k } from "react/jsx-runtime";
5
- import { createContext as V, useRef as C, useState as R, useMemo as I, useCallback as D, useEffect as b, useContext as q } from "react";
6
- class u extends Error {
1
+ var B = Object.defineProperty;
2
+ var j = (e, t, n) => t in e ? B(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var E = (e, t, n) => j(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsx as f, jsxs as N } from "react/jsx-runtime";
5
+ import { createContext as z, useRef as M, useState as K, useMemo as P, useCallback as D, useEffect as v, useContext as H } from "react";
6
+ class w extends Error {
7
7
  constructor(n, a, s) {
8
8
  super(a);
9
- y(this, "code");
10
- y(this, "cause");
9
+ E(this, "code");
10
+ E(this, "cause");
11
11
  this.name = "WalletKitError", this.code = n, this.cause = s;
12
12
  }
13
13
  }
14
- function B(t) {
14
+ function G(e) {
15
15
  return [
16
- t.audience ?? "Wallet Login",
16
+ e.audience ?? "Wallet Login",
17
17
  "",
18
- `Wallet: ${t.wallet}`,
19
- `Address: ${t.address}`,
20
- `Chain: ${t.chainType}`,
21
- `Nonce: ${t.nonce}`,
18
+ `Wallet: ${e.wallet}`,
19
+ `Address: ${e.address}`,
20
+ `Chain: ${e.chainType}`,
21
+ `Nonce: ${e.nonce}`,
22
22
  `Issued At: ${(/* @__PURE__ */ new Date()).toISOString()}`
23
23
  ].join(`
24
24
  `);
25
25
  }
26
- async function L(t) {
26
+ async function X(e) {
27
27
  var s;
28
- if (!((s = t.auth) != null && s.enabled)) return;
29
- if (!t.auth.getNonce || !t.auth.verifySignature)
30
- throw new u("AUTH_FAILED", "Wallet auth requires getNonce and verifySignature callbacks.");
31
- const e = await t.auth.getNonce({
32
- wallet: t.wallet,
33
- address: t.account.address,
34
- chainType: t.account.chainType,
35
- audience: t.auth.audience
36
- }), n = B({
37
- nonce: e,
38
- address: t.account.address,
39
- wallet: t.wallet,
40
- chainType: t.account.chainType,
41
- audience: t.auth.audience
42
- }), a = await t.signMessage(n).catch((h) => {
43
- throw new u("SIGNATURE_REJECTED", "Wallet signature was rejected or failed.", h);
28
+ if (!((s = e.auth) != null && s.enabled)) return;
29
+ if (!e.auth.getNonce || !e.auth.verifySignature)
30
+ throw new w("AUTH_FAILED", "Wallet auth requires getNonce and verifySignature callbacks.");
31
+ const t = await e.auth.getNonce({
32
+ wallet: e.wallet,
33
+ address: e.account.address,
34
+ chainType: e.account.chainType,
35
+ audience: e.auth.audience
36
+ }), n = G({
37
+ nonce: t,
38
+ address: e.account.address,
39
+ wallet: e.wallet,
40
+ chainType: e.account.chainType,
41
+ audience: e.auth.audience
42
+ }), a = await e.signMessage(n).catch((h) => {
43
+ throw new w("SIGNATURE_REJECTED", "Wallet signature was rejected or failed.", h);
44
44
  });
45
- return t.auth.verifySignature({
46
- wallet: t.wallet,
47
- address: t.account.address,
48
- chainType: t.account.chainType,
49
- audience: t.auth.audience,
50
- nonce: e,
45
+ return e.auth.verifySignature({
46
+ wallet: e.wallet,
47
+ address: e.account.address,
48
+ chainType: e.account.chainType,
49
+ audience: e.auth.audience,
50
+ nonce: t,
51
51
  message: n,
52
52
  signature: a
53
53
  });
54
54
  }
55
- async function z(t) {
56
- var e;
57
- if (!((e = t.auth) != null && e.enabled) || !t.auth.refreshJwt || !t.session || !t.wallet || !t.account)
58
- return t.session;
55
+ async function Y(e) {
56
+ var t;
57
+ if (!((t = e.auth) != null && t.enabled) || !e.auth.refreshJwt || !e.session || !e.wallet || !e.account)
58
+ return e.session;
59
59
  try {
60
- return await t.auth.refreshJwt({
61
- token: t.session.token,
62
- refreshToken: t.session.refreshToken,
63
- wallet: t.wallet,
64
- address: t.account.address
60
+ return await e.auth.refreshJwt({
61
+ token: e.session.token,
62
+ refreshToken: e.session.refreshToken,
63
+ wallet: e.wallet,
64
+ address: e.account.address
65
65
  });
66
66
  } catch (n) {
67
- throw new u("JWT_REFRESH_FAILED", "JWT refresh failed.", n);
67
+ throw new w("JWT_REFRESH_FAILED", "JWT refresh failed.", n);
68
68
  }
69
69
  }
70
- function H(t, e = 6e4) {
71
- return Math.max(0, t.expiresAt - Date.now() - e);
70
+ function Q(e, t = 6e4) {
71
+ return Math.max(0, e.expiresAt - Date.now() - t);
72
72
  }
73
- const A = {
73
+ const _ = {
74
74
  metamask: "https://metamask.app.link/dapp/",
75
75
  okx: "okx://wallet/dapp/url?dappUrl=",
76
76
  phantom: "https://phantom.app/ul/browse/"
77
77
  };
78
- function G() {
78
+ function Z() {
79
79
  return typeof navigator > "u" ? !1 : /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
80
80
  }
81
- function Y(t) {
82
- return t != null && t.dappUrl ? t.dappUrl : typeof window > "u" ? "" : window.location.href;
81
+ function R(e) {
82
+ return e != null && e.dappUrl ? e.dappUrl : typeof window > "u" ? "" : window.location.href;
83
83
  }
84
- function W(t, e, n) {
85
- const a = encodeURIComponent(e);
86
- return t === "metamask" ? `${(n == null ? void 0 : n.metamask) ?? A.metamask}${e.replace(/^https?:\/\//, "")}` : t === "okx" ? `${(n == null ? void 0 : n.okx) ?? A.okx}${a}` : `${(n == null ? void 0 : n.phantom) ?? A.phantom}${a}?ref=${a}`;
84
+ function F(e, t, n) {
85
+ const a = encodeURIComponent(t);
86
+ return e === "metamask" ? `${(n == null ? void 0 : n.metamask) ?? _.metamask}${t.replace(/^https?:\/\//, "")}` : e === "okx" ? `${(n == null ? void 0 : n.okx) ?? _.okx}${a}` : `${(n == null ? void 0 : n.phantom) ?? _.phantom}${a}?ref=${a}`;
87
87
  }
88
- class j {
88
+ class L {
89
89
  constructor() {
90
- y(this, "listeners", /* @__PURE__ */ new Map());
90
+ E(this, "listeners", /* @__PURE__ */ new Map());
91
91
  }
92
- on(e, n) {
93
- const a = this.listeners.get(e) ?? /* @__PURE__ */ new Set();
94
- return a.add(n), this.listeners.set(e, a), () => this.off(e, n);
92
+ on(t, n) {
93
+ const a = this.listeners.get(t) ?? /* @__PURE__ */ new Set();
94
+ return a.add(n), this.listeners.set(t, a), () => this.off(t, n);
95
95
  }
96
- off(e, n) {
96
+ off(t, n) {
97
97
  var a;
98
- (a = this.listeners.get(e)) == null || a.delete(n);
98
+ (a = this.listeners.get(t)) == null || a.delete(n);
99
99
  }
100
- emit(e, n) {
100
+ emit(t, n) {
101
101
  var a;
102
- (a = this.listeners.get(e)) == null || a.forEach((s) => s(n));
102
+ (a = this.listeners.get(t)) == null || a.forEach((s) => s(n));
103
103
  }
104
104
  removeAllListeners() {
105
105
  this.listeners.clear();
106
106
  }
107
107
  }
108
- function M(t) {
108
+ function W(e) {
109
109
  var n;
110
- if (t instanceof u) return t;
111
- const e = t;
112
- return (e == null ? void 0 : e.code) === 4001 || (e == null ? void 0 : e.code) === "ACTION_REJECTED" ? new u("USER_REJECTED", e.message ?? "User rejected wallet request.", t) : (n = e == null ? void 0 : e.message) != null && n.toLowerCase().includes("timeout") ? new u("CONNECT_TIMEOUT", e.message, t) : new u("UNKNOWN", (e == null ? void 0 : e.message) ?? "Unexpected wallet error.", t);
110
+ if (e instanceof w) return e;
111
+ const t = e;
112
+ return (t == null ? void 0 : t.code) === 4001 || (t == null ? void 0 : t.code) === "ACTION_REJECTED" ? new w("USER_REJECTED", t.message ?? "User rejected wallet request.", e) : (n = t == null ? void 0 : t.message) != null && n.toLowerCase().includes("timeout") ? new w("CONNECT_TIMEOUT", t.message, e) : new w("UNKNOWN", (t == null ? void 0 : t.message) ?? "Unexpected wallet error.", e);
113
113
  }
114
- function X(t, e, n) {
114
+ function ee(e, t, n) {
115
115
  let a;
116
- const s = new Promise((h, f) => {
117
- a = setTimeout(() => f(new u("CONNECT_TIMEOUT", n)), e);
116
+ const s = new Promise((h, g) => {
117
+ a = setTimeout(() => g(new w("CONNECT_TIMEOUT", n)), t);
118
118
  });
119
- return Promise.race([t, s]).finally(() => {
119
+ return Promise.race([e, s]).finally(() => {
120
120
  a && clearTimeout(a);
121
121
  });
122
122
  }
123
- const Q = "rainbow-wallet-kit:state";
124
- class Z {
125
- constructor(e, n) {
126
- y(this, "channel");
127
- y(this, "tabId", Math.random().toString(36).slice(2));
128
- y(this, "handleStorage", (e) => {
129
- if (!(e.key !== this.storageKey || !e.newValue))
123
+ const te = "rainbow-wallet-kit:state";
124
+ class ne {
125
+ constructor(t, n) {
126
+ E(this, "channel");
127
+ E(this, "tabId", Math.random().toString(36).slice(2));
128
+ E(this, "handleStorage", (t) => {
129
+ if (!(t.key !== this.storageKey || !t.newValue))
130
130
  try {
131
- const n = JSON.parse(e.newValue);
131
+ const n = JSON.parse(t.newValue);
132
132
  n.tabId !== this.tabId && this.emitter.emit("state", n.state);
133
133
  } catch {
134
134
  }
135
135
  });
136
- this.emitter = e, this.storageKey = n, !(typeof window > "u") && ("BroadcastChannel" in window && (this.channel = new BroadcastChannel(Q), this.channel.onmessage = (a) => {
136
+ this.emitter = t, this.storageKey = n, !(typeof window > "u") && ("BroadcastChannel" in window && (this.channel = new BroadcastChannel(te), this.channel.onmessage = (a) => {
137
137
  var s;
138
138
  ((s = a.data) == null ? void 0 : s.tabId) !== this.tabId && this.emitter.emit("state", a.data.state);
139
139
  }), window.addEventListener("storage", this.handleStorage));
140
140
  }
141
- publish(e) {
141
+ publish(t) {
142
142
  var a;
143
143
  if (typeof window > "u") return;
144
- const n = { tabId: this.tabId, state: e };
144
+ const n = { tabId: this.tabId, state: t };
145
145
  localStorage.setItem(this.storageKey, JSON.stringify(n)), (a = this.channel) == null || a.postMessage(n);
146
146
  }
147
147
  read() {
148
148
  if (typeof window > "u") return;
149
- const e = localStorage.getItem(this.storageKey);
150
- if (e)
149
+ const t = localStorage.getItem(this.storageKey);
150
+ if (t)
151
151
  try {
152
- return JSON.parse(e).state;
152
+ return JSON.parse(t).state;
153
153
  } catch {
154
154
  return;
155
155
  }
156
156
  }
157
157
  destroy() {
158
- var e;
159
- (e = this.channel) == null || e.close(), typeof window < "u" && window.removeEventListener("storage", this.handleStorage);
158
+ var t;
159
+ (t = this.channel) == null || t.close(), typeof window < "u" && window.removeEventListener("storage", this.handleStorage);
160
160
  }
161
161
  }
162
- function S(t) {
163
- var a, s, h;
162
+ function S(e) {
163
+ var h, g;
164
164
  if (typeof window > "u") return;
165
- const e = t === "okx" ? (a = window.okxwallet) == null ? void 0 : a.ethereum : window.ethereum, n = (e == null ? void 0 : e.providers) ?? ((s = window.ethereum) == null ? void 0 : s.providers);
165
+ const t = ae(e), n = t.flatMap((l) => l.providers ?? []), a = x([...t, ...n]);
166
+ if (e === "okx") {
167
+ const l = a.find(p);
168
+ if (l) return l;
169
+ if ((h = window.okxwallet) != null && h.request) return window.okxwallet;
170
+ }
166
171
  if (n != null && n.length) {
167
- const f = n.find((w) => t === "metamask" ? w.isMetaMask && !w.isOkxWallet : w.isOkxWallet);
168
- if (f) return f;
172
+ const l = n.find((y) => e === "metamask" ? y.isMetaMask && !y.isOkxWallet : p(y));
173
+ if (l) return l;
169
174
  }
170
- if (t === "metamask" && (e != null && e.isMetaMask) && !e.isOkxWallet || t === "okx" && (e != null && e.isOkxWallet || (h = window.okxwallet) != null && h.ethereum)) return e;
175
+ const s = e === "metamask" ? window.ethereum : ((g = window.okxwallet) == null ? void 0 : g.ethereum) ?? window.ethereum;
176
+ if (e === "metamask" && (s != null && s.isMetaMask) && !p(s) || e === "okx" && s && p(s)) return s;
177
+ }
178
+ function ae(e) {
179
+ var n, a;
180
+ const t = [
181
+ window.ethereum,
182
+ window.okxwallet,
183
+ (n = window.okxwallet) == null ? void 0 : n.ethereum
184
+ ];
185
+ return x(e === "metamask" ? [window.ethereum, ...((a = window.ethereum) == null ? void 0 : a.providers) ?? []] : t);
186
+ }
187
+ function x(e) {
188
+ return e.filter((t, n, a) => !!(t != null && t.request) && a.indexOf(t) === n);
189
+ }
190
+ function p(e) {
191
+ return !!(e != null && e.isOkxWallet || e != null && e.isOKExWallet || e != null && e.isOKXWallet);
171
192
  }
172
- function ee(t) {
173
- if (t)
174
- return Number.parseInt(t, 16);
193
+ function se(e) {
194
+ if (e)
195
+ return Number.parseInt(e, 16);
175
196
  }
176
- function x(t) {
197
+ function U(e) {
177
198
  return {
178
- id: t.id,
179
- name: t.name,
199
+ id: e.id,
200
+ name: e.name,
180
201
  chainType: "evm",
181
- icon: t.icon,
182
- installed: () => !!S(t.id),
202
+ icon: e.icon,
203
+ installed: () => !!S(e.id),
183
204
  connect: async () => {
184
- const e = S(t.id);
185
- if (!e)
186
- throw new u("PROVIDER_NOT_FOUND", `${t.name} provider was not found.`);
187
- const n = await e.request({ method: "eth_requestAccounts" }), a = await e.request({ method: "eth_chainId" }).catch(() => {
205
+ const t = S(e.id);
206
+ if (!t)
207
+ throw new w("PROVIDER_NOT_FOUND", `${e.name} provider was not found.`);
208
+ const n = await t.request({ method: "eth_requestAccounts" }), a = await t.request({ method: "eth_chainId" }).catch(() => {
188
209
  }), s = n[0];
189
- if (!s) throw new u("PROVIDER_NOT_FOUND", `${t.name} did not return an address.`);
210
+ if (!s) throw new w("PROVIDER_NOT_FOUND", `${e.name} did not return an address.`);
190
211
  return {
191
212
  address: s,
192
213
  chainType: "evm",
193
- chainId: ee(a)
214
+ chainId: se(a)
194
215
  };
195
216
  },
196
- signMessage: async (e, n) => {
197
- const a = S(t.id);
198
- if (!a) throw new u("PROVIDER_NOT_FOUND", `${t.name} provider was not found.`);
217
+ signMessage: async (t, n) => {
218
+ const a = S(e.id);
219
+ if (!a) throw new w("PROVIDER_NOT_FOUND", `${e.name} provider was not found.`);
199
220
  return a.request({
200
221
  method: "personal_sign",
201
- params: [e, n.address]
222
+ params: [t, n.address]
202
223
  });
203
224
  },
204
- getDeepLink: (e) => W(t.id, e, t.deepLinks)
225
+ getDeepLink: (t) => F(e.id, t, e.deepLinks)
205
226
  };
206
227
  }
207
- function O() {
208
- var t, e;
228
+ function A() {
229
+ var e, t;
209
230
  if (!(typeof window > "u"))
210
- return (e = (t = window.phantom) == null ? void 0 : t.solana) != null && e.isPhantom ? window.phantom.solana : void 0;
231
+ return (t = (e = window.phantom) == null ? void 0 : e.solana) != null && t.isPhantom ? window.phantom.solana : void 0;
211
232
  }
212
- function te(t) {
213
- let e = "";
214
- return t.forEach((n) => {
215
- e += String.fromCharCode(n);
216
- }), btoa(e);
233
+ function oe(e) {
234
+ let t = "";
235
+ return e.forEach((n) => {
236
+ t += String.fromCharCode(n);
237
+ }), btoa(t);
217
238
  }
218
- function ne(t) {
239
+ function re(e) {
219
240
  return {
220
241
  id: "phantom",
221
242
  name: "Phantom",
222
243
  chainType: "solana",
223
244
  icon: "P",
224
- installed: () => !!O(),
245
+ installed: () => !!A(),
225
246
  connect: async () => {
226
- const e = O();
227
- if (!e) throw new u("PROVIDER_NOT_FOUND", "Phantom provider was not found.");
228
- const a = (await e.connect()).publicKey.toString();
247
+ const t = A();
248
+ if (!t) throw new w("PROVIDER_NOT_FOUND", "Phantom provider was not found.");
249
+ const a = (await t.connect()).publicKey.toString();
229
250
  return {
230
251
  address: a,
231
252
  publicKey: a,
@@ -234,217 +255,233 @@ function ne(t) {
234
255
  };
235
256
  },
236
257
  disconnect: async () => {
237
- var e, n;
238
- await ((n = (e = O()) == null ? void 0 : e.disconnect) == null ? void 0 : n.call(e));
258
+ var t, n;
259
+ await ((n = (t = A()) == null ? void 0 : t.disconnect) == null ? void 0 : n.call(t));
239
260
  },
240
- signMessage: async (e) => {
241
- const n = O();
242
- if (!n) throw new u("PROVIDER_NOT_FOUND", "Phantom provider was not found.");
243
- const a = new TextEncoder().encode(e), { signature: s } = await n.signMessage(a, "utf8");
244
- return te(s);
261
+ signMessage: async (t) => {
262
+ const n = A();
263
+ if (!n) throw new w("PROVIDER_NOT_FOUND", "Phantom provider was not found.");
264
+ const a = new TextEncoder().encode(t), { signature: s } = await n.signMessage(a, "utf8");
265
+ return oe(s);
245
266
  },
246
- getDeepLink: (e) => W("phantom", e, t)
267
+ getDeepLink: (t) => F("phantom", t, e)
247
268
  };
248
269
  }
249
- function ae(t) {
270
+ function ce(e) {
250
271
  return [
251
- x({ id: "metamask", name: "MetaMask", icon: "M", deepLinks: t }),
252
- x({ id: "okx", name: "OKX Wallet", icon: "O", deepLinks: t }),
253
- ne(t)
272
+ U({ id: "metamask", name: "MetaMask", icon: "M", deepLinks: e }),
273
+ U({ id: "okx", name: "OKX Wallet", icon: "O", deepLinks: e }),
274
+ re(e)
254
275
  ];
255
276
  }
256
- const se = 3e4, re = "rainbow-wallet-kit:wallet-state", oe = {
277
+ const ie = 3e4, de = "rainbow-wallet-kit:wallet-state", le = {
257
278
  status: "idle",
258
279
  updatedAt: Date.now()
259
- }, U = V(void 0);
260
- function ue({
261
- children: t,
262
- auth: e,
280
+ }, J = z(void 0);
281
+ function me({
282
+ children: e,
283
+ auth: t,
263
284
  deepLinks: n,
264
- connectTimeoutMs: a = se,
265
- storageKey: s = re,
285
+ connectTimeoutMs: a = ie,
286
+ storageKey: s = de,
266
287
  initialWallet: h,
267
- autoConnect: f
288
+ autoConnect: g
268
289
  }) {
269
- const w = C(new j()), T = C(null), [o, v] = R(oe), c = I(() => ae(n), [n]), l = D((r) => {
270
- var i;
271
- v(r), w.current.emit("state", r), (i = T.current) == null || i.publish(r);
272
- }, []), E = D(
273
- async (r) => {
274
- const i = c.find((d) => d.id === r);
275
- if (!i) return;
276
- if (!i.installed() && (n == null ? void 0 : n.enabled) !== !1 && G()) {
277
- window.location.href = i.getDeepLink(Y(n));
290
+ const l = M(new L()), y = M(null), [r, k] = K(le), i = P(() => ce(n), [n]), u = D((o) => {
291
+ var c;
292
+ k(o), l.current.emit("state", o), (c = y.current) == null || c.publish(o);
293
+ }, []), O = D(
294
+ async (o) => {
295
+ const c = i.find((d) => d.id === o);
296
+ if (!c) return;
297
+ if (!c.installed() && (n == null ? void 0 : n.enabled) !== !1 && (n != null && n.openOnConnect) && Z()) {
298
+ window.location.href = c.getDeepLink(R(n));
278
299
  return;
279
300
  }
280
- const p = {
281
- ...o,
301
+ if (!c.installed()) {
302
+ const d = new w("PROVIDER_NOT_FOUND", `${c.name} extension was not found.`);
303
+ throw u({
304
+ status: "error",
305
+ wallet: o,
306
+ error: d,
307
+ updatedAt: Date.now()
308
+ }), l.current.emit("error", d), d;
309
+ }
310
+ const m = {
311
+ ...r,
282
312
  status: "connecting",
283
- wallet: r,
313
+ wallet: o,
284
314
  error: void 0,
285
315
  updatedAt: Date.now()
286
316
  };
287
- l(p);
317
+ u(m);
288
318
  try {
289
- const d = await X(
290
- i.connect(),
319
+ const d = await ee(
320
+ c.connect(),
291
321
  a,
292
- `${i.name} connection timed out.`
293
- ), g = await L({
294
- auth: e,
295
- wallet: r,
322
+ `${c.name} connection timed out.`
323
+ ), T = await X({
324
+ auth: t,
325
+ wallet: o,
296
326
  account: d,
297
- signMessage: (F) => i.signMessage(F, d)
327
+ signMessage: (V) => c.signMessage(V, d)
298
328
  });
299
- l({
329
+ u({
300
330
  status: "connected",
301
- wallet: r,
331
+ wallet: o,
302
332
  account: d,
303
- auth: g,
333
+ auth: T,
304
334
  updatedAt: Date.now()
305
- }), w.current.emit("accountChanged", d);
335
+ }), l.current.emit("accountChanged", d);
306
336
  } catch (d) {
307
- const g = M(d);
308
- throw l({
337
+ const T = W(d);
338
+ throw u({
309
339
  status: "error",
310
- wallet: r,
311
- error: g,
340
+ wallet: o,
341
+ error: T,
312
342
  updatedAt: Date.now()
313
- }), w.current.emit("error", g), g;
343
+ }), l.current.emit("error", T), T;
314
344
  }
315
345
  },
316
- [e, a, n, l, o, c]
317
- ), _ = D(async () => {
318
- var p;
319
- const r = c.find((d) => d.id === o.wallet);
320
- await ((p = r == null ? void 0 : r.disconnect) == null ? void 0 : p.call(r));
321
- const i = {
346
+ [t, a, n, u, r, i]
347
+ ), C = D(
348
+ (o) => {
349
+ const c = i.find((m) => m.id === o);
350
+ !c || (n == null ? void 0 : n.enabled) === !1 || typeof window > "u" || (window.location.href = c.getDeepLink(R(n)));
351
+ },
352
+ [n, i]
353
+ ), I = D(async () => {
354
+ var m;
355
+ const o = i.find((d) => d.id === r.wallet);
356
+ await ((m = o == null ? void 0 : o.disconnect) == null ? void 0 : m.call(o));
357
+ const c = {
322
358
  status: "disconnected",
323
359
  updatedAt: Date.now()
324
360
  };
325
- l(i), w.current.emit("disconnect", void 0);
326
- }, [l, o.wallet, c]), N = D(async () => {
327
- const r = await z({
328
- auth: e,
329
- session: o.auth,
330
- wallet: o.wallet,
331
- account: o.account
361
+ u(c), l.current.emit("disconnect", void 0);
362
+ }, [u, r.wallet, i]), b = D(async () => {
363
+ const o = await Y({
364
+ auth: t,
365
+ session: r.auth,
366
+ wallet: r.wallet,
367
+ account: r.account
332
368
  });
333
- r && o.status === "connected" && l({
334
- ...o,
335
- auth: r,
369
+ o && r.status === "connected" && u({
370
+ ...r,
371
+ auth: o,
336
372
  updatedAt: Date.now()
337
373
  });
338
- }, [e, l, o]);
339
- b(() => {
340
- const r = new Z(w.current, s);
341
- T.current = r;
342
- const i = r.read();
343
- i && v(i);
344
- const p = w.current.on("state", (d) => {
345
- v((g) => d.updatedAt >= g.updatedAt ? d : g);
374
+ }, [t, u, r]);
375
+ v(() => {
376
+ const o = new ne(l.current, s);
377
+ y.current = o;
378
+ const c = o.read();
379
+ c && k(c);
380
+ const m = l.current.on("state", (d) => {
381
+ k((T) => d.updatedAt >= T.updatedAt ? d : T);
346
382
  });
347
383
  return () => {
348
- p(), r.destroy();
384
+ m(), o.destroy();
349
385
  };
350
- }, [s]), b(() => {
351
- f && h && E(h).catch(() => {
386
+ }, [s]), v(() => {
387
+ g && h && O(h).catch(() => {
352
388
  });
353
- }, [f, E, h]), b(() => {
354
- if (!o.auth || o.status !== "connected") return;
355
- const r = H(o.auth, e == null ? void 0 : e.renewalWindowMs), i = window.setTimeout(() => {
356
- N().catch((p) => {
357
- const d = M(p);
358
- l({ ...o, status: "error", error: d, updatedAt: Date.now() });
389
+ }, [g, O, h]), v(() => {
390
+ if (!r.auth || r.status !== "connected") return;
391
+ const o = Q(r.auth, t == null ? void 0 : t.renewalWindowMs), c = window.setTimeout(() => {
392
+ b().catch((m) => {
393
+ const d = W(m);
394
+ u({ ...r, status: "error", error: d, updatedAt: Date.now() });
359
395
  });
360
- }, r);
361
- return () => window.clearTimeout(i);
362
- }, [e == null ? void 0 : e.renewalWindowMs, l, N, o]);
363
- const $ = I(
396
+ }, o);
397
+ return () => window.clearTimeout(c);
398
+ }, [t == null ? void 0 : t.renewalWindowMs, u, b, r]);
399
+ const q = P(
364
400
  () => ({
365
- state: o,
366
- wallets: c,
367
- connect: E,
368
- disconnect: _,
369
- refreshAuth: N
401
+ state: r,
402
+ wallets: i,
403
+ connect: O,
404
+ disconnect: I,
405
+ openWalletApp: C,
406
+ refreshAuth: b
370
407
  }),
371
- [E, _, N, o, c]
408
+ [O, I, C, b, r, i]
372
409
  );
373
- return /* @__PURE__ */ m(U.Provider, { value: $, children: t });
410
+ return /* @__PURE__ */ f(J.Provider, { value: q, children: e });
374
411
  }
375
- function ce() {
376
- const t = q(U);
377
- if (!t)
412
+ function ue() {
413
+ const e = H(J);
414
+ if (!e)
378
415
  throw new Error("useWallet must be used inside WalletProvider.");
379
- return t;
416
+ return e;
380
417
  }
381
- function he({
382
- label: t = "Connect Wallet",
383
- className: e = "",
418
+ function ge({
419
+ label: e = "Connect Wallet",
420
+ className: t = "",
384
421
  preferredWallets: n,
385
422
  onError: a
386
423
  }) {
387
- const { state: s, wallets: h, connect: f, disconnect: w } = ce(), [T, o] = R(!1), v = n != null && n.length ? n.flatMap((c) => h.filter((l) => l.id === c)) : h;
388
- return s.status === "connected" && s.account ? /* @__PURE__ */ k("div", { className: `rwk-root ${e}`, children: [
389
- /* @__PURE__ */ k("button", { className: "rwk-account", type: "button", onClick: () => o((c) => !c), children: [
390
- /* @__PURE__ */ m("span", { className: "rwk-status-dot" }),
391
- /* @__PURE__ */ m("span", { children: P(s.account.address) })
424
+ const { state: s, wallets: h, connect: g, disconnect: l } = ue(), [y, r] = K(!1), k = n != null && n.length ? n.flatMap((i) => h.filter((u) => u.id === i)) : h;
425
+ return s.status === "connected" && s.account ? /* @__PURE__ */ N("div", { className: `rwk-root ${t}`, children: [
426
+ /* @__PURE__ */ N("button", { className: "rwk-account", type: "button", onClick: () => r((i) => !i), children: [
427
+ /* @__PURE__ */ f("span", { className: "rwk-status-dot" }),
428
+ /* @__PURE__ */ f("span", { children: $(s.account.address) })
392
429
  ] }),
393
- T ? /* @__PURE__ */ k("div", { className: "rwk-panel", role: "dialog", "aria-label": "Wallet account", children: [
394
- /* @__PURE__ */ k("div", { className: "rwk-account-row", children: [
395
- /* @__PURE__ */ m("span", { children: s.wallet }),
396
- /* @__PURE__ */ m("strong", { children: P(s.account.address) })
430
+ y ? /* @__PURE__ */ N("div", { className: "rwk-panel", role: "dialog", "aria-label": "Wallet account", children: [
431
+ /* @__PURE__ */ N("div", { className: "rwk-account-row", children: [
432
+ /* @__PURE__ */ f("span", { children: s.wallet }),
433
+ /* @__PURE__ */ f("strong", { children: $(s.account.address) })
397
434
  ] }),
398
- /* @__PURE__ */ m("button", { className: "rwk-disconnect", type: "button", onClick: () => void w(), children: "Disconnect" })
435
+ /* @__PURE__ */ f("button", { className: "rwk-disconnect", type: "button", onClick: () => void l(), children: "Disconnect" })
399
436
  ] }) : null
400
- ] }) : /* @__PURE__ */ k("div", { className: `rwk-root ${e}`, children: [
401
- /* @__PURE__ */ m(
437
+ ] }) : /* @__PURE__ */ N("div", { className: `rwk-root ${t}`, children: [
438
+ /* @__PURE__ */ f(
402
439
  "button",
403
440
  {
404
441
  className: "rwk-connect",
405
442
  type: "button",
406
443
  disabled: s.status === "connecting",
407
- onClick: () => o((c) => !c),
408
- children: s.status === "connecting" ? "Connecting..." : t
444
+ onClick: () => r((i) => !i),
445
+ children: s.status === "connecting" ? "Connecting..." : e
409
446
  }
410
447
  ),
411
- T ? /* @__PURE__ */ k("div", { className: "rwk-panel", role: "dialog", "aria-label": "Connect wallet", children: [
412
- v.map((c) => /* @__PURE__ */ k(
448
+ y ? /* @__PURE__ */ N("div", { className: "rwk-panel", role: "dialog", "aria-label": "Connect wallet", children: [
449
+ k.map((i) => /* @__PURE__ */ N(
413
450
  "button",
414
451
  {
415
452
  className: "rwk-wallet",
416
453
  type: "button",
417
454
  onClick: () => {
418
- f(c.id).then(() => o(!1)).catch((l) => a == null ? void 0 : a(l));
455
+ g(i.id).then(() => r(!1)).catch((u) => a == null ? void 0 : a(u));
419
456
  },
420
457
  children: [
421
- /* @__PURE__ */ m("span", { className: "rwk-wallet-icon", children: c.icon }),
422
- /* @__PURE__ */ m("span", { children: c.name }),
423
- /* @__PURE__ */ m("small", { children: c.installed() ? "Detected" : "Open app" })
458
+ /* @__PURE__ */ f("span", { className: "rwk-wallet-icon", children: i.icon }),
459
+ /* @__PURE__ */ f("span", { children: i.name }),
460
+ /* @__PURE__ */ f("small", { children: i.installed() ? "Detected" : "Not installed" })
424
461
  ]
425
462
  },
426
- c.id
463
+ i.id
427
464
  )),
428
- s.error ? /* @__PURE__ */ m("p", { className: "rwk-error", children: s.error.message }) : null
465
+ s.error ? /* @__PURE__ */ f("p", { className: "rwk-error", children: s.error.message }) : null
429
466
  ] }) : null
430
467
  ] });
431
468
  }
432
- function P(t) {
433
- return t.length <= 12 ? t : `${t.slice(0, 6)}...${t.slice(-4)}`;
469
+ function $(e) {
470
+ return e.length <= 12 ? e : `${e.slice(0, 6)}...${e.slice(-4)}`;
434
471
  }
435
472
  export {
436
- he as ConnectWalletButton,
437
- j as EventEmitter,
438
- U as WalletContext,
439
- u as WalletKitError,
440
- ue as WalletProvider,
441
- Z as WalletStateSync,
442
- L as authenticateWallet,
443
- B as createNonceMessage,
444
- ae as createWalletAdapters,
445
- M as normalizeWalletError,
446
- z as refreshJwtSession,
447
- ce as useWallet,
448
- X as withTimeout
473
+ ge as ConnectWalletButton,
474
+ L as EventEmitter,
475
+ J as WalletContext,
476
+ w as WalletKitError,
477
+ me as WalletProvider,
478
+ ne as WalletStateSync,
479
+ X as authenticateWallet,
480
+ G as createNonceMessage,
481
+ ce as createWalletAdapters,
482
+ W as normalizeWalletError,
483
+ Y as refreshJwtSession,
484
+ ue as useWallet,
485
+ ee as withTimeout
449
486
  };
450
487
  //# sourceMappingURL=index.mjs.map