cppay-sdk 0.0.2-beta.27 → 0.0.2-beta.28

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/react.js CHANGED
@@ -1,198 +1,18 @@
1
- import { _ as __toESM, a as base, c as tap, d as expand, f as require_browser, g as __require, h as __commonJSMin, i as bsc, l as switchMap, m as payment_dialog_default, n as optimism, o as arbitrum, p as injectStyle, r as mainnet, s as timeout, t as polygon, u as retry } from "./polygon-1pLQCNfb.js";
2
- import { t as cppay_default } from "./cppay-BcCDwXlg.js";
1
+ import { t as cppay_default } from "./cppay-Dhqe5Hz_.js";
2
+ import { n as payment_dialog_default, t as injectStyle } from "./inject-style-aMqJSA89.js";
3
+ import * as QRCode from "qrcode";
3
4
  import { EMPTY, defer, timer } from "rxjs";
5
+ import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
4
6
  import { createWalletClient, custom, parseUnits } from "viem";
7
+ import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
5
8
  import { createAppKit } from "@reown/appkit";
6
9
  import { EthersAdapter } from "@reown/appkit-adapter-ethers";
7
10
  import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
8
- /**
9
- * @license React
10
- * react-jsx-runtime.production.js
11
- *
12
- * Copyright (c) Meta Platforms, Inc. and affiliates.
13
- *
14
- * This source code is licensed under the MIT license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- */
17
- var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) => {
18
- var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
19
- function r(e, n, r) {
20
- var i = null;
21
- if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
22
- else r = n;
23
- return n = r.ref, {
24
- $$typeof: t,
25
- type: e,
26
- key: i,
27
- ref: n === void 0 ? null : n,
28
- props: r
29
- };
30
- }
31
- e.Fragment = n, e.jsx = r, e.jsxs = r;
32
- })), require_react_jsx_runtime_development = /* @__PURE__ */ __commonJSMin(((e) => {
33
- process.env.NODE_ENV !== "production" && (function() {
34
- function t(e) {
35
- if (e == null) return null;
36
- if (typeof e == "function") return e.$$typeof === de ? null : e.displayName || e.name || null;
37
- if (typeof e == "string") return e;
38
- switch (e) {
39
- case m: return "Fragment";
40
- case ae: return "Profiler";
41
- case ie: return "StrictMode";
42
- case le: return "Suspense";
43
- case ue: return "SuspenseList";
44
- case _: return "Activity";
45
- }
46
- if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
47
- case re: return "Portal";
48
- case se: return e.displayName || "Context";
49
- case oe: return (e._context.displayName || "Context") + ".Consumer";
50
- case ce:
51
- var n = e.render;
52
- return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
53
- case h: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
54
- case g:
55
- n = e._payload, e = e._init;
56
- try {
57
- return t(e(n));
58
- } catch {}
59
- }
60
- return null;
61
- }
62
- function n(e) {
63
- return "" + e;
64
- }
65
- function r(e) {
66
- try {
67
- n(e);
68
- var t = !1;
69
- } catch {
70
- t = !0;
71
- }
72
- if (t) {
73
- t = console;
74
- var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
75
- return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
76
- }
77
- }
78
- function i(e) {
79
- if (e === m) return "<>";
80
- if (typeof e == "object" && e && e.$$typeof === g) return "<...>";
81
- try {
82
- var n = t(e);
83
- return n ? "<" + n + ">" : "<...>";
84
- } catch {
85
- return "<...>";
86
- }
87
- }
88
- function o() {
89
- var e = v.A;
90
- return e === null ? null : e.getOwner();
91
- }
92
- function s() {
93
- return Error("react-stack-top-frame");
94
- }
95
- function c(e) {
96
- if (fe.call(e, "key")) {
97
- var t = Object.getOwnPropertyDescriptor(e, "key").get;
98
- if (t && t.isReactWarning) return !1;
99
- }
100
- return e.key !== void 0;
101
- }
102
- function l(e, t) {
103
- function n() {
104
- b || (b = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
105
- }
106
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
107
- get: n,
108
- configurable: !0
109
- });
110
- }
111
- function ee() {
112
- var e = t(this.type);
113
- return x[e] || (x[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
114
- }
115
- function te(e, t, n, r, i, a) {
116
- var o = n.ref;
117
- return e = {
118
- $$typeof: p,
119
- type: e,
120
- key: t,
121
- props: n,
122
- _owner: r
123
- }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
124
- enumerable: !1,
125
- value: null
126
- }) : Object.defineProperty(e, "ref", {
127
- enumerable: !1,
128
- get: ee
129
- }), e._store = {}, Object.defineProperty(e._store, "validated", {
130
- configurable: !1,
131
- enumerable: !1,
132
- writable: !0,
133
- value: 0
134
- }), Object.defineProperty(e, "_debugInfo", {
135
- configurable: !1,
136
- enumerable: !1,
137
- writable: !0,
138
- value: null
139
- }), Object.defineProperty(e, "_debugStack", {
140
- configurable: !1,
141
- enumerable: !1,
142
- writable: !0,
143
- value: i
144
- }), Object.defineProperty(e, "_debugTask", {
145
- configurable: !1,
146
- enumerable: !1,
147
- writable: !0,
148
- value: a
149
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
150
- }
151
- function u(e, n, i, a, s, ee) {
152
- var u = n.children;
153
- if (u !== void 0) if (a) if (pe(u)) {
154
- for (a = 0; a < u.length; a++) ne(u[a]);
155
- Object.freeze && Object.freeze(u);
156
- } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
157
- else ne(u);
158
- if (fe.call(n, "key")) {
159
- u = t(e);
160
- var d = Object.keys(n).filter(function(e) {
161
- return e !== "key";
162
- });
163
- a = 0 < d.length ? "{key: someKey, " + d.join(": ..., ") + ": ...}" : "{key: someKey}", w[u + a] || (d = 0 < d.length ? "{" + d.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, u, d, u), w[u + a] = !0);
164
- }
165
- if (u = null, i !== void 0 && (r(i), u = "" + i), c(n) && (r(n.key), u = "" + n.key), "key" in n) for (var f in i = {}, n) f !== "key" && (i[f] = n[f]);
166
- else i = n;
167
- return u && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), te(e, u, i, o(), s, ee);
168
- }
169
- function ne(e) {
170
- d(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === g && (e._payload.status === "fulfilled" ? d(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
171
- }
172
- function d(e) {
173
- return typeof e == "object" && !!e && e.$$typeof === p;
174
- }
175
- var f = __require("react"), p = Symbol.for("react.transitional.element"), re = Symbol.for("react.portal"), m = Symbol.for("react.fragment"), ie = Symbol.for("react.strict_mode"), ae = Symbol.for("react.profiler"), oe = Symbol.for("react.consumer"), se = Symbol.for("react.context"), ce = Symbol.for("react.forward_ref"), le = Symbol.for("react.suspense"), ue = Symbol.for("react.suspense_list"), h = Symbol.for("react.memo"), g = Symbol.for("react.lazy"), _ = Symbol.for("react.activity"), de = Symbol.for("react.client.reference"), v = f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, fe = Object.prototype.hasOwnProperty, pe = Array.isArray, y = console.createTask ? console.createTask : function() {
176
- return null;
177
- };
178
- f = { react_stack_bottom_frame: function(e) {
179
- return e();
180
- } };
181
- var b, x = {}, S = f.react_stack_bottom_frame.bind(f, s)(), C = y(i(s)), w = {};
182
- e.Fragment = m, e.jsx = function(e, t, n) {
183
- var r = 1e4 > v.recentlyCreatedOwnerStacks++;
184
- return u(e, t, n, !1, r ? Error("react-stack-top-frame") : S, r ? y(i(e)) : C);
185
- }, e.jsxs = function(e, t, n) {
186
- var r = 1e4 > v.recentlyCreatedOwnerStacks++;
187
- return u(e, t, n, !0, r ? Error("react-stack-top-frame") : S, r ? y(i(e)) : C);
188
- };
189
- })();
190
- })), require_jsx_runtime = /* @__PURE__ */ __commonJSMin(((e, t) => {
191
- process.env.NODE_ENV === "production" ? t.exports = require_react_jsx_runtime_production() : t.exports = require_react_jsx_runtime_development();
192
- })), import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), import_jsx_runtime = require_jsx_runtime(), PaymentDialog_default = React.memo(({ open: e, onClose: i, apikey: a, plain: o, orderId: l, amount: u, intervalDays: h, onExpired: g, onSuccess: _, onFailed: de, onError: b }) => {
193
- let x = useMemo(() => new cppay_default(a), [a]), [S, T] = useState("select"), [E, D] = useState(!1), [O, k] = useState(!1), [A, me] = useState([]), [j, M] = useState(), [N, P] = useState(), [F, he] = useState(), [I, L] = useState(), [R, z] = useState(!1), [B, V] = useState(), H = useRef(null), U = useRef(null);
11
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
+ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain: d, orderId: f, amount: p, intervalDays: m, onExpired: h, onSuccess: g, onFailed: _, onError: v }) => {
13
+ let y = useMemo(() => new cppay_default(u), [u]), [b, x] = useState("select"), [S, C] = useState(!1), [w, T] = useState(!1), [E, D] = useState([]), [O, k] = useState(), [A, j] = useState(), [M, N] = useState(), [P, F] = useState(), [I, L] = useState(!1), [R, z] = useState(), B = useRef(null), V = useRef(null);
194
14
  useEffect(() => {
195
- typeof window < "u" && !H.current && (H.current = createAppKit({
15
+ typeof window < "u" && !B.current && (B.current = createAppKit({
196
16
  debug: !1,
197
17
  enableNetworkSwitch: !1,
198
18
  adapters: [new EthersAdapter()],
@@ -213,22 +33,22 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
213
33
  icons: ["https://cppay.com/icon.png"]
214
34
  },
215
35
  features: { analytics: !1 }
216
- }), L(H.current.getAddress()), V(H.current.getProvider("eip155")), H.current.subscribeAccount((e) => {
217
- e.isConnected ? L(e.address) : (L(void 0), V(void 0));
218
- }), H.current.subscribeProviders((e) => {
36
+ }), F(B.current.getAddress()), z(B.current.getProvider("eip155")), B.current.subscribeAccount((e) => {
37
+ e.isConnected ? F(e.address) : (F(void 0), z(void 0));
38
+ }), B.current.subscribeProviders((e) => {
219
39
  let t = e?.eip155;
220
- V(t);
40
+ z(t);
221
41
  }));
222
42
  }, []);
223
- let W = async () => {
43
+ let H = async () => {
224
44
  try {
225
- z(!0), H.current && await H.current.open();
45
+ L(!0), B.current && await B.current.open();
226
46
  } catch (e) {
227
- console.error("钱包连接失败:", e), b?.(e);
47
+ console.error("钱包连接失败:", e), v?.(e);
228
48
  } finally {
229
- z(!1);
49
+ L(!1);
230
50
  }
231
- }, G = useMemo(() => A.find((e) => e.chain === j), [A, j]), K = useMemo(() => G?.tokens || [], [G]), q = useMemo(() => K.find((e) => e.symbol === N), [K, N]), J = (e) => [
51
+ }, U = useMemo(() => E.find((e) => e.chain === O), [E, O]), W = useMemo(() => U?.tokens || [], [U]), G = useMemo(() => W.find((e) => e.symbol === A), [W, A]), K = (e) => [
232
52
  "USDT",
233
53
  "USDC",
234
54
  "BUSD",
@@ -236,50 +56,50 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
236
56
  "TUSD",
237
57
  "USDD",
238
58
  "FDUSD"
239
- ].includes(e.toUpperCase()) ? 2 : 6, Y = (e, t) => {
59
+ ].includes(e.toUpperCase()) ? 2 : 6, q = (e, t) => {
240
60
  let n = parseFloat(e);
241
61
  return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
242
- }, X = useMemo(() => {
243
- if (!N || !q) return "0";
244
- let e = parseFloat(q.price);
62
+ }, J = useMemo(() => {
63
+ if (!A || !G) return "0";
64
+ let e = parseFloat(G.price);
245
65
  if (isNaN(e) || e === 0) return "0";
246
- let t = J(N);
247
- return Y((parseFloat(u) / e).toFixed(t), t);
66
+ let t = K(A);
67
+ return q((parseFloat(p) / e).toFixed(t), t);
248
68
  }, [
249
- u,
250
- N,
251
- q
252
- ]), ge = async () => {
69
+ p,
70
+ A,
71
+ G
72
+ ]), Y = async () => {
253
73
  try {
254
- D(!0);
255
- let e = await x.getSupportedChains();
256
- me(e), e.length > 0 && M(e[0].chain);
74
+ C(!0);
75
+ let e = await y.getSupportedChains();
76
+ D(e), e.length > 0 && k(e[0].chain);
257
77
  } catch (e) {
258
- b?.(e);
78
+ v?.(e);
259
79
  } finally {
260
- D(!1);
80
+ C(!1);
261
81
  }
262
- }, _e = async (e) => {
263
- if (B) try {
264
- await B.request({
82
+ }, X = async (e) => {
83
+ if (R) try {
84
+ await R.request({
265
85
  method: "wallet_switchEthereumChain",
266
86
  params: [{ chainId: `0x${e.toString(16)}` }]
267
87
  });
268
88
  } catch (e) {
269
89
  throw e.code === 4902 ? Error("请在钱包中添加该网络") : e;
270
90
  }
271
- }, ve = async () => {
272
- if (!(!I || !B || !Z.current || !q || !G)) try {
273
- D(!0);
91
+ }, be = async () => {
92
+ if (!(!P || !R || !Z.current || !G || !U)) try {
93
+ C(!0);
274
94
  let e = Z.current;
275
- await _e(G.chainId);
95
+ await X(U.chainId);
276
96
  let t = createWalletClient({
277
- account: I,
278
- transport: custom(B)
97
+ account: P,
98
+ transport: custom(R)
279
99
  });
280
- if (q.address) {
100
+ if (G.address) {
281
101
  let n = await t.writeContract({
282
- address: q.address,
102
+ address: G.address,
283
103
  abi: [{
284
104
  name: "transfer",
285
105
  type: "function",
@@ -294,34 +114,34 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
294
114
  outputs: [{ type: "bool" }]
295
115
  }],
296
116
  functionName: "transfer",
297
- args: [e.receiveAddress, parseUnits(e.paymentAmount, q.decimals)],
117
+ args: [e.receiveAddress, parseUnits(e.paymentAmount, G.decimals)],
298
118
  chain: null
299
119
  });
300
120
  console.log("转账交易哈希:", n);
301
121
  } else {
302
122
  let n = await t.sendTransaction({
303
123
  to: e.receiveAddress,
304
- value: parseUnits(e.paymentAmount, q.decimals),
124
+ value: parseUnits(e.paymentAmount, G.decimals),
305
125
  chain: null
306
126
  });
307
127
  console.log("转账交易哈希:", n);
308
128
  }
309
- D(!1), k(!0), Q(e.paymentId);
129
+ C(!1), T(!0), Q(e.paymentId);
310
130
  } catch (e) {
311
- console.error("钱包支付失败:", e), b?.(e), D(!1);
131
+ console.error("钱包支付失败:", e), v?.(e), C(!1);
312
132
  }
313
- }, ye = async () => {
314
- if (!(!I || !B || !Z.current || !q || !G)) try {
315
- D(!0);
133
+ }, xe = async () => {
134
+ if (!(!P || !R || !Z.current || !G || !U)) try {
135
+ C(!0);
316
136
  let e = Z.current;
317
- await _e(G.chainId);
137
+ await X(U.chainId);
318
138
  let t = createWalletClient({
319
- account: I,
320
- transport: custom(B)
139
+ account: P,
140
+ transport: custom(R)
321
141
  });
322
- if (!q.address) throw Error("订阅支付不支持原生代币");
142
+ if (!G.address) throw Error("订阅支付不支持原生代币");
323
143
  let n = await t.writeContract({
324
- address: q.address,
144
+ address: G.address,
325
145
  abi: [{
326
146
  name: "approve",
327
147
  type: "function",
@@ -336,94 +156,94 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
336
156
  outputs: [{ type: "bool" }]
337
157
  }],
338
158
  functionName: "approve",
339
- args: [e.spenderAddress, parseUnits(e.approveAmount, q.decimals)],
159
+ args: [e.spenderAddress, parseUnits(e.approveAmount, G.decimals)],
340
160
  chain: null
341
161
  });
342
- console.log("授权交易哈希:", n), D(!1), k(!0), Q(e.subscriptionId);
162
+ console.log("授权交易哈希:", n), C(!1), T(!0), Q(e.subscriptionId);
343
163
  } catch (e) {
344
- console.error("钱包授权失败:", e), b?.(e), D(!1);
164
+ console.error("钱包授权失败:", e), v?.(e), C(!1);
345
165
  }
346
- }, be = async () => {
347
- if (!I) {
348
- b?.(/* @__PURE__ */ Error("请先连接钱包"));
166
+ }, Se = async () => {
167
+ if (!P) {
168
+ v?.(/* @__PURE__ */ Error("请先连接钱包"));
349
169
  return;
350
170
  }
351
- o === "one-time" ? await ve() : o === "subscription" && await ye();
352
- }, Z = useRef(null), xe = async () => {
353
- if (!(!j || !N)) try {
354
- D(!0);
171
+ d === "one-time" ? await be() : d === "subscription" && await xe();
172
+ }, Z = useRef(null), Ce = async () => {
173
+ if (!(!O || !A)) try {
174
+ C(!0);
355
175
  let e = "";
356
- o === "one-time" ? (Z.current = await x.createOnetimePayment({
357
- paymentChain: j,
358
- paymentToken: N,
359
- orderId: l,
360
- amount: X
361
- }), e = `${j.toLowerCase()}:${Z.current.receiveAddress}?amount=${Z.current.paymentAmount}`) : o === "subscription" && (Z.current = await x.createSubscriptionPayment({
362
- paymentChain: j,
363
- paymentToken: N,
364
- orderId: l,
365
- amountOfUsd: X,
366
- intervalDays: h || 30
367
- }), e = `${j.toLowerCase()}:${Z.current.spenderAddress}?amount=${Z.current.approveAmount}`), T("payment"), he(await import_browser.toDataURL(e, {
176
+ d === "one-time" ? (Z.current = await y.createOnetimePayment({
177
+ paymentChain: O,
178
+ paymentToken: A,
179
+ orderId: f,
180
+ amount: J
181
+ }), e = `${O.toLowerCase()}:${Z.current.receiveAddress}?amount=${Z.current.paymentAmount}`) : d === "subscription" && (Z.current = await y.createSubscriptionPayment({
182
+ paymentChain: O,
183
+ paymentToken: A,
184
+ orderId: f,
185
+ amountOfUsd: J,
186
+ intervalDays: m || 30
187
+ }), e = `${O.toLowerCase()}:${Z.current.spenderAddress}?amount=${Z.current.approveAmount}`), x("payment"), N(await QRCode.toDataURL(e, {
368
188
  width: 200,
369
189
  margin: 2,
370
190
  errorCorrectionLevel: "H"
371
191
  }));
372
192
  } catch (e) {
373
- b?.(e);
193
+ v?.(e);
374
194
  } finally {
375
- D(!1);
195
+ C(!1);
376
196
  }
377
- }, Se = async () => {
197
+ }, we = async () => {
378
198
  if (Z.current) try {
379
- k(!0), o === "one-time" ? Q(Z.current.paymentId) : o === "subscription" && Q(Z.current.subscriptionId);
199
+ T(!0), d === "one-time" ? Q(Z.current.paymentId) : d === "subscription" && Q(Z.current.subscriptionId);
380
200
  } catch (e) {
381
- console.error("支付状态检查错误:", e), b?.(e), k(!1);
201
+ console.error("支付状态检查错误:", e), v?.(e), T(!1);
382
202
  }
383
203
  }, Q = (e) => {
384
- let t = () => defer(() => o === "subscription" ? x.checkSubscriptionPaymentStatus({ subscriptionId: e }) : x.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
204
+ let t = () => defer(() => d === "subscription" ? y.checkSubscriptionPaymentStatus({ subscriptionId: e }) : y.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
385
205
  count: 3,
386
206
  delay: 2e3
387
207
  }));
388
- U.current?.unsubscribe(), U.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
389
- e.status === "expired" && (k(!1), g?.(e)), e.status === "paid" && (k(!1), T("success"), _?.(e)), e.status === "failed" && (k(!1), de?.(e)), e.status === "approved" && (k(!1), T("success"), _?.(e));
208
+ V.current?.unsubscribe(), V.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
209
+ e.status === "expired" && (T(!1), h?.(e)), e.status === "paid" && (T(!1), x("success"), g?.(e)), e.status === "failed" && (T(!1), _?.(e)), e.status === "approved" && (T(!1), x("success"), g?.(e));
390
210
  })).subscribe({ error: (e) => {
391
- console.error("支付状态检查错误:", e), k(!1), b?.(e);
211
+ console.error("支付状态检查错误:", e), T(!1), v?.(e);
392
212
  } });
393
- }, Ce = async () => {
213
+ }, Te = async () => {
394
214
  if (!Z.current) return;
395
- let e = o === "subscription" ? Z.current.spenderAddress : Z.current.receiveAddress;
215
+ let e = d === "subscription" ? Z.current.spenderAddress : Z.current.receiveAddress;
396
216
  e && await navigator.clipboard.writeText(e);
397
217
  }, $ = () => {
398
- E || O || (i(), setTimeout(() => {
399
- T("select"), Z.current = null;
218
+ S || w || (n(), setTimeout(() => {
219
+ x("select"), Z.current = null;
400
220
  }, 300));
401
221
  };
402
222
  return useEffect(() => {
403
- e && A.length === 0 && ge();
404
- }, [e]), useEffect(() => {
405
- K.length > 0 && P(K[0].symbol);
406
- }, [K]), useEffect(() => () => {
407
- U.current?.unsubscribe();
408
- }, []), e ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
223
+ t && E.length === 0 && Y();
224
+ }, [t]), useEffect(() => {
225
+ W.length > 0 && j(W[0].symbol);
226
+ }, [W]), useEffect(() => () => {
227
+ V.current?.unsubscribe();
228
+ }, []), t ? /* @__PURE__ */ jsx("div", {
409
229
  className: "_cppay-overlay",
410
- onClick: (e) => e.target === e.currentTarget && !E && !O && $(),
411
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
230
+ onClick: (e) => e.target === e.currentTarget && !S && !w && $(),
231
+ children: /* @__PURE__ */ jsxs("div", {
412
232
  className: "_cppay-dialog",
413
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
233
+ children: [/* @__PURE__ */ jsxs("div", {
414
234
  className: "_cppay-header",
415
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
235
+ children: [/* @__PURE__ */ jsx("h2", {
416
236
  className: "_cppay-title",
417
- children: S === "select" ? "选择支付方式" : "完成支付"
418
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
237
+ children: b === "select" ? "选择支付方式" : "完成支付"
238
+ }), /* @__PURE__ */ jsx("button", {
419
239
  onClick: $,
420
- disabled: E || O,
240
+ disabled: S || w,
421
241
  className: "_cppay-close-btn",
422
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
242
+ children: /* @__PURE__ */ jsx("svg", {
423
243
  fill: "none",
424
244
  stroke: "currentColor",
425
245
  viewBox: "0 0 24 24",
426
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
246
+ children: /* @__PURE__ */ jsx("path", {
427
247
  strokeLinecap: "round",
428
248
  strokeLinejoin: "round",
429
249
  strokeWidth: 2,
@@ -431,115 +251,115 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
431
251
  })
432
252
  })
433
253
  })]
434
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
254
+ }), /* @__PURE__ */ jsx("div", {
435
255
  className: "_cppay-content",
436
- children: S === "success" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
256
+ children: b === "success" ? /* @__PURE__ */ jsxs("div", {
437
257
  style: {
438
258
  textAlign: "center",
439
259
  padding: "2rem 0"
440
260
  },
441
261
  children: [
442
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
262
+ /* @__PURE__ */ jsx("div", {
443
263
  style: {
444
264
  fontSize: "64px",
445
265
  marginBottom: "1rem"
446
266
  },
447
267
  children: "✅"
448
268
  }),
449
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
269
+ /* @__PURE__ */ jsx("h3", {
450
270
  style: {
451
271
  fontSize: "1.5rem",
452
272
  fontWeight: 600,
453
273
  color: "#10b981",
454
274
  margin: "0 0 0.5rem 0"
455
275
  },
456
- children: o === "subscription" ? "授权成功!" : "支付成功!"
276
+ children: d === "subscription" ? "授权成功!" : "支付成功!"
457
277
  }),
458
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
278
+ /* @__PURE__ */ jsx("p", {
459
279
  style: {
460
280
  color: "#6b7280",
461
281
  margin: 0
462
282
  },
463
- children: o === "subscription" ? "订阅已激活" : "交易已完成"
283
+ children: d === "subscription" ? "订阅已激活" : "交易已完成"
464
284
  })
465
285
  ]
466
- }) : S === "select" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
467
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
286
+ }) : b === "select" ? /* @__PURE__ */ jsxs("div", { children: [
287
+ /* @__PURE__ */ jsxs("div", {
468
288
  className: "_cppay-section",
469
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
289
+ children: [/* @__PURE__ */ jsx("label", {
470
290
  className: "_cppay-label",
471
291
  children: "支付网络"
472
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
292
+ }), /* @__PURE__ */ jsx("div", {
473
293
  className: "_cppay-grid",
474
- children: A.map((e) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
475
- onClick: () => M(e.chain),
476
- className: `_cppay-select-btn ${j === e.chain ? "_cppay-selected" : ""}`,
477
- children: [e.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
294
+ children: E.map((e) => /* @__PURE__ */ jsxs("button", {
295
+ onClick: () => k(e.chain),
296
+ className: `_cppay-select-btn ${O === e.chain ? "_cppay-selected" : ""}`,
297
+ children: [e.icon && /* @__PURE__ */ jsx("img", {
478
298
  src: e.icon,
479
299
  alt: e.chain
480
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: e.chain })]
300
+ }), /* @__PURE__ */ jsx("span", { children: e.chain })]
481
301
  }, e.chain))
482
302
  })]
483
303
  }),
484
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
304
+ /* @__PURE__ */ jsxs("div", {
485
305
  className: "_cppay-section",
486
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
306
+ children: [/* @__PURE__ */ jsx("label", {
487
307
  className: "_cppay-label",
488
308
  children: "支付代币"
489
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
309
+ }), /* @__PURE__ */ jsx("div", {
490
310
  className: "_cppay-grid",
491
- children: K.map((e) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
492
- onClick: () => P(e.symbol),
493
- className: `_cppay-select-btn ${N === e.symbol ? "_cppay-selected" : ""}`,
494
- children: [e.icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
311
+ children: W.map((e) => /* @__PURE__ */ jsxs("button", {
312
+ onClick: () => j(e.symbol),
313
+ className: `_cppay-select-btn ${A === e.symbol ? "_cppay-selected" : ""}`,
314
+ children: [e.icon && /* @__PURE__ */ jsx("img", {
495
315
  src: e.icon,
496
316
  alt: e.symbol
497
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: e.symbol })]
317
+ }), /* @__PURE__ */ jsx("span", { children: e.symbol })]
498
318
  }, e.symbol))
499
319
  })]
500
320
  }),
501
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
321
+ /* @__PURE__ */ jsx("div", {
502
322
  className: "_cppay-section",
503
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
323
+ children: /* @__PURE__ */ jsx("div", {
504
324
  className: "_cppay-price-box",
505
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
325
+ children: /* @__PURE__ */ jsxs("div", {
506
326
  className: "_cppay-price-row",
507
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
327
+ children: [/* @__PURE__ */ jsx("span", {
508
328
  className: "_cppay-price-label",
509
329
  children: "支付金额"
510
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
330
+ }), /* @__PURE__ */ jsxs("div", {
511
331
  className: "_cppay-price-amount",
512
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
332
+ children: [/* @__PURE__ */ jsxs("div", {
513
333
  className: "_cppay-price-main",
514
334
  children: [
515
- X ?? "-",
335
+ J ?? "-",
516
336
  " ",
517
- N ?? ""
337
+ A ?? ""
518
338
  ]
519
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
339
+ }), /* @__PURE__ */ jsxs("div", {
520
340
  className: "_cppay-price-sub",
521
- children: ["≈ $", u]
341
+ children: ["≈ $", p]
522
342
  })]
523
343
  })]
524
344
  })
525
345
  })
526
346
  }),
527
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
347
+ /* @__PURE__ */ jsx("div", {
528
348
  className: "_cppay-section",
529
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
530
- onClick: xe,
531
- disabled: !j || !N || E,
349
+ children: /* @__PURE__ */ jsx("button", {
350
+ onClick: Ce,
351
+ disabled: !O || !A || S,
532
352
  className: "_cppay-btn _cppay-btn-primary",
533
- children: E ? "处理中..." : "继续支付"
353
+ children: S ? "处理中..." : "继续支付"
534
354
  })
535
355
  })
536
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
537
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
356
+ ] }) : /* @__PURE__ */ jsxs("div", { children: [
357
+ /* @__PURE__ */ jsx("div", {
538
358
  className: "_cppay-qr-container",
539
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
359
+ children: /* @__PURE__ */ jsx("div", {
540
360
  className: "_cppay-qr-code",
541
- children: F && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
542
- src: F,
361
+ children: M && /* @__PURE__ */ jsx("img", {
362
+ src: M,
543
363
  alt: "Payment QR Code",
544
364
  style: {
545
365
  width: "160px",
@@ -549,35 +369,35 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
549
369
  })
550
370
  })
551
371
  }),
552
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
372
+ /* @__PURE__ */ jsxs("div", {
553
373
  className: "_cppay-section",
554
374
  children: [
555
- N && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
375
+ A && /* @__PURE__ */ jsxs("div", {
556
376
  className: "_cppay-info-box",
557
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
377
+ children: [/* @__PURE__ */ jsx("div", {
558
378
  className: "_cppay-info-label",
559
- children: o === "subscription" ? "授权金额" : "支付金额"
560
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
379
+ children: d === "subscription" ? "授权金额" : "支付金额"
380
+ }), /* @__PURE__ */ jsx("div", {
561
381
  className: "_cppay-info-value",
562
- children: o === "subscription" ? `${Y(Z.current.approveAmount, J(N))} ${N}` : `${Y(Z.current.paymentAmount, J(N))} ${N}`
382
+ children: d === "subscription" ? `${q(Z.current.approveAmount, K(A))} ${A}` : `${q(Z.current.paymentAmount, K(A))} ${A}`
563
383
  })]
564
384
  }),
565
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
385
+ /* @__PURE__ */ jsxs("div", {
566
386
  className: "_cppay-info-box",
567
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
387
+ children: [/* @__PURE__ */ jsx("div", {
568
388
  className: "_cppay-info-label",
569
- children: o === "subscription" ? "授权合约地址" : "支付地址"
570
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
389
+ children: d === "subscription" ? "授权合约地址" : "支付地址"
390
+ }), /* @__PURE__ */ jsxs("div", {
571
391
  className: "_cppay-address-row",
572
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: o === "subscription" ? Z.current.spenderAddress : Z.current.receiveAddress }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
573
- onClick: Ce,
392
+ children: [/* @__PURE__ */ jsx("code", { children: d === "subscription" ? Z.current.spenderAddress : Z.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
393
+ onClick: Te,
574
394
  className: "_cppay-copy-btn",
575
395
  title: "复制地址",
576
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
396
+ children: /* @__PURE__ */ jsx("svg", {
577
397
  fill: "none",
578
398
  stroke: "currentColor",
579
399
  viewBox: "0 0 24 24",
580
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
400
+ children: /* @__PURE__ */ jsx("path", {
581
401
  strokeLinecap: "round",
582
402
  strokeLinejoin: "round",
583
403
  strokeWidth: 2,
@@ -587,17 +407,17 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
587
407
  })]
588
408
  })]
589
409
  }),
590
- o === "subscription" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
410
+ d === "subscription" && /* @__PURE__ */ jsxs("div", {
591
411
  className: "_cppay-info-box",
592
412
  style: {
593
413
  background: "#fff3cd",
594
414
  borderColor: "#ffc107"
595
415
  },
596
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
416
+ children: [/* @__PURE__ */ jsx("div", {
597
417
  className: "_cppay-info-label",
598
418
  style: { color: "#856404" },
599
419
  children: "📌 订阅说明"
600
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
420
+ }), /* @__PURE__ */ jsx("div", {
601
421
  className: "_cppay-info-value",
602
422
  style: {
603
423
  fontSize: "12px",
@@ -608,22 +428,22 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
608
428
  })
609
429
  ]
610
430
  }),
611
- !O && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
431
+ !w && /* @__PURE__ */ jsx("div", {
612
432
  className: "_cppay-section",
613
- children: I ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
433
+ children: P ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
614
434
  className: "_cppay-btn-container",
615
- children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
616
- onClick: be,
617
- disabled: E,
435
+ children: [/* @__PURE__ */ jsx("button", {
436
+ onClick: Se,
437
+ disabled: S,
618
438
  className: "_cppay-btn _cppay-btn-primary",
619
- children: E ? o === "subscription" ? "授权中..." : "支付中..." : o === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
620
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
621
- onClick: W,
622
- disabled: E,
439
+ children: S ? d === "subscription" ? "授权中..." : "支付中..." : d === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
440
+ }), /* @__PURE__ */ jsx("button", {
441
+ onClick: H,
442
+ disabled: S,
623
443
  className: "_cppay-btn _cppay-btn-primary",
624
444
  children: "💰钱包状态"
625
445
  })]
626
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
446
+ }), /* @__PURE__ */ jsxs("div", {
627
447
  style: {
628
448
  textAlign: "center",
629
449
  marginTop: "8px",
@@ -632,13 +452,13 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
632
452
  },
633
453
  children: [
634
454
  "已连接: ",
635
- I.slice(0, 6),
455
+ P.slice(0, 6),
636
456
  "...",
637
- I.slice(-4)
457
+ P.slice(-4)
638
458
  ]
639
- })] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
640
- onClick: W,
641
- disabled: R,
459
+ })] }) : /* @__PURE__ */ jsx("button", {
460
+ onClick: H,
461
+ disabled: I,
642
462
  className: "_cppay-btn _cppay-btn-secondary",
643
463
  style: {
644
464
  display: "flex",
@@ -648,23 +468,23 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
648
468
  padding: "0.75rem 1rem",
649
469
  width: "100%"
650
470
  },
651
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: R ? "连接中..." : "💳 连接钱包" })
471
+ children: /* @__PURE__ */ jsx("span", { children: I ? "连接中..." : "💳 连接钱包" })
652
472
  })
653
473
  }),
654
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
474
+ /* @__PURE__ */ jsx("div", {
655
475
  className: "_cppay-section",
656
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
657
- onClick: Se,
658
- disabled: O,
476
+ children: /* @__PURE__ */ jsx("button", {
477
+ onClick: we,
478
+ disabled: w,
659
479
  className: "_cppay-btn _cppay-btn-primary",
660
- children: O ? "检查中..." : "我已完成支付"
480
+ children: w ? "检查中..." : "我已完成支付"
661
481
  })
662
482
  }),
663
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
483
+ /* @__PURE__ */ jsx("div", {
664
484
  className: "_cppay-section",
665
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
666
- onClick: () => T("select"),
667
- disabled: E || O,
485
+ children: /* @__PURE__ */ jsx("button", {
486
+ onClick: () => x("select"),
487
+ disabled: S || w,
668
488
  className: "_cppay-btn _cppay-btn-text",
669
489
  children: "更改支付方式"
670
490
  })
@@ -684,9 +504,9 @@ const CppayProvider = ({ apikey: e, children: t }) => {
684
504
  }, [i]), l = useCallback((e) => {
685
505
  i?.onError?.(e);
686
506
  }, [i]);
687
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CppayContext.Provider, {
507
+ return /* @__PURE__ */ jsxs(CppayContext.Provider, {
688
508
  value: { showPayment: o },
689
- children: [t, i && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaymentDialog_default, {
509
+ children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
690
510
  open: n,
691
511
  onClose: s,
692
512
  apikey: e,