cppay-sdk 0.0.2-beta.27 → 0.0.2-beta.29
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/{cppay-BcCDwXlg.js → cppay-CCxKnEWz.js} +9 -9
- package/dist/cppay-D2T3pCwj.cjs +1 -0
- package/dist/cppay-sdk.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/inject-style-Boo8CMsU.cjs +1 -0
- package/dist/inject-style-CWza6SKp.js +7 -0
- package/dist/react.cjs +1 -6
- package/dist/react.js +245 -385
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +138 -104
- package/package.json +4 -2
- package/dist/cppay-DnxPUyM2.cjs +0 -1
- package/dist/polygon-1pLQCNfb.js +0 -3952
- package/dist/polygon-zw79IkW8.cjs +0 -15
package/dist/react.js
CHANGED
|
@@ -1,198 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { t as cppay_default } from "./cppay-CCxKnEWz.js";
|
|
2
|
+
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-CWza6SKp.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
|
-
|
|
10
|
-
|
|
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: a, plain: o, orderId: s, amount: c, intervalDays: l, onExpired: u, onSuccess: d, onFailed: f, onError: p }) => {
|
|
13
|
+
let m = useMemo(() => new cppay_default(a), [a]), [h, g] = useState("select"), [_, v] = useState(!1), [y, b] = useState(!1), [x, S] = useState(), [C, w] = useState(!1), [T, E] = useState([]), [D, O] = useState(), [k, A] = useState(), [j, M] = useState(), [N, P] = useState(), [F, I] = useState(!1), [L, R] = useState(), z = useRef(null), B = useRef(null);
|
|
194
14
|
useEffect(() => {
|
|
195
|
-
typeof window < "u" && !
|
|
15
|
+
typeof window < "u" && !z.current && (z.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
|
-
}),
|
|
217
|
-
e.isConnected ?
|
|
218
|
-
}),
|
|
36
|
+
}), P(z.current.getAddress()), R(z.current.getProvider("eip155")), z.current.subscribeAccount((e) => {
|
|
37
|
+
e.isConnected ? P(e.address) : (P(void 0), R(void 0));
|
|
38
|
+
}), z.current.subscribeProviders((e) => {
|
|
219
39
|
let t = e?.eip155;
|
|
220
|
-
|
|
40
|
+
R(t);
|
|
221
41
|
}));
|
|
222
42
|
}, []);
|
|
223
|
-
let
|
|
43
|
+
let V = async () => {
|
|
224
44
|
try {
|
|
225
|
-
|
|
45
|
+
I(!0), S(void 0), z.current && await z.current.open();
|
|
226
46
|
} catch (e) {
|
|
227
|
-
console.error("钱包连接失败:", e),
|
|
47
|
+
console.error("钱包连接失败:", e), S(e instanceof Error ? e.message : "钱包连接失败"), p?.(e);
|
|
228
48
|
} finally {
|
|
229
|
-
|
|
49
|
+
I(!1);
|
|
230
50
|
}
|
|
231
|
-
},
|
|
51
|
+
}, H = useMemo(() => T.find((e) => e.chain === D), [T, D]), U = useMemo(() => H?.tokens || [], [H]), W = useMemo(() => U.find((e) => e.symbol === k), [U, k]), G = (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,
|
|
59
|
+
].includes(e.toUpperCase()) ? 2 : 6, K = (e, t) => {
|
|
240
60
|
let n = parseFloat(e);
|
|
241
61
|
return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
|
|
242
|
-
},
|
|
243
|
-
if (!
|
|
244
|
-
let e = parseFloat(
|
|
62
|
+
}, q = useMemo(() => {
|
|
63
|
+
if (!k || !W) return "0";
|
|
64
|
+
let e = parseFloat(W.price);
|
|
245
65
|
if (isNaN(e) || e === 0) return "0";
|
|
246
|
-
let t =
|
|
247
|
-
return
|
|
66
|
+
let t = G(k);
|
|
67
|
+
return K((parseFloat(c) / e).toFixed(t), t);
|
|
248
68
|
}, [
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
]),
|
|
69
|
+
c,
|
|
70
|
+
k,
|
|
71
|
+
W
|
|
72
|
+
]), Te = async () => {
|
|
253
73
|
try {
|
|
254
|
-
|
|
255
|
-
let e = await
|
|
256
|
-
|
|
74
|
+
v(!0), S(void 0);
|
|
75
|
+
let e = await m.getSupportedChains();
|
|
76
|
+
E(e), e.length > 0 && O(e[0].chain);
|
|
257
77
|
} catch (e) {
|
|
258
|
-
|
|
78
|
+
S(e instanceof Error ? e.message : "加载支付网络失败"), p?.(e);
|
|
259
79
|
} finally {
|
|
260
|
-
|
|
80
|
+
v(!1);
|
|
261
81
|
}
|
|
262
|
-
},
|
|
263
|
-
if (
|
|
264
|
-
await
|
|
82
|
+
}, J = async (e) => {
|
|
83
|
+
if (L) try {
|
|
84
|
+
await L.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
|
-
},
|
|
272
|
-
if (!(!
|
|
273
|
-
|
|
274
|
-
let e =
|
|
275
|
-
await
|
|
91
|
+
}, Ee = async () => {
|
|
92
|
+
if (!(!N || !L || !Y.current || !W || !H)) try {
|
|
93
|
+
v(!0);
|
|
94
|
+
let e = Y.current;
|
|
95
|
+
await J(H.chainId);
|
|
276
96
|
let t = createWalletClient({
|
|
277
|
-
account:
|
|
278
|
-
transport: custom(
|
|
97
|
+
account: N,
|
|
98
|
+
transport: custom(L)
|
|
279
99
|
});
|
|
280
|
-
if (
|
|
100
|
+
if (W.address) {
|
|
281
101
|
let n = await t.writeContract({
|
|
282
|
-
address:
|
|
102
|
+
address: W.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,
|
|
117
|
+
args: [e.receiveAddress, parseUnits(e.paymentAmount, W.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,
|
|
124
|
+
value: parseUnits(e.paymentAmount, W.decimals),
|
|
305
125
|
chain: null
|
|
306
126
|
});
|
|
307
127
|
console.log("转账交易哈希:", n);
|
|
308
128
|
}
|
|
309
|
-
|
|
129
|
+
v(!1), b(!0), Z(e.paymentId);
|
|
310
130
|
} catch (e) {
|
|
311
|
-
console.error("钱包支付失败:", e),
|
|
131
|
+
console.error("钱包支付失败:", e), S(e instanceof Error ? e.message : "钱包支付失败"), p?.(e), v(!1);
|
|
312
132
|
}
|
|
313
|
-
},
|
|
314
|
-
if (!(!
|
|
315
|
-
|
|
316
|
-
let e =
|
|
317
|
-
await
|
|
133
|
+
}, De = async () => {
|
|
134
|
+
if (!(!N || !L || !Y.current || !W || !H)) try {
|
|
135
|
+
v(!0);
|
|
136
|
+
let e = Y.current;
|
|
137
|
+
await J(H.chainId);
|
|
318
138
|
let t = createWalletClient({
|
|
319
|
-
account:
|
|
320
|
-
transport: custom(
|
|
139
|
+
account: N,
|
|
140
|
+
transport: custom(L)
|
|
321
141
|
});
|
|
322
|
-
if (!
|
|
142
|
+
if (!W.address) throw Error("订阅支付不支持原生代币");
|
|
323
143
|
let n = await t.writeContract({
|
|
324
|
-
address:
|
|
144
|
+
address: W.address,
|
|
325
145
|
abi: [{
|
|
326
146
|
name: "approve",
|
|
327
147
|
type: "function",
|
|
@@ -336,94 +156,95 @@ 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,
|
|
159
|
+
args: [e.spenderAddress, parseUnits(e.approveAmount, W.decimals)],
|
|
340
160
|
chain: null
|
|
341
161
|
});
|
|
342
|
-
console.log("授权交易哈希:", n),
|
|
162
|
+
console.log("授权交易哈希:", n), v(!1), b(!0), Z(e.subscriptionId);
|
|
343
163
|
} catch (e) {
|
|
344
|
-
console.error("钱包授权失败:", e),
|
|
164
|
+
console.error("钱包授权失败:", e), S(e instanceof Error ? e.message : "钱包授权失败"), p?.(e), v(!1);
|
|
345
165
|
}
|
|
346
|
-
},
|
|
347
|
-
if (!
|
|
348
|
-
|
|
166
|
+
}, Oe = async () => {
|
|
167
|
+
if (!N) {
|
|
168
|
+
let e = "请先连接钱包";
|
|
169
|
+
S(e), p?.(Error(e));
|
|
349
170
|
return;
|
|
350
171
|
}
|
|
351
|
-
o === "one-time" ? await
|
|
352
|
-
},
|
|
353
|
-
if (!(!
|
|
354
|
-
|
|
172
|
+
o === "one-time" ? await Ee() : o === "subscription" && await De();
|
|
173
|
+
}, Y = useRef(null), X = async () => {
|
|
174
|
+
if (!(!D || !k)) try {
|
|
175
|
+
v(!0), S(void 0);
|
|
355
176
|
let e = "";
|
|
356
|
-
o === "one-time" ? (
|
|
357
|
-
paymentChain:
|
|
358
|
-
paymentToken:
|
|
359
|
-
orderId:
|
|
360
|
-
amount:
|
|
361
|
-
}), e = `${
|
|
362
|
-
paymentChain:
|
|
363
|
-
paymentToken:
|
|
364
|
-
orderId:
|
|
365
|
-
amountOfUsd:
|
|
366
|
-
intervalDays:
|
|
367
|
-
}), e = `${
|
|
177
|
+
o === "one-time" ? (Y.current = await m.createOnetimePayment({
|
|
178
|
+
paymentChain: D,
|
|
179
|
+
paymentToken: k,
|
|
180
|
+
orderId: s,
|
|
181
|
+
amount: q
|
|
182
|
+
}), e = `${D.toLowerCase()}:${Y.current.receiveAddress}?amount=${Y.current.paymentAmount}`) : o === "subscription" && (Y.current = await m.createSubscriptionPayment({
|
|
183
|
+
paymentChain: D,
|
|
184
|
+
paymentToken: k,
|
|
185
|
+
orderId: s,
|
|
186
|
+
amountOfUsd: q,
|
|
187
|
+
intervalDays: l || 30
|
|
188
|
+
}), e = `${D.toLowerCase()}:${Y.current.spenderAddress}?amount=${Y.current.approveAmount}`), g("payment"), M(await QRCode.toDataURL(e, {
|
|
368
189
|
width: 200,
|
|
369
190
|
margin: 2,
|
|
370
191
|
errorCorrectionLevel: "H"
|
|
371
192
|
}));
|
|
372
193
|
} catch (e) {
|
|
373
|
-
|
|
194
|
+
S(e instanceof Error ? e.message : "创建支付失败"), p?.(e);
|
|
374
195
|
} finally {
|
|
375
|
-
|
|
196
|
+
v(!1);
|
|
376
197
|
}
|
|
377
|
-
},
|
|
378
|
-
if (
|
|
379
|
-
|
|
198
|
+
}, ke = async () => {
|
|
199
|
+
if (Y.current) try {
|
|
200
|
+
b(!0), S(void 0), o === "one-time" ? Z(Y.current.paymentId) : o === "subscription" && Z(Y.current.subscriptionId);
|
|
380
201
|
} catch (e) {
|
|
381
|
-
console.error("支付状态检查错误:", e),
|
|
202
|
+
console.error("支付状态检查错误:", e), S(e instanceof Error ? e.message : "检查支付状态失败"), p?.(e), b(!1);
|
|
382
203
|
}
|
|
383
|
-
},
|
|
384
|
-
let t = () => defer(() => o === "subscription" ?
|
|
204
|
+
}, Z = (e) => {
|
|
205
|
+
let t = () => defer(() => o === "subscription" ? m.checkSubscriptionPaymentStatus({ subscriptionId: e }) : m.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
|
|
385
206
|
count: 3,
|
|
386
207
|
delay: 2e3
|
|
387
208
|
}));
|
|
388
|
-
|
|
389
|
-
e.status === "expired" && (
|
|
209
|
+
B.current?.unsubscribe(), B.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
|
|
210
|
+
e.status === "expired" && (b(!1), u?.(e)), e.status === "paid" && (b(!1), g("success"), d?.(e)), e.status === "failed" && (b(!1), f?.(e)), e.status === "approved" && (b(!1), g("success"), d?.(e));
|
|
390
211
|
})).subscribe({ error: (e) => {
|
|
391
|
-
console.error("支付状态检查错误:", e),
|
|
212
|
+
console.error("支付状态检查错误:", e), S(e instanceof Error ? e.message : "检查支付状态失败"), b(!1), p?.(e);
|
|
392
213
|
} });
|
|
393
|
-
},
|
|
394
|
-
if (!
|
|
395
|
-
let e = o === "subscription" ?
|
|
214
|
+
}, Q = async () => {
|
|
215
|
+
if (!Y.current) return;
|
|
216
|
+
let e = o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress;
|
|
396
217
|
e && await navigator.clipboard.writeText(e);
|
|
397
218
|
}, $ = () => {
|
|
398
|
-
|
|
399
|
-
|
|
219
|
+
_ || y || (n(), setTimeout(() => {
|
|
220
|
+
g("select"), S(void 0), Y.current = null;
|
|
400
221
|
}, 300));
|
|
401
222
|
};
|
|
402
223
|
return useEffect(() => {
|
|
403
|
-
|
|
404
|
-
}, [
|
|
405
|
-
|
|
406
|
-
}, [
|
|
407
|
-
|
|
408
|
-
}, []),
|
|
224
|
+
t && T.length === 0 && Te();
|
|
225
|
+
}, [t]), useEffect(() => {
|
|
226
|
+
U.length > 0 && A(U[0].symbol);
|
|
227
|
+
}, [U]), useEffect(() => () => {
|
|
228
|
+
B.current?.unsubscribe();
|
|
229
|
+
}, []), t ? /* @__PURE__ */ jsx("div", {
|
|
409
230
|
className: "_cppay-overlay",
|
|
410
|
-
onClick: (e) => e.target === e.currentTarget && !
|
|
411
|
-
children: /* @__PURE__ */
|
|
231
|
+
onClick: (e) => e.target === e.currentTarget && !_ && !y && $(),
|
|
232
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
412
233
|
className: "_cppay-dialog",
|
|
413
|
-
children: [/* @__PURE__ */
|
|
234
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
414
235
|
className: "_cppay-header",
|
|
415
|
-
children: [/* @__PURE__ */
|
|
236
|
+
children: [/* @__PURE__ */ jsx("h2", {
|
|
416
237
|
className: "_cppay-title",
|
|
417
|
-
children:
|
|
418
|
-
}), /* @__PURE__ */
|
|
238
|
+
children: h === "select" ? "选择支付方式" : "完成支付"
|
|
239
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
419
240
|
onClick: $,
|
|
420
|
-
disabled:
|
|
241
|
+
disabled: _ || y,
|
|
421
242
|
className: "_cppay-close-btn",
|
|
422
|
-
children: /* @__PURE__ */
|
|
243
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
423
244
|
fill: "none",
|
|
424
245
|
stroke: "currentColor",
|
|
425
246
|
viewBox: "0 0 24 24",
|
|
426
|
-
children: /* @__PURE__ */
|
|
247
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
427
248
|
strokeLinecap: "round",
|
|
428
249
|
strokeLinejoin: "round",
|
|
429
250
|
strokeWidth: 2,
|
|
@@ -431,22 +252,22 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
431
252
|
})
|
|
432
253
|
})
|
|
433
254
|
})]
|
|
434
|
-
}), /* @__PURE__ */
|
|
255
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
435
256
|
className: "_cppay-content",
|
|
436
|
-
children:
|
|
257
|
+
children: h === "success" ? /* @__PURE__ */ jsxs("div", {
|
|
437
258
|
style: {
|
|
438
259
|
textAlign: "center",
|
|
439
260
|
padding: "2rem 0"
|
|
440
261
|
},
|
|
441
262
|
children: [
|
|
442
|
-
/* @__PURE__ */
|
|
263
|
+
/* @__PURE__ */ jsx("div", {
|
|
443
264
|
style: {
|
|
444
265
|
fontSize: "64px",
|
|
445
266
|
marginBottom: "1rem"
|
|
446
267
|
},
|
|
447
268
|
children: "✅"
|
|
448
269
|
}),
|
|
449
|
-
/* @__PURE__ */
|
|
270
|
+
/* @__PURE__ */ jsx("h3", {
|
|
450
271
|
style: {
|
|
451
272
|
fontSize: "1.5rem",
|
|
452
273
|
fontWeight: 600,
|
|
@@ -455,7 +276,7 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
455
276
|
},
|
|
456
277
|
children: o === "subscription" ? "授权成功!" : "支付成功!"
|
|
457
278
|
}),
|
|
458
|
-
/* @__PURE__ */
|
|
279
|
+
/* @__PURE__ */ jsx("p", {
|
|
459
280
|
style: {
|
|
460
281
|
color: "#6b7280",
|
|
461
282
|
margin: 0
|
|
@@ -463,83 +284,102 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
463
284
|
children: o === "subscription" ? "订阅已激活" : "交易已完成"
|
|
464
285
|
})
|
|
465
286
|
]
|
|
466
|
-
}) :
|
|
467
|
-
/* @__PURE__ */
|
|
287
|
+
}) : h === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
288
|
+
/* @__PURE__ */ jsxs("div", {
|
|
468
289
|
className: "_cppay-section",
|
|
469
|
-
children: [/* @__PURE__ */
|
|
290
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
470
291
|
className: "_cppay-label",
|
|
471
292
|
children: "支付网络"
|
|
472
|
-
}), /* @__PURE__ */
|
|
293
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
473
294
|
className: "_cppay-grid",
|
|
474
|
-
children:
|
|
475
|
-
onClick: () =>
|
|
476
|
-
className: `_cppay-select-btn ${
|
|
477
|
-
children: [e.icon && /* @__PURE__ */
|
|
295
|
+
children: T.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
296
|
+
onClick: () => O(e.chain),
|
|
297
|
+
className: `_cppay-select-btn ${D === e.chain ? "_cppay-selected" : ""}`,
|
|
298
|
+
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
478
299
|
src: e.icon,
|
|
479
300
|
alt: e.chain
|
|
480
|
-
}), /* @__PURE__ */
|
|
301
|
+
}), /* @__PURE__ */ jsx("span", { children: e.chain })]
|
|
481
302
|
}, e.chain))
|
|
482
303
|
})]
|
|
483
304
|
}),
|
|
484
|
-
/* @__PURE__ */
|
|
305
|
+
/* @__PURE__ */ jsxs("div", {
|
|
485
306
|
className: "_cppay-section",
|
|
486
|
-
children: [/* @__PURE__ */
|
|
307
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
487
308
|
className: "_cppay-label",
|
|
488
309
|
children: "支付代币"
|
|
489
|
-
}), /* @__PURE__ */
|
|
310
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
490
311
|
className: "_cppay-grid",
|
|
491
|
-
children:
|
|
492
|
-
onClick: () =>
|
|
493
|
-
className: `_cppay-select-btn ${
|
|
494
|
-
children: [e.icon && /* @__PURE__ */
|
|
312
|
+
children: U.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
313
|
+
onClick: () => A(e.symbol),
|
|
314
|
+
className: `_cppay-select-btn ${k === e.symbol ? "_cppay-selected" : ""}`,
|
|
315
|
+
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
495
316
|
src: e.icon,
|
|
496
317
|
alt: e.symbol
|
|
497
|
-
}), /* @__PURE__ */
|
|
318
|
+
}), /* @__PURE__ */ jsx("span", { children: e.symbol })]
|
|
498
319
|
}, e.symbol))
|
|
499
320
|
})]
|
|
500
321
|
}),
|
|
501
|
-
/* @__PURE__ */
|
|
322
|
+
/* @__PURE__ */ jsx("div", {
|
|
502
323
|
className: "_cppay-section",
|
|
503
|
-
children: /* @__PURE__ */
|
|
324
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
504
325
|
className: "_cppay-price-box",
|
|
505
|
-
children: /* @__PURE__ */
|
|
326
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
506
327
|
className: "_cppay-price-row",
|
|
507
|
-
children: [/* @__PURE__ */
|
|
328
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
508
329
|
className: "_cppay-price-label",
|
|
509
330
|
children: "支付金额"
|
|
510
|
-
}), /* @__PURE__ */
|
|
331
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
511
332
|
className: "_cppay-price-amount",
|
|
512
|
-
children: [/* @__PURE__ */
|
|
333
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
513
334
|
className: "_cppay-price-main",
|
|
514
335
|
children: [
|
|
515
|
-
|
|
336
|
+
q ?? "-",
|
|
516
337
|
" ",
|
|
517
|
-
|
|
338
|
+
k ?? ""
|
|
518
339
|
]
|
|
519
|
-
}), /* @__PURE__ */
|
|
340
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
520
341
|
className: "_cppay-price-sub",
|
|
521
|
-
children: ["≈ $",
|
|
342
|
+
children: ["≈ $", c]
|
|
522
343
|
})]
|
|
523
344
|
})]
|
|
524
345
|
})
|
|
525
346
|
})
|
|
526
347
|
}),
|
|
527
|
-
/* @__PURE__ */ (
|
|
348
|
+
/* @__PURE__ */ jsxs("div", {
|
|
528
349
|
className: "_cppay-section",
|
|
529
|
-
children: /* @__PURE__ */ (
|
|
530
|
-
|
|
531
|
-
|
|
350
|
+
children: [x && /* @__PURE__ */ jsxs("div", {
|
|
351
|
+
className: "_cppay-error-tooltip-wrapper",
|
|
352
|
+
onMouseEnter: () => w(!0),
|
|
353
|
+
onMouseLeave: () => w(!1),
|
|
354
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
355
|
+
className: "_cppay-error-tooltip",
|
|
356
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
357
|
+
viewBox: "0 0 20 20",
|
|
358
|
+
fill: "currentColor",
|
|
359
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
360
|
+
fillRule: "evenodd",
|
|
361
|
+
d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
|
|
362
|
+
clipRule: "evenodd"
|
|
363
|
+
})
|
|
364
|
+
}), /* @__PURE__ */ jsx("span", { children: x })]
|
|
365
|
+
}), C && /* @__PURE__ */ jsx("div", {
|
|
366
|
+
className: "_cppay-error-tooltip-full",
|
|
367
|
+
children: x
|
|
368
|
+
})]
|
|
369
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
370
|
+
onClick: X,
|
|
371
|
+
disabled: !D || !k || _,
|
|
532
372
|
className: "_cppay-btn _cppay-btn-primary",
|
|
533
|
-
children:
|
|
534
|
-
})
|
|
373
|
+
children: _ ? "处理中..." : "继续支付"
|
|
374
|
+
})]
|
|
535
375
|
})
|
|
536
|
-
] }) : /* @__PURE__ */
|
|
537
|
-
/* @__PURE__ */
|
|
376
|
+
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
377
|
+
/* @__PURE__ */ jsx("div", {
|
|
538
378
|
className: "_cppay-qr-container",
|
|
539
|
-
children: /* @__PURE__ */
|
|
379
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
540
380
|
className: "_cppay-qr-code",
|
|
541
|
-
children:
|
|
542
|
-
src:
|
|
381
|
+
children: j && /* @__PURE__ */ jsx("img", {
|
|
382
|
+
src: j,
|
|
543
383
|
alt: "Payment QR Code",
|
|
544
384
|
style: {
|
|
545
385
|
width: "160px",
|
|
@@ -549,35 +389,35 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
549
389
|
})
|
|
550
390
|
})
|
|
551
391
|
}),
|
|
552
|
-
/* @__PURE__ */
|
|
392
|
+
/* @__PURE__ */ jsxs("div", {
|
|
553
393
|
className: "_cppay-section",
|
|
554
394
|
children: [
|
|
555
|
-
|
|
395
|
+
k && /* @__PURE__ */ jsxs("div", {
|
|
556
396
|
className: "_cppay-info-box",
|
|
557
|
-
children: [/* @__PURE__ */
|
|
397
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
558
398
|
className: "_cppay-info-label",
|
|
559
399
|
children: o === "subscription" ? "授权金额" : "支付金额"
|
|
560
|
-
}), /* @__PURE__ */
|
|
400
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
561
401
|
className: "_cppay-info-value",
|
|
562
|
-
children: o === "subscription" ? `${Y
|
|
402
|
+
children: o === "subscription" ? `${K(Y.current.approveAmount, G(k))} ${k}` : `${K(Y.current.paymentAmount, G(k))} ${k}`
|
|
563
403
|
})]
|
|
564
404
|
}),
|
|
565
|
-
/* @__PURE__ */
|
|
405
|
+
/* @__PURE__ */ jsxs("div", {
|
|
566
406
|
className: "_cppay-info-box",
|
|
567
|
-
children: [/* @__PURE__ */
|
|
407
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
568
408
|
className: "_cppay-info-label",
|
|
569
409
|
children: o === "subscription" ? "授权合约地址" : "支付地址"
|
|
570
|
-
}), /* @__PURE__ */
|
|
410
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
571
411
|
className: "_cppay-address-row",
|
|
572
|
-
children: [/* @__PURE__ */
|
|
573
|
-
onClick:
|
|
412
|
+
children: [/* @__PURE__ */ jsx("code", { children: o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
413
|
+
onClick: Q,
|
|
574
414
|
className: "_cppay-copy-btn",
|
|
575
415
|
title: "复制地址",
|
|
576
|
-
children: /* @__PURE__ */
|
|
416
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
577
417
|
fill: "none",
|
|
578
418
|
stroke: "currentColor",
|
|
579
419
|
viewBox: "0 0 24 24",
|
|
580
|
-
children: /* @__PURE__ */
|
|
420
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
581
421
|
strokeLinecap: "round",
|
|
582
422
|
strokeLinejoin: "round",
|
|
583
423
|
strokeWidth: 2,
|
|
@@ -587,17 +427,17 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
587
427
|
})]
|
|
588
428
|
})]
|
|
589
429
|
}),
|
|
590
|
-
o === "subscription" && /* @__PURE__ */
|
|
430
|
+
o === "subscription" && /* @__PURE__ */ jsxs("div", {
|
|
591
431
|
className: "_cppay-info-box",
|
|
592
432
|
style: {
|
|
593
433
|
background: "#fff3cd",
|
|
594
434
|
borderColor: "#ffc107"
|
|
595
435
|
},
|
|
596
|
-
children: [/* @__PURE__ */
|
|
436
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
597
437
|
className: "_cppay-info-label",
|
|
598
438
|
style: { color: "#856404" },
|
|
599
439
|
children: "📌 订阅说明"
|
|
600
|
-
}), /* @__PURE__ */
|
|
440
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
601
441
|
className: "_cppay-info-value",
|
|
602
442
|
style: {
|
|
603
443
|
fontSize: "12px",
|
|
@@ -608,22 +448,42 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
608
448
|
})
|
|
609
449
|
]
|
|
610
450
|
}),
|
|
611
|
-
|
|
451
|
+
x && /* @__PURE__ */ jsxs("div", {
|
|
452
|
+
className: "_cppay-error-tooltip-wrapper",
|
|
453
|
+
onMouseEnter: () => w(!0),
|
|
454
|
+
onMouseLeave: () => w(!1),
|
|
455
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
456
|
+
className: "_cppay-error-tooltip",
|
|
457
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
458
|
+
viewBox: "0 0 20 20",
|
|
459
|
+
fill: "currentColor",
|
|
460
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
461
|
+
fillRule: "evenodd",
|
|
462
|
+
d: "M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",
|
|
463
|
+
clipRule: "evenodd"
|
|
464
|
+
})
|
|
465
|
+
}), /* @__PURE__ */ jsx("span", { children: x })]
|
|
466
|
+
}), C && /* @__PURE__ */ jsx("div", {
|
|
467
|
+
className: "_cppay-error-tooltip-full",
|
|
468
|
+
children: x
|
|
469
|
+
})]
|
|
470
|
+
}),
|
|
471
|
+
!y && /* @__PURE__ */ jsx("div", {
|
|
612
472
|
className: "_cppay-section",
|
|
613
|
-
children:
|
|
473
|
+
children: N ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
614
474
|
className: "_cppay-btn-container",
|
|
615
|
-
children: [/* @__PURE__ */
|
|
616
|
-
onClick:
|
|
617
|
-
disabled:
|
|
475
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
476
|
+
onClick: Oe,
|
|
477
|
+
disabled: _,
|
|
618
478
|
className: "_cppay-btn _cppay-btn-primary",
|
|
619
|
-
children:
|
|
620
|
-
}), /* @__PURE__ */
|
|
621
|
-
onClick:
|
|
622
|
-
disabled:
|
|
479
|
+
children: _ ? o === "subscription" ? "授权中..." : "支付中..." : o === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
|
|
480
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
481
|
+
onClick: V,
|
|
482
|
+
disabled: _,
|
|
623
483
|
className: "_cppay-btn _cppay-btn-primary",
|
|
624
484
|
children: "💰钱包状态"
|
|
625
485
|
})]
|
|
626
|
-
}), /* @__PURE__ */
|
|
486
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
627
487
|
style: {
|
|
628
488
|
textAlign: "center",
|
|
629
489
|
marginTop: "8px",
|
|
@@ -632,13 +492,13 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
632
492
|
},
|
|
633
493
|
children: [
|
|
634
494
|
"已连接: ",
|
|
635
|
-
|
|
495
|
+
N.slice(0, 6),
|
|
636
496
|
"...",
|
|
637
|
-
|
|
497
|
+
N.slice(-4)
|
|
638
498
|
]
|
|
639
|
-
})] }) : /* @__PURE__ */
|
|
640
|
-
onClick:
|
|
641
|
-
disabled:
|
|
499
|
+
})] }) : /* @__PURE__ */ jsx("button", {
|
|
500
|
+
onClick: V,
|
|
501
|
+
disabled: F,
|
|
642
502
|
className: "_cppay-btn _cppay-btn-secondary",
|
|
643
503
|
style: {
|
|
644
504
|
display: "flex",
|
|
@@ -648,23 +508,23 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
648
508
|
padding: "0.75rem 1rem",
|
|
649
509
|
width: "100%"
|
|
650
510
|
},
|
|
651
|
-
children: /* @__PURE__ */
|
|
511
|
+
children: /* @__PURE__ */ jsx("span", { children: F ? "连接中..." : "💳 连接钱包" })
|
|
652
512
|
})
|
|
653
513
|
}),
|
|
654
|
-
/* @__PURE__ */
|
|
514
|
+
/* @__PURE__ */ jsx("div", {
|
|
655
515
|
className: "_cppay-section",
|
|
656
|
-
children: /* @__PURE__ */
|
|
657
|
-
onClick:
|
|
658
|
-
disabled:
|
|
516
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
517
|
+
onClick: ke,
|
|
518
|
+
disabled: y,
|
|
659
519
|
className: "_cppay-btn _cppay-btn-primary",
|
|
660
|
-
children:
|
|
520
|
+
children: y ? "检查中..." : "我已完成支付"
|
|
661
521
|
})
|
|
662
522
|
}),
|
|
663
|
-
/* @__PURE__ */
|
|
523
|
+
/* @__PURE__ */ jsx("div", {
|
|
664
524
|
className: "_cppay-section",
|
|
665
|
-
children: /* @__PURE__ */
|
|
666
|
-
onClick: () =>
|
|
667
|
-
disabled:
|
|
525
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
526
|
+
onClick: () => g("select"),
|
|
527
|
+
disabled: _ || y,
|
|
668
528
|
className: "_cppay-btn _cppay-btn-text",
|
|
669
529
|
children: "更改支付方式"
|
|
670
530
|
})
|
|
@@ -675,27 +535,27 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) =>
|
|
|
675
535
|
}) : null;
|
|
676
536
|
}), CppayContext = createContext(null);
|
|
677
537
|
const CppayProvider = ({ apikey: e, children: t }) => {
|
|
678
|
-
let [n, r] = useState(!1), [i,
|
|
679
|
-
|
|
680
|
-
}, []),
|
|
538
|
+
let [n, r] = useState(!1), [i, be] = useState(null), xe = useCallback((e) => {
|
|
539
|
+
be(e), r(!0);
|
|
540
|
+
}, []), Se = useCallback(() => {
|
|
681
541
|
r(!1);
|
|
682
|
-
}, []),
|
|
542
|
+
}, []), Ce = useCallback((e) => {
|
|
683
543
|
i?.onSuccess?.(e), r(!1);
|
|
684
|
-
}, [i]),
|
|
544
|
+
}, [i]), we = useCallback((e) => {
|
|
685
545
|
i?.onError?.(e);
|
|
686
546
|
}, [i]);
|
|
687
|
-
return /* @__PURE__ */
|
|
688
|
-
value: { showPayment:
|
|
689
|
-
children: [t, i && /* @__PURE__ */
|
|
547
|
+
return /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
548
|
+
value: { showPayment: xe },
|
|
549
|
+
children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
690
550
|
open: n,
|
|
691
|
-
onClose:
|
|
551
|
+
onClose: Se,
|
|
692
552
|
apikey: e,
|
|
693
553
|
plain: i.plain,
|
|
694
554
|
orderId: i.orderId,
|
|
695
555
|
amount: i.amount,
|
|
696
556
|
intervalDays: i.intervalDays,
|
|
697
|
-
onSuccess:
|
|
698
|
-
onError:
|
|
557
|
+
onSuccess: Ce,
|
|
558
|
+
onError: we
|
|
699
559
|
})]
|
|
700
560
|
});
|
|
701
561
|
}, useCppayPayment = () => {
|