cppay-sdk 0.0.2-beta.28 → 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-Dhqe5Hz_.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-aMqJSA89.js → inject-style-CWza6SKp.js} +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +193 -153
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +134 -103
- package/package.json +3 -1
- package/dist/cppay-DnxPUyM2.cjs +0 -1
- package/dist/inject-style-CvrNZeWB.cjs +0 -1
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as cppay_default } from "./cppay-
|
|
2
|
-
import { n as payment_dialog_default, t as injectStyle } from "./inject-style-
|
|
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
3
|
import * as QRCode from "qrcode";
|
|
4
4
|
import { EMPTY, defer, timer } from "rxjs";
|
|
5
5
|
import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
|
|
@@ -9,10 +9,10 @@ import { createAppKit } from "@reown/appkit";
|
|
|
9
9
|
import { EthersAdapter } from "@reown/appkit-adapter-ethers";
|
|
10
10
|
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey:
|
|
13
|
-
let
|
|
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);
|
|
14
14
|
useEffect(() => {
|
|
15
|
-
typeof window < "u" && !
|
|
15
|
+
typeof window < "u" && !z.current && (z.current = createAppKit({
|
|
16
16
|
debug: !1,
|
|
17
17
|
enableNetworkSwitch: !1,
|
|
18
18
|
adapters: [new EthersAdapter()],
|
|
@@ -33,22 +33,22 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
33
33
|
icons: ["https://cppay.com/icon.png"]
|
|
34
34
|
},
|
|
35
35
|
features: { analytics: !1 }
|
|
36
|
-
}),
|
|
37
|
-
e.isConnected ?
|
|
38
|
-
}),
|
|
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) => {
|
|
39
39
|
let t = e?.eip155;
|
|
40
|
-
|
|
40
|
+
R(t);
|
|
41
41
|
}));
|
|
42
42
|
}, []);
|
|
43
|
-
let
|
|
43
|
+
let V = async () => {
|
|
44
44
|
try {
|
|
45
|
-
|
|
45
|
+
I(!0), S(void 0), z.current && await z.current.open();
|
|
46
46
|
} catch (e) {
|
|
47
|
-
console.error("钱包连接失败:", e),
|
|
47
|
+
console.error("钱包连接失败:", e), S(e instanceof Error ? e.message : "钱包连接失败"), p?.(e);
|
|
48
48
|
} finally {
|
|
49
|
-
|
|
49
|
+
I(!1);
|
|
50
50
|
}
|
|
51
|
-
},
|
|
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) => [
|
|
52
52
|
"USDT",
|
|
53
53
|
"USDC",
|
|
54
54
|
"BUSD",
|
|
@@ -56,50 +56,50 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
56
56
|
"TUSD",
|
|
57
57
|
"USDD",
|
|
58
58
|
"FDUSD"
|
|
59
|
-
].includes(e.toUpperCase()) ? 2 : 6,
|
|
59
|
+
].includes(e.toUpperCase()) ? 2 : 6, K = (e, t) => {
|
|
60
60
|
let n = parseFloat(e);
|
|
61
61
|
return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
|
|
62
|
-
},
|
|
63
|
-
if (!
|
|
64
|
-
let e = parseFloat(
|
|
62
|
+
}, q = useMemo(() => {
|
|
63
|
+
if (!k || !W) return "0";
|
|
64
|
+
let e = parseFloat(W.price);
|
|
65
65
|
if (isNaN(e) || e === 0) return "0";
|
|
66
|
-
let t =
|
|
67
|
-
return
|
|
66
|
+
let t = G(k);
|
|
67
|
+
return K((parseFloat(c) / e).toFixed(t), t);
|
|
68
68
|
}, [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
]),
|
|
69
|
+
c,
|
|
70
|
+
k,
|
|
71
|
+
W
|
|
72
|
+
]), Te = async () => {
|
|
73
73
|
try {
|
|
74
|
-
|
|
75
|
-
let e = await
|
|
76
|
-
|
|
74
|
+
v(!0), S(void 0);
|
|
75
|
+
let e = await m.getSupportedChains();
|
|
76
|
+
E(e), e.length > 0 && O(e[0].chain);
|
|
77
77
|
} catch (e) {
|
|
78
|
-
|
|
78
|
+
S(e instanceof Error ? e.message : "加载支付网络失败"), p?.(e);
|
|
79
79
|
} finally {
|
|
80
|
-
|
|
80
|
+
v(!1);
|
|
81
81
|
}
|
|
82
|
-
},
|
|
83
|
-
if (
|
|
84
|
-
await
|
|
82
|
+
}, J = async (e) => {
|
|
83
|
+
if (L) try {
|
|
84
|
+
await L.request({
|
|
85
85
|
method: "wallet_switchEthereumChain",
|
|
86
86
|
params: [{ chainId: `0x${e.toString(16)}` }]
|
|
87
87
|
});
|
|
88
88
|
} catch (e) {
|
|
89
89
|
throw e.code === 4902 ? Error("请在钱包中添加该网络") : e;
|
|
90
90
|
}
|
|
91
|
-
},
|
|
92
|
-
if (!(!
|
|
93
|
-
|
|
94
|
-
let e =
|
|
95
|
-
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);
|
|
96
96
|
let t = createWalletClient({
|
|
97
|
-
account:
|
|
98
|
-
transport: custom(
|
|
97
|
+
account: N,
|
|
98
|
+
transport: custom(L)
|
|
99
99
|
});
|
|
100
|
-
if (
|
|
100
|
+
if (W.address) {
|
|
101
101
|
let n = await t.writeContract({
|
|
102
|
-
address:
|
|
102
|
+
address: W.address,
|
|
103
103
|
abi: [{
|
|
104
104
|
name: "transfer",
|
|
105
105
|
type: "function",
|
|
@@ -114,34 +114,34 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
114
114
|
outputs: [{ type: "bool" }]
|
|
115
115
|
}],
|
|
116
116
|
functionName: "transfer",
|
|
117
|
-
args: [e.receiveAddress, parseUnits(e.paymentAmount,
|
|
117
|
+
args: [e.receiveAddress, parseUnits(e.paymentAmount, W.decimals)],
|
|
118
118
|
chain: null
|
|
119
119
|
});
|
|
120
120
|
console.log("转账交易哈希:", n);
|
|
121
121
|
} else {
|
|
122
122
|
let n = await t.sendTransaction({
|
|
123
123
|
to: e.receiveAddress,
|
|
124
|
-
value: parseUnits(e.paymentAmount,
|
|
124
|
+
value: parseUnits(e.paymentAmount, W.decimals),
|
|
125
125
|
chain: null
|
|
126
126
|
});
|
|
127
127
|
console.log("转账交易哈希:", n);
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
v(!1), b(!0), Z(e.paymentId);
|
|
130
130
|
} catch (e) {
|
|
131
|
-
console.error("钱包支付失败:", e),
|
|
131
|
+
console.error("钱包支付失败:", e), S(e instanceof Error ? e.message : "钱包支付失败"), p?.(e), v(!1);
|
|
132
132
|
}
|
|
133
|
-
},
|
|
134
|
-
if (!(!
|
|
135
|
-
|
|
136
|
-
let e =
|
|
137
|
-
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);
|
|
138
138
|
let t = createWalletClient({
|
|
139
|
-
account:
|
|
140
|
-
transport: custom(
|
|
139
|
+
account: N,
|
|
140
|
+
transport: custom(L)
|
|
141
141
|
});
|
|
142
|
-
if (!
|
|
142
|
+
if (!W.address) throw Error("订阅支付不支持原生代币");
|
|
143
143
|
let n = await t.writeContract({
|
|
144
|
-
address:
|
|
144
|
+
address: W.address,
|
|
145
145
|
abi: [{
|
|
146
146
|
name: "approve",
|
|
147
147
|
type: "function",
|
|
@@ -156,88 +156,89 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
156
156
|
outputs: [{ type: "bool" }]
|
|
157
157
|
}],
|
|
158
158
|
functionName: "approve",
|
|
159
|
-
args: [e.spenderAddress, parseUnits(e.approveAmount,
|
|
159
|
+
args: [e.spenderAddress, parseUnits(e.approveAmount, W.decimals)],
|
|
160
160
|
chain: null
|
|
161
161
|
});
|
|
162
|
-
console.log("授权交易哈希:", n),
|
|
162
|
+
console.log("授权交易哈希:", n), v(!1), b(!0), Z(e.subscriptionId);
|
|
163
163
|
} catch (e) {
|
|
164
|
-
console.error("钱包授权失败:", e),
|
|
164
|
+
console.error("钱包授权失败:", e), S(e instanceof Error ? e.message : "钱包授权失败"), p?.(e), v(!1);
|
|
165
165
|
}
|
|
166
|
-
},
|
|
167
|
-
if (!
|
|
168
|
-
|
|
166
|
+
}, Oe = async () => {
|
|
167
|
+
if (!N) {
|
|
168
|
+
let e = "请先连接钱包";
|
|
169
|
+
S(e), p?.(Error(e));
|
|
169
170
|
return;
|
|
170
171
|
}
|
|
171
|
-
|
|
172
|
-
},
|
|
173
|
-
if (!(!
|
|
174
|
-
|
|
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);
|
|
175
176
|
let e = "";
|
|
176
|
-
|
|
177
|
-
paymentChain:
|
|
178
|
-
paymentToken:
|
|
179
|
-
orderId:
|
|
180
|
-
amount:
|
|
181
|
-
}), e = `${
|
|
182
|
-
paymentChain:
|
|
183
|
-
paymentToken:
|
|
184
|
-
orderId:
|
|
185
|
-
amountOfUsd:
|
|
186
|
-
intervalDays:
|
|
187
|
-
}), 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, {
|
|
188
189
|
width: 200,
|
|
189
190
|
margin: 2,
|
|
190
191
|
errorCorrectionLevel: "H"
|
|
191
192
|
}));
|
|
192
193
|
} catch (e) {
|
|
193
|
-
|
|
194
|
+
S(e instanceof Error ? e.message : "创建支付失败"), p?.(e);
|
|
194
195
|
} finally {
|
|
195
|
-
|
|
196
|
+
v(!1);
|
|
196
197
|
}
|
|
197
|
-
},
|
|
198
|
-
if (
|
|
199
|
-
|
|
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);
|
|
200
201
|
} catch (e) {
|
|
201
|
-
console.error("支付状态检查错误:", e),
|
|
202
|
+
console.error("支付状态检查错误:", e), S(e instanceof Error ? e.message : "检查支付状态失败"), p?.(e), b(!1);
|
|
202
203
|
}
|
|
203
|
-
},
|
|
204
|
-
let t = () => defer(() =>
|
|
204
|
+
}, Z = (e) => {
|
|
205
|
+
let t = () => defer(() => o === "subscription" ? m.checkSubscriptionPaymentStatus({ subscriptionId: e }) : m.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
|
|
205
206
|
count: 3,
|
|
206
207
|
delay: 2e3
|
|
207
208
|
}));
|
|
208
|
-
|
|
209
|
-
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));
|
|
210
211
|
})).subscribe({ error: (e) => {
|
|
211
|
-
console.error("支付状态检查错误:", e),
|
|
212
|
+
console.error("支付状态检查错误:", e), S(e instanceof Error ? e.message : "检查支付状态失败"), b(!1), p?.(e);
|
|
212
213
|
} });
|
|
213
|
-
},
|
|
214
|
-
if (!
|
|
215
|
-
let e =
|
|
214
|
+
}, Q = async () => {
|
|
215
|
+
if (!Y.current) return;
|
|
216
|
+
let e = o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress;
|
|
216
217
|
e && await navigator.clipboard.writeText(e);
|
|
217
218
|
}, $ = () => {
|
|
218
|
-
|
|
219
|
-
|
|
219
|
+
_ || y || (n(), setTimeout(() => {
|
|
220
|
+
g("select"), S(void 0), Y.current = null;
|
|
220
221
|
}, 300));
|
|
221
222
|
};
|
|
222
223
|
return useEffect(() => {
|
|
223
|
-
t &&
|
|
224
|
+
t && T.length === 0 && Te();
|
|
224
225
|
}, [t]), useEffect(() => {
|
|
225
|
-
|
|
226
|
-
}, [
|
|
227
|
-
|
|
226
|
+
U.length > 0 && A(U[0].symbol);
|
|
227
|
+
}, [U]), useEffect(() => () => {
|
|
228
|
+
B.current?.unsubscribe();
|
|
228
229
|
}, []), t ? /* @__PURE__ */ jsx("div", {
|
|
229
230
|
className: "_cppay-overlay",
|
|
230
|
-
onClick: (e) => e.target === e.currentTarget && !
|
|
231
|
+
onClick: (e) => e.target === e.currentTarget && !_ && !y && $(),
|
|
231
232
|
children: /* @__PURE__ */ jsxs("div", {
|
|
232
233
|
className: "_cppay-dialog",
|
|
233
234
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
234
235
|
className: "_cppay-header",
|
|
235
236
|
children: [/* @__PURE__ */ jsx("h2", {
|
|
236
237
|
className: "_cppay-title",
|
|
237
|
-
children:
|
|
238
|
+
children: h === "select" ? "选择支付方式" : "完成支付"
|
|
238
239
|
}), /* @__PURE__ */ jsx("button", {
|
|
239
240
|
onClick: $,
|
|
240
|
-
disabled:
|
|
241
|
+
disabled: _ || y,
|
|
241
242
|
className: "_cppay-close-btn",
|
|
242
243
|
children: /* @__PURE__ */ jsx("svg", {
|
|
243
244
|
fill: "none",
|
|
@@ -253,7 +254,7 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
253
254
|
})]
|
|
254
255
|
}), /* @__PURE__ */ jsx("div", {
|
|
255
256
|
className: "_cppay-content",
|
|
256
|
-
children:
|
|
257
|
+
children: h === "success" ? /* @__PURE__ */ jsxs("div", {
|
|
257
258
|
style: {
|
|
258
259
|
textAlign: "center",
|
|
259
260
|
padding: "2rem 0"
|
|
@@ -273,17 +274,17 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
273
274
|
color: "#10b981",
|
|
274
275
|
margin: "0 0 0.5rem 0"
|
|
275
276
|
},
|
|
276
|
-
children:
|
|
277
|
+
children: o === "subscription" ? "授权成功!" : "支付成功!"
|
|
277
278
|
}),
|
|
278
279
|
/* @__PURE__ */ jsx("p", {
|
|
279
280
|
style: {
|
|
280
281
|
color: "#6b7280",
|
|
281
282
|
margin: 0
|
|
282
283
|
},
|
|
283
|
-
children:
|
|
284
|
+
children: o === "subscription" ? "订阅已激活" : "交易已完成"
|
|
284
285
|
})
|
|
285
286
|
]
|
|
286
|
-
}) :
|
|
287
|
+
}) : h === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
287
288
|
/* @__PURE__ */ jsxs("div", {
|
|
288
289
|
className: "_cppay-section",
|
|
289
290
|
children: [/* @__PURE__ */ jsx("label", {
|
|
@@ -291,9 +292,9 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
291
292
|
children: "支付网络"
|
|
292
293
|
}), /* @__PURE__ */ jsx("div", {
|
|
293
294
|
className: "_cppay-grid",
|
|
294
|
-
children:
|
|
295
|
-
onClick: () =>
|
|
296
|
-
className: `_cppay-select-btn ${
|
|
295
|
+
children: T.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
296
|
+
onClick: () => O(e.chain),
|
|
297
|
+
className: `_cppay-select-btn ${D === e.chain ? "_cppay-selected" : ""}`,
|
|
297
298
|
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
298
299
|
src: e.icon,
|
|
299
300
|
alt: e.chain
|
|
@@ -308,9 +309,9 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
308
309
|
children: "支付代币"
|
|
309
310
|
}), /* @__PURE__ */ jsx("div", {
|
|
310
311
|
className: "_cppay-grid",
|
|
311
|
-
children:
|
|
312
|
-
onClick: () =>
|
|
313
|
-
className: `_cppay-select-btn ${
|
|
312
|
+
children: U.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
313
|
+
onClick: () => A(e.symbol),
|
|
314
|
+
className: `_cppay-select-btn ${k === e.symbol ? "_cppay-selected" : ""}`,
|
|
314
315
|
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
315
316
|
src: e.icon,
|
|
316
317
|
alt: e.symbol
|
|
@@ -332,34 +333,53 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
332
333
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
333
334
|
className: "_cppay-price-main",
|
|
334
335
|
children: [
|
|
335
|
-
|
|
336
|
+
q ?? "-",
|
|
336
337
|
" ",
|
|
337
|
-
|
|
338
|
+
k ?? ""
|
|
338
339
|
]
|
|
339
340
|
}), /* @__PURE__ */ jsxs("div", {
|
|
340
341
|
className: "_cppay-price-sub",
|
|
341
|
-
children: ["≈ $",
|
|
342
|
+
children: ["≈ $", c]
|
|
342
343
|
})]
|
|
343
344
|
})]
|
|
344
345
|
})
|
|
345
346
|
})
|
|
346
347
|
}),
|
|
347
|
-
/* @__PURE__ */
|
|
348
|
+
/* @__PURE__ */ jsxs("div", {
|
|
348
349
|
className: "_cppay-section",
|
|
349
|
-
children: /* @__PURE__ */
|
|
350
|
-
|
|
351
|
-
|
|
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 || _,
|
|
352
372
|
className: "_cppay-btn _cppay-btn-primary",
|
|
353
|
-
children:
|
|
354
|
-
})
|
|
373
|
+
children: _ ? "处理中..." : "继续支付"
|
|
374
|
+
})]
|
|
355
375
|
})
|
|
356
376
|
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
357
377
|
/* @__PURE__ */ jsx("div", {
|
|
358
378
|
className: "_cppay-qr-container",
|
|
359
379
|
children: /* @__PURE__ */ jsx("div", {
|
|
360
380
|
className: "_cppay-qr-code",
|
|
361
|
-
children:
|
|
362
|
-
src:
|
|
381
|
+
children: j && /* @__PURE__ */ jsx("img", {
|
|
382
|
+
src: j,
|
|
363
383
|
alt: "Payment QR Code",
|
|
364
384
|
style: {
|
|
365
385
|
width: "160px",
|
|
@@ -372,25 +392,25 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
372
392
|
/* @__PURE__ */ jsxs("div", {
|
|
373
393
|
className: "_cppay-section",
|
|
374
394
|
children: [
|
|
375
|
-
|
|
395
|
+
k && /* @__PURE__ */ jsxs("div", {
|
|
376
396
|
className: "_cppay-info-box",
|
|
377
397
|
children: [/* @__PURE__ */ jsx("div", {
|
|
378
398
|
className: "_cppay-info-label",
|
|
379
|
-
children:
|
|
399
|
+
children: o === "subscription" ? "授权金额" : "支付金额"
|
|
380
400
|
}), /* @__PURE__ */ jsx("div", {
|
|
381
401
|
className: "_cppay-info-value",
|
|
382
|
-
children:
|
|
402
|
+
children: o === "subscription" ? `${K(Y.current.approveAmount, G(k))} ${k}` : `${K(Y.current.paymentAmount, G(k))} ${k}`
|
|
383
403
|
})]
|
|
384
404
|
}),
|
|
385
405
|
/* @__PURE__ */ jsxs("div", {
|
|
386
406
|
className: "_cppay-info-box",
|
|
387
407
|
children: [/* @__PURE__ */ jsx("div", {
|
|
388
408
|
className: "_cppay-info-label",
|
|
389
|
-
children:
|
|
409
|
+
children: o === "subscription" ? "授权合约地址" : "支付地址"
|
|
390
410
|
}), /* @__PURE__ */ jsxs("div", {
|
|
391
411
|
className: "_cppay-address-row",
|
|
392
|
-
children: [/* @__PURE__ */ jsx("code", { children:
|
|
393
|
-
onClick:
|
|
412
|
+
children: [/* @__PURE__ */ jsx("code", { children: o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
413
|
+
onClick: Q,
|
|
394
414
|
className: "_cppay-copy-btn",
|
|
395
415
|
title: "复制地址",
|
|
396
416
|
children: /* @__PURE__ */ jsx("svg", {
|
|
@@ -407,7 +427,7 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
407
427
|
})]
|
|
408
428
|
})]
|
|
409
429
|
}),
|
|
410
|
-
|
|
430
|
+
o === "subscription" && /* @__PURE__ */ jsxs("div", {
|
|
411
431
|
className: "_cppay-info-box",
|
|
412
432
|
style: {
|
|
413
433
|
background: "#fff3cd",
|
|
@@ -428,18 +448,38 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
428
448
|
})
|
|
429
449
|
]
|
|
430
450
|
}),
|
|
431
|
-
|
|
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", {
|
|
432
472
|
className: "_cppay-section",
|
|
433
|
-
children:
|
|
473
|
+
children: N ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
434
474
|
className: "_cppay-btn-container",
|
|
435
475
|
children: [/* @__PURE__ */ jsx("button", {
|
|
436
|
-
onClick:
|
|
437
|
-
disabled:
|
|
476
|
+
onClick: Oe,
|
|
477
|
+
disabled: _,
|
|
438
478
|
className: "_cppay-btn _cppay-btn-primary",
|
|
439
|
-
children:
|
|
479
|
+
children: _ ? o === "subscription" ? "授权中..." : "支付中..." : o === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
|
|
440
480
|
}), /* @__PURE__ */ jsx("button", {
|
|
441
|
-
onClick:
|
|
442
|
-
disabled:
|
|
481
|
+
onClick: V,
|
|
482
|
+
disabled: _,
|
|
443
483
|
className: "_cppay-btn _cppay-btn-primary",
|
|
444
484
|
children: "💰钱包状态"
|
|
445
485
|
})]
|
|
@@ -452,13 +492,13 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
452
492
|
},
|
|
453
493
|
children: [
|
|
454
494
|
"已连接: ",
|
|
455
|
-
|
|
495
|
+
N.slice(0, 6),
|
|
456
496
|
"...",
|
|
457
|
-
|
|
497
|
+
N.slice(-4)
|
|
458
498
|
]
|
|
459
499
|
})] }) : /* @__PURE__ */ jsx("button", {
|
|
460
|
-
onClick:
|
|
461
|
-
disabled:
|
|
500
|
+
onClick: V,
|
|
501
|
+
disabled: F,
|
|
462
502
|
className: "_cppay-btn _cppay-btn-secondary",
|
|
463
503
|
style: {
|
|
464
504
|
display: "flex",
|
|
@@ -468,23 +508,23 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
468
508
|
padding: "0.75rem 1rem",
|
|
469
509
|
width: "100%"
|
|
470
510
|
},
|
|
471
|
-
children: /* @__PURE__ */ jsx("span", { children:
|
|
511
|
+
children: /* @__PURE__ */ jsx("span", { children: F ? "连接中..." : "💳 连接钱包" })
|
|
472
512
|
})
|
|
473
513
|
}),
|
|
474
514
|
/* @__PURE__ */ jsx("div", {
|
|
475
515
|
className: "_cppay-section",
|
|
476
516
|
children: /* @__PURE__ */ jsx("button", {
|
|
477
|
-
onClick:
|
|
478
|
-
disabled:
|
|
517
|
+
onClick: ke,
|
|
518
|
+
disabled: y,
|
|
479
519
|
className: "_cppay-btn _cppay-btn-primary",
|
|
480
|
-
children:
|
|
520
|
+
children: y ? "检查中..." : "我已完成支付"
|
|
481
521
|
})
|
|
482
522
|
}),
|
|
483
523
|
/* @__PURE__ */ jsx("div", {
|
|
484
524
|
className: "_cppay-section",
|
|
485
525
|
children: /* @__PURE__ */ jsx("button", {
|
|
486
|
-
onClick: () =>
|
|
487
|
-
disabled:
|
|
526
|
+
onClick: () => g("select"),
|
|
527
|
+
disabled: _ || y,
|
|
488
528
|
className: "_cppay-btn _cppay-btn-text",
|
|
489
529
|
children: "更改支付方式"
|
|
490
530
|
})
|
|
@@ -495,27 +535,27 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: u, plain:
|
|
|
495
535
|
}) : null;
|
|
496
536
|
}), CppayContext = createContext(null);
|
|
497
537
|
const CppayProvider = ({ apikey: e, children: t }) => {
|
|
498
|
-
let [n, r] = useState(!1), [i,
|
|
499
|
-
|
|
500
|
-
}, []),
|
|
538
|
+
let [n, r] = useState(!1), [i, be] = useState(null), xe = useCallback((e) => {
|
|
539
|
+
be(e), r(!0);
|
|
540
|
+
}, []), Se = useCallback(() => {
|
|
501
541
|
r(!1);
|
|
502
|
-
}, []),
|
|
542
|
+
}, []), Ce = useCallback((e) => {
|
|
503
543
|
i?.onSuccess?.(e), r(!1);
|
|
504
|
-
}, [i]),
|
|
544
|
+
}, [i]), we = useCallback((e) => {
|
|
505
545
|
i?.onError?.(e);
|
|
506
546
|
}, [i]);
|
|
507
547
|
return /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
508
|
-
value: { showPayment:
|
|
548
|
+
value: { showPayment: xe },
|
|
509
549
|
children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
510
550
|
open: n,
|
|
511
|
-
onClose:
|
|
551
|
+
onClose: Se,
|
|
512
552
|
apikey: e,
|
|
513
553
|
plain: i.plain,
|
|
514
554
|
orderId: i.orderId,
|
|
515
555
|
amount: i.amount,
|
|
516
556
|
intervalDays: i.intervalDays,
|
|
517
|
-
onSuccess:
|
|
518
|
-
onError:
|
|
557
|
+
onSuccess: Ce,
|
|
558
|
+
onError: we
|
|
519
559
|
})]
|
|
520
560
|
});
|
|
521
561
|
}, useCppayPayment = () => {
|