@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/README.md +10 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +301 -264
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,231 +1,252 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { createContext as
|
|
6
|
-
class
|
|
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
|
-
|
|
10
|
-
|
|
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
|
|
14
|
+
function G(e) {
|
|
15
15
|
return [
|
|
16
|
-
|
|
16
|
+
e.audience ?? "Wallet Login",
|
|
17
17
|
"",
|
|
18
|
-
`Wallet: ${
|
|
19
|
-
`Address: ${
|
|
20
|
-
`Chain: ${
|
|
21
|
-
`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
|
|
26
|
+
async function X(e) {
|
|
27
27
|
var s;
|
|
28
|
-
if (!((s =
|
|
29
|
-
if (!
|
|
30
|
-
throw new
|
|
31
|
-
const
|
|
32
|
-
wallet:
|
|
33
|
-
address:
|
|
34
|
-
chainType:
|
|
35
|
-
audience:
|
|
36
|
-
}), n =
|
|
37
|
-
nonce:
|
|
38
|
-
address:
|
|
39
|
-
wallet:
|
|
40
|
-
chainType:
|
|
41
|
-
audience:
|
|
42
|
-
}), a = await
|
|
43
|
-
throw new
|
|
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
|
|
46
|
-
wallet:
|
|
47
|
-
address:
|
|
48
|
-
chainType:
|
|
49
|
-
audience:
|
|
50
|
-
nonce:
|
|
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
|
|
56
|
-
var
|
|
57
|
-
if (!((
|
|
58
|
-
return
|
|
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
|
|
61
|
-
token:
|
|
62
|
-
refreshToken:
|
|
63
|
-
wallet:
|
|
64
|
-
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
|
|
67
|
+
throw new w("JWT_REFRESH_FAILED", "JWT refresh failed.", n);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
function
|
|
71
|
-
return Math.max(0,
|
|
70
|
+
function Q(e, t = 6e4) {
|
|
71
|
+
return Math.max(0, e.expiresAt - Date.now() - t);
|
|
72
72
|
}
|
|
73
|
-
const
|
|
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
|
|
78
|
+
function Z() {
|
|
79
79
|
return typeof navigator > "u" ? !1 : /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
81
|
+
function R(e) {
|
|
82
|
+
return e != null && e.dappUrl ? e.dappUrl : typeof window > "u" ? "" : window.location.href;
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
const a = encodeURIComponent(
|
|
86
|
-
return
|
|
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
|
|
88
|
+
class L {
|
|
89
89
|
constructor() {
|
|
90
|
-
|
|
90
|
+
E(this, "listeners", /* @__PURE__ */ new Map());
|
|
91
91
|
}
|
|
92
|
-
on(
|
|
93
|
-
const a = this.listeners.get(
|
|
94
|
-
return a.add(n), this.listeners.set(
|
|
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(
|
|
96
|
+
off(t, n) {
|
|
97
97
|
var a;
|
|
98
|
-
(a = this.listeners.get(
|
|
98
|
+
(a = this.listeners.get(t)) == null || a.delete(n);
|
|
99
99
|
}
|
|
100
|
-
emit(
|
|
100
|
+
emit(t, n) {
|
|
101
101
|
var a;
|
|
102
|
-
(a = this.listeners.get(
|
|
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
|
|
108
|
+
function W(e) {
|
|
109
109
|
var n;
|
|
110
|
-
if (
|
|
111
|
-
const
|
|
112
|
-
return (
|
|
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
|
|
114
|
+
function ee(e, t, n) {
|
|
115
115
|
let a;
|
|
116
|
-
const s = new Promise((h,
|
|
117
|
-
a = setTimeout(() =>
|
|
116
|
+
const s = new Promise((h, g) => {
|
|
117
|
+
a = setTimeout(() => g(new w("CONNECT_TIMEOUT", n)), t);
|
|
118
118
|
});
|
|
119
|
-
return Promise.race([
|
|
119
|
+
return Promise.race([e, s]).finally(() => {
|
|
120
120
|
a && clearTimeout(a);
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
const
|
|
124
|
-
class
|
|
125
|
-
constructor(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (!(
|
|
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(
|
|
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 =
|
|
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(
|
|
141
|
+
publish(t) {
|
|
142
142
|
var a;
|
|
143
143
|
if (typeof window > "u") return;
|
|
144
|
-
const n = { tabId: this.tabId, state:
|
|
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
|
|
150
|
-
if (
|
|
149
|
+
const t = localStorage.getItem(this.storageKey);
|
|
150
|
+
if (t)
|
|
151
151
|
try {
|
|
152
|
-
return JSON.parse(
|
|
152
|
+
return JSON.parse(t).state;
|
|
153
153
|
} catch {
|
|
154
154
|
return;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
destroy() {
|
|
158
|
-
var
|
|
159
|
-
(
|
|
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(
|
|
163
|
-
var
|
|
162
|
+
function S(e) {
|
|
163
|
+
var h, g;
|
|
164
164
|
if (typeof window > "u") return;
|
|
165
|
-
const
|
|
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
|
|
168
|
-
if (
|
|
172
|
+
const l = n.find((y) => e === "metamask" ? y.isMetaMask && !y.isOkxWallet : p(y));
|
|
173
|
+
if (l) return l;
|
|
169
174
|
}
|
|
170
|
-
|
|
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
|
|
173
|
-
if (
|
|
174
|
-
return Number.parseInt(
|
|
193
|
+
function se(e) {
|
|
194
|
+
if (e)
|
|
195
|
+
return Number.parseInt(e, 16);
|
|
175
196
|
}
|
|
176
|
-
function
|
|
197
|
+
function U(e) {
|
|
177
198
|
return {
|
|
178
|
-
id:
|
|
179
|
-
name:
|
|
199
|
+
id: e.id,
|
|
200
|
+
name: e.name,
|
|
180
201
|
chainType: "evm",
|
|
181
|
-
icon:
|
|
182
|
-
installed: () => !!S(
|
|
202
|
+
icon: e.icon,
|
|
203
|
+
installed: () => !!S(e.id),
|
|
183
204
|
connect: async () => {
|
|
184
|
-
const
|
|
185
|
-
if (!
|
|
186
|
-
throw new
|
|
187
|
-
const n = await
|
|
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
|
|
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:
|
|
214
|
+
chainId: se(a)
|
|
194
215
|
};
|
|
195
216
|
},
|
|
196
|
-
signMessage: async (
|
|
197
|
-
const a = S(
|
|
198
|
-
if (!a) throw new
|
|
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: [
|
|
222
|
+
params: [t, n.address]
|
|
202
223
|
});
|
|
203
224
|
},
|
|
204
|
-
getDeepLink: (
|
|
225
|
+
getDeepLink: (t) => F(e.id, t, e.deepLinks)
|
|
205
226
|
};
|
|
206
227
|
}
|
|
207
|
-
function
|
|
208
|
-
var
|
|
228
|
+
function A() {
|
|
229
|
+
var e, t;
|
|
209
230
|
if (!(typeof window > "u"))
|
|
210
|
-
return (
|
|
231
|
+
return (t = (e = window.phantom) == null ? void 0 : e.solana) != null && t.isPhantom ? window.phantom.solana : void 0;
|
|
211
232
|
}
|
|
212
|
-
function
|
|
213
|
-
let
|
|
214
|
-
return
|
|
215
|
-
|
|
216
|
-
}), btoa(
|
|
233
|
+
function oe(e) {
|
|
234
|
+
let t = "";
|
|
235
|
+
return e.forEach((n) => {
|
|
236
|
+
t += String.fromCharCode(n);
|
|
237
|
+
}), btoa(t);
|
|
217
238
|
}
|
|
218
|
-
function
|
|
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: () => !!
|
|
245
|
+
installed: () => !!A(),
|
|
225
246
|
connect: async () => {
|
|
226
|
-
const
|
|
227
|
-
if (!
|
|
228
|
-
const a = (await
|
|
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
|
|
238
|
-
await ((n = (
|
|
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 (
|
|
241
|
-
const n =
|
|
242
|
-
if (!n) throw new
|
|
243
|
-
const a = new TextEncoder().encode(
|
|
244
|
-
return
|
|
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: (
|
|
267
|
+
getDeepLink: (t) => F("phantom", t, e)
|
|
247
268
|
};
|
|
248
269
|
}
|
|
249
|
-
function
|
|
270
|
+
function ce(e) {
|
|
250
271
|
return [
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
|
277
|
+
const ie = 3e4, de = "rainbow-wallet-kit:wallet-state", le = {
|
|
257
278
|
status: "idle",
|
|
258
279
|
updatedAt: Date.now()
|
|
259
|
-
},
|
|
260
|
-
function
|
|
261
|
-
children:
|
|
262
|
-
auth:
|
|
280
|
+
}, J = z(void 0);
|
|
281
|
+
function me({
|
|
282
|
+
children: e,
|
|
283
|
+
auth: t,
|
|
263
284
|
deepLinks: n,
|
|
264
|
-
connectTimeoutMs: a =
|
|
265
|
-
storageKey: s =
|
|
285
|
+
connectTimeoutMs: a = ie,
|
|
286
|
+
storageKey: s = de,
|
|
266
287
|
initialWallet: h,
|
|
267
|
-
autoConnect:
|
|
288
|
+
autoConnect: g
|
|
268
289
|
}) {
|
|
269
|
-
const
|
|
270
|
-
var
|
|
271
|
-
|
|
272
|
-
}, []),
|
|
273
|
-
async (
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
276
|
-
if (!
|
|
277
|
-
window.location.href =
|
|
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
|
-
|
|
281
|
-
|
|
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:
|
|
313
|
+
wallet: o,
|
|
284
314
|
error: void 0,
|
|
285
315
|
updatedAt: Date.now()
|
|
286
316
|
};
|
|
287
|
-
|
|
317
|
+
u(m);
|
|
288
318
|
try {
|
|
289
|
-
const d = await
|
|
290
|
-
|
|
319
|
+
const d = await ee(
|
|
320
|
+
c.connect(),
|
|
291
321
|
a,
|
|
292
|
-
`${
|
|
293
|
-
),
|
|
294
|
-
auth:
|
|
295
|
-
wallet:
|
|
322
|
+
`${c.name} connection timed out.`
|
|
323
|
+
), T = await X({
|
|
324
|
+
auth: t,
|
|
325
|
+
wallet: o,
|
|
296
326
|
account: d,
|
|
297
|
-
signMessage: (
|
|
327
|
+
signMessage: (V) => c.signMessage(V, d)
|
|
298
328
|
});
|
|
299
|
-
|
|
329
|
+
u({
|
|
300
330
|
status: "connected",
|
|
301
|
-
wallet:
|
|
331
|
+
wallet: o,
|
|
302
332
|
account: d,
|
|
303
|
-
auth:
|
|
333
|
+
auth: T,
|
|
304
334
|
updatedAt: Date.now()
|
|
305
|
-
}),
|
|
335
|
+
}), l.current.emit("accountChanged", d);
|
|
306
336
|
} catch (d) {
|
|
307
|
-
const
|
|
308
|
-
throw
|
|
337
|
+
const T = W(d);
|
|
338
|
+
throw u({
|
|
309
339
|
status: "error",
|
|
310
|
-
wallet:
|
|
311
|
-
error:
|
|
340
|
+
wallet: o,
|
|
341
|
+
error: T,
|
|
312
342
|
updatedAt: Date.now()
|
|
313
|
-
}),
|
|
343
|
+
}), l.current.emit("error", T), T;
|
|
314
344
|
}
|
|
315
345
|
},
|
|
316
|
-
[
|
|
317
|
-
),
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
326
|
-
}, [
|
|
327
|
-
const
|
|
328
|
-
auth:
|
|
329
|
-
session:
|
|
330
|
-
wallet:
|
|
331
|
-
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
|
-
|
|
334
|
-
...
|
|
335
|
-
auth:
|
|
369
|
+
o && r.status === "connected" && u({
|
|
370
|
+
...r,
|
|
371
|
+
auth: o,
|
|
336
372
|
updatedAt: Date.now()
|
|
337
373
|
});
|
|
338
|
-
}, [
|
|
339
|
-
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
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
|
-
|
|
384
|
+
m(), o.destroy();
|
|
349
385
|
};
|
|
350
|
-
}, [s]),
|
|
351
|
-
|
|
386
|
+
}, [s]), v(() => {
|
|
387
|
+
g && h && O(h).catch(() => {
|
|
352
388
|
});
|
|
353
|
-
}, [
|
|
354
|
-
if (!
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
const d =
|
|
358
|
-
|
|
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
|
-
},
|
|
361
|
-
return () => window.clearTimeout(
|
|
362
|
-
}, [
|
|
363
|
-
const
|
|
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:
|
|
366
|
-
wallets:
|
|
367
|
-
connect:
|
|
368
|
-
disconnect:
|
|
369
|
-
|
|
401
|
+
state: r,
|
|
402
|
+
wallets: i,
|
|
403
|
+
connect: O,
|
|
404
|
+
disconnect: I,
|
|
405
|
+
openWalletApp: C,
|
|
406
|
+
refreshAuth: b
|
|
370
407
|
}),
|
|
371
|
-
[
|
|
408
|
+
[O, I, C, b, r, i]
|
|
372
409
|
);
|
|
373
|
-
return /* @__PURE__ */
|
|
410
|
+
return /* @__PURE__ */ f(J.Provider, { value: q, children: e });
|
|
374
411
|
}
|
|
375
|
-
function
|
|
376
|
-
const
|
|
377
|
-
if (!
|
|
412
|
+
function ue() {
|
|
413
|
+
const e = H(J);
|
|
414
|
+
if (!e)
|
|
378
415
|
throw new Error("useWallet must be used inside WalletProvider.");
|
|
379
|
-
return
|
|
416
|
+
return e;
|
|
380
417
|
}
|
|
381
|
-
function
|
|
382
|
-
label:
|
|
383
|
-
className:
|
|
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:
|
|
388
|
-
return s.status === "connected" && s.account ? /* @__PURE__ */
|
|
389
|
-
/* @__PURE__ */
|
|
390
|
-
/* @__PURE__ */
|
|
391
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
394
|
-
/* @__PURE__ */
|
|
395
|
-
/* @__PURE__ */
|
|
396
|
-
/* @__PURE__ */
|
|
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__ */
|
|
435
|
+
/* @__PURE__ */ f("button", { className: "rwk-disconnect", type: "button", onClick: () => void l(), children: "Disconnect" })
|
|
399
436
|
] }) : null
|
|
400
|
-
] }) : /* @__PURE__ */
|
|
401
|
-
/* @__PURE__ */
|
|
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: () =>
|
|
408
|
-
children: s.status === "connecting" ? "Connecting..." :
|
|
444
|
+
onClick: () => r((i) => !i),
|
|
445
|
+
children: s.status === "connecting" ? "Connecting..." : e
|
|
409
446
|
}
|
|
410
447
|
),
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
455
|
+
g(i.id).then(() => r(!1)).catch((u) => a == null ? void 0 : a(u));
|
|
419
456
|
},
|
|
420
457
|
children: [
|
|
421
|
-
/* @__PURE__ */
|
|
422
|
-
/* @__PURE__ */
|
|
423
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
463
|
+
i.id
|
|
427
464
|
)),
|
|
428
|
-
s.error ? /* @__PURE__ */
|
|
465
|
+
s.error ? /* @__PURE__ */ f("p", { className: "rwk-error", children: s.error.message }) : null
|
|
429
466
|
] }) : null
|
|
430
467
|
] });
|
|
431
468
|
}
|
|
432
|
-
function
|
|
433
|
-
return
|
|
469
|
+
function $(e) {
|
|
470
|
+
return e.length <= 12 ? e : `${e.slice(0, 6)}...${e.slice(-4)}`;
|
|
434
471
|
}
|
|
435
472
|
export {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|