cppay-sdk 0.0.2-beta.20 → 0.0.2-beta.22
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-LnYTnh4d.js → cppay-BcCDwXlg.js} +4 -2
- package/dist/cppay-DnxPUyM2.cjs +1 -0
- package/dist/cppay-sdk.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +7 -0
- package/dist/react.js +400 -141
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +68 -8
- package/dist/vue.js +404 -123
- package/dist/walletconnect-B0L70Mgc.js +1239 -0
- package/dist/walletconnect-B_n5YF-h.cjs +8 -0
- package/package.json +8 -2
- package/dist/browser-B4fiRjvC.cjs +0 -8
- package/dist/browser-Dm8HHcNy.js +0 -1239
- package/dist/cppay-ClXaSwp8.cjs +0 -1
package/dist/react.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
import { t as cppay_default } from "./cppay-
|
|
1
|
+
import { a as payment_dialog_default, i as injectStyle, n as metamask_default, o as __toESM, r as require_browser, t as walletconnect_default } from "./walletconnect-B0L70Mgc.js";
|
|
2
|
+
import { t as cppay_default } from "./cppay-BcCDwXlg.js";
|
|
3
3
|
import { EMPTY, defer, timer } from "rxjs";
|
|
4
4
|
import { expand, retry, switchMap, tap, timeout } from "rxjs/operators";
|
|
5
|
+
import { createWalletClient, custom, parseUnits } from "viem";
|
|
6
|
+
import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
7
|
+
import EthereumProvider from "@walletconnect/ethereum-provider";
|
|
5
8
|
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
-
var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialog_default = React.memo(({ open:
|
|
8
|
-
let
|
|
9
|
-
useMemo(() => H.find((t) => t.symbol === I), [H, I]);
|
|
10
|
-
let U = (t) => [
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialog_default = React.memo(({ open: e, onClose: t, apikey: r, plain: i, orderId: l, amount: u, intervalDays: d, onExpired: we, onSuccess: f, onFailed: p, onError: m }) => {
|
|
11
|
+
let h = useMemo(() => new cppay_default(r), [r]), [g, _] = useState("select"), [v, y] = useState(!1), [b, x] = useState([]), [S, C] = useState(""), [w, T] = useState(""), [E, D] = useState(""), [O, k] = useState(""), [A, j] = useState(!1), [M, N] = useState(null), P = useRef(null), F = useRef(null), I = useMemo(() => b.find((e) => e.chain === S), [b, S]), L = useMemo(() => I?.tokens || [], [I]), R = useMemo(() => L.find((e) => e.symbol === w), [L, w]), z = (e) => [
|
|
11
12
|
"USDT",
|
|
12
13
|
"USDC",
|
|
13
14
|
"BUSD",
|
|
@@ -15,98 +16,258 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
15
16
|
"TUSD",
|
|
16
17
|
"USDD",
|
|
17
18
|
"FDUSD"
|
|
18
|
-
].includes(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
].includes(e.toUpperCase()) ? 2 : 6, B = (e) => ({
|
|
20
|
+
ETH: mainnet,
|
|
21
|
+
BSC: bsc,
|
|
22
|
+
Polygon: polygon,
|
|
23
|
+
Arbitrum: arbitrum,
|
|
24
|
+
Optimism: optimism,
|
|
25
|
+
Base: base
|
|
26
|
+
})[e] || mainnet, V = (e, t) => {
|
|
27
|
+
let n = parseFloat(e);
|
|
28
|
+
return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
|
|
29
|
+
}, H = useMemo(() => {
|
|
30
|
+
if (!w || !R) return "0";
|
|
31
|
+
let e = parseFloat(R.price);
|
|
32
|
+
if (isNaN(e) || e === 0) return "0";
|
|
33
|
+
let t = z(w);
|
|
34
|
+
return V((parseFloat(u) / e).toFixed(t), t);
|
|
25
35
|
}, [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
]),
|
|
36
|
+
u,
|
|
37
|
+
w,
|
|
38
|
+
R
|
|
39
|
+
]), U = async () => {
|
|
30
40
|
try {
|
|
31
|
-
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
} catch (
|
|
35
|
-
|
|
41
|
+
y(!0);
|
|
42
|
+
let e = await h.getSupportedChains();
|
|
43
|
+
x(e), e.length > 0 && C(e[0].chain);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
m?.(e);
|
|
46
|
+
} finally {
|
|
47
|
+
y(!1);
|
|
48
|
+
}
|
|
49
|
+
}, W = async (e) => {
|
|
50
|
+
try {
|
|
51
|
+
if (j(!0), e === "metamask") {
|
|
52
|
+
if (typeof window < "u" && window.ethereum?.isMetaMask) {
|
|
53
|
+
let e = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
54
|
+
if (e && e.length > 0) {
|
|
55
|
+
k(e[0]), N("metamask");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw Error("请安装 MetaMask 扩展");
|
|
60
|
+
}
|
|
61
|
+
if (e === "walletconnect") {
|
|
62
|
+
let e = await EthereumProvider.init({
|
|
63
|
+
projectId: "8d2e1854d3f1782e45aa15fbd8938894",
|
|
64
|
+
chains: [1],
|
|
65
|
+
showQrModal: !0,
|
|
66
|
+
optionalChains: [
|
|
67
|
+
56,
|
|
68
|
+
137,
|
|
69
|
+
42161,
|
|
70
|
+
10,
|
|
71
|
+
8453
|
|
72
|
+
],
|
|
73
|
+
methods: [
|
|
74
|
+
"eth_sendTransaction",
|
|
75
|
+
"eth_signTransaction",
|
|
76
|
+
"eth_sign",
|
|
77
|
+
"personal_sign",
|
|
78
|
+
"eth_signTypedData"
|
|
79
|
+
],
|
|
80
|
+
events: ["chainChanged", "accountsChanged"],
|
|
81
|
+
metadata: {
|
|
82
|
+
name: "Cppay",
|
|
83
|
+
description: "Cppay Payment Gateway",
|
|
84
|
+
url: typeof window < "u" ? window.location.origin : "https://cppay.com",
|
|
85
|
+
icons: ["https://cppay.com/icon.png"]
|
|
86
|
+
},
|
|
87
|
+
rpcMap: {
|
|
88
|
+
1: "https://ethereum.publicnode.com",
|
|
89
|
+
56: "https://bsc-dataseed.binance.org",
|
|
90
|
+
137: "https://polygon-rpc.com",
|
|
91
|
+
42161: "https://arb1.arbitrum.io/rpc",
|
|
92
|
+
10: "https://mainnet.optimism.io",
|
|
93
|
+
8453: "https://mainnet.base.org"
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
await e.enable();
|
|
97
|
+
let t = await e.request({ method: "eth_accounts" });
|
|
98
|
+
t && t.length > 0 && (k(t[0]), N("walletconnect"), P.current = e);
|
|
99
|
+
}
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error("钱包连接失败:", e), m?.(e);
|
|
36
102
|
} finally {
|
|
37
103
|
j(!1);
|
|
38
104
|
}
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
105
|
+
}, G = async (e) => {
|
|
106
|
+
let t;
|
|
107
|
+
if (t = M === "walletconnect" ? P.current : window.ethereum, t) try {
|
|
108
|
+
await t.request({
|
|
109
|
+
method: "wallet_switchEthereumChain",
|
|
110
|
+
params: [{ chainId: `0x${e.toString(16)}` }]
|
|
111
|
+
});
|
|
112
|
+
} catch (e) {
|
|
113
|
+
throw e.code === 4902 ? Error("请在钱包中添加该网络") : e;
|
|
114
|
+
}
|
|
115
|
+
}, K = async () => {
|
|
116
|
+
if (!(!O || !Y.current || !R)) try {
|
|
117
|
+
y(!0);
|
|
118
|
+
let e = Y.current, t = B(S);
|
|
119
|
+
await G(I.chainId);
|
|
120
|
+
let n = createWalletClient({
|
|
121
|
+
account: O,
|
|
122
|
+
chain: t,
|
|
123
|
+
transport: custom(M === "walletconnect" ? P.current : window.ethereum)
|
|
124
|
+
});
|
|
125
|
+
if (R.address) {
|
|
126
|
+
let t = await n.writeContract({
|
|
127
|
+
address: R.address,
|
|
128
|
+
abi: [{
|
|
129
|
+
name: "transfer",
|
|
130
|
+
type: "function",
|
|
131
|
+
stateMutability: "nonpayable",
|
|
132
|
+
inputs: [{
|
|
133
|
+
name: "to",
|
|
134
|
+
type: "address"
|
|
135
|
+
}, {
|
|
136
|
+
name: "amount",
|
|
137
|
+
type: "uint256"
|
|
138
|
+
}],
|
|
139
|
+
outputs: [{ type: "bool" }]
|
|
140
|
+
}],
|
|
141
|
+
functionName: "transfer",
|
|
142
|
+
args: [e.receiveAddress, parseUnits(e.paymentAmount, R.decimals)],
|
|
143
|
+
chain: null
|
|
144
|
+
});
|
|
145
|
+
console.log("转账交易哈希:", t);
|
|
146
|
+
} else {
|
|
147
|
+
let t = await n.sendTransaction({
|
|
148
|
+
to: e.receiveAddress,
|
|
149
|
+
value: parseUnits(e.paymentAmount, R.decimals),
|
|
150
|
+
chain: null
|
|
151
|
+
});
|
|
152
|
+
console.log("转账交易哈希:", t);
|
|
153
|
+
}
|
|
154
|
+
Z(e.paymentId);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.error("钱包支付失败:", e), m?.(e);
|
|
157
|
+
} finally {
|
|
158
|
+
y(!1);
|
|
159
|
+
}
|
|
160
|
+
}, q = async () => {
|
|
161
|
+
if (!(!O || !Y.current || !R)) try {
|
|
162
|
+
y(!0);
|
|
163
|
+
let e = Y.current, t = B(S);
|
|
164
|
+
await G(I.chainId);
|
|
165
|
+
let n = createWalletClient({
|
|
166
|
+
account: O,
|
|
167
|
+
chain: t,
|
|
168
|
+
transport: custom(M === "walletconnect" ? P.current : window.ethereum)
|
|
169
|
+
});
|
|
170
|
+
if (!R.address) throw Error("订阅支付不支持原生代币");
|
|
171
|
+
let r = await n.writeContract({
|
|
172
|
+
address: R.address,
|
|
173
|
+
abi: [{
|
|
174
|
+
name: "approve",
|
|
175
|
+
type: "function",
|
|
176
|
+
stateMutability: "nonpayable",
|
|
177
|
+
inputs: [{
|
|
178
|
+
name: "spender",
|
|
179
|
+
type: "address"
|
|
180
|
+
}, {
|
|
181
|
+
name: "amount",
|
|
182
|
+
type: "uint256"
|
|
183
|
+
}],
|
|
184
|
+
outputs: [{ type: "bool" }]
|
|
185
|
+
}],
|
|
186
|
+
functionName: "approve",
|
|
187
|
+
args: [e.spenderAddress, parseUnits(e.approveAmount, R.decimals)],
|
|
188
|
+
chain: null
|
|
189
|
+
});
|
|
190
|
+
console.log("授权交易哈希:", r), Z(e.subscriptionId);
|
|
191
|
+
} catch (e) {
|
|
192
|
+
console.error("钱包授权失败:", e), m?.(e);
|
|
193
|
+
} finally {
|
|
194
|
+
y(!1);
|
|
195
|
+
}
|
|
196
|
+
}, J = async () => {
|
|
197
|
+
if (!O) {
|
|
198
|
+
m?.(/* @__PURE__ */ Error("请先连接钱包"));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
i === "one-time" ? await K() : i === "subscription" && await q();
|
|
202
|
+
}, Y = useRef(null), X = async () => {
|
|
203
|
+
if (!(!S || !w)) try {
|
|
204
|
+
y(!0);
|
|
205
|
+
let e = "";
|
|
206
|
+
i === "one-time" ? (Y.current = await h.createOnetimePayment({
|
|
207
|
+
paymentChain: S,
|
|
208
|
+
paymentToken: w,
|
|
209
|
+
orderId: l,
|
|
210
|
+
amount: H
|
|
211
|
+
}), e = `${S.toLowerCase()}:${Y.current.receiveAddress}?amount=${Y.current.paymentAmount}`) : i === "subscription" && (Y.current = await h.createSubscriptionPayment({
|
|
212
|
+
paymentChain: S,
|
|
213
|
+
paymentToken: w,
|
|
214
|
+
orderId: l,
|
|
215
|
+
amountOfUsd: H,
|
|
216
|
+
intervalDays: d || 30
|
|
217
|
+
}), e = `${S.toLowerCase()}:${Y.current.spenderAddress}?amount=${Y.current.approveAmount}`), _("payment"), D(await import_browser.toDataURL(e, {
|
|
55
218
|
width: 200,
|
|
56
219
|
margin: 2,
|
|
57
220
|
errorCorrectionLevel: "H"
|
|
58
221
|
}));
|
|
59
|
-
} catch (
|
|
60
|
-
|
|
222
|
+
} catch (e) {
|
|
223
|
+
m?.(e);
|
|
61
224
|
} finally {
|
|
62
|
-
|
|
225
|
+
y(!1);
|
|
63
226
|
}
|
|
64
|
-
},
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
} catch (
|
|
68
|
-
console.error("支付状态检查错误:",
|
|
69
|
-
} finally {
|
|
70
|
-
j(!1);
|
|
227
|
+
}, Te = async () => {
|
|
228
|
+
if (Y.current) try {
|
|
229
|
+
y(!0), i === "one-time" ? Z(Y.current.paymentId) : i === "subscription" && Z(Y.current.subscriptionId);
|
|
230
|
+
} catch (e) {
|
|
231
|
+
console.error("支付状态检查错误:", e), m?.(e), y(!1);
|
|
71
232
|
}
|
|
72
|
-
},
|
|
73
|
-
let
|
|
233
|
+
}, Z = (e) => {
|
|
234
|
+
let t = () => defer(() => i === "subscription" ? h.checkSubscriptionPaymentStatus({ subscriptionId: e }) : h.checkOnetimePaymentStatus({ paymentId: e })).pipe(timeout(15e3), retry({
|
|
74
235
|
count: 3,
|
|
75
236
|
delay: 2e3
|
|
76
237
|
}));
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})).subscribe({ error: (
|
|
80
|
-
console.error("支付状态检查错误:",
|
|
238
|
+
F.current?.unsubscribe(), F.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
|
|
239
|
+
e.status === "expired" && (y(!1), we?.(e)), e.status === "paid" && (y(!1), _("success"), f?.(e)), e.status === "failed" && (y(!1), p?.(e)), e.status === "approved" && (y(!1), _("success"), f?.(e));
|
|
240
|
+
})).subscribe({ error: (e) => {
|
|
241
|
+
console.error("支付状态检查错误:", e), y(!1), m?.(e);
|
|
81
242
|
} });
|
|
82
|
-
},
|
|
83
|
-
if (!
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, 300);
|
|
243
|
+
}, Q = async () => {
|
|
244
|
+
if (!Y.current) return;
|
|
245
|
+
let e = i === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress;
|
|
246
|
+
e && await navigator.clipboard.writeText(e);
|
|
247
|
+
}, $ = () => {
|
|
248
|
+
v || (t(), setTimeout(() => {
|
|
249
|
+
_("select"), Y.current = null;
|
|
250
|
+
}, 300));
|
|
90
251
|
};
|
|
91
252
|
return useEffect(() => {
|
|
92
|
-
|
|
93
|
-
}, [
|
|
94
|
-
|
|
95
|
-
}, [
|
|
96
|
-
|
|
97
|
-
}, []),
|
|
253
|
+
e && b.length === 0 && U();
|
|
254
|
+
}, [e]), useEffect(() => {
|
|
255
|
+
L.length > 0 && T(L[0].symbol);
|
|
256
|
+
}, [L]), useEffect(() => () => {
|
|
257
|
+
F.current?.unsubscribe();
|
|
258
|
+
}, []), e ? /* @__PURE__ */ jsx("div", {
|
|
98
259
|
className: "_cppay-overlay",
|
|
99
|
-
onClick: (
|
|
260
|
+
onClick: (e) => e.target === e.currentTarget && !v && $(),
|
|
100
261
|
children: /* @__PURE__ */ jsxs("div", {
|
|
101
262
|
className: "_cppay-dialog",
|
|
102
263
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
103
264
|
className: "_cppay-header",
|
|
104
265
|
children: [/* @__PURE__ */ jsx("h2", {
|
|
105
266
|
className: "_cppay-title",
|
|
106
|
-
children:
|
|
267
|
+
children: g === "select" ? "选择支付方式" : "完成支付"
|
|
107
268
|
}), /* @__PURE__ */ jsx("button", {
|
|
108
|
-
onClick:
|
|
109
|
-
disabled:
|
|
269
|
+
onClick: $,
|
|
270
|
+
disabled: v,
|
|
110
271
|
className: "_cppay-close-btn",
|
|
111
272
|
children: /* @__PURE__ */ jsx("svg", {
|
|
112
273
|
fill: "none",
|
|
@@ -122,7 +283,37 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
122
283
|
})]
|
|
123
284
|
}), /* @__PURE__ */ jsx("div", {
|
|
124
285
|
className: "_cppay-content",
|
|
125
|
-
children:
|
|
286
|
+
children: g === "success" ? /* @__PURE__ */ jsxs("div", {
|
|
287
|
+
style: {
|
|
288
|
+
textAlign: "center",
|
|
289
|
+
padding: "2rem 0"
|
|
290
|
+
},
|
|
291
|
+
children: [
|
|
292
|
+
/* @__PURE__ */ jsx("div", {
|
|
293
|
+
style: {
|
|
294
|
+
fontSize: "64px",
|
|
295
|
+
marginBottom: "1rem"
|
|
296
|
+
},
|
|
297
|
+
children: "✅"
|
|
298
|
+
}),
|
|
299
|
+
/* @__PURE__ */ jsx("h3", {
|
|
300
|
+
style: {
|
|
301
|
+
fontSize: "1.5rem",
|
|
302
|
+
fontWeight: 600,
|
|
303
|
+
color: "#10b981",
|
|
304
|
+
margin: "0 0 0.5rem 0"
|
|
305
|
+
},
|
|
306
|
+
children: i === "subscription" ? "授权成功!" : "支付成功!"
|
|
307
|
+
}),
|
|
308
|
+
/* @__PURE__ */ jsx("p", {
|
|
309
|
+
style: {
|
|
310
|
+
color: "#6b7280",
|
|
311
|
+
margin: 0
|
|
312
|
+
},
|
|
313
|
+
children: i === "subscription" ? "订阅已激活" : "交易已完成"
|
|
314
|
+
})
|
|
315
|
+
]
|
|
316
|
+
}) : g === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
126
317
|
/* @__PURE__ */ jsxs("div", {
|
|
127
318
|
className: "_cppay-section",
|
|
128
319
|
children: [/* @__PURE__ */ jsx("label", {
|
|
@@ -130,14 +321,14 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
130
321
|
children: "支付网络"
|
|
131
322
|
}), /* @__PURE__ */ jsx("div", {
|
|
132
323
|
className: "_cppay-grid",
|
|
133
|
-
children:
|
|
134
|
-
onClick: () =>
|
|
135
|
-
className: `_cppay-select-btn ${
|
|
136
|
-
children: [
|
|
137
|
-
src:
|
|
138
|
-
alt:
|
|
139
|
-
}), /* @__PURE__ */ jsx("span", { children:
|
|
140
|
-
},
|
|
324
|
+
children: b.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
325
|
+
onClick: () => C(e.chain),
|
|
326
|
+
className: `_cppay-select-btn ${S === e.chain ? "_cppay-selected" : ""}`,
|
|
327
|
+
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
328
|
+
src: e.icon,
|
|
329
|
+
alt: e.chain
|
|
330
|
+
}), /* @__PURE__ */ jsx("span", { children: e.chain })]
|
|
331
|
+
}, e.chain))
|
|
141
332
|
})]
|
|
142
333
|
}),
|
|
143
334
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -147,14 +338,14 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
147
338
|
children: "支付代币"
|
|
148
339
|
}), /* @__PURE__ */ jsx("div", {
|
|
149
340
|
className: "_cppay-grid",
|
|
150
|
-
children:
|
|
151
|
-
onClick: () =>
|
|
152
|
-
className: `_cppay-select-btn ${
|
|
153
|
-
children: [
|
|
154
|
-
src:
|
|
155
|
-
alt:
|
|
156
|
-
}), /* @__PURE__ */ jsx("span", { children:
|
|
157
|
-
},
|
|
341
|
+
children: L.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
342
|
+
onClick: () => T(e.symbol),
|
|
343
|
+
className: `_cppay-select-btn ${w === e.symbol ? "_cppay-selected" : ""}`,
|
|
344
|
+
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
345
|
+
src: e.icon,
|
|
346
|
+
alt: e.symbol
|
|
347
|
+
}), /* @__PURE__ */ jsx("span", { children: e.symbol })]
|
|
348
|
+
}, e.symbol))
|
|
158
349
|
})]
|
|
159
350
|
}),
|
|
160
351
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -171,13 +362,13 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
171
362
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
172
363
|
className: "_cppay-price-main",
|
|
173
364
|
children: [
|
|
174
|
-
|
|
365
|
+
H,
|
|
175
366
|
" ",
|
|
176
|
-
|
|
367
|
+
w
|
|
177
368
|
]
|
|
178
369
|
}), /* @__PURE__ */ jsxs("div", {
|
|
179
370
|
className: "_cppay-price-sub",
|
|
180
|
-
children: ["≈ $",
|
|
371
|
+
children: ["≈ $", u]
|
|
181
372
|
})]
|
|
182
373
|
})]
|
|
183
374
|
})
|
|
@@ -186,10 +377,10 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
186
377
|
/* @__PURE__ */ jsx("div", {
|
|
187
378
|
className: "_cppay-section",
|
|
188
379
|
children: /* @__PURE__ */ jsx("button", {
|
|
189
|
-
onClick:
|
|
190
|
-
disabled: !
|
|
380
|
+
onClick: X,
|
|
381
|
+
disabled: !S || !w || v,
|
|
191
382
|
className: "_cppay-btn _cppay-btn-primary",
|
|
192
|
-
children:
|
|
383
|
+
children: v ? "处理中..." : "继续支付"
|
|
193
384
|
})
|
|
194
385
|
})
|
|
195
386
|
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
@@ -197,17 +388,13 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
197
388
|
className: "_cppay-qr-container",
|
|
198
389
|
children: /* @__PURE__ */ jsx("div", {
|
|
199
390
|
className: "_cppay-qr-code",
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
padding: "16px",
|
|
203
|
-
borderRadius: "16px"
|
|
204
|
-
},
|
|
205
|
-
children: R && /* @__PURE__ */ jsx("img", {
|
|
206
|
-
src: R,
|
|
391
|
+
children: E && /* @__PURE__ */ jsx("img", {
|
|
392
|
+
src: E,
|
|
207
393
|
alt: "Payment QR Code",
|
|
208
394
|
style: {
|
|
209
|
-
width: "
|
|
210
|
-
height: "
|
|
395
|
+
width: "160px",
|
|
396
|
+
height: "160px",
|
|
397
|
+
display: "block"
|
|
211
398
|
}
|
|
212
399
|
})
|
|
213
400
|
})
|
|
@@ -219,21 +406,21 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
219
406
|
className: "_cppay-info-box",
|
|
220
407
|
children: [/* @__PURE__ */ jsx("div", {
|
|
221
408
|
className: "_cppay-info-label",
|
|
222
|
-
children:
|
|
409
|
+
children: i === "subscription" ? "授权金额" : "支付金额"
|
|
223
410
|
}), /* @__PURE__ */ jsx("div", {
|
|
224
411
|
className: "_cppay-info-value",
|
|
225
|
-
children:
|
|
412
|
+
children: i === "subscription" ? `${V(Y.current.approveAmount, z(w))} ${w}` : `${V(Y.current.paymentAmount, z(w))} ${w}`
|
|
226
413
|
})]
|
|
227
414
|
}),
|
|
228
415
|
/* @__PURE__ */ jsxs("div", {
|
|
229
416
|
className: "_cppay-info-box",
|
|
230
417
|
children: [/* @__PURE__ */ jsx("div", {
|
|
231
418
|
className: "_cppay-info-label",
|
|
232
|
-
children:
|
|
419
|
+
children: i === "subscription" ? "授权合约地址" : "支付地址"
|
|
233
420
|
}), /* @__PURE__ */ jsxs("div", {
|
|
234
421
|
className: "_cppay-address-row",
|
|
235
|
-
children: [/* @__PURE__ */ jsx("code", { children:
|
|
236
|
-
onClick:
|
|
422
|
+
children: [/* @__PURE__ */ jsx("code", { children: i === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
423
|
+
onClick: Q,
|
|
237
424
|
className: "_cppay-copy-btn",
|
|
238
425
|
title: "复制地址",
|
|
239
426
|
children: /* @__PURE__ */ jsx("svg", {
|
|
@@ -250,7 +437,7 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
250
437
|
})]
|
|
251
438
|
})]
|
|
252
439
|
}),
|
|
253
|
-
|
|
440
|
+
i === "subscription" && /* @__PURE__ */ jsxs("div", {
|
|
254
441
|
className: "_cppay-info-box",
|
|
255
442
|
style: {
|
|
256
443
|
background: "#fff3cd",
|
|
@@ -271,21 +458,93 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
271
458
|
})
|
|
272
459
|
]
|
|
273
460
|
}),
|
|
461
|
+
/* @__PURE__ */ jsx("div", {
|
|
462
|
+
className: "_cppay-section",
|
|
463
|
+
children: O ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
|
|
464
|
+
onClick: J,
|
|
465
|
+
disabled: v,
|
|
466
|
+
className: "_cppay-btn _cppay-btn-primary",
|
|
467
|
+
children: v ? i === "subscription" ? "授权中..." : "支付中..." : i === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
|
|
468
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
469
|
+
style: {
|
|
470
|
+
textAlign: "center",
|
|
471
|
+
marginTop: "8px",
|
|
472
|
+
fontSize: "12px",
|
|
473
|
+
color: "#666"
|
|
474
|
+
},
|
|
475
|
+
children: [
|
|
476
|
+
"已连接: ",
|
|
477
|
+
O.slice(0, 6),
|
|
478
|
+
"...",
|
|
479
|
+
O.slice(-4)
|
|
480
|
+
]
|
|
481
|
+
})] }) : /* @__PURE__ */ jsxs("div", {
|
|
482
|
+
style: {
|
|
483
|
+
display: "flex",
|
|
484
|
+
flexDirection: "row",
|
|
485
|
+
gap: "0.5rem",
|
|
486
|
+
justifyContent: "center"
|
|
487
|
+
},
|
|
488
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
489
|
+
onClick: () => W("metamask"),
|
|
490
|
+
disabled: A,
|
|
491
|
+
className: "_cppay-btn _cppay-btn-secondary",
|
|
492
|
+
style: {
|
|
493
|
+
display: "flex",
|
|
494
|
+
alignItems: "center",
|
|
495
|
+
justifyContent: "center",
|
|
496
|
+
gap: "0.5rem",
|
|
497
|
+
padding: "0.5rem 1rem",
|
|
498
|
+
fontSize: "14px",
|
|
499
|
+
flex: "1"
|
|
500
|
+
},
|
|
501
|
+
children: [/* @__PURE__ */ jsx("img", {
|
|
502
|
+
src: metamask_default,
|
|
503
|
+
alt: "MetaMask",
|
|
504
|
+
style: {
|
|
505
|
+
width: "20px",
|
|
506
|
+
height: "20px"
|
|
507
|
+
}
|
|
508
|
+
}), /* @__PURE__ */ jsx("span", { children: "MetaMask" })]
|
|
509
|
+
}), /* @__PURE__ */ jsxs("button", {
|
|
510
|
+
onClick: () => W("walletconnect"),
|
|
511
|
+
disabled: A,
|
|
512
|
+
className: "_cppay-btn _cppay-btn-secondary",
|
|
513
|
+
style: {
|
|
514
|
+
display: "flex",
|
|
515
|
+
alignItems: "center",
|
|
516
|
+
justifyContent: "center",
|
|
517
|
+
gap: "0.5rem",
|
|
518
|
+
padding: "0.5rem 1rem",
|
|
519
|
+
fontSize: "14px",
|
|
520
|
+
flex: "1"
|
|
521
|
+
},
|
|
522
|
+
children: [/* @__PURE__ */ jsx("img", {
|
|
523
|
+
src: walletconnect_default,
|
|
524
|
+
alt: "WalletConnect",
|
|
525
|
+
style: {
|
|
526
|
+
width: "20px",
|
|
527
|
+
height: "20px"
|
|
528
|
+
}
|
|
529
|
+
}), /* @__PURE__ */ jsx("span", { children: "WalletConnect" })]
|
|
530
|
+
})]
|
|
531
|
+
})
|
|
532
|
+
}),
|
|
274
533
|
/* @__PURE__ */ jsx("div", {
|
|
275
534
|
className: "_cppay-section",
|
|
276
535
|
children: /* @__PURE__ */ jsx("button", {
|
|
277
|
-
onClick:
|
|
278
|
-
disabled:
|
|
536
|
+
onClick: Te,
|
|
537
|
+
disabled: v,
|
|
279
538
|
className: "_cppay-btn _cppay-btn-primary",
|
|
280
|
-
children:
|
|
539
|
+
children: v ? "检查中..." : "我已完成支付"
|
|
281
540
|
})
|
|
282
541
|
}),
|
|
283
542
|
/* @__PURE__ */ jsx("div", {
|
|
284
543
|
className: "_cppay-section",
|
|
285
544
|
children: /* @__PURE__ */ jsx("button", {
|
|
286
|
-
onClick: () =>
|
|
287
|
-
disabled:
|
|
288
|
-
className: "_cppay-btn _cppay-btn-
|
|
545
|
+
onClick: () => _("select"),
|
|
546
|
+
disabled: v,
|
|
547
|
+
className: "_cppay-btn _cppay-btn-text",
|
|
289
548
|
children: "更改支付方式"
|
|
290
549
|
})
|
|
291
550
|
})
|
|
@@ -294,34 +553,34 @@ var import_browser = /* @__PURE__ */ __toESM(require_browser(), 1), PaymentDialo
|
|
|
294
553
|
})
|
|
295
554
|
}) : null;
|
|
296
555
|
}), CppayContext = createContext(null);
|
|
297
|
-
const CppayProvider = ({ apikey:
|
|
298
|
-
let [
|
|
299
|
-
|
|
300
|
-
}, []),
|
|
301
|
-
|
|
302
|
-
}, []),
|
|
303
|
-
|
|
304
|
-
}, [
|
|
305
|
-
|
|
306
|
-
}, [
|
|
556
|
+
const CppayProvider = ({ apikey: e, children: t }) => {
|
|
557
|
+
let [n, r] = useState(!1), [i, a] = useState(null), o = useCallback((e) => {
|
|
558
|
+
a(e), r(!0);
|
|
559
|
+
}, []), s = useCallback(() => {
|
|
560
|
+
r(!1);
|
|
561
|
+
}, []), Ce = useCallback((e) => {
|
|
562
|
+
i?.onSuccess?.(e), r(!1);
|
|
563
|
+
}, [i]), c = useCallback((e) => {
|
|
564
|
+
i?.onError?.(e);
|
|
565
|
+
}, [i]);
|
|
307
566
|
return /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
308
|
-
value: { showPayment:
|
|
309
|
-
children: [
|
|
310
|
-
open:
|
|
311
|
-
onClose:
|
|
312
|
-
apikey:
|
|
313
|
-
plain:
|
|
314
|
-
orderId:
|
|
315
|
-
amount:
|
|
316
|
-
intervalDays:
|
|
317
|
-
onSuccess:
|
|
318
|
-
onError:
|
|
567
|
+
value: { showPayment: o },
|
|
568
|
+
children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
569
|
+
open: n,
|
|
570
|
+
onClose: s,
|
|
571
|
+
apikey: e,
|
|
572
|
+
plain: i.plain,
|
|
573
|
+
orderId: i.orderId,
|
|
574
|
+
amount: i.amount,
|
|
575
|
+
intervalDays: i.intervalDays,
|
|
576
|
+
onSuccess: Ce,
|
|
577
|
+
onError: c
|
|
319
578
|
})]
|
|
320
579
|
});
|
|
321
580
|
}, useCppayPayment = () => {
|
|
322
|
-
let
|
|
323
|
-
if (!
|
|
324
|
-
return
|
|
581
|
+
let e = useContext(CppayContext);
|
|
582
|
+
if (!e) throw Error("useCppayPayment must be used within CppayProvider");
|
|
583
|
+
return e;
|
|
325
584
|
};
|
|
326
585
|
injectStyle(payment_dialog_default);
|
|
327
586
|
export { CppayProvider, PaymentDialog_default as PaymentDialog, useCppayPayment };
|