miniwallet 0.1.11 → 0.1.13

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.
@@ -1,32 +1,26 @@
1
1
  import "./miniwallet.css";
2
- import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
3
- import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { createContext as e, useCallback as t, useContext as n, useEffect as r, useMemo as i, useState as a } from "react";
3
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
4
4
  //#region src/MiniWalletContext.tsx
5
- var MiniWalletContext = createContext(null);
5
+ var c = e(null);
6
6
  //#endregion
7
7
  //#region src/utils/formatUnits.ts
8
- function parseUnitValue(value) {
9
- if (typeof value === "bigint") return value;
10
- const trimmed = value.trim();
11
- if (!trimmed) throw new Error("value must not be empty");
12
- return BigInt(trimmed);
8
+ function l(e) {
9
+ if (typeof e == "bigint") return e;
10
+ let t = e.trim();
11
+ if (!t) throw Error("value must not be empty");
12
+ return BigInt(t);
13
13
  }
14
- /**
15
- * Convert smallest-unit amount (e.g. wei) to a human-readable decimal string.
16
- */
17
- function formatUnits(value, decimals) {
18
- if (!Number.isInteger(decimals) || decimals < 0) throw new Error("decimals must be a non-negative integer");
19
- const amount = parseUnitValue(value);
20
- if (decimals === 0) return amount.toString();
21
- const divisor = 10n ** BigInt(decimals);
22
- const integer = amount / divisor;
23
- const fraction = amount % divisor;
24
- if (fraction === 0n) return integer.toString();
25
- return `${integer}.${fraction.toString().padStart(decimals, "0").replace(/0+$/, "")}`;
14
+ function u(e, t) {
15
+ if (!Number.isInteger(t) || t < 0) throw Error("decimals must be a non-negative integer");
16
+ let n = l(e);
17
+ if (t === 0) return n.toString();
18
+ let r = 10n ** BigInt(t), i = n / r, a = n % r;
19
+ return a === 0n ? i.toString() : `${i}.${a.toString().padStart(t, "0").replace(/0+$/, "")}`;
26
20
  }
27
21
  //#endregion
28
22
  //#region src/constants.ts
29
- var WALLETS = [
23
+ var d = [
30
24
  {
31
25
  id: "metamask",
32
26
  name: "MetaMask",
@@ -47,16 +41,13 @@ var WALLETS = [
47
41
  name: "Coinbase",
48
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"
49
43
  }
50
- ];
51
- /** EIP-6963 rdns → wallet id */
52
- var RDNS_TO_WALLET_ID = {
44
+ ], f = {
53
45
  "io.metamask": "metamask",
54
46
  "com.okex.wallet": "okx",
55
47
  "com.okx.wallet": "okx",
56
48
  "app.phantom": "phantom",
57
49
  "com.coinbase.wallet": "coinbase"
58
- };
59
- var DEFAULT_CHAINS = [
50
+ }, p = [
60
51
  {
61
52
  id: 1,
62
53
  name: "Ethereum",
@@ -78,336 +69,258 @@ var DEFAULT_CHAINS = [
78
69
  ];
79
70
  //#endregion
80
71
  //#region src/MiniWalletProvider.tsx
81
- function MiniWalletProvider({ children, chains = [] }) {
82
- const [account, setAccount] = useState("");
83
- const [selectedWalletId, setSelectedWalletId] = useState("");
84
- const [selectedChainId, setSelectedChainId] = useState(0);
85
- const [balanceValue, setBalanceValue] = useState("");
86
- const [connectingWallet] = useState(null);
87
- const eip6963ProvidersRef = useRef({});
88
- const [providersVersion, setProvidersVersion] = useState(0);
89
- const chainsList = useMemo(() => {
90
- return chains.length > 0 ? chains : DEFAULT_CHAINS;
91
- }, [chains]);
92
- const curWalletProvider = useMemo(() => {
93
- return eip6963ProvidersRef.current[selectedWalletId] ?? null;
94
- }, [providersVersion, selectedWalletId]);
95
- const wallet = useMemo(() => {
96
- return WALLETS.find((w) => w.id === selectedWalletId);
97
- }, [selectedWalletId]);
98
- const isConnected = useMemo(() => {
99
- return !!account;
100
- }, [account]);
101
- const selectedChain = useMemo(() => {
102
- return chainsList.find((c) => c.id === selectedChainId) || null;
103
- }, [chainsList, selectedChainId]);
104
- const balance = useMemo(() => {
105
- if (!selectedChain || !balanceValue || !selectedChain?.decimals) return "0";
106
- return Number(formatUnits(balanceValue, selectedChain.decimals)).toFixed(3);
107
- }, [balanceValue, selectedChain]);
108
- const connect = useCallback(async (w) => {
109
- const { id } = w;
110
- console.log("eip6963Providers: ", eip6963ProvidersRef.current);
111
- const provider = eip6963ProvidersRef.current[id];
112
- if (!provider || typeof provider.request !== "function") {
72
+ function m({ children: e, chains: n = [] }) {
73
+ let [s, l] = a(""), [m, h] = a(""), [g, _] = a(0), [v, y] = a(""), [b] = a(null), [x, S] = a({}), C = i(() => n.length > 0 ? n : p, [n]), w = i(() => x[m] ?? null, [x, m]), T = i(() => d.find((e) => e.id === m), [m]), E = i(() => !!s, [s]), D = i(() => C.find((e) => e.id === g) || null, [C, g]), O = i(() => !D || !v || !D?.decimals ? "0" : Number(u(v, D.decimals)).toFixed(3), [v, D]), k = t(async (e) => {
74
+ let { id: t } = e, n = x[t];
75
+ if (!n) {
113
76
  alert("请安装钱包");
114
77
  return;
115
78
  }
116
79
  try {
117
- console.log("provider: ", provider);
118
- const accounts = await provider.request({ method: "eth_requestAccounts" });
119
- console.log("accounts: ", accounts);
120
- console.log("provider.chainId: ", provider.chainId);
121
- const chainId = parseInt(String(provider.chainId ?? "0x0"), 16);
122
- setAccount(accounts[0]);
123
- setSelectedWalletId(id);
124
- setSelectedChainId(chainId);
125
- localStorage.setItem("miniwallet:lastWalletId", id);
126
- } catch (error) {
127
- console.log("error: ", error);
128
- const e = error;
129
- const errCode = e?.code ?? "";
130
- const errMsg = e?.message ?? "";
131
- if (errCode === -32002) {
132
- alert(`连接已发起,请在扩展中确认连接`);
80
+ console.log("provider: ", n);
81
+ let e = await n.request({ method: "eth_requestAccounts" });
82
+ console.log("accounts: ", e), console.log("provider.chainId: ", n.chainId);
83
+ let r = parseInt(String(n.chainId ?? "0x0"), 16);
84
+ l(e[0]), h(t), _(r), localStorage.setItem("miniwallet:lastWalletId", t);
85
+ } catch (e) {
86
+ console.log("error: ", e);
87
+ let t = e, n = t?.code ?? "", r = t?.message ?? "";
88
+ if (n === -32002) {
89
+ alert("连接已发起,请在扩展中确认连接");
133
90
  return;
134
91
  }
135
- alert(`Connect failed${errCode && `\n${errCode}`}${errMsg && `\n${errMsg}`}`);
92
+ alert(`Connect failed${n && `\n${n}`}${r && `\n${r}`}`);
136
93
  }
137
- }, []);
138
- const disconnect = useCallback(async () => {
94
+ }, [x]), A = t(async () => {
139
95
  try {
140
- if (!curWalletProvider || !selectedWalletId) {
96
+ if (!w || !m) {
141
97
  alert("请安装钱包");
142
98
  return;
143
99
  }
144
- if (selectedWalletId !== "okx") await curWalletProvider.request({
100
+ m !== "okx" && await w.request({
145
101
  method: "wallet_revokePermissions",
146
102
  params: [{ eth_accounts: {} }]
147
103
  });
148
104
  } catch (e) {
149
105
  console.error("disconnect error: ", e);
150
106
  } finally {
151
- setAccount("");
152
- setSelectedWalletId("");
153
- setSelectedChainId(0);
154
- localStorage.removeItem("miniwallet:lastWalletId");
107
+ l(""), h(""), _(0), localStorage.removeItem("miniwallet:lastWalletId");
155
108
  }
156
- }, [curWalletProvider, selectedWalletId]);
157
- const switchChain = useCallback(async (chain) => {
158
- if (!curWalletProvider) {
109
+ }, [w, m]), j = t(async (e) => {
110
+ if (!w) {
159
111
  alert("钱包不存在");
160
112
  return;
161
113
  }
162
114
  try {
163
- await curWalletProvider.request({
115
+ await w.request({
164
116
  method: "wallet_switchEthereumChain",
165
- params: [{ chainId: `0x${chain.id.toString(16)}` }]
166
- });
167
- setSelectedChainId(chain.id);
168
- } catch (switchError) {
169
- console.log("switchError: ", switchError);
170
- const e = switchError;
171
- const errCode = e?.code ?? "";
172
- const errMsg = e?.message ?? "";
173
- alert(`Switch failed${errCode && `\n${errCode}`}${errMsg && `\n${errMsg}`}`);
117
+ params: [{ chainId: `0x${e.id.toString(16)}` }]
118
+ }), _(e.id);
119
+ } catch (e) {
120
+ console.log("switchError: ", e);
121
+ let t = e, n = t?.code ?? "", r = t?.message ?? "";
122
+ alert(`Switch failed${n && `\n${n}`}${r && `\n${r}`}`);
174
123
  }
175
- }, [curWalletProvider]);
176
- const getBalance = useCallback(async () => {
124
+ }, [w]), M = t(async () => {
177
125
  try {
178
- if (!account || !curWalletProvider) return;
179
- const balanceRes = await curWalletProvider.request({
126
+ if (!s || !w) return;
127
+ let e = await w.request({
180
128
  method: "eth_getBalance",
181
- params: [account, "latest"]
129
+ params: [s, "latest"]
182
130
  });
183
- setBalanceValue(BigInt(balanceRes).toString());
131
+ y(BigInt(e).toString());
184
132
  } catch (e) {
185
133
  console.error("getBalance error: ", e);
186
134
  }
187
- }, [account, curWalletProvider]);
188
- const value = useMemo(() => ({
189
- account,
190
- balance,
191
- isConnected,
192
- connectingWallet,
193
- selectedChain,
194
- wallet,
195
- chains: chainsList,
196
- connect,
197
- switchChain,
198
- disconnect
135
+ }, [s, w]), N = i(() => ({
136
+ account: s,
137
+ balance: O,
138
+ isConnected: E,
139
+ connectingWallet: b,
140
+ selectedChain: D,
141
+ wallet: T,
142
+ chains: C,
143
+ connect: k,
144
+ switchChain: j,
145
+ disconnect: A
199
146
  }), [
200
- account,
201
- balance,
202
- isConnected,
203
- connectingWallet,
204
- selectedChain,
205
- wallet,
206
- chainsList,
207
- connect,
208
- switchChain,
209
- disconnect
147
+ s,
148
+ O,
149
+ E,
150
+ b,
151
+ D,
152
+ T,
153
+ C,
154
+ k,
155
+ j,
156
+ A
210
157
  ]);
211
- useEffect(() => {
212
- const handler = ((event) => {
213
- const { info, provider } = event.detail ?? {};
214
- const walletId = RDNS_TO_WALLET_ID[info?.rdns];
215
- if (!walletId || typeof provider?.request !== "function") return;
216
- if (eip6963ProvidersRef.current[walletId] === provider) return;
217
- eip6963ProvidersRef.current = {
218
- ...eip6963ProvidersRef.current,
219
- [walletId]: provider
220
- };
221
- setProvidersVersion((v) => v + 1);
158
+ return r(() => {
159
+ let e = ((e) => {
160
+ let { info: t, provider: n } = e.detail ?? {}, r = f[t?.rdns];
161
+ !r || !n?.request || S((e) => e[r] === n ? e : {
162
+ ...e,
163
+ [r]: n
164
+ });
222
165
  });
223
- window.addEventListener("eip6963:announceProvider", handler);
224
- window.dispatchEvent(new Event("eip6963:requestProvider"));
225
- return () => {
226
- window.removeEventListener("eip6963:announceProvider", handler);
227
- };
228
- }, []);
229
- useEffect(() => {
230
- if (selectedChainId) getBalance();
231
- }, [getBalance, selectedChainId]);
232
- useEffect(() => {
233
- if (!isConnected || !curWalletProvider?.on) return;
234
- const handleChainChanged = (chainId) => {
235
- console.log("ChainChanged chainId: ", chainId);
236
- setSelectedChainId(parseInt(chainId, 16));
166
+ return window.addEventListener("eip6963:announceProvider", e), window.dispatchEvent(new Event("eip6963:requestProvider")), () => {
167
+ window.removeEventListener("eip6963:announceProvider", e), S({});
237
168
  };
238
- const handleAccountsChanged = (accounts) => {
239
- console.log("AccountsChanged accounts: ", accounts);
240
- setAccount(accounts[0] ?? "");
169
+ }, []), r(() => {
170
+ g && M();
171
+ }, [M, g]), r(() => {
172
+ if (!E || !w?.on) return;
173
+ let e = (e) => {
174
+ console.log("ChainChanged chainId: ", e), _(parseInt(e, 16));
175
+ }, t = (e) => {
176
+ console.log("AccountsChanged accounts: ", e), l(e[0] ?? "");
241
177
  };
242
- console.log("Listen chainChanged and accountsChanged");
243
- curWalletProvider.on("chainChanged", handleChainChanged);
244
- curWalletProvider.on("accountsChanged", handleAccountsChanged);
245
- return () => {
246
- console.log("RemoveListener chainChanged and accountsChanged");
247
- curWalletProvider.removeListener?.("chainChanged", handleChainChanged);
248
- curWalletProvider.removeListener?.("accountsChanged", handleAccountsChanged);
178
+ return console.log("Listen chainChanged and accountsChanged"), w.on("chainChanged", e), w.on("accountsChanged", t), () => {
179
+ console.log("RemoveListener chainChanged and accountsChanged"), w.removeListener("chainChanged", e), w.removeListener("accountsChanged", t);
249
180
  };
250
- }, [curWalletProvider, isConnected]);
251
- useEffect(() => {
252
- if (!account) return;
253
- const timer = setInterval(getBalance, 1e4);
254
- return () => clearInterval(timer);
255
- }, [account, getBalance]);
256
- useEffect(() => {
257
- const lastWalletId = localStorage.getItem("miniwallet:lastWalletId");
258
- if (!lastWalletId) return;
259
- const provider = eip6963ProvidersRef.current[lastWalletId];
260
- if (!provider) return;
261
- let cancelled = false;
262
- (async () => {
263
- const accounts = await provider.request({ method: "eth_accounts" });
264
- if (cancelled) return;
265
- if (!accounts?.length) {
266
- localStorage.removeItem("miniwallet:lastWalletId");
267
- return;
181
+ }, [E, w]), r(() => {
182
+ if (!s) return;
183
+ let e = setInterval(M, 1e4);
184
+ return () => clearInterval(e);
185
+ }, [s, M]), r(() => {
186
+ let e = localStorage.getItem("miniwallet:lastWalletId");
187
+ if (!e) return;
188
+ let t = x[e];
189
+ if (!t) return;
190
+ let n = !1;
191
+ return (async () => {
192
+ let r = await t.request({ method: "eth_accounts" });
193
+ if (!n) {
194
+ if (!r?.length) {
195
+ localStorage.removeItem("miniwallet:lastWalletId");
196
+ return;
197
+ }
198
+ l(r[0]), h(e), _(parseInt(t.chainId, 16));
268
199
  }
269
- setAccount(accounts[0]);
270
- setSelectedWalletId(lastWalletId);
271
- setSelectedChainId(parseInt(String(provider.chainId ?? "0x0"), 16));
272
- })();
273
- return () => {
274
- cancelled = true;
200
+ })(), () => {
201
+ n = !0;
275
202
  };
276
- }, [providersVersion]);
277
- return /* @__PURE__ */ jsx(MiniWalletContext.Provider, {
278
- value,
279
- children
203
+ }, [x]), /* @__PURE__ */ o(c.Provider, {
204
+ value: N,
205
+ children: e
280
206
  });
281
207
  }
282
208
  //#endregion
283
209
  //#region src/useMiniWallet.ts
284
- function useMiniWallet() {
285
- const ctx = useContext(MiniWalletContext);
286
- if (!ctx) throw new Error("useMiniWallet 必须在 MiniWalletProvider 内使用");
287
- return ctx;
210
+ function h() {
211
+ let e = n(c);
212
+ if (!e) throw Error("useMiniWallet 必须在 MiniWalletProvider 内使用");
213
+ return e;
288
214
  }
289
215
  //#endregion
290
216
  //#region src/icons/disconnect.svg
291
- var disconnect_default = "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";
217
+ var g = "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";
292
218
  //#endregion
293
219
  //#region src/MiniWalletButton.tsx
294
- function MiniWalletButton({ label = "Connect Wallet" }) {
295
- const { account, balance, isConnected, selectedChain, wallet, switchChain, chains, connect, disconnect } = useMiniWallet();
296
- const [modalOpen, setModalOpen] = useState(false);
297
- const [accountModalOpen, setAccountModalOpen] = useState(false);
298
- const [copyLabel, setCopyLabel] = useState("复制地址");
299
- const accountText = useMemo(() => {
300
- if (account) return `${account.slice(0, 6)}...${account.slice(-4)}`;
301
- return "";
302
- }, [account]);
303
- const openModal = useCallback(() => {
304
- setModalOpen(true);
305
- }, []);
306
- const closeModal = useCallback(() => {
307
- setModalOpen(false);
308
- }, []);
309
- const copyAddress = useCallback(async () => {
220
+ function _({ label: e = "Connect Wallet" }) {
221
+ let { account: n, balance: c, isConnected: l, selectedChain: u, wallet: f, switchChain: p, chains: m, connect: _, disconnect: v } = h(), [y, b] = a(!1), [x, S] = a(!1), [C, w] = a("复制地址"), T = i(() => n ? `${n.slice(0, 6)}...${n.slice(-4)}` : "", [n]), E = t(() => {
222
+ b(!0);
223
+ }, []), D = t(() => {
224
+ b(!1);
225
+ }, []), O = t(async () => {
310
226
  try {
311
- await navigator.clipboard.writeText(account);
312
- setCopyLabel("已复制!");
313
- setTimeout(() => {
314
- setCopyLabel("复制地址");
227
+ await navigator.clipboard.writeText(n), w("已复制!"), setTimeout(() => {
228
+ w("复制地址");
315
229
  }, 1e3);
316
- } catch (err) {
317
- console.error("copy", err);
230
+ } catch (e) {
231
+ console.error("copy", e);
318
232
  }
319
- }, [account]);
320
- useEffect(() => {
321
- if (isConnected) setModalOpen(false);
322
- }, [isConnected]);
323
- return isConnected ? /* @__PURE__ */ jsxs("section", {
233
+ }, [n]);
234
+ return r(() => {
235
+ l && b(!1);
236
+ }, [l]), l ? /* @__PURE__ */ s("section", {
324
237
  className: "inline-flex items-center justify-center text-center",
325
238
  children: [
326
- /* @__PURE__ */ jsx("select", {
327
- value: selectedChain?.id,
328
- onChange: (e) => switchChain(chains.find((c) => c.id === Number(e.target.value))),
239
+ /* @__PURE__ */ o("select", {
240
+ value: u?.id,
241
+ onChange: (e) => p(m.find((t) => t.id === Number(e.target.value))),
329
242
  className: "bg-transparent1 mr-4 cursor-pointer rounded-sm border-none p-1 text-gray-600 outline-none hover:bg-gray-100",
330
- children: chains.map((chain) => /* @__PURE__ */ jsx("option", {
331
- value: chain.id,
332
- children: chain.name
333
- }, chain.id))
243
+ children: m.map((e) => /* @__PURE__ */ o("option", {
244
+ value: e.id,
245
+ children: e.name
246
+ }, e.id))
334
247
  }),
335
- /* @__PURE__ */ jsxs("div", {
248
+ /* @__PURE__ */ s("div", {
336
249
  className: "flex items-center justify-center rounded-2xl bg-white pr-3 shadow-lg inset-ring-1 shadow-gray-200 inset-ring-gray-100",
337
- children: [/* @__PURE__ */ jsxs("div", {
250
+ children: [/* @__PURE__ */ s("div", {
338
251
  onClick: () => {
339
- setAccountModalOpen(true);
252
+ S(!0);
340
253
  },
341
254
  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",
342
255
  children: [
343
- wallet && /* @__PURE__ */ jsx("img", {
344
- src: wallet.icon,
345
- alt: wallet.name,
256
+ f && /* @__PURE__ */ o("img", {
257
+ src: f.icon,
258
+ alt: f.name,
346
259
  className: "h-6 w-6"
347
260
  }),
348
- /* @__PURE__ */ jsx("div", {
261
+ /* @__PURE__ */ o("div", {
349
262
  className: "mr-1",
350
- children: accountText
263
+ children: T
351
264
  }),
352
- /* @__PURE__ */ jsxs("span", {
265
+ /* @__PURE__ */ s("span", {
353
266
  className: "text-sm text-gray-400",
354
267
  children: [
355
268
  "(",
356
- balance,
269
+ c,
357
270
  " ",
358
- selectedChain?.symbol ?? "",
271
+ u?.symbol ?? "",
359
272
  ")"
360
273
  ]
361
274
  })
362
275
  ]
363
- }), /* @__PURE__ */ jsx("button", {
276
+ }), /* @__PURE__ */ o("button", {
364
277
  className: "ml-1 h-6 w-6 cursor-pointer rounded-full",
365
- onClick: disconnect,
366
- children: /* @__PURE__ */ jsx("img", {
367
- src: disconnect_default,
278
+ onClick: v,
279
+ children: /* @__PURE__ */ o("img", {
280
+ src: g,
368
281
  alt: "disconnect",
369
282
  className: "h-[22px] w-6"
370
283
  })
371
284
  })]
372
285
  }),
373
- accountModalOpen && /* @__PURE__ */ jsx("div", {
286
+ x && /* @__PURE__ */ o("div", {
374
287
  className: "z-index-10 fixed top-0 right-0 bottom-0 left-0 bg-[rgba(0,0,0,0.5)]",
375
- children: /* @__PURE__ */ jsxs("div", {
288
+ children: /* @__PURE__ */ s("div", {
376
289
  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",
377
290
  children: [
378
- /* @__PURE__ */ jsx("div", {
291
+ /* @__PURE__ */ o("div", {
379
292
  className: "mb-[-12px] w-full text-right",
380
- children: /* @__PURE__ */ jsx("button", {
293
+ children: /* @__PURE__ */ o("button", {
381
294
  className: "mr-[-20px] cursor-pointer rounded-full p-1 hover:bg-gray-100",
382
295
  onClick: () => {
383
- setAccountModalOpen(false);
296
+ S(!1);
384
297
  },
385
- children: /* @__PURE__ */ jsxs("svg", {
298
+ children: /* @__PURE__ */ s("svg", {
386
299
  xmlns: "http://www.w3.org/2000/svg",
387
300
  viewBox: "0 0 24 24",
388
301
  fill: "none",
389
302
  stroke: "currentColor",
390
303
  strokeWidth: "2",
391
304
  className: "h-8 w-8",
392
- children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
305
+ children: [/* @__PURE__ */ o("path", { d: "M18 6 6 18" }), /* @__PURE__ */ o("path", { d: "m6 6 12 12" })]
393
306
  })
394
307
  })
395
308
  }),
396
- wallet && /* @__PURE__ */ jsx("img", {
397
- src: wallet.icon,
398
- alt: wallet.name,
309
+ f && /* @__PURE__ */ o("img", {
310
+ src: f.icon,
311
+ alt: f.name,
399
312
  className: "h-16 w-16"
400
313
  }),
401
- /* @__PURE__ */ jsx("p", { children: accountText }),
402
- /* @__PURE__ */ jsxs("div", {
314
+ /* @__PURE__ */ o("p", { children: T }),
315
+ /* @__PURE__ */ s("div", {
403
316
  className: "mt-2 w-full space-x-10",
404
- children: [/* @__PURE__ */ jsx("button", {
405
- onClick: copyAddress,
317
+ children: [/* @__PURE__ */ o("button", {
318
+ onClick: O,
406
319
  className: "w-[112px] cursor-pointer rounded-xl bg-gray-700 py-2 text-white shadow-md shadow-gray-500/50 outline-none",
407
- children: copyLabel
408
- }), /* @__PURE__ */ jsx("button", {
320
+ children: C
321
+ }), /* @__PURE__ */ o("button", {
409
322
  type: "button",
410
- onClick: disconnect,
323
+ onClick: v,
411
324
  className: "w-[112px] cursor-pointer rounded-xl bg-red-400 py-2 text-white shadow-md shadow-red-500/50 outline-none",
412
325
  children: "断开连接"
413
326
  })]
@@ -416,60 +329,60 @@ function MiniWalletButton({ label = "Connect Wallet" }) {
416
329
  })
417
330
  })
418
331
  ]
419
- }) : /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("button", {
332
+ }) : /* @__PURE__ */ s("div", { children: [/* @__PURE__ */ o("button", {
420
333
  type: "button",
421
- onClick: openModal,
334
+ onClick: E,
422
335
  className: "cursor-pointer rounded-xl bg-blue-500 px-4 py-2 text-white shadow-lg shadow-blue-500/50",
423
- children: label
424
- }), modalOpen && /* @__PURE__ */ jsx("div", {
336
+ children: e
337
+ }), y && /* @__PURE__ */ o("div", {
425
338
  className: "z-index-10 fixed top-0 right-0 bottom-0 left-0 bg-[rgba(0,0,0,0.5)]",
426
- children: /* @__PURE__ */ jsxs("div", {
339
+ children: /* @__PURE__ */ s("div", {
427
340
  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",
428
- children: [/* @__PURE__ */ jsxs("div", {
341
+ children: [/* @__PURE__ */ s("div", {
429
342
  className: "mb-2 flex items-center justify-between",
430
- children: [/* @__PURE__ */ jsx("span", {
343
+ children: [/* @__PURE__ */ o("span", {
431
344
  className: "text-2xl font-bold",
432
345
  children: "Connect Wallet"
433
- }), /* @__PURE__ */ jsx("button", {
346
+ }), /* @__PURE__ */ o("button", {
434
347
  type: "button",
435
348
  "aria-label": "Close",
436
349
  className: "cursor-pointer rounded-full p-1 hover:bg-gray-100",
437
- onClick: closeModal,
438
- children: /* @__PURE__ */ jsxs("svg", {
350
+ onClick: D,
351
+ children: /* @__PURE__ */ s("svg", {
439
352
  xmlns: "http://www.w3.org/2000/svg",
440
353
  viewBox: "0 0 24 24",
441
354
  fill: "none",
442
355
  stroke: "currentColor",
443
356
  strokeWidth: "2",
444
357
  className: "h-8 w-8",
445
- children: [/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }), /* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })]
358
+ children: [/* @__PURE__ */ o("path", { d: "M18 6 6 18" }), /* @__PURE__ */ o("path", { d: "m6 6 12 12" })]
446
359
  })
447
360
  })]
448
- }), /* @__PURE__ */ jsx("div", {
361
+ }), /* @__PURE__ */ o("div", {
449
362
  className: "relative w-full space-y-4",
450
- children: WALLETS.map((w) => /* @__PURE__ */ jsxs("button", {
363
+ children: d.map((e) => /* @__PURE__ */ s("button", {
451
364
  type: "button",
452
- onClick: () => connect(w),
365
+ onClick: () => _(e),
453
366
  className: "flex w-full cursor-pointer items-center gap-2 rounded-xl border border-gray-300 px-4 py-2 hover:bg-gray-100",
454
- children: [/* @__PURE__ */ jsx("img", {
455
- src: w.icon,
456
- alt: w.name,
367
+ children: [/* @__PURE__ */ o("img", {
368
+ src: e.icon,
369
+ alt: e.name,
457
370
  className: "h-8 w-8"
458
- }), /* @__PURE__ */ jsxs("div", {
371
+ }), /* @__PURE__ */ s("div", {
459
372
  className: "flex flex-col justify-between text-left",
460
- children: [/* @__PURE__ */ jsx("p", { children: w.name }), /* @__PURE__ */ jsxs("span", {
373
+ children: [/* @__PURE__ */ o("p", { children: e.name }), /* @__PURE__ */ s("span", {
461
374
  className: "text-xs text-gray-500",
462
375
  children: [
463
376
  "Connect your ",
464
- w.name,
377
+ e.name,
465
378
  " wallet"
466
379
  ]
467
380
  })]
468
381
  })]
469
- }, w.id))
382
+ }, e.id))
470
383
  })]
471
384
  })
472
385
  })] });
473
386
  }
474
387
  //#endregion
475
- export { MiniWalletButton, MiniWalletProvider, useMiniWallet };
388
+ export { _ as MiniWalletButton, m as MiniWalletProvider, h as useMiniWallet };