miniwallet 0.1.16 → 0.1.18
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 +149 -142
- 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 = await n.request({ method: "eth_chainId" }), a = parseInt(String(i || "0x0"), 16);
|
|
82
|
+
u(r[0]), g(t), v(a), 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,140 +89,148 @@ 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 () => {
|
|
194
200
|
let r = await t.request({ method: "eth_accounts" });
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
l(r[0]), h(e), _(parseInt(t.chainId, 16));
|
|
201
|
+
if (n) return;
|
|
202
|
+
if (!r?.length) {
|
|
203
|
+
localStorage.removeItem("miniwallet:lastWalletId");
|
|
204
|
+
return;
|
|
201
205
|
}
|
|
206
|
+
let i = await t.request({ method: "eth_chainId" });
|
|
207
|
+
u(r[0]), g(e), v(parseInt(String(i || "0x0"), 16));
|
|
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 = i(() => l && !d, [l, d]), A = t(() => {
|
|
224
230
|
x(!0);
|
|
225
|
-
}, []),
|
|
226
|
-
x(!1);
|
|
227
|
-
}, []),
|
|
231
|
+
}, []), j = t(() => {
|
|
232
|
+
x(!1), C(!1), T(!1);
|
|
233
|
+
}, []), M = t(async () => {
|
|
228
234
|
try {
|
|
229
235
|
await navigator.clipboard.writeText(n), D("已复制!"), setTimeout(() => {
|
|
230
236
|
D("复制地址");
|
|
@@ -234,93 +240,96 @@ function _({ label: e = "Connect Wallet" }) {
|
|
|
234
240
|
}
|
|
235
241
|
}, [n]);
|
|
236
242
|
return r(() => {
|
|
237
|
-
l &&
|
|
238
|
-
}, [l]), l ? /* @__PURE__ */
|
|
243
|
+
l && j();
|
|
244
|
+
}, [j, 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__ */ c("select", {
|
|
248
|
+
value: k ? "unknow" : 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
|
-
}, e.id))
|
|
254
|
+
}, e.id)), k && /* @__PURE__ */ s("option", {
|
|
255
|
+
value: "unknow",
|
|
256
|
+
children: "未知的网络"
|
|
257
|
+
}, "unknow")]
|
|
249
258
|
}),
|
|
250
|
-
/* @__PURE__ */
|
|
259
|
+
/* @__PURE__ */ c("div", {
|
|
251
260
|
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__ */
|
|
261
|
+
children: [/* @__PURE__ */ c("div", {
|
|
253
262
|
onClick: () => {
|
|
254
263
|
T(!0);
|
|
255
264
|
},
|
|
256
265
|
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
266
|
children: [
|
|
258
|
-
p && /* @__PURE__ */
|
|
267
|
+
p && /* @__PURE__ */ s("img", {
|
|
259
268
|
src: p.icon,
|
|
260
269
|
alt: p.name,
|
|
261
270
|
className: "h-6 w-6"
|
|
262
271
|
}),
|
|
263
|
-
/* @__PURE__ */
|
|
272
|
+
/* @__PURE__ */ s("div", {
|
|
264
273
|
className: "mr-1",
|
|
265
274
|
children: O
|
|
266
275
|
}),
|
|
267
|
-
/* @__PURE__ */
|
|
276
|
+
/* @__PURE__ */ c("span", {
|
|
268
277
|
className: "text-sm text-gray-400",
|
|
269
278
|
children: [
|
|
270
279
|
"(",
|
|
271
|
-
|
|
280
|
+
a,
|
|
272
281
|
" ",
|
|
273
|
-
|
|
282
|
+
d?.symbol ?? "",
|
|
274
283
|
")"
|
|
275
284
|
]
|
|
276
285
|
})
|
|
277
286
|
]
|
|
278
|
-
}), /* @__PURE__ */
|
|
287
|
+
}), /* @__PURE__ */ s("button", {
|
|
279
288
|
className: "ml-1 h-6 w-6 cursor-pointer rounded-full",
|
|
280
289
|
onClick: y,
|
|
281
|
-
children: /* @__PURE__ */
|
|
282
|
-
src:
|
|
290
|
+
children: /* @__PURE__ */ s("img", {
|
|
291
|
+
src: _,
|
|
283
292
|
alt: "disconnect",
|
|
284
293
|
className: "h-[22px] w-6"
|
|
285
294
|
})
|
|
286
295
|
})]
|
|
287
296
|
}),
|
|
288
|
-
w && /* @__PURE__ */
|
|
297
|
+
w && /* @__PURE__ */ s("div", {
|
|
289
298
|
className: "z-index-10 fixed top-0 right-0 bottom-0 left-0 bg-[rgba(0,0,0,0.5)]",
|
|
290
|
-
children: /* @__PURE__ */
|
|
299
|
+
children: /* @__PURE__ */ c("div", {
|
|
291
300
|
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
301
|
children: [
|
|
293
|
-
/* @__PURE__ */
|
|
302
|
+
/* @__PURE__ */ s("div", {
|
|
294
303
|
className: "mb-[-12px] w-full text-right",
|
|
295
|
-
children: /* @__PURE__ */
|
|
304
|
+
children: /* @__PURE__ */ s("button", {
|
|
296
305
|
className: "mr-[-20px] cursor-pointer rounded-full p-1 hover:bg-gray-100",
|
|
297
306
|
onClick: () => {
|
|
298
307
|
T(!1);
|
|
299
308
|
},
|
|
300
|
-
children: /* @__PURE__ */
|
|
309
|
+
children: /* @__PURE__ */ c("svg", {
|
|
301
310
|
xmlns: "http://www.w3.org/2000/svg",
|
|
302
311
|
viewBox: "0 0 24 24",
|
|
303
312
|
fill: "none",
|
|
304
313
|
stroke: "currentColor",
|
|
305
314
|
strokeWidth: "2",
|
|
306
315
|
className: "h-8 w-8",
|
|
307
|
-
children: [/* @__PURE__ */
|
|
316
|
+
children: [/* @__PURE__ */ s("path", { d: "M18 6 6 18" }), /* @__PURE__ */ s("path", { d: "m6 6 12 12" })]
|
|
308
317
|
})
|
|
309
318
|
})
|
|
310
319
|
}),
|
|
311
|
-
p && /* @__PURE__ */
|
|
320
|
+
p && /* @__PURE__ */ s("img", {
|
|
312
321
|
src: p.icon,
|
|
313
322
|
alt: p.name,
|
|
314
323
|
className: "h-16 w-16"
|
|
315
324
|
}),
|
|
316
|
-
/* @__PURE__ */
|
|
317
|
-
/* @__PURE__ */
|
|
325
|
+
/* @__PURE__ */ s("p", { children: O }),
|
|
326
|
+
/* @__PURE__ */ c("div", {
|
|
318
327
|
className: "mt-2 w-full space-x-10",
|
|
319
|
-
children: [/* @__PURE__ */
|
|
320
|
-
onClick:
|
|
328
|
+
children: [/* @__PURE__ */ s("button", {
|
|
329
|
+
onClick: M,
|
|
321
330
|
className: "w-[112px] cursor-pointer rounded-xl bg-gray-700 py-2 text-white shadow-md shadow-gray-500/50 outline-none",
|
|
322
331
|
children: E
|
|
323
|
-
}), /* @__PURE__ */
|
|
332
|
+
}), /* @__PURE__ */ s("button", {
|
|
324
333
|
type: "button",
|
|
325
334
|
onClick: y,
|
|
326
335
|
className: "w-[112px] cursor-pointer rounded-xl bg-red-400 py-2 text-white shadow-md shadow-red-500/50 outline-none",
|
|
@@ -331,70 +340,68 @@ function _({ label: e = "Connect Wallet" }) {
|
|
|
331
340
|
})
|
|
332
341
|
})
|
|
333
342
|
]
|
|
334
|
-
}) : /* @__PURE__ */
|
|
343
|
+
}) : /* @__PURE__ */ c("div", { children: [/* @__PURE__ */ s("button", {
|
|
335
344
|
type: "button",
|
|
336
|
-
onClick:
|
|
345
|
+
onClick: A,
|
|
337
346
|
className: "cursor-pointer rounded-xl bg-blue-500 px-4 py-2 text-white shadow-lg shadow-blue-500/50",
|
|
338
347
|
children: e
|
|
339
|
-
}), b && /* @__PURE__ */
|
|
348
|
+
}), b && /* @__PURE__ */ s("div", {
|
|
340
349
|
className: "z-index-10 fixed top-0 right-0 bottom-0 left-0 bg-[rgba(0,0,0,0.5)]",
|
|
341
|
-
children: /* @__PURE__ */
|
|
350
|
+
children: /* @__PURE__ */ c("div", {
|
|
342
351
|
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__ */
|
|
352
|
+
children: [/* @__PURE__ */ c("div", {
|
|
344
353
|
className: "mb-2 flex items-center justify-between",
|
|
345
|
-
children: [/* @__PURE__ */
|
|
354
|
+
children: [/* @__PURE__ */ s("span", {
|
|
346
355
|
className: "text-2xl font-bold",
|
|
347
356
|
children: "Connect Wallet"
|
|
348
|
-
}), /* @__PURE__ */
|
|
357
|
+
}), /* @__PURE__ */ s("button", {
|
|
349
358
|
type: "button",
|
|
350
359
|
"aria-label": "Close",
|
|
351
360
|
className: "cursor-pointer rounded-full p-1 hover:bg-gray-100",
|
|
352
|
-
onClick:
|
|
353
|
-
|
|
354
|
-
},
|
|
355
|
-
children: /* @__PURE__ */ s("svg", {
|
|
361
|
+
onClick: j,
|
|
362
|
+
children: /* @__PURE__ */ c("svg", {
|
|
356
363
|
xmlns: "http://www.w3.org/2000/svg",
|
|
357
364
|
viewBox: "0 0 24 24",
|
|
358
365
|
fill: "none",
|
|
359
366
|
stroke: "currentColor",
|
|
360
367
|
strokeWidth: "2",
|
|
361
368
|
className: "h-8 w-8",
|
|
362
|
-
children: [/* @__PURE__ */
|
|
369
|
+
children: [/* @__PURE__ */ s("path", { d: "M18 6 6 18" }), /* @__PURE__ */ s("path", { d: "m6 6 12 12" })]
|
|
363
370
|
})
|
|
364
371
|
})]
|
|
365
|
-
}), /* @__PURE__ */
|
|
372
|
+
}), /* @__PURE__ */ c("div", {
|
|
366
373
|
className: "relative w-full space-y-4",
|
|
367
|
-
children: [S && u && /* @__PURE__ */
|
|
374
|
+
children: [S && u && /* @__PURE__ */ c("div", {
|
|
368
375
|
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
376
|
children: [
|
|
370
|
-
/* @__PURE__ */
|
|
377
|
+
/* @__PURE__ */ c("div", { children: [
|
|
371
378
|
"正在连接",
|
|
372
379
|
u.name,
|
|
373
380
|
"..."
|
|
374
381
|
] }),
|
|
375
|
-
/* @__PURE__ */
|
|
382
|
+
/* @__PURE__ */ s("div", {
|
|
376
383
|
className: "my-1.5 text-xs",
|
|
377
384
|
children: "请在扩展中确认连接"
|
|
378
385
|
}),
|
|
379
|
-
/* @__PURE__ */
|
|
386
|
+
/* @__PURE__ */ s("img", {
|
|
380
387
|
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
388
|
alt: "spin",
|
|
382
389
|
className: "h-8 w-8 animate-[spin_2s_linear_infinite]"
|
|
383
390
|
})
|
|
384
391
|
]
|
|
385
|
-
}),
|
|
392
|
+
}), f.map((e) => /* @__PURE__ */ c("button", {
|
|
386
393
|
type: "button",
|
|
387
394
|
onClick: () => {
|
|
388
395
|
C(!0), v(e);
|
|
389
396
|
},
|
|
390
397
|
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__ */
|
|
398
|
+
children: [/* @__PURE__ */ s("img", {
|
|
392
399
|
src: e.icon,
|
|
393
400
|
alt: e.name,
|
|
394
401
|
className: "h-8 w-8"
|
|
395
|
-
}), /* @__PURE__ */
|
|
402
|
+
}), /* @__PURE__ */ c("div", {
|
|
396
403
|
className: "flex flex-col justify-between text-left",
|
|
397
|
-
children: [/* @__PURE__ */
|
|
404
|
+
children: [/* @__PURE__ */ s("p", { children: e.name }), /* @__PURE__ */ c("span", {
|
|
398
405
|
className: "text-xs text-gray-500",
|
|
399
406
|
children: [
|
|
400
407
|
"Connect your ",
|
|
@@ -409,4 +416,4 @@ function _({ label: e = "Connect Wallet" }) {
|
|
|
409
416
|
})] });
|
|
410
417
|
}
|
|
411
418
|
//#endregion
|
|
412
|
-
export {
|
|
419
|
+
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.18",
|
|
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": {
|