@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/README.md +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +283 -262
- 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 Y(
|
|
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
116
|
const s = new Promise((h, g) => {
|
|
117
|
-
a = setTimeout(() => g(new
|
|
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
|
|
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: () => !!
|
|
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 =
|
|
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,233 +255,233 @@ function ae(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
288
|
autoConnect: g
|
|
268
289
|
}) {
|
|
269
|
-
const
|
|
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
|
-
|
|
272
|
-
}, []),
|
|
273
|
-
async (
|
|
274
|
-
const c = i.find((d) => d.id ===
|
|
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) &&
|
|
277
|
-
window.location.href = c.getDeepLink(
|
|
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
|
|
282
|
-
throw
|
|
302
|
+
const d = new w("PROVIDER_NOT_FOUND", `${c.name} extension was not found.`);
|
|
303
|
+
throw u({
|
|
283
304
|
status: "error",
|
|
284
|
-
wallet:
|
|
305
|
+
wallet: o,
|
|
285
306
|
error: d,
|
|
286
307
|
updatedAt: Date.now()
|
|
287
|
-
}),
|
|
308
|
+
}), l.current.emit("error", d), d;
|
|
288
309
|
}
|
|
289
|
-
const
|
|
290
|
-
...
|
|
310
|
+
const m = {
|
|
311
|
+
...r,
|
|
291
312
|
status: "connecting",
|
|
292
|
-
wallet:
|
|
313
|
+
wallet: o,
|
|
293
314
|
error: void 0,
|
|
294
315
|
updatedAt: Date.now()
|
|
295
316
|
};
|
|
296
|
-
|
|
317
|
+
u(m);
|
|
297
318
|
try {
|
|
298
|
-
const d = await
|
|
319
|
+
const d = await ee(
|
|
299
320
|
c.connect(),
|
|
300
321
|
a,
|
|
301
322
|
`${c.name} connection timed out.`
|
|
302
|
-
),
|
|
303
|
-
auth:
|
|
304
|
-
wallet:
|
|
323
|
+
), T = await X({
|
|
324
|
+
auth: t,
|
|
325
|
+
wallet: o,
|
|
305
326
|
account: d,
|
|
306
|
-
signMessage: (
|
|
327
|
+
signMessage: (V) => c.signMessage(V, d)
|
|
307
328
|
});
|
|
308
|
-
|
|
329
|
+
u({
|
|
309
330
|
status: "connected",
|
|
310
|
-
wallet:
|
|
331
|
+
wallet: o,
|
|
311
332
|
account: d,
|
|
312
|
-
auth:
|
|
333
|
+
auth: T,
|
|
313
334
|
updatedAt: Date.now()
|
|
314
|
-
}),
|
|
335
|
+
}), l.current.emit("accountChanged", d);
|
|
315
336
|
} catch (d) {
|
|
316
|
-
const
|
|
317
|
-
throw
|
|
337
|
+
const T = W(d);
|
|
338
|
+
throw u({
|
|
318
339
|
status: "error",
|
|
319
|
-
wallet:
|
|
320
|
-
error:
|
|
340
|
+
wallet: o,
|
|
341
|
+
error: T,
|
|
321
342
|
updatedAt: Date.now()
|
|
322
|
-
}),
|
|
343
|
+
}), l.current.emit("error", T), T;
|
|
323
344
|
}
|
|
324
345
|
},
|
|
325
|
-
[
|
|
326
|
-
),
|
|
327
|
-
(
|
|
328
|
-
const c = i.find((
|
|
329
|
-
!c || (n == null ? void 0 : n.enabled) === !1 || typeof window > "u" || (window.location.href = c.getDeepLink(
|
|
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
|
-
),
|
|
333
|
-
var
|
|
334
|
-
const
|
|
335
|
-
await ((
|
|
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
|
-
|
|
341
|
-
}, [
|
|
342
|
-
const
|
|
343
|
-
auth:
|
|
344
|
-
session:
|
|
345
|
-
wallet:
|
|
346
|
-
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
|
-
|
|
349
|
-
...
|
|
350
|
-
auth:
|
|
369
|
+
o && r.status === "connected" && u({
|
|
370
|
+
...r,
|
|
371
|
+
auth: o,
|
|
351
372
|
updatedAt: Date.now()
|
|
352
373
|
});
|
|
353
|
-
}, [
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
const c =
|
|
358
|
-
c &&
|
|
359
|
-
const
|
|
360
|
-
|
|
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
|
-
|
|
384
|
+
m(), o.destroy();
|
|
364
385
|
};
|
|
365
|
-
}, [s]),
|
|
366
|
-
g && h &&
|
|
386
|
+
}, [s]), v(() => {
|
|
387
|
+
g && h && O(h).catch(() => {
|
|
367
388
|
});
|
|
368
|
-
}, [g,
|
|
369
|
-
if (!
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
const d =
|
|
373
|
-
|
|
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
|
-
},
|
|
396
|
+
}, o);
|
|
376
397
|
return () => window.clearTimeout(c);
|
|
377
|
-
}, [
|
|
378
|
-
const
|
|
398
|
+
}, [t == null ? void 0 : t.renewalWindowMs, u, b, r]);
|
|
399
|
+
const q = P(
|
|
379
400
|
() => ({
|
|
380
|
-
state:
|
|
401
|
+
state: r,
|
|
381
402
|
wallets: i,
|
|
382
|
-
connect:
|
|
383
|
-
disconnect:
|
|
384
|
-
openWalletApp:
|
|
385
|
-
refreshAuth:
|
|
403
|
+
connect: O,
|
|
404
|
+
disconnect: I,
|
|
405
|
+
openWalletApp: C,
|
|
406
|
+
refreshAuth: b
|
|
386
407
|
}),
|
|
387
|
-
[
|
|
408
|
+
[O, I, C, b, r, i]
|
|
388
409
|
);
|
|
389
|
-
return /* @__PURE__ */
|
|
410
|
+
return /* @__PURE__ */ f(J.Provider, { value: q, children: e });
|
|
390
411
|
}
|
|
391
|
-
function
|
|
392
|
-
const
|
|
393
|
-
if (!
|
|
412
|
+
function ue() {
|
|
413
|
+
const e = H(J);
|
|
414
|
+
if (!e)
|
|
394
415
|
throw new Error("useWallet must be used inside WalletProvider.");
|
|
395
|
-
return
|
|
416
|
+
return e;
|
|
396
417
|
}
|
|
397
|
-
function
|
|
398
|
-
label:
|
|
399
|
-
className:
|
|
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:
|
|
404
|
-
return s.status === "connected" && s.account ? /* @__PURE__ */
|
|
405
|
-
/* @__PURE__ */
|
|
406
|
-
/* @__PURE__ */
|
|
407
|
-
/* @__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) })
|
|
408
429
|
] }),
|
|
409
|
-
|
|
410
|
-
/* @__PURE__ */
|
|
411
|
-
/* @__PURE__ */
|
|
412
|
-
/* @__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) })
|
|
413
434
|
] }),
|
|
414
|
-
/* @__PURE__ */
|
|
435
|
+
/* @__PURE__ */ f("button", { className: "rwk-disconnect", type: "button", onClick: () => void l(), children: "Disconnect" })
|
|
415
436
|
] }) : null
|
|
416
|
-
] }) : /* @__PURE__ */
|
|
417
|
-
/* @__PURE__ */
|
|
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: () =>
|
|
424
|
-
children: s.status === "connecting" ? "Connecting..." :
|
|
444
|
+
onClick: () => r((i) => !i),
|
|
445
|
+
children: s.status === "connecting" ? "Connecting..." : e
|
|
425
446
|
}
|
|
426
447
|
),
|
|
427
|
-
|
|
428
|
-
|
|
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(() =>
|
|
455
|
+
g(i.id).then(() => r(!1)).catch((u) => a == null ? void 0 : a(u));
|
|
435
456
|
},
|
|
436
457
|
children: [
|
|
437
|
-
/* @__PURE__ */
|
|
438
|
-
/* @__PURE__ */
|
|
439
|
-
/* @__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" })
|
|
440
461
|
]
|
|
441
462
|
},
|
|
442
463
|
i.id
|
|
443
464
|
)),
|
|
444
|
-
s.error ? /* @__PURE__ */
|
|
465
|
+
s.error ? /* @__PURE__ */ f("p", { className: "rwk-error", children: s.error.message }) : null
|
|
445
466
|
] }) : null
|
|
446
467
|
] });
|
|
447
468
|
}
|
|
448
|
-
function
|
|
449
|
-
return
|
|
469
|
+
function $(e) {
|
|
470
|
+
return e.length <= 12 ? e : `${e.slice(0, 6)}...${e.slice(-4)}`;
|
|
450
471
|
}
|
|
451
472
|
export {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
464
|
-
|
|
484
|
+
ue as useWallet,
|
|
485
|
+
ee as withTimeout
|
|
465
486
|
};
|
|
466
487
|
//# sourceMappingURL=index.mjs.map
|