@qinzhehan/rainbow-wallet-kit 0.1.1 → 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 V = Object.defineProperty;
2
- var q = (t, e, n) => e in t ? V(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var p = (t, e, n) => q(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { jsx as m, jsxs as T } from "react/jsx-runtime";
5
- import { createContext as B, useRef as I, useState as U, useMemo as M, useCallback as E, useEffect as b, useContext as z } 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
- p(this, "code");
10
- p(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 H(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 G(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 = H({
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 Y(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 j(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 X() {
78
+ function Z() {
79
79
  return typeof navigator > "u" ? !1 : /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
80
80
  }
81
- function x(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 $(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 Q {
88
+ class L {
89
89
  constructor() {
90
- p(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 R(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 Z(t, e, n) {
114
+ function ee(e, t, n) {
115
115
  let a;
116
116
  const s = new Promise((h, g) => {
117
- a = setTimeout(() => g(new u("CONNECT_TIMEOUT", n)), e);
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 L = "rainbow-wallet-kit:state";
124
- class ee {
125
- constructor(e, n) {
126
- p(this, "channel");
127
- p(this, "tabId", Math.random().toString(36).slice(2));
128
- p(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(L), 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 _(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 g = n.find((w) => t === "metamask" ? w.isMetaMask && !w.isOkxWallet : w.isOkxWallet);
168
- if (g) return g;
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 te(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 P(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: () => !!_(t.id),
202
+ icon: e.icon,
203
+ installed: () => !!S(e.id),
183
204
  connect: async () => {
184
- const e = _(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: te(a)
214
+ chainId: se(a)
194
215
  };
195
216
  },
196
- signMessage: async (e, n) => {
197
- const a = _(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) => $(t.id, e, t.deepLinks)
225
+ getDeepLink: (t) => F(e.id, t, e.deepLinks)
205
226
  };
206
227
  }
207
- function k() {
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 ne(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 ae(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: () => !!k(),
245
+ installed: () => !!A(),
225
246
  connect: async () => {
226
- const e = k();
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,233 +255,233 @@ function ae(t) {
234
255
  };
235
256
  },
236
257
  disconnect: async () => {
237
- var e, n;
238
- await ((n = (e = k()) == 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 = k();
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 ne(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) => $("phantom", e, t)
267
+ getDeepLink: (t) => F("phantom", t, e)
247
268
  };
248
269
  }
249
- function se(t) {
270
+ function ce(e) {
250
271
  return [
251
- P({ id: "metamask", name: "MetaMask", icon: "M", deepLinks: t }),
252
- P({ id: "okx", name: "OKX Wallet", icon: "O", deepLinks: t }),
253
- ae(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 re = 3e4, oe = "rainbow-wallet-kit:wallet-state", ce = {
277
+ const ie = 3e4, de = "rainbow-wallet-kit:wallet-state", le = {
257
278
  status: "idle",
258
279
  updatedAt: Date.now()
259
- }, F = B(void 0);
260
- function we({
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 = re,
265
- storageKey: s = oe,
285
+ connectTimeoutMs: a = ie,
286
+ storageKey: s = de,
266
287
  initialWallet: h,
267
288
  autoConnect: g
268
289
  }) {
269
- const w = I(new Q()), N = I(null), [o, v] = U(ce), i = M(() => se(n), [n]), l = E((r) => {
290
+ const l = M(new L()), y = M(null), [r, k] = K(le), i = P(() => ce(n), [n]), u = D((o) => {
270
291
  var c;
271
- v(r), w.current.emit("state", r), (c = N.current) == null || c.publish(r);
272
- }, []), D = E(
273
- async (r) => {
274
- const c = i.find((d) => d.id === r);
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);
275
296
  if (!c) return;
276
- if (!c.installed() && (n == null ? void 0 : n.enabled) !== !1 && (n != null && n.openOnConnect) && X()) {
277
- window.location.href = c.getDeepLink(x(n));
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
301
  if (!c.installed()) {
281
- const d = new u("PROVIDER_NOT_FOUND", `${c.name} extension was not found.`);
282
- throw l({
302
+ const d = new w("PROVIDER_NOT_FOUND", `${c.name} extension was not found.`);
303
+ throw u({
283
304
  status: "error",
284
- wallet: r,
305
+ wallet: o,
285
306
  error: d,
286
307
  updatedAt: Date.now()
287
- }), w.current.emit("error", d), d;
308
+ }), l.current.emit("error", d), d;
288
309
  }
289
- const f = {
290
- ...o,
310
+ const m = {
311
+ ...r,
291
312
  status: "connecting",
292
- wallet: r,
313
+ wallet: o,
293
314
  error: void 0,
294
315
  updatedAt: Date.now()
295
316
  };
296
- l(f);
317
+ u(m);
297
318
  try {
298
- const d = await Z(
319
+ const d = await ee(
299
320
  c.connect(),
300
321
  a,
301
322
  `${c.name} connection timed out.`
302
- ), y = await G({
303
- auth: e,
304
- wallet: r,
323
+ ), T = await X({
324
+ auth: t,
325
+ wallet: o,
305
326
  account: d,
306
- signMessage: (K) => c.signMessage(K, d)
327
+ signMessage: (V) => c.signMessage(V, d)
307
328
  });
308
- l({
329
+ u({
309
330
  status: "connected",
310
- wallet: r,
331
+ wallet: o,
311
332
  account: d,
312
- auth: y,
333
+ auth: T,
313
334
  updatedAt: Date.now()
314
- }), w.current.emit("accountChanged", d);
335
+ }), l.current.emit("accountChanged", d);
315
336
  } catch (d) {
316
- const y = R(d);
317
- throw l({
337
+ const T = W(d);
338
+ throw u({
318
339
  status: "error",
319
- wallet: r,
320
- error: y,
340
+ wallet: o,
341
+ error: T,
321
342
  updatedAt: Date.now()
322
- }), w.current.emit("error", y), y;
343
+ }), l.current.emit("error", T), T;
323
344
  }
324
345
  },
325
- [e, a, n, l, o, i]
326
- ), S = E(
327
- (r) => {
328
- const c = i.find((f) => f.id === r);
329
- !c || (n == null ? void 0 : n.enabled) === !1 || typeof window > "u" || (window.location.href = c.getDeepLink(x(n)));
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)));
330
351
  },
331
352
  [n, i]
332
- ), C = E(async () => {
333
- var f;
334
- const r = i.find((d) => d.id === o.wallet);
335
- await ((f = r == null ? void 0 : r.disconnect) == null ? void 0 : f.call(r));
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));
336
357
  const c = {
337
358
  status: "disconnected",
338
359
  updatedAt: Date.now()
339
360
  };
340
- l(c), w.current.emit("disconnect", void 0);
341
- }, [l, o.wallet, i]), O = E(async () => {
342
- const r = await Y({
343
- auth: e,
344
- session: o.auth,
345
- wallet: o.wallet,
346
- 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
347
368
  });
348
- r && o.status === "connected" && l({
349
- ...o,
350
- auth: r,
369
+ o && r.status === "connected" && u({
370
+ ...r,
371
+ auth: o,
351
372
  updatedAt: Date.now()
352
373
  });
353
- }, [e, l, o]);
354
- b(() => {
355
- const r = new ee(w.current, s);
356
- N.current = r;
357
- const c = r.read();
358
- c && v(c);
359
- const f = w.current.on("state", (d) => {
360
- v((y) => d.updatedAt >= y.updatedAt ? d : y);
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);
361
382
  });
362
383
  return () => {
363
- f(), r.destroy();
384
+ m(), o.destroy();
364
385
  };
365
- }, [s]), b(() => {
366
- g && h && D(h).catch(() => {
386
+ }, [s]), v(() => {
387
+ g && h && O(h).catch(() => {
367
388
  });
368
- }, [g, D, h]), b(() => {
369
- if (!o.auth || o.status !== "connected") return;
370
- const r = j(o.auth, e == null ? void 0 : e.renewalWindowMs), c = window.setTimeout(() => {
371
- O().catch((f) => {
372
- const d = R(f);
373
- 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() });
374
395
  });
375
- }, r);
396
+ }, o);
376
397
  return () => window.clearTimeout(c);
377
- }, [e == null ? void 0 : e.renewalWindowMs, l, O, o]);
378
- const J = M(
398
+ }, [t == null ? void 0 : t.renewalWindowMs, u, b, r]);
399
+ const q = P(
379
400
  () => ({
380
- state: o,
401
+ state: r,
381
402
  wallets: i,
382
- connect: D,
383
- disconnect: C,
384
- openWalletApp: S,
385
- refreshAuth: O
403
+ connect: O,
404
+ disconnect: I,
405
+ openWalletApp: C,
406
+ refreshAuth: b
386
407
  }),
387
- [D, C, S, O, o, i]
408
+ [O, I, C, b, r, i]
388
409
  );
389
- return /* @__PURE__ */ m(F.Provider, { value: J, children: t });
410
+ return /* @__PURE__ */ f(J.Provider, { value: q, children: e });
390
411
  }
391
- function ie() {
392
- const t = z(F);
393
- if (!t)
412
+ function ue() {
413
+ const e = H(J);
414
+ if (!e)
394
415
  throw new Error("useWallet must be used inside WalletProvider.");
395
- return t;
416
+ return e;
396
417
  }
397
- function he({
398
- label: t = "Connect Wallet",
399
- className: e = "",
418
+ function ge({
419
+ label: e = "Connect Wallet",
420
+ className: t = "",
400
421
  preferredWallets: n,
401
422
  onError: a
402
423
  }) {
403
- const { state: s, wallets: h, connect: g, disconnect: w } = ie(), [N, o] = U(!1), v = n != null && n.length ? n.flatMap((i) => h.filter((l) => l.id === i)) : h;
404
- return s.status === "connected" && s.account ? /* @__PURE__ */ T("div", { className: `rwk-root ${e}`, children: [
405
- /* @__PURE__ */ T("button", { className: "rwk-account", type: "button", onClick: () => o((i) => !i), children: [
406
- /* @__PURE__ */ m("span", { className: "rwk-status-dot" }),
407
- /* @__PURE__ */ m("span", { children: W(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) })
408
429
  ] }),
409
- N ? /* @__PURE__ */ T("div", { className: "rwk-panel", role: "dialog", "aria-label": "Wallet account", children: [
410
- /* @__PURE__ */ T("div", { className: "rwk-account-row", children: [
411
- /* @__PURE__ */ m("span", { children: s.wallet }),
412
- /* @__PURE__ */ m("strong", { children: W(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) })
413
434
  ] }),
414
- /* @__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" })
415
436
  ] }) : null
416
- ] }) : /* @__PURE__ */ T("div", { className: `rwk-root ${e}`, children: [
417
- /* @__PURE__ */ m(
437
+ ] }) : /* @__PURE__ */ N("div", { className: `rwk-root ${t}`, children: [
438
+ /* @__PURE__ */ f(
418
439
  "button",
419
440
  {
420
441
  className: "rwk-connect",
421
442
  type: "button",
422
443
  disabled: s.status === "connecting",
423
- onClick: () => o((i) => !i),
424
- children: s.status === "connecting" ? "Connecting..." : t
444
+ onClick: () => r((i) => !i),
445
+ children: s.status === "connecting" ? "Connecting..." : e
425
446
  }
426
447
  ),
427
- N ? /* @__PURE__ */ T("div", { className: "rwk-panel", role: "dialog", "aria-label": "Connect wallet", children: [
428
- v.map((i) => /* @__PURE__ */ T(
448
+ y ? /* @__PURE__ */ N("div", { className: "rwk-panel", role: "dialog", "aria-label": "Connect wallet", children: [
449
+ k.map((i) => /* @__PURE__ */ N(
429
450
  "button",
430
451
  {
431
452
  className: "rwk-wallet",
432
453
  type: "button",
433
454
  onClick: () => {
434
- g(i.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));
435
456
  },
436
457
  children: [
437
- /* @__PURE__ */ m("span", { className: "rwk-wallet-icon", children: i.icon }),
438
- /* @__PURE__ */ m("span", { children: i.name }),
439
- /* @__PURE__ */ m("small", { children: i.installed() ? "Detected" : "Not installed" })
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" })
440
461
  ]
441
462
  },
442
463
  i.id
443
464
  )),
444
- 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
445
466
  ] }) : null
446
467
  ] });
447
468
  }
448
- function W(t) {
449
- 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)}`;
450
471
  }
451
472
  export {
452
- he as ConnectWalletButton,
453
- Q as EventEmitter,
454
- F as WalletContext,
455
- u as WalletKitError,
456
- we as WalletProvider,
457
- ee as WalletStateSync,
458
- G as authenticateWallet,
459
- H as createNonceMessage,
460
- se as createWalletAdapters,
461
- R as normalizeWalletError,
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,
462
483
  Y as refreshJwtSession,
463
- ie as useWallet,
464
- Z as withTimeout
484
+ ue as useWallet,
485
+ ee as withTimeout
465
486
  };
466
487
  //# sourceMappingURL=index.mjs.map