miniwallet 0.1.16 → 0.1.17
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/miniwallet.js +136 -132
- package/package.json +1 -3
package/dist/miniwallet.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import "./miniwallet.css";
|
|
2
|
-
import { createContext as e, useCallback as t, useContext as n, useEffect as r, useMemo as i,
|
|
3
|
-
import { jsx as
|
|
2
|
+
import { createContext as e, useCallback as t, useContext as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
|
|
3
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
4
4
|
//#region src/MiniWalletContext.tsx
|
|
5
|
-
var
|
|
5
|
+
var l = e(null);
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/utils/formatUnits.ts
|
|
8
|
-
function
|
|
8
|
+
function u(e) {
|
|
9
9
|
if (typeof e == "bigint") return e;
|
|
10
10
|
let t = e.trim();
|
|
11
11
|
if (!t) throw Error("value must not be empty");
|
|
12
12
|
return BigInt(t);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function d(e, t) {
|
|
15
15
|
if (!Number.isInteger(t) || t < 0) throw Error("decimals must be a non-negative integer");
|
|
16
|
-
let n =
|
|
16
|
+
let n = u(e);
|
|
17
17
|
if (t === 0) return n.toString();
|
|
18
18
|
let r = 10n ** BigInt(t), i = n / r, a = n % r;
|
|
19
19
|
return a === 0n ? i.toString() : `${i}.${a.toString().padStart(t, "0").replace(/0+$/, "")}`;
|
|
20
20
|
}
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/constants.ts
|
|
23
|
-
var
|
|
23
|
+
var f = [
|
|
24
24
|
{
|
|
25
25
|
id: "metamask",
|
|
26
26
|
name: "MetaMask",
|
|
@@ -41,13 +41,13 @@ var d = [
|
|
|
41
41
|
name: "Coinbase",
|
|
42
42
|
icon: "data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1783439807758'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='13209'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M1024%20186.181818a186.181818%20186.181818%200%200%200-186.181818-186.181818H186.181818a186.181818%20186.181818%200%200%200-186.181818%20186.181818v651.636364a186.181818%20186.181818%200%200%200%20186.181818%20186.181818h651.636364a186.181818%20186.181818%200%200%200%20186.181818-186.181818V186.181818z'%20fill='%232C5FF6'%20p-id='13210'%3e%3c/path%3e%3cpath%20d='M512%20870.4a358.4%20358.4%200%201%200%200-716.8%20358.4%20358.4%200%200%200%200%20716.8zM422.4%20394.984727h179.2a27.461818%2027.461818%200%200%201%2027.461818%2027.415273v179.2a27.461818%2027.461818%200%200%201-27.461818%2027.461818h-179.2a27.461818%2027.461818%200%200%201-27.461818-27.461818v-179.2a27.461818%2027.461818%200%200%201%2027.461818-27.461818z'%20fill='%23FFFFFF'%20p-id='13211'%3e%3c/path%3e%3c/svg%3e"
|
|
43
43
|
}
|
|
44
|
-
],
|
|
44
|
+
], p = {
|
|
45
45
|
"io.metamask": "metamask",
|
|
46
46
|
"com.okex.wallet": "okx",
|
|
47
47
|
"com.okx.wallet": "okx",
|
|
48
48
|
"app.phantom": "phantom",
|
|
49
49
|
"com.coinbase.wallet": "coinbase"
|
|
50
|
-
},
|
|
50
|
+
}, m = [
|
|
51
51
|
{
|
|
52
52
|
id: 1,
|
|
53
53
|
name: "Ethereum",
|
|
@@ -69,19 +69,17 @@ var d = [
|
|
|
69
69
|
];
|
|
70
70
|
//#endregion
|
|
71
71
|
//#region src/MiniWalletProvider.tsx
|
|
72
|
-
function
|
|
73
|
-
let [
|
|
74
|
-
let { id: t } = e, n = S[t];
|
|
75
|
-
if (!n) {
|
|
76
|
-
alert("请安装钱包");
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
72
|
+
function h({ children: e, chains: n = [] }) {
|
|
73
|
+
let [c, u] = o(""), [h, g] = o(""), [_, v] = o(0), [y, b] = o(""), [x, S] = o(null), C = a({}), [w, T] = o(0), E = i(() => n.length > 0 ? n : m, [n]), D = i(() => f.find((e) => e.id === h), [h]), O = i(() => !!c, [c]), k = i(() => E.find((e) => e.id === _) || null, [E, _]), A = i(() => !k || !y || !k?.decimals ? "0" : Number(d(y, k.decimals)).toFixed(3), [y, k]), j = t(async (e) => {
|
|
79
74
|
try {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
let { id: t } = e, n = C.current[t];
|
|
76
|
+
if (!n) {
|
|
77
|
+
alert("请安装钱包");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
S(e);
|
|
81
|
+
let r = await n.request({ method: "eth_requestAccounts" }), i = parseInt(String(n.chainId ?? "0x0"), 16);
|
|
82
|
+
u(r[0]), g(t), v(i), localStorage.setItem("miniwallet:lastWalletId", t);
|
|
85
83
|
} catch (e) {
|
|
86
84
|
console.log("error: ", e);
|
|
87
85
|
let t = e, n = t?.code ?? "", r = t?.message ?? "";
|
|
@@ -91,103 +89,111 @@ function m({ children: e, chains: n = [] }) {
|
|
|
91
89
|
}
|
|
92
90
|
alert(`Connect failed${n && `\n${n}`}${r && `\n${r}`}`);
|
|
93
91
|
} finally {
|
|
94
|
-
|
|
92
|
+
S(null);
|
|
95
93
|
}
|
|
96
|
-
}, [
|
|
94
|
+
}, []), M = t(async () => {
|
|
97
95
|
try {
|
|
98
|
-
|
|
96
|
+
let e = C.current[h];
|
|
97
|
+
if (!e || !h) {
|
|
99
98
|
alert("请安装钱包");
|
|
100
99
|
return;
|
|
101
100
|
}
|
|
102
|
-
|
|
101
|
+
h !== "okx" && await e.request({
|
|
103
102
|
method: "wallet_revokePermissions",
|
|
104
103
|
params: [{ eth_accounts: {} }]
|
|
105
104
|
});
|
|
106
105
|
} catch (e) {
|
|
107
106
|
console.error("disconnect error: ", e);
|
|
108
107
|
} finally {
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
}, [T, m]), M = t(async (e) => {
|
|
112
|
-
if (!T) {
|
|
113
|
-
alert("钱包不存在");
|
|
114
|
-
return;
|
|
108
|
+
u(""), g(""), v(0), localStorage.removeItem("miniwallet:lastWalletId");
|
|
115
109
|
}
|
|
110
|
+
}, [h]), N = t(async (e) => {
|
|
116
111
|
try {
|
|
117
|
-
|
|
112
|
+
let t = C.current[h];
|
|
113
|
+
if (!t) {
|
|
114
|
+
alert("钱包不存在");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
await t.request({
|
|
118
118
|
method: "wallet_switchEthereumChain",
|
|
119
119
|
params: [{ chainId: `0x${e.id.toString(16)}` }]
|
|
120
|
-
}),
|
|
120
|
+
}), v(e.id);
|
|
121
121
|
} catch (e) {
|
|
122
122
|
console.log("switchError: ", e);
|
|
123
123
|
let t = e, n = t?.code ?? "", r = t?.message ?? "";
|
|
124
124
|
alert(`Switch failed${n && `\n${n}`}${r && `\n${r}`}`);
|
|
125
125
|
}
|
|
126
|
-
}, [
|
|
126
|
+
}, [h]), P = t(async () => {
|
|
127
127
|
try {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
let e = C.current[h];
|
|
129
|
+
if (!c || !e) return;
|
|
130
|
+
let t = await e.request({
|
|
130
131
|
method: "eth_getBalance",
|
|
131
|
-
params: [
|
|
132
|
+
params: [c, "latest"]
|
|
132
133
|
});
|
|
133
|
-
|
|
134
|
+
b(BigInt(t).toString());
|
|
134
135
|
} catch (e) {
|
|
135
136
|
console.error("getBalance error: ", e);
|
|
136
137
|
}
|
|
137
|
-
}, [
|
|
138
|
-
account:
|
|
139
|
-
balance:
|
|
140
|
-
isConnected:
|
|
141
|
-
connectingWallet:
|
|
142
|
-
selectedChain:
|
|
143
|
-
wallet:
|
|
144
|
-
chains:
|
|
145
|
-
connect:
|
|
146
|
-
switchChain:
|
|
147
|
-
disconnect:
|
|
138
|
+
}, [c, h]), F = i(() => ({
|
|
139
|
+
account: c,
|
|
140
|
+
balance: A,
|
|
141
|
+
isConnected: O,
|
|
142
|
+
connectingWallet: x,
|
|
143
|
+
selectedChain: k,
|
|
144
|
+
wallet: D,
|
|
145
|
+
chains: E,
|
|
146
|
+
connect: j,
|
|
147
|
+
switchChain: N,
|
|
148
|
+
disconnect: M
|
|
148
149
|
}), [
|
|
149
|
-
|
|
150
|
+
c,
|
|
151
|
+
A,
|
|
152
|
+
O,
|
|
153
|
+
x,
|
|
150
154
|
k,
|
|
151
155
|
D,
|
|
152
|
-
b,
|
|
153
|
-
O,
|
|
154
156
|
E,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
M
|
|
158
|
-
j
|
|
157
|
+
j,
|
|
158
|
+
N,
|
|
159
|
+
M
|
|
159
160
|
]);
|
|
160
161
|
return r(() => {
|
|
161
162
|
let e = ((e) => {
|
|
162
|
-
let { info: t, provider: n } = e.detail ?? {}, r =
|
|
163
|
-
!r || !n?.request || C
|
|
164
|
-
...
|
|
163
|
+
let { info: t, provider: n } = e.detail ?? {}, r = p[t?.rdns];
|
|
164
|
+
!r || !n?.request || C.current[r] !== n && (C.current = {
|
|
165
|
+
...C.current,
|
|
165
166
|
[r]: n
|
|
166
|
-
});
|
|
167
|
+
}, T((e) => e + 1));
|
|
167
168
|
});
|
|
168
169
|
return window.addEventListener("eip6963:announceProvider", e), window.dispatchEvent(new Event("eip6963:requestProvider")), () => {
|
|
169
|
-
window.removeEventListener("eip6963:announceProvider", e)
|
|
170
|
+
window.removeEventListener("eip6963:announceProvider", e);
|
|
170
171
|
};
|
|
171
172
|
}, []), r(() => {
|
|
172
|
-
|
|
173
|
-
}, [
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
_ && P();
|
|
174
|
+
}, [P, _]), r(() => {
|
|
175
|
+
let e = C.current[h];
|
|
176
|
+
if (!O || !e?.on) return;
|
|
177
|
+
let t = (e) => {
|
|
178
|
+
console.log("ChainChanged chainId: ", e), v(parseInt(e, 16));
|
|
179
|
+
}, n = (e) => {
|
|
180
|
+
console.log("AccountsChanged accounts: ", e), u(e[0] ?? "");
|
|
179
181
|
};
|
|
180
|
-
return console.log("Listen chainChanged and accountsChanged"),
|
|
181
|
-
console.log("RemoveListener chainChanged and accountsChanged"),
|
|
182
|
+
return console.log("Listen chainChanged and accountsChanged"), e.on("chainChanged", t), e.on("accountsChanged", n), () => {
|
|
183
|
+
console.log("RemoveListener chainChanged and accountsChanged"), e.removeListener("chainChanged", t), e.removeListener("accountsChanged", n);
|
|
182
184
|
};
|
|
183
|
-
}, [
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
}, [
|
|
186
|
+
O,
|
|
187
|
+
h,
|
|
188
|
+
w
|
|
189
|
+
]), r(() => {
|
|
190
|
+
if (!c) return;
|
|
191
|
+
let e = setInterval(P, 1e4);
|
|
186
192
|
return () => clearInterval(e);
|
|
187
|
-
}, [
|
|
193
|
+
}, [c, P]), r(() => {
|
|
188
194
|
let e = localStorage.getItem("miniwallet:lastWalletId");
|
|
189
195
|
if (!e) return;
|
|
190
|
-
let t =
|
|
196
|
+
let t = C.current[e];
|
|
191
197
|
if (!t) return;
|
|
192
198
|
let n = !1;
|
|
193
199
|
return (async () => {
|
|
@@ -197,33 +203,33 @@ function m({ children: e, chains: n = [] }) {
|
|
|
197
203
|
localStorage.removeItem("miniwallet:lastWalletId");
|
|
198
204
|
return;
|
|
199
205
|
}
|
|
200
|
-
|
|
206
|
+
u(r[0]), g(e), v(parseInt(t.chainId, 16));
|
|
201
207
|
}
|
|
202
208
|
})(), () => {
|
|
203
209
|
n = !0;
|
|
204
210
|
};
|
|
205
|
-
}, [
|
|
206
|
-
value:
|
|
211
|
+
}, [w]), /* @__PURE__ */ s(l.Provider, {
|
|
212
|
+
value: F,
|
|
207
213
|
children: e
|
|
208
214
|
});
|
|
209
215
|
}
|
|
210
216
|
//#endregion
|
|
211
217
|
//#region src/useMiniWallet.ts
|
|
212
|
-
function
|
|
213
|
-
let e = n(
|
|
218
|
+
function g() {
|
|
219
|
+
let e = n(l);
|
|
214
220
|
if (!e) throw Error("useMiniWallet 必须在 MiniWalletProvider 内使用");
|
|
215
221
|
return e;
|
|
216
222
|
}
|
|
217
223
|
//#endregion
|
|
218
224
|
//#region src/icons/disconnect.svg
|
|
219
|
-
var
|
|
225
|
+
var _ = "data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1783575961451'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='5071'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M512.922%2063.583c248.335%200%20449.712%20201.384%20449.712%20449.71%200%20248.333-201.377%20449.702-449.712%20449.702-248.333%200-449.71-201.369-449.71-449.702%200-248.326%20201.377-449.71%20449.71-449.71z%20m148.683%20213.634l-35.351%2061.247a206.8%20206.8%200%200%201%2034.37%2027.739c37.359%2037.351%2060.475%2088.96%2060.475%20145.955%200%2057.004-23.117%20108.607-60.475%20145.965-37.344%2037.352-88.945%2060.469-145.949%2060.469-56.987%200-108.606-23.117-145.965-60.469-37.359-37.359-60.461-88.962-60.461-145.965%200-56.995%2023.117-108.605%2060.461-145.955a209.04%20209.04%200%200%201%2027.762-23.286l-35.43-61.359a278.69%20278.69%200%200%200-42.279%2034.69c-50.156%2050.148-81.18%20119.417-81.18%20195.91%200%2076.504%2031.041%20145.773%2081.18%20195.929%2050.139%2050.139%20119.408%2081.166%20195.912%2081.166%2076.502%200%20145.771-31.026%20195.91-81.166%2050.156-50.156%2081.182-119.425%2081.182-195.929%200-76.494-31.026-145.763-81.182-195.91a277.704%20277.704%200%200%200-48.98-39.031zM473.618%20128.865v337.849h75.458V128.865h-75.458z'%20fill='%23e6523f'%20p-id='5072'%3e%3c/path%3e%3c/svg%3e";
|
|
220
226
|
//#endregion
|
|
221
227
|
//#region src/MiniWalletButton.tsx
|
|
222
|
-
function
|
|
223
|
-
let { account: n, balance:
|
|
228
|
+
function v({ label: e = "Connect Wallet" }) {
|
|
229
|
+
let { account: n, balance: a, isConnected: l, connectingWallet: u, selectedChain: d, wallet: p, switchChain: m, chains: h, connect: v, disconnect: y } = g(), [b, x] = o(!1), [S, C] = o(!1), [w, T] = o(!1), [E, D] = o("复制地址"), O = i(() => n ? `${n.slice(0, 6)}...${n.slice(-4)}` : "", [n]), k = t(() => {
|
|
224
230
|
x(!0);
|
|
225
231
|
}, []), A = t(() => {
|
|
226
|
-
x(!1);
|
|
232
|
+
x(!1), C(!1);
|
|
227
233
|
}, []), j = t(async () => {
|
|
228
234
|
try {
|
|
229
235
|
await navigator.clipboard.writeText(n), D("已复制!"), setTimeout(() => {
|
|
@@ -234,93 +240,93 @@ function _({ label: e = "Connect Wallet" }) {
|
|
|
234
240
|
}
|
|
235
241
|
}, [n]);
|
|
236
242
|
return r(() => {
|
|
237
|
-
l &&
|
|
238
|
-
}, [l]), l ? /* @__PURE__ */
|
|
243
|
+
l && A();
|
|
244
|
+
}, [A, l]), l ? /* @__PURE__ */ c("section", {
|
|
239
245
|
className: "inline-flex items-center justify-center text-center",
|
|
240
246
|
children: [
|
|
241
|
-
/* @__PURE__ */
|
|
242
|
-
value:
|
|
243
|
-
onChange: (e) => m(
|
|
247
|
+
/* @__PURE__ */ s("select", {
|
|
248
|
+
value: d?.id,
|
|
249
|
+
onChange: (e) => m(h.find((t) => t.id === Number(e.target.value))),
|
|
244
250
|
className: "bg-transparent1 mr-4 cursor-pointer rounded-sm border-none p-1 text-gray-600 outline-none hover:bg-gray-100",
|
|
245
|
-
children:
|
|
251
|
+
children: h.map((e) => /* @__PURE__ */ s("option", {
|
|
246
252
|
value: e.id,
|
|
247
253
|
children: e.name
|
|
248
254
|
}, e.id))
|
|
249
255
|
}),
|
|
250
|
-
/* @__PURE__ */
|
|
256
|
+
/* @__PURE__ */ c("div", {
|
|
251
257
|
className: "flex items-center justify-center rounded-2xl bg-white pr-3 shadow-lg inset-ring-1 shadow-gray-200 inset-ring-gray-100",
|
|
252
|
-
children: [/* @__PURE__ */
|
|
258
|
+
children: [/* @__PURE__ */ c("div", {
|
|
253
259
|
onClick: () => {
|
|
254
260
|
T(!0);
|
|
255
261
|
},
|
|
256
262
|
className: "flex cursor-pointer items-center justify-center space-x-2 rounded-l-2xl py-2.5 pr-1 pl-3 hover:bg-gray-50",
|
|
257
263
|
children: [
|
|
258
|
-
p && /* @__PURE__ */
|
|
264
|
+
p && /* @__PURE__ */ s("img", {
|
|
259
265
|
src: p.icon,
|
|
260
266
|
alt: p.name,
|
|
261
267
|
className: "h-6 w-6"
|
|
262
268
|
}),
|
|
263
|
-
/* @__PURE__ */
|
|
269
|
+
/* @__PURE__ */ s("div", {
|
|
264
270
|
className: "mr-1",
|
|
265
271
|
children: O
|
|
266
272
|
}),
|
|
267
|
-
/* @__PURE__ */
|
|
273
|
+
/* @__PURE__ */ c("span", {
|
|
268
274
|
className: "text-sm text-gray-400",
|
|
269
275
|
children: [
|
|
270
276
|
"(",
|
|
271
|
-
|
|
277
|
+
a,
|
|
272
278
|
" ",
|
|
273
|
-
|
|
279
|
+
d?.symbol ?? "",
|
|
274
280
|
")"
|
|
275
281
|
]
|
|
276
282
|
})
|
|
277
283
|
]
|
|
278
|
-
}), /* @__PURE__ */
|
|
284
|
+
}), /* @__PURE__ */ s("button", {
|
|
279
285
|
className: "ml-1 h-6 w-6 cursor-pointer rounded-full",
|
|
280
286
|
onClick: y,
|
|
281
|
-
children: /* @__PURE__ */
|
|
282
|
-
src:
|
|
287
|
+
children: /* @__PURE__ */ s("img", {
|
|
288
|
+
src: _,
|
|
283
289
|
alt: "disconnect",
|
|
284
290
|
className: "h-[22px] w-6"
|
|
285
291
|
})
|
|
286
292
|
})]
|
|
287
293
|
}),
|
|
288
|
-
w && /* @__PURE__ */
|
|
294
|
+
w && /* @__PURE__ */ s("div", {
|
|
289
295
|
className: "z-index-10 fixed top-0 right-0 bottom-0 left-0 bg-[rgba(0,0,0,0.5)]",
|
|
290
|
-
children: /* @__PURE__ */
|
|
296
|
+
children: /* @__PURE__ */ c("div", {
|
|
291
297
|
className: "absolute top-1/2 left-1/2 flex h-auto w-[380px] -translate-x-1/2 -translate-y-1/2 flex-col items-center gap-3 rounded-3xl bg-white p-10 pt-5 text-center",
|
|
292
298
|
children: [
|
|
293
|
-
/* @__PURE__ */
|
|
299
|
+
/* @__PURE__ */ s("div", {
|
|
294
300
|
className: "mb-[-12px] w-full text-right",
|
|
295
|
-
children: /* @__PURE__ */
|
|
301
|
+
children: /* @__PURE__ */ s("button", {
|
|
296
302
|
className: "mr-[-20px] cursor-pointer rounded-full p-1 hover:bg-gray-100",
|
|
297
303
|
onClick: () => {
|
|
298
304
|
T(!1);
|
|
299
305
|
},
|
|
300
|
-
children: /* @__PURE__ */
|
|
306
|
+
children: /* @__PURE__ */ c("svg", {
|
|
301
307
|
xmlns: "http://www.w3.org/2000/svg",
|
|
302
308
|
viewBox: "0 0 24 24",
|
|
303
309
|
fill: "none",
|
|
304
310
|
stroke: "currentColor",
|
|
305
311
|
strokeWidth: "2",
|
|
306
312
|
className: "h-8 w-8",
|
|
307
|
-
children: [/* @__PURE__ */
|
|
313
|
+
children: [/* @__PURE__ */ s("path", { d: "M18 6 6 18" }), /* @__PURE__ */ s("path", { d: "m6 6 12 12" })]
|
|
308
314
|
})
|
|
309
315
|
})
|
|
310
316
|
}),
|
|
311
|
-
p && /* @__PURE__ */
|
|
317
|
+
p && /* @__PURE__ */ s("img", {
|
|
312
318
|
src: p.icon,
|
|
313
319
|
alt: p.name,
|
|
314
320
|
className: "h-16 w-16"
|
|
315
321
|
}),
|
|
316
|
-
/* @__PURE__ */
|
|
317
|
-
/* @__PURE__ */
|
|
322
|
+
/* @__PURE__ */ s("p", { children: O }),
|
|
323
|
+
/* @__PURE__ */ c("div", {
|
|
318
324
|
className: "mt-2 w-full space-x-10",
|
|
319
|
-
children: [/* @__PURE__ */
|
|
325
|
+
children: [/* @__PURE__ */ s("button", {
|
|
320
326
|
onClick: j,
|
|
321
327
|
className: "w-[112px] cursor-pointer rounded-xl bg-gray-700 py-2 text-white shadow-md shadow-gray-500/50 outline-none",
|
|
322
328
|
children: E
|
|
323
|
-
}), /* @__PURE__ */
|
|
329
|
+
}), /* @__PURE__ */ s("button", {
|
|
324
330
|
type: "button",
|
|
325
331
|
onClick: y,
|
|
326
332
|
className: "w-[112px] cursor-pointer rounded-xl bg-red-400 py-2 text-white shadow-md shadow-red-500/50 outline-none",
|
|
@@ -331,70 +337,68 @@ function _({ label: e = "Connect Wallet" }) {
|
|
|
331
337
|
})
|
|
332
338
|
})
|
|
333
339
|
]
|
|
334
|
-
}) : /* @__PURE__ */
|
|
340
|
+
}) : /* @__PURE__ */ c("div", { children: [/* @__PURE__ */ s("button", {
|
|
335
341
|
type: "button",
|
|
336
342
|
onClick: k,
|
|
337
343
|
className: "cursor-pointer rounded-xl bg-blue-500 px-4 py-2 text-white shadow-lg shadow-blue-500/50",
|
|
338
344
|
children: e
|
|
339
|
-
}), b && /* @__PURE__ */
|
|
345
|
+
}), b && /* @__PURE__ */ s("div", {
|
|
340
346
|
className: "z-index-10 fixed top-0 right-0 bottom-0 left-0 bg-[rgba(0,0,0,0.5)]",
|
|
341
|
-
children: /* @__PURE__ */
|
|
347
|
+
children: /* @__PURE__ */ c("div", {
|
|
342
348
|
className: "absolute top-1/2 left-1/2 flex h-auto w-[380px] -translate-x-1/2 -translate-y-1/2 flex-col gap-3 rounded-3xl bg-white p-6",
|
|
343
|
-
children: [/* @__PURE__ */
|
|
349
|
+
children: [/* @__PURE__ */ c("div", {
|
|
344
350
|
className: "mb-2 flex items-center justify-between",
|
|
345
|
-
children: [/* @__PURE__ */
|
|
351
|
+
children: [/* @__PURE__ */ s("span", {
|
|
346
352
|
className: "text-2xl font-bold",
|
|
347
353
|
children: "Connect Wallet"
|
|
348
|
-
}), /* @__PURE__ */
|
|
354
|
+
}), /* @__PURE__ */ s("button", {
|
|
349
355
|
type: "button",
|
|
350
356
|
"aria-label": "Close",
|
|
351
357
|
className: "cursor-pointer rounded-full p-1 hover:bg-gray-100",
|
|
352
|
-
onClick:
|
|
353
|
-
|
|
354
|
-
},
|
|
355
|
-
children: /* @__PURE__ */ s("svg", {
|
|
358
|
+
onClick: A,
|
|
359
|
+
children: /* @__PURE__ */ c("svg", {
|
|
356
360
|
xmlns: "http://www.w3.org/2000/svg",
|
|
357
361
|
viewBox: "0 0 24 24",
|
|
358
362
|
fill: "none",
|
|
359
363
|
stroke: "currentColor",
|
|
360
364
|
strokeWidth: "2",
|
|
361
365
|
className: "h-8 w-8",
|
|
362
|
-
children: [/* @__PURE__ */
|
|
366
|
+
children: [/* @__PURE__ */ s("path", { d: "M18 6 6 18" }), /* @__PURE__ */ s("path", { d: "m6 6 12 12" })]
|
|
363
367
|
})
|
|
364
368
|
})]
|
|
365
|
-
}), /* @__PURE__ */
|
|
369
|
+
}), /* @__PURE__ */ c("div", {
|
|
366
370
|
className: "relative w-full space-y-4",
|
|
367
|
-
children: [S && u && /* @__PURE__ */
|
|
371
|
+
children: [S && u && /* @__PURE__ */ c("div", {
|
|
368
372
|
className: "absolute inset-0 mb-0 flex flex-col items-center justify-center rounded-xl bg-[rgba(255,255,255,0.9)] text-black",
|
|
369
373
|
children: [
|
|
370
|
-
/* @__PURE__ */
|
|
374
|
+
/* @__PURE__ */ c("div", { children: [
|
|
371
375
|
"正在连接",
|
|
372
376
|
u.name,
|
|
373
377
|
"..."
|
|
374
378
|
] }),
|
|
375
|
-
/* @__PURE__ */
|
|
379
|
+
/* @__PURE__ */ s("div", {
|
|
376
380
|
className: "my-1.5 text-xs",
|
|
377
381
|
children: "请在扩展中确认连接"
|
|
378
382
|
}),
|
|
379
|
-
/* @__PURE__ */
|
|
383
|
+
/* @__PURE__ */ s("img", {
|
|
380
384
|
src: "data:image/svg+xml,%3c?xml%20version='1.0'%20standalone='no'?%3e%3c!DOCTYPE%20svg%20PUBLIC%20'-//W3C//DTD%20SVG%201.1//EN'%20'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'%3e%3csvg%20t='1783646544006'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='78324'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='32'%20height='32'%3e%3cpath%20d='M512%20907c-24.852%200-45-20.148-45-45s20.148-45%2045-45c168.446%200%20305-136.554%20305-305S680.446%20207%20512%20207%20207%20343.554%20207%20512c0%2024.852-20.148%2045-45%2045S117%20536.852%20117%20512c0-218.152%20176.848-395%20395-395S907%20293.848%20907%20512%20730.152%20907%20512%20907z'%20fill='%23444444'%20p-id='78325'%3e%3c/path%3e%3c/svg%3e",
|
|
381
385
|
alt: "spin",
|
|
382
386
|
className: "h-8 w-8 animate-[spin_2s_linear_infinite]"
|
|
383
387
|
})
|
|
384
388
|
]
|
|
385
|
-
}),
|
|
389
|
+
}), f.map((e) => /* @__PURE__ */ c("button", {
|
|
386
390
|
type: "button",
|
|
387
391
|
onClick: () => {
|
|
388
392
|
C(!0), v(e);
|
|
389
393
|
},
|
|
390
394
|
className: "flex w-full cursor-pointer items-center gap-2 rounded-xl border border-gray-300 px-4 py-2 hover:bg-gray-100",
|
|
391
|
-
children: [/* @__PURE__ */
|
|
395
|
+
children: [/* @__PURE__ */ s("img", {
|
|
392
396
|
src: e.icon,
|
|
393
397
|
alt: e.name,
|
|
394
398
|
className: "h-8 w-8"
|
|
395
|
-
}), /* @__PURE__ */
|
|
399
|
+
}), /* @__PURE__ */ c("div", {
|
|
396
400
|
className: "flex flex-col justify-between text-left",
|
|
397
|
-
children: [/* @__PURE__ */
|
|
401
|
+
children: [/* @__PURE__ */ s("p", { children: e.name }), /* @__PURE__ */ c("span", {
|
|
398
402
|
className: "text-xs text-gray-500",
|
|
399
403
|
children: [
|
|
400
404
|
"Connect your ",
|
|
@@ -409,4 +413,4 @@ function _({ label: e = "Connect Wallet" }) {
|
|
|
409
413
|
})] });
|
|
410
414
|
}
|
|
411
415
|
//#endregion
|
|
412
|
-
export {
|
|
416
|
+
export { v as MiniWalletButton, h as MiniWalletProvider, g as useMiniWallet };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miniwallet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "React wallet connect button with multi-wallet support via EIP-6963",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/miniwallet.js",
|
|
@@ -22,10 +22,8 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "vite",
|
|
24
24
|
"build": "tsc -b && vite build",
|
|
25
|
-
"build:demo": "tsc -b && vite build --mode demo",
|
|
26
25
|
"lint": "eslint .",
|
|
27
26
|
"preview": "vite preview",
|
|
28
|
-
"preview:demo": "vite preview --outDir dist-demo",
|
|
29
27
|
"prepublishOnly": "pnpm build"
|
|
30
28
|
},
|
|
31
29
|
"peerDependencies": {
|