cppay-sdk 0.0.2-beta.31 → 0.0.2-beta.33
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-DXZVBIDi.cjs → cppay-BYRjTzRF.cjs} +1 -1
- package/dist/{cppay-BPtRBPjB.js → cppay-C_gp2ZZ3.js} +4 -7
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +18 -8
- package/dist/index.js +1 -1
- package/dist/locales-DAKREZkH.cjs +1 -0
- package/dist/locales-DGvDecya.js +112 -0
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +141 -2
- package/dist/react.js +540 -434
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +131 -12
- package/dist/vue.js +454 -351
- package/package.json +1 -1
- package/dist/cppay-sdk.css +0 -2
- package/dist/inject-style-Boo8CMsU.cjs +0 -1
- package/dist/inject-style-CWza6SKp.js +0 -7
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
|
|
1
|
+
import { t as cppay_default } from "./cppay-C_gp2ZZ3.js";
|
|
2
|
+
import { n as injectStyle, r as payment_dialog_default, t as getLocaleMessages } from "./locales-DGvDecya.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";
|
|
@@ -7,12 +7,12 @@ import { createWalletClient, custom, parseUnits } from "viem";
|
|
|
7
7
|
import { arbitrum, base, bsc, mainnet, optimism, polygon } from "viem/chains";
|
|
8
8
|
import { createAppKit } from "@reown/appkit";
|
|
9
9
|
import { EthersAdapter } from "@reown/appkit-adapter-ethers";
|
|
10
|
-
import
|
|
10
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
var
|
|
13
|
-
let
|
|
12
|
+
var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount: _, intervalDays: ge, locale: _e = "zh-CN", onSuccess: ve, onExpired: ye, onFailed: be, onError: v, Slots: xe, paymentStep: y, onPaymentStepChange: b, loading: x = !1, isCheckingPayment: S = !1, error: C, onErrorChange: w }) => {
|
|
13
|
+
let T = useMemo(() => new cppay_default(t, n), [t, n]), E = useMemo(() => getLocaleMessages(_e), [_e]), [D, Se] = useState([]), [O, k] = useState(), [A, j] = useState(), [M, N] = useState(), [P, F] = useState(), [I, L] = useState(!1), [R, z] = useState(), [B, Ce] = useState(""), [V, we] = useState(!1), [Te, H] = useState(!1), U = useRef(null), W = useRef(null), G = useRef(null);
|
|
14
14
|
useEffect(() => {
|
|
15
|
-
typeof window < "u" && !
|
|
15
|
+
typeof window < "u" && !U.current && (U.current = createAppKit({
|
|
16
16
|
debug: !1,
|
|
17
17
|
enableNetworkSwitch: !1,
|
|
18
18
|
adapters: [new EthersAdapter()],
|
|
@@ -33,22 +33,24 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
|
|
|
33
33
|
icons: ["https://cppay.com/icon.png"]
|
|
34
34
|
},
|
|
35
35
|
features: { analytics: !1 }
|
|
36
|
-
}),
|
|
37
|
-
e.isConnected ?
|
|
38
|
-
}),
|
|
36
|
+
}), F(U.current.getAddress()), z(U.current.getProvider("eip155")), U.current.subscribeAccount((e) => {
|
|
37
|
+
e.isConnected ? F(e.address) : (F(void 0), z(void 0));
|
|
38
|
+
}), U.current.subscribeProviders((e) => {
|
|
39
39
|
let t = e?.eip155;
|
|
40
|
-
|
|
40
|
+
z(t);
|
|
41
41
|
}));
|
|
42
42
|
}, []);
|
|
43
|
-
let
|
|
43
|
+
let Ee = async () => {
|
|
44
44
|
try {
|
|
45
|
-
|
|
45
|
+
L(!0), w?.(void 0), U.current && await U.current.open();
|
|
46
46
|
} catch (e) {
|
|
47
|
-
console.error("钱包连接失败:", e)
|
|
47
|
+
console.error("钱包连接失败:", e);
|
|
48
|
+
let t = e instanceof Error ? e.message : E.walletConnectionFailed;
|
|
49
|
+
w?.(t), v?.(e);
|
|
48
50
|
} finally {
|
|
49
|
-
|
|
51
|
+
L(!1);
|
|
50
52
|
}
|
|
51
|
-
},
|
|
53
|
+
}, K = useMemo(() => D.find((e) => e.chain === O), [D, O]), q = useMemo(() => K?.tokens || [], [K]), J = useMemo(() => q.find((e) => e.symbol === A), [q, A]), Y = (e) => [
|
|
52
54
|
"USDT",
|
|
53
55
|
"USDC",
|
|
54
56
|
"BUSD",
|
|
@@ -56,92 +58,97 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
|
|
|
56
58
|
"TUSD",
|
|
57
59
|
"USDD",
|
|
58
60
|
"FDUSD"
|
|
59
|
-
].includes(e.toUpperCase()) ? 2 : 6,
|
|
61
|
+
].includes(e.toUpperCase()) ? 2 : 6, X = (e, t) => {
|
|
60
62
|
let n = parseFloat(e);
|
|
61
63
|
return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
|
|
62
|
-
},
|
|
63
|
-
if (
|
|
64
|
-
let e =
|
|
64
|
+
}, De = (e) => {
|
|
65
|
+
if (e <= 0) return E.expired;
|
|
66
|
+
let t = Math.floor(e / 3600), n = Math.floor(e % 3600 / 60), r = e % 60;
|
|
67
|
+
return t > 0 ? `${t}${E.hours}${n}${E.minutes}${r}${E.seconds}` : `${n}${E.minutes}${r}${E.seconds}`;
|
|
68
|
+
}, Oe = (e) => {
|
|
69
|
+
G.current && clearInterval(G.current);
|
|
70
|
+
let t = () => {
|
|
71
|
+
let t = e - Math.floor(Date.now() / 1e3);
|
|
72
|
+
Ce(De(t)), t <= 0 && (b("expired"), ke());
|
|
73
|
+
};
|
|
74
|
+
t(), G.current = setInterval(t, 1e3);
|
|
75
|
+
}, ke = () => {
|
|
76
|
+
G.current &&= (clearInterval(G.current), null);
|
|
77
|
+
}, Z = useMemo(() => {
|
|
78
|
+
if (!A || !J) return "0";
|
|
79
|
+
let e = parseFloat(J.price);
|
|
65
80
|
if (isNaN(e) || e === 0) return "0";
|
|
66
|
-
let t =
|
|
67
|
-
return
|
|
81
|
+
let t = Y(A);
|
|
82
|
+
return X((parseFloat(_) / e).toFixed(t), t);
|
|
68
83
|
}, [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
]),
|
|
84
|
+
_,
|
|
85
|
+
A,
|
|
86
|
+
J
|
|
87
|
+
]), Ae = async () => {
|
|
73
88
|
try {
|
|
74
|
-
|
|
75
|
-
let e = await
|
|
76
|
-
|
|
89
|
+
w?.(void 0);
|
|
90
|
+
let e = await T.getSupportedChains();
|
|
91
|
+
Se(e), e.length > 0 && k(e[0].chain);
|
|
77
92
|
} catch (e) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
v(!1);
|
|
93
|
+
let t = e instanceof Error ? e.message : E.loadPaymentNetworkFailed;
|
|
94
|
+
w?.(t), v?.(e);
|
|
81
95
|
}
|
|
82
|
-
},
|
|
83
|
-
if (
|
|
84
|
-
await
|
|
96
|
+
}, je = async (e) => {
|
|
97
|
+
if (R) try {
|
|
98
|
+
await R.request({
|
|
85
99
|
method: "wallet_switchEthereumChain",
|
|
86
100
|
params: [{ chainId: `0x${e.toString(16)}` }]
|
|
87
101
|
});
|
|
88
102
|
} catch (e) {
|
|
89
|
-
throw e.code === 4902 ? Error(
|
|
103
|
+
throw e.code === 4902 ? Error(E.pleaseAddNetwork) : e;
|
|
90
104
|
}
|
|
91
|
-
},
|
|
92
|
-
if (!(!
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
await J(H.chainId);
|
|
105
|
+
}, Me = async () => {
|
|
106
|
+
if (!(!P || !R || !Q.current || !J || !K)) try {
|
|
107
|
+
let e = Q.current;
|
|
108
|
+
await je(K.chainId);
|
|
96
109
|
let t = createWalletClient({
|
|
97
|
-
account:
|
|
98
|
-
transport: custom(
|
|
110
|
+
account: P,
|
|
111
|
+
transport: custom(R)
|
|
99
112
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
type: "uint256"
|
|
113
|
-
}],
|
|
114
|
-
outputs: [{ type: "bool" }]
|
|
113
|
+
J.address ? await t.writeContract({
|
|
114
|
+
address: J.address,
|
|
115
|
+
abi: [{
|
|
116
|
+
name: "transfer",
|
|
117
|
+
type: "function",
|
|
118
|
+
stateMutability: "nonpayable",
|
|
119
|
+
inputs: [{
|
|
120
|
+
name: "to",
|
|
121
|
+
type: "address"
|
|
122
|
+
}, {
|
|
123
|
+
name: "amount",
|
|
124
|
+
type: "uint256"
|
|
115
125
|
}],
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
console.log("转账交易哈希:", n);
|
|
128
|
-
}
|
|
129
|
-
v(!1), b(!0), Z(e.paymentId);
|
|
126
|
+
outputs: [{ type: "bool" }]
|
|
127
|
+
}],
|
|
128
|
+
functionName: "transfer",
|
|
129
|
+
args: [e.receiveAddress, parseUnits(e.paymentAmount, J.decimals)],
|
|
130
|
+
chain: null
|
|
131
|
+
}) : await t.sendTransaction({
|
|
132
|
+
to: e.receiveAddress,
|
|
133
|
+
value: parseUnits(e.paymentAmount, J.decimals),
|
|
134
|
+
chain: null
|
|
135
|
+
}), N(void 0);
|
|
130
136
|
} catch (e) {
|
|
131
|
-
console.error("钱包支付失败:", e)
|
|
137
|
+
console.error("钱包支付失败:", e);
|
|
138
|
+
let t = e instanceof Error ? e.message : E.walletPaymentFailed;
|
|
139
|
+
w?.(t), v?.(e);
|
|
132
140
|
}
|
|
133
|
-
},
|
|
134
|
-
if (!(!
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
await J(H.chainId);
|
|
141
|
+
}, Ne = async () => {
|
|
142
|
+
if (!(!P || !R || !Q.current || !J || !K)) try {
|
|
143
|
+
let e = Q.current;
|
|
144
|
+
await je(K.chainId);
|
|
138
145
|
let t = createWalletClient({
|
|
139
|
-
account:
|
|
140
|
-
transport: custom(
|
|
146
|
+
account: P,
|
|
147
|
+
transport: custom(R)
|
|
141
148
|
});
|
|
142
|
-
if (!
|
|
143
|
-
|
|
144
|
-
address:
|
|
149
|
+
if (!J.address) throw Error(E.subscriptionDoesNotSupportNative);
|
|
150
|
+
await t.writeContract({
|
|
151
|
+
address: J.address,
|
|
145
152
|
abi: [{
|
|
146
153
|
name: "approve",
|
|
147
154
|
type: "function",
|
|
@@ -156,89 +163,430 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
|
|
|
156
163
|
outputs: [{ type: "bool" }]
|
|
157
164
|
}],
|
|
158
165
|
functionName: "approve",
|
|
159
|
-
args: [e.spenderAddress, parseUnits(e.approveAmount,
|
|
166
|
+
args: [e.spenderAddress, parseUnits(e.approveAmount, J.decimals)],
|
|
160
167
|
chain: null
|
|
161
|
-
});
|
|
162
|
-
console.log("授权交易哈希:", n), v(!1), b(!0), Z(e.subscriptionId);
|
|
168
|
+
}), N(void 0);
|
|
163
169
|
} catch (e) {
|
|
164
|
-
console.error("钱包授权失败:", e)
|
|
170
|
+
console.error("钱包授权失败:", e);
|
|
171
|
+
let t = e instanceof Error ? e.message : E.walletPaymentFailed;
|
|
172
|
+
w?.(t), v?.(e);
|
|
165
173
|
}
|
|
166
|
-
},
|
|
167
|
-
if (!
|
|
168
|
-
let e =
|
|
169
|
-
|
|
174
|
+
}, Pe = async () => {
|
|
175
|
+
if (!P) {
|
|
176
|
+
let e = E.pleaseConnectWallet;
|
|
177
|
+
w?.(e), v?.(Error(e));
|
|
170
178
|
return;
|
|
171
179
|
}
|
|
172
|
-
|
|
173
|
-
},
|
|
174
|
-
if (!(!
|
|
175
|
-
|
|
180
|
+
h === "one-time" ? await Me() : h === "subscription" && await Ne();
|
|
181
|
+
}, Q = useRef(null), Fe = async () => {
|
|
182
|
+
if (!(!O || !A)) try {
|
|
183
|
+
w?.(void 0);
|
|
176
184
|
let e = "";
|
|
177
|
-
|
|
178
|
-
paymentChain:
|
|
179
|
-
paymentToken:
|
|
180
|
-
orderId:
|
|
181
|
-
amount:
|
|
182
|
-
}), e = `${
|
|
183
|
-
paymentChain:
|
|
184
|
-
paymentToken:
|
|
185
|
-
orderId:
|
|
186
|
-
amountOfUsd:
|
|
187
|
-
intervalDays:
|
|
188
|
-
}), e = `${
|
|
185
|
+
h === "one-time" ? (Q.current = await T.createOnetimePayment({
|
|
186
|
+
paymentChain: O,
|
|
187
|
+
paymentToken: A,
|
|
188
|
+
orderId: g,
|
|
189
|
+
amount: Z
|
|
190
|
+
}), e = `${O.toLowerCase()}:${Q.current.receiveAddress}?amount=${Q.current.paymentAmount}`, Oe(Q.current.expireAt), $({ paymentId: Q.current.paymentId })) : h === "subscription" && (Q.current = await T.createSubscriptionPayment({
|
|
191
|
+
paymentChain: O,
|
|
192
|
+
paymentToken: A,
|
|
193
|
+
orderId: g,
|
|
194
|
+
amountOfUsd: Z,
|
|
195
|
+
intervalDays: ge || 30
|
|
196
|
+
}), e = `${O.toLowerCase()}:${Q.current.spenderAddress}?amount=${Q.current.approveAmount}`, Oe(Q.current.expireAt), $({ subscriptionId: Q.current.subscriptionId })), b("payment"), N(await QRCode.toDataURL(e, {
|
|
189
197
|
width: 200,
|
|
190
198
|
margin: 2,
|
|
191
199
|
errorCorrectionLevel: "H"
|
|
192
200
|
}));
|
|
193
201
|
} catch (e) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
v(!1);
|
|
202
|
+
let t = e instanceof Error ? e.message : E.createPaymentFailed;
|
|
203
|
+
w?.(t), v?.(e);
|
|
197
204
|
}
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
}, Q = async () => {
|
|
215
|
-
if (!Y.current) return;
|
|
216
|
-
let e = o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress;
|
|
217
|
-
e && await navigator.clipboard.writeText(e);
|
|
218
|
-
}, $ = () => {
|
|
219
|
-
_ || y || (n(), setTimeout(() => {
|
|
220
|
-
g("select"), S(void 0), Y.current = null;
|
|
221
|
-
}, 300));
|
|
205
|
+
}, $ = (e) => {
|
|
206
|
+
W.current?.unsubscribe();
|
|
207
|
+
let t = () => defer(() => h === "subscription" ? T.checkSubscriptionPaymentStatus(e) : T.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
|
|
208
|
+
W.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((e) => {
|
|
209
|
+
(e.status === "paid" || e.status === "approved") && (b("success"), ve?.(e)), e.status === "expired" && (b("expired"), ye?.(e)), e.status === "failed" && (b("failed"), be?.(e));
|
|
210
|
+
})).subscribe({
|
|
211
|
+
error: (e) => {
|
|
212
|
+
if (Q.current) {
|
|
213
|
+
let t = e instanceof Error ? e.message : E.checkPaymentStatusFailed;
|
|
214
|
+
b("error"), w?.(t), v?.(e);
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
complete: () => {
|
|
218
|
+
W.current?.unsubscribe();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
222
221
|
};
|
|
223
222
|
return useEffect(() => {
|
|
224
|
-
|
|
225
|
-
}, [
|
|
226
|
-
|
|
227
|
-
}, [
|
|
228
|
-
|
|
229
|
-
}, []),
|
|
223
|
+
D.length === 0 && Ae();
|
|
224
|
+
}, []), useEffect(() => {
|
|
225
|
+
q.length > 0 && j(q[0].symbol);
|
|
226
|
+
}, [q]), useEffect(() => (g && $({ orderId: g }), () => {
|
|
227
|
+
W.current?.unsubscribe(), ke();
|
|
228
|
+
}), [g]), /* @__PURE__ */ jsx("div", {
|
|
229
|
+
className: "_cppay-content",
|
|
230
|
+
children: y === "success" ? /* @__PURE__ */ jsxs("div", {
|
|
231
|
+
className: "_cppay-state-container",
|
|
232
|
+
children: [
|
|
233
|
+
/* @__PURE__ */ jsx("div", {
|
|
234
|
+
className: "_cppay-state-icon",
|
|
235
|
+
children: "✅"
|
|
236
|
+
}),
|
|
237
|
+
/* @__PURE__ */ jsx("h3", {
|
|
238
|
+
className: "_cppay-state-title",
|
|
239
|
+
children: h === "subscription" ? E.authorizationSuccess : E.paymentSuccess
|
|
240
|
+
}),
|
|
241
|
+
/* @__PURE__ */ jsx("p", {
|
|
242
|
+
className: "_cppay-state-message",
|
|
243
|
+
children: h === "subscription" ? E.subscriptionActivated : E.transactionCompleted
|
|
244
|
+
})
|
|
245
|
+
]
|
|
246
|
+
}) : y === "expired" ? /* @__PURE__ */ jsxs("div", {
|
|
247
|
+
className: "_cppay-state-container",
|
|
248
|
+
children: [
|
|
249
|
+
/* @__PURE__ */ jsx("div", {
|
|
250
|
+
className: "_cppay-state-icon",
|
|
251
|
+
children: "⏰"
|
|
252
|
+
}),
|
|
253
|
+
/* @__PURE__ */ jsx("h3", {
|
|
254
|
+
className: "_cppay-state-title",
|
|
255
|
+
children: E.paymentExpired
|
|
256
|
+
}),
|
|
257
|
+
/* @__PURE__ */ jsx("button", {
|
|
258
|
+
onClick: () => b("select"),
|
|
259
|
+
disabled: x || S,
|
|
260
|
+
className: "_cppay-btn _cppay-btn-text",
|
|
261
|
+
children: E.returnButton
|
|
262
|
+
})
|
|
263
|
+
]
|
|
264
|
+
}) : y === "error" ? /* @__PURE__ */ jsxs("div", {
|
|
265
|
+
className: "_cppay-state-container",
|
|
266
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
267
|
+
className: "_cppay-state-icon",
|
|
268
|
+
children: "❌"
|
|
269
|
+
}), /* @__PURE__ */ jsx("h3", {
|
|
270
|
+
className: "_cppay-state-title",
|
|
271
|
+
children: C || E.error
|
|
272
|
+
})]
|
|
273
|
+
}) : y === "failed" ? /* @__PURE__ */ jsxs("div", {
|
|
274
|
+
className: "_cppay-state-container",
|
|
275
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
276
|
+
className: "_cppay-state-icon",
|
|
277
|
+
children: "❌"
|
|
278
|
+
}), /* @__PURE__ */ jsx("h3", {
|
|
279
|
+
className: "_cppay-state-title",
|
|
280
|
+
children: E.paymentFailed
|
|
281
|
+
})]
|
|
282
|
+
}) : y === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
283
|
+
xe?.ChooseTop,
|
|
284
|
+
/* @__PURE__ */ jsxs("div", {
|
|
285
|
+
className: "_cppay-section",
|
|
286
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
287
|
+
className: "_cppay-label",
|
|
288
|
+
children: E.paymentNetwork
|
|
289
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
290
|
+
className: "_cppay-grid",
|
|
291
|
+
children: D.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
292
|
+
onClick: () => k(e.chain),
|
|
293
|
+
className: `_cppay-select-btn ${O === e.chain ? "_cppay-selected" : ""}`,
|
|
294
|
+
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
295
|
+
src: e.icon,
|
|
296
|
+
alt: e.chain
|
|
297
|
+
}), /* @__PURE__ */ jsx("span", { children: e.chain })]
|
|
298
|
+
}, e.chain))
|
|
299
|
+
})]
|
|
300
|
+
}),
|
|
301
|
+
/* @__PURE__ */ jsxs("div", {
|
|
302
|
+
className: "_cppay-section",
|
|
303
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
304
|
+
className: "_cppay-label",
|
|
305
|
+
children: E.paymentToken
|
|
306
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
307
|
+
className: "_cppay-grid",
|
|
308
|
+
children: q.map((e) => /* @__PURE__ */ jsxs("button", {
|
|
309
|
+
onClick: () => j(e.symbol),
|
|
310
|
+
className: `_cppay-select-btn ${A === e.symbol ? "_cppay-selected" : ""}`,
|
|
311
|
+
children: [e.icon && /* @__PURE__ */ jsx("img", {
|
|
312
|
+
src: e.icon,
|
|
313
|
+
alt: e.symbol
|
|
314
|
+
}), /* @__PURE__ */ jsx("span", { children: e.symbol })]
|
|
315
|
+
}, e.symbol))
|
|
316
|
+
})]
|
|
317
|
+
}),
|
|
318
|
+
xe?.ChooseBottom,
|
|
319
|
+
/* @__PURE__ */ jsx("div", {
|
|
320
|
+
className: "_cppay-section",
|
|
321
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
322
|
+
className: "_cppay-price-box",
|
|
323
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
324
|
+
className: "_cppay-price-row",
|
|
325
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
326
|
+
className: "_cppay-price-label",
|
|
327
|
+
children: E.paymentAmount
|
|
328
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
329
|
+
className: "_cppay-price-amount",
|
|
330
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
331
|
+
className: "_cppay-price-main",
|
|
332
|
+
children: [
|
|
333
|
+
Z ?? "-",
|
|
334
|
+
" ",
|
|
335
|
+
A ?? ""
|
|
336
|
+
]
|
|
337
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
338
|
+
className: "_cppay-price-sub",
|
|
339
|
+
children: ["≈ $", _]
|
|
340
|
+
})]
|
|
341
|
+
})]
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
}),
|
|
345
|
+
/* @__PURE__ */ jsxs("div", {
|
|
346
|
+
className: "_cppay-section",
|
|
347
|
+
children: [C && /* @__PURE__ */ jsxs("div", {
|
|
348
|
+
className: "_cppay-error-tooltip-wrapper",
|
|
349
|
+
onMouseEnter: () => H(!0),
|
|
350
|
+
onMouseLeave: () => H(!1),
|
|
351
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
352
|
+
className: "_cppay-error-tooltip",
|
|
353
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
354
|
+
viewBox: "0 0 20 20",
|
|
355
|
+
fill: "currentColor",
|
|
356
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
357
|
+
fillRule: "evenodd",
|
|
358
|
+
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",
|
|
359
|
+
clipRule: "evenodd"
|
|
360
|
+
})
|
|
361
|
+
}), /* @__PURE__ */ jsx("span", { children: C })]
|
|
362
|
+
}), Te && /* @__PURE__ */ jsx("div", {
|
|
363
|
+
className: "_cppay-error-tooltip-full",
|
|
364
|
+
children: C
|
|
365
|
+
})]
|
|
366
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
367
|
+
onClick: Fe,
|
|
368
|
+
disabled: !O || !A || x,
|
|
369
|
+
className: "_cppay-btn _cppay-btn-primary",
|
|
370
|
+
children: x ? E.processing : E.continuePayment
|
|
371
|
+
})]
|
|
372
|
+
})
|
|
373
|
+
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
374
|
+
/* @__PURE__ */ jsx("div", {
|
|
375
|
+
className: "_cppay-qr-container",
|
|
376
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
377
|
+
className: "_cppay-qr-code",
|
|
378
|
+
children: M && /* @__PURE__ */ jsx("img", {
|
|
379
|
+
src: M,
|
|
380
|
+
alt: "Payment QR Code",
|
|
381
|
+
className: "_cppay-qr-image"
|
|
382
|
+
})
|
|
383
|
+
})
|
|
384
|
+
}),
|
|
385
|
+
/* @__PURE__ */ jsxs("div", {
|
|
386
|
+
className: "_cppay-section",
|
|
387
|
+
children: [
|
|
388
|
+
J && /* @__PURE__ */ jsx("div", {
|
|
389
|
+
className: "_cppay-info-box",
|
|
390
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
391
|
+
className: "_cppay-info-flex-container",
|
|
392
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
393
|
+
className: "_cppay-info-flex-child",
|
|
394
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
395
|
+
className: "_cppay-info-label",
|
|
396
|
+
children: h === "subscription" ? E.authorizationAmount : E.paymentAmount
|
|
397
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
398
|
+
className: "_cppay-info-value _cppay-info-value-flex",
|
|
399
|
+
children: [/* @__PURE__ */ jsx("span", { children: h === "subscription" ? `${X(Q.current.approveAmount, Y(J.symbol))} ${J.symbol}` : `${X(Q.current.paymentAmount, Y(J.symbol))} ${J.symbol}` }), /* @__PURE__ */ jsxs("span", { children: ["≈ $", _] })]
|
|
400
|
+
})]
|
|
401
|
+
})
|
|
402
|
+
})
|
|
403
|
+
}),
|
|
404
|
+
/* @__PURE__ */ jsx("div", {
|
|
405
|
+
className: "_cppay-info-box",
|
|
406
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
407
|
+
className: "_cppay-info-flex-child",
|
|
408
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
409
|
+
className: "_cppay-info-label _cppay-info-label-flex",
|
|
410
|
+
children: [/* @__PURE__ */ jsx("span", { children: h === "subscription" ? E.authorizationContractAddress : E.paymentAddress }), B && /* @__PURE__ */ jsxs("span", {
|
|
411
|
+
className: "_cppay-countdown",
|
|
412
|
+
children: ["⏰ ", B]
|
|
413
|
+
})]
|
|
414
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
415
|
+
className: "_cppay-address-row",
|
|
416
|
+
children: [/* @__PURE__ */ jsx("code", { children: h === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
417
|
+
onClick: async () => {
|
|
418
|
+
if (!Q.current) return;
|
|
419
|
+
let e = h === "subscription" ? Q.current.spenderAddress : Q.current.receiveAddress;
|
|
420
|
+
if (e) try {
|
|
421
|
+
await navigator.clipboard.writeText(e), we(!0), setTimeout(() => {
|
|
422
|
+
we(!1);
|
|
423
|
+
}, 2e3);
|
|
424
|
+
} catch (e) {
|
|
425
|
+
console.error("复制失败:", e);
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
className: `_cppay-copy-btn ${V ? "_cppay-copy-success" : ""}`,
|
|
429
|
+
title: V ? E.copied : E.copyAddress,
|
|
430
|
+
children: V ? /* @__PURE__ */ jsx("svg", {
|
|
431
|
+
className: "_cppay-copy-icon",
|
|
432
|
+
viewBox: "0 0 24 24",
|
|
433
|
+
fill: "currentColor",
|
|
434
|
+
children: /* @__PURE__ */ jsx("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" })
|
|
435
|
+
}) : /* @__PURE__ */ jsxs("svg", {
|
|
436
|
+
className: "_cppay-copy-icon",
|
|
437
|
+
viewBox: "0 0 24 24",
|
|
438
|
+
fill: "none",
|
|
439
|
+
stroke: "currentColor",
|
|
440
|
+
strokeWidth: "2",
|
|
441
|
+
children: [/* @__PURE__ */ jsx("path", { d: "M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" }), /* @__PURE__ */ jsx("rect", {
|
|
442
|
+
x: "8",
|
|
443
|
+
y: "2",
|
|
444
|
+
width: "8",
|
|
445
|
+
height: "4",
|
|
446
|
+
rx: "1",
|
|
447
|
+
ry: "1"
|
|
448
|
+
})]
|
|
449
|
+
})
|
|
450
|
+
})]
|
|
451
|
+
})]
|
|
452
|
+
})
|
|
453
|
+
}),
|
|
454
|
+
h === "subscription" && /* @__PURE__ */ jsxs("div", {
|
|
455
|
+
className: "_cppay-info-box _cppay-subscription-box",
|
|
456
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
457
|
+
className: "_cppay-info-label _cppay-subscription-label",
|
|
458
|
+
children: E.subscriptionNotice
|
|
459
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
460
|
+
className: "_cppay-info-value _cppay-subscription-message",
|
|
461
|
+
children: E.subscriptionNoticeMessage
|
|
462
|
+
})]
|
|
463
|
+
})
|
|
464
|
+
]
|
|
465
|
+
}),
|
|
466
|
+
C && /* @__PURE__ */ jsxs("div", {
|
|
467
|
+
className: "_cppay-error-tooltip-wrapper",
|
|
468
|
+
onMouseEnter: () => H(!0),
|
|
469
|
+
onMouseLeave: () => H(!1),
|
|
470
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
471
|
+
className: "_cppay-error-tooltip",
|
|
472
|
+
children: [/* @__PURE__ */ jsx("svg", {
|
|
473
|
+
viewBox: "0 0 20 20",
|
|
474
|
+
fill: "currentColor",
|
|
475
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
476
|
+
fillRule: "evenodd",
|
|
477
|
+
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",
|
|
478
|
+
clipRule: "evenodd"
|
|
479
|
+
})
|
|
480
|
+
}), /* @__PURE__ */ jsx("span", { children: C })]
|
|
481
|
+
}), Te && /* @__PURE__ */ jsx("div", {
|
|
482
|
+
className: "_cppay-error-tooltip-full",
|
|
483
|
+
children: C
|
|
484
|
+
})]
|
|
485
|
+
}),
|
|
486
|
+
!S && /* @__PURE__ */ jsx("div", {
|
|
487
|
+
className: "_cppay-section",
|
|
488
|
+
children: P ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
|
|
489
|
+
onClick: Pe,
|
|
490
|
+
disabled: x,
|
|
491
|
+
className: "_cppay-btn _cppay-btn-primary",
|
|
492
|
+
children: x ? h === "subscription" ? E.authorizing : E.processing : h === "subscription" ? `💳 ${E.connectWallet}` : `💳 ${E.walletPay}`
|
|
493
|
+
}), /* @__PURE__ */ jsxs("button", {
|
|
494
|
+
onClick: Ee,
|
|
495
|
+
disabled: x,
|
|
496
|
+
className: "_cppay-btn _cppay-wallet-address-btn",
|
|
497
|
+
title: E.clickToModifyWallet,
|
|
498
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
499
|
+
className: "_cppay-wallet-address-text",
|
|
500
|
+
children: [
|
|
501
|
+
P.slice(0, 10),
|
|
502
|
+
"...",
|
|
503
|
+
P.slice(-4)
|
|
504
|
+
]
|
|
505
|
+
}), /* @__PURE__ */ jsx("svg", {
|
|
506
|
+
className: "_cppay-wallet-arrow",
|
|
507
|
+
viewBox: "0 0 24 24",
|
|
508
|
+
fill: "none",
|
|
509
|
+
stroke: "currentColor",
|
|
510
|
+
strokeWidth: "2",
|
|
511
|
+
children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
|
|
512
|
+
})]
|
|
513
|
+
})] }) : /* @__PURE__ */ jsx("button", {
|
|
514
|
+
onClick: Ee,
|
|
515
|
+
disabled: I,
|
|
516
|
+
className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
|
|
517
|
+
children: /* @__PURE__ */ jsx("span", { children: I ? E.processing : `💳 ${E.connectWallet}` })
|
|
518
|
+
})
|
|
519
|
+
}),
|
|
520
|
+
/* @__PURE__ */ jsx("div", {
|
|
521
|
+
className: "_cppay-section",
|
|
522
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
523
|
+
onClick: () => {
|
|
524
|
+
b("payment");
|
|
525
|
+
},
|
|
526
|
+
disabled: S,
|
|
527
|
+
className: "_cppay-btn _cppay-btn-primary",
|
|
528
|
+
children: S ? E.checking : E.completedPayment
|
|
529
|
+
})
|
|
530
|
+
}),
|
|
531
|
+
/* @__PURE__ */ jsx("hr", { className: "_cppay-divider" }),
|
|
532
|
+
/* @__PURE__ */ jsx("div", {
|
|
533
|
+
className: "_cppay-section",
|
|
534
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
535
|
+
onClick: () => b("select"),
|
|
536
|
+
disabled: x || S,
|
|
537
|
+
className: "_cppay-btn _cppay-btn-text",
|
|
538
|
+
children: E.changePaymentMethod
|
|
539
|
+
})
|
|
540
|
+
})
|
|
541
|
+
] })
|
|
542
|
+
});
|
|
543
|
+
}, PaymentDialog_default = ({ open: e, onClose: t, ott: n, apikey: i, plain: a, orderId: o, amount: s, intervalDays: c, locale: l, onExpired: se, onSuccess: u, onFailed: ce, onError: le, Slots: ue }) => {
|
|
544
|
+
let [d, de] = useState("select"), [f, fe] = useState(!1), [p, pe] = useState(!1), [me, he] = useState();
|
|
545
|
+
useEffect(() => {
|
|
546
|
+
if (d === "success") {
|
|
547
|
+
let e = setTimeout(() => {
|
|
548
|
+
m();
|
|
549
|
+
}, 1e3);
|
|
550
|
+
return () => clearTimeout(e);
|
|
551
|
+
}
|
|
552
|
+
}, [d]), useEffect(() => {
|
|
553
|
+
e || (de("select"), he(void 0), fe(!1), pe(!1));
|
|
554
|
+
}, [e]), useEffect(() => {
|
|
555
|
+
if (!e) return;
|
|
556
|
+
let t = (e) => {
|
|
557
|
+
e.key === "Escape" && !f && !p && m();
|
|
558
|
+
};
|
|
559
|
+
return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
|
|
560
|
+
}, [
|
|
561
|
+
e,
|
|
562
|
+
f,
|
|
563
|
+
p
|
|
564
|
+
]);
|
|
565
|
+
let m = () => {
|
|
566
|
+
f || p || t();
|
|
567
|
+
}, h = useMemo(() => getLocaleMessages(l), [l]);
|
|
568
|
+
return e ? /* @__PURE__ */ jsx("div", {
|
|
230
569
|
className: "_cppay-overlay",
|
|
231
|
-
onClick: (e) => e.target === e.currentTarget && !
|
|
570
|
+
onClick: (e) => e.target === e.currentTarget && !f && !p && m(),
|
|
232
571
|
children: /* @__PURE__ */ jsxs("div", {
|
|
233
572
|
className: "_cppay-dialog",
|
|
234
573
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
235
574
|
className: "_cppay-header",
|
|
236
575
|
children: [/* @__PURE__ */ jsx("h2", {
|
|
237
576
|
className: "_cppay-title",
|
|
238
|
-
children:
|
|
577
|
+
children: (() => {
|
|
578
|
+
switch (d) {
|
|
579
|
+
case "success": return h.paymentResult;
|
|
580
|
+
case "expired": return h.paymentExpired;
|
|
581
|
+
case "failed": return h.paymentFailed;
|
|
582
|
+
case "error": return h.error;
|
|
583
|
+
case "payment": return h.completePayment;
|
|
584
|
+
default: return h.selectPaymentMethod;
|
|
585
|
+
}
|
|
586
|
+
})()
|
|
239
587
|
}), /* @__PURE__ */ jsx("button", {
|
|
240
|
-
onClick:
|
|
241
|
-
disabled:
|
|
588
|
+
onClick: m,
|
|
589
|
+
disabled: f || p,
|
|
242
590
|
className: "_cppay-close-btn",
|
|
243
591
|
children: /* @__PURE__ */ jsx("svg", {
|
|
244
592
|
fill: "none",
|
|
@@ -252,310 +600,68 @@ var PaymentDialog_default = React.memo(({ open: t, onClose: n, apikey: a, plain:
|
|
|
252
600
|
})
|
|
253
601
|
})
|
|
254
602
|
})]
|
|
255
|
-
}), /* @__PURE__ */ jsx(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
color: "#10b981",
|
|
275
|
-
margin: "0 0 0.5rem 0"
|
|
276
|
-
},
|
|
277
|
-
children: o === "subscription" ? "授权成功!" : "支付成功!"
|
|
278
|
-
}),
|
|
279
|
-
/* @__PURE__ */ jsx("p", {
|
|
280
|
-
style: {
|
|
281
|
-
color: "#6b7280",
|
|
282
|
-
margin: 0
|
|
283
|
-
},
|
|
284
|
-
children: o === "subscription" ? "订阅已激活" : "交易已完成"
|
|
285
|
-
})
|
|
286
|
-
]
|
|
287
|
-
}) : h === "select" ? /* @__PURE__ */ jsxs("div", { children: [
|
|
288
|
-
/* @__PURE__ */ jsxs("div", {
|
|
289
|
-
className: "_cppay-section",
|
|
290
|
-
children: [/* @__PURE__ */ jsx("label", {
|
|
291
|
-
className: "_cppay-label",
|
|
292
|
-
children: "支付网络"
|
|
293
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
294
|
-
className: "_cppay-grid",
|
|
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", {
|
|
299
|
-
src: e.icon,
|
|
300
|
-
alt: e.chain
|
|
301
|
-
}), /* @__PURE__ */ jsx("span", { children: e.chain })]
|
|
302
|
-
}, e.chain))
|
|
303
|
-
})]
|
|
304
|
-
}),
|
|
305
|
-
/* @__PURE__ */ jsxs("div", {
|
|
306
|
-
className: "_cppay-section",
|
|
307
|
-
children: [/* @__PURE__ */ jsx("label", {
|
|
308
|
-
className: "_cppay-label",
|
|
309
|
-
children: "支付代币"
|
|
310
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
311
|
-
className: "_cppay-grid",
|
|
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", {
|
|
316
|
-
src: e.icon,
|
|
317
|
-
alt: e.symbol
|
|
318
|
-
}), /* @__PURE__ */ jsx("span", { children: e.symbol })]
|
|
319
|
-
}, e.symbol))
|
|
320
|
-
})]
|
|
321
|
-
}),
|
|
322
|
-
/* @__PURE__ */ jsx("div", {
|
|
323
|
-
className: "_cppay-section",
|
|
324
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
325
|
-
className: "_cppay-price-box",
|
|
326
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
327
|
-
className: "_cppay-price-row",
|
|
328
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
329
|
-
className: "_cppay-price-label",
|
|
330
|
-
children: "支付金额"
|
|
331
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
332
|
-
className: "_cppay-price-amount",
|
|
333
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
334
|
-
className: "_cppay-price-main",
|
|
335
|
-
children: [
|
|
336
|
-
q ?? "-",
|
|
337
|
-
" ",
|
|
338
|
-
k ?? ""
|
|
339
|
-
]
|
|
340
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
341
|
-
className: "_cppay-price-sub",
|
|
342
|
-
children: ["≈ $", c]
|
|
343
|
-
})]
|
|
344
|
-
})]
|
|
345
|
-
})
|
|
346
|
-
})
|
|
347
|
-
}),
|
|
348
|
-
/* @__PURE__ */ jsxs("div", {
|
|
349
|
-
className: "_cppay-section",
|
|
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 || _,
|
|
372
|
-
className: "_cppay-btn _cppay-btn-primary",
|
|
373
|
-
children: _ ? "处理中..." : "继续支付"
|
|
374
|
-
})]
|
|
375
|
-
})
|
|
376
|
-
] }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
377
|
-
/* @__PURE__ */ jsx("div", {
|
|
378
|
-
className: "_cppay-qr-container",
|
|
379
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
380
|
-
className: "_cppay-qr-code",
|
|
381
|
-
children: j && /* @__PURE__ */ jsx("img", {
|
|
382
|
-
src: j,
|
|
383
|
-
alt: "Payment QR Code",
|
|
384
|
-
style: {
|
|
385
|
-
width: "160px",
|
|
386
|
-
height: "160px",
|
|
387
|
-
display: "block"
|
|
388
|
-
}
|
|
389
|
-
})
|
|
390
|
-
})
|
|
391
|
-
}),
|
|
392
|
-
/* @__PURE__ */ jsxs("div", {
|
|
393
|
-
className: "_cppay-section",
|
|
394
|
-
children: [
|
|
395
|
-
k && /* @__PURE__ */ jsxs("div", {
|
|
396
|
-
className: "_cppay-info-box",
|
|
397
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
398
|
-
className: "_cppay-info-label",
|
|
399
|
-
children: o === "subscription" ? "授权金额" : "支付金额"
|
|
400
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
401
|
-
className: "_cppay-info-value",
|
|
402
|
-
children: o === "subscription" ? `${K(Y.current.approveAmount, G(k))} ${k}` : `${K(Y.current.paymentAmount, G(k))} ${k}`
|
|
403
|
-
})]
|
|
404
|
-
}),
|
|
405
|
-
/* @__PURE__ */ jsxs("div", {
|
|
406
|
-
className: "_cppay-info-box",
|
|
407
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
408
|
-
className: "_cppay-info-label",
|
|
409
|
-
children: o === "subscription" ? "授权合约地址" : "支付地址"
|
|
410
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
411
|
-
className: "_cppay-address-row",
|
|
412
|
-
children: [/* @__PURE__ */ jsx("code", { children: o === "subscription" ? Y.current.spenderAddress : Y.current.receiveAddress }), /* @__PURE__ */ jsx("button", {
|
|
413
|
-
onClick: Q,
|
|
414
|
-
className: "_cppay-copy-btn",
|
|
415
|
-
title: "复制地址",
|
|
416
|
-
children: /* @__PURE__ */ jsx("svg", {
|
|
417
|
-
fill: "none",
|
|
418
|
-
stroke: "currentColor",
|
|
419
|
-
viewBox: "0 0 24 24",
|
|
420
|
-
children: /* @__PURE__ */ jsx("path", {
|
|
421
|
-
strokeLinecap: "round",
|
|
422
|
-
strokeLinejoin: "round",
|
|
423
|
-
strokeWidth: 2,
|
|
424
|
-
d: "M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
425
|
-
})
|
|
426
|
-
})
|
|
427
|
-
})]
|
|
428
|
-
})]
|
|
429
|
-
}),
|
|
430
|
-
o === "subscription" && /* @__PURE__ */ jsxs("div", {
|
|
431
|
-
className: "_cppay-info-box",
|
|
432
|
-
style: {
|
|
433
|
-
background: "#fff3cd",
|
|
434
|
-
borderColor: "#ffc107"
|
|
435
|
-
},
|
|
436
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
437
|
-
className: "_cppay-info-label",
|
|
438
|
-
style: { color: "#856404" },
|
|
439
|
-
children: "📌 订阅说明"
|
|
440
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
441
|
-
className: "_cppay-info-value",
|
|
442
|
-
style: {
|
|
443
|
-
fontSize: "12px",
|
|
444
|
-
color: "#856404"
|
|
445
|
-
},
|
|
446
|
-
children: "订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。"
|
|
447
|
-
})]
|
|
448
|
-
})
|
|
449
|
-
]
|
|
450
|
-
}),
|
|
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", {
|
|
472
|
-
className: "_cppay-section",
|
|
473
|
-
children: N ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
474
|
-
className: "_cppay-btn-container",
|
|
475
|
-
children: [/* @__PURE__ */ jsx("button", {
|
|
476
|
-
onClick: Oe,
|
|
477
|
-
disabled: _,
|
|
478
|
-
className: "_cppay-btn _cppay-btn-primary",
|
|
479
|
-
children: _ ? o === "subscription" ? "授权中..." : "支付中..." : o === "subscription" ? "💳 钱包授权" : "💳 钱包支付"
|
|
480
|
-
}), /* @__PURE__ */ jsx("button", {
|
|
481
|
-
onClick: V,
|
|
482
|
-
disabled: _,
|
|
483
|
-
className: "_cppay-btn _cppay-btn-primary",
|
|
484
|
-
children: "💰钱包状态"
|
|
485
|
-
})]
|
|
486
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
487
|
-
style: {
|
|
488
|
-
textAlign: "center",
|
|
489
|
-
marginTop: "8px",
|
|
490
|
-
fontSize: "12px",
|
|
491
|
-
color: "#666"
|
|
492
|
-
},
|
|
493
|
-
children: [
|
|
494
|
-
"已连接: ",
|
|
495
|
-
N.slice(0, 6),
|
|
496
|
-
"...",
|
|
497
|
-
N.slice(-4)
|
|
498
|
-
]
|
|
499
|
-
})] }) : /* @__PURE__ */ jsx("button", {
|
|
500
|
-
onClick: V,
|
|
501
|
-
disabled: F,
|
|
502
|
-
className: "_cppay-btn _cppay-btn-secondary",
|
|
503
|
-
style: {
|
|
504
|
-
display: "flex",
|
|
505
|
-
alignItems: "center",
|
|
506
|
-
justifyContent: "center",
|
|
507
|
-
gap: "0.5rem",
|
|
508
|
-
padding: "0.75rem 1rem",
|
|
509
|
-
width: "100%"
|
|
510
|
-
},
|
|
511
|
-
children: /* @__PURE__ */ jsx("span", { children: F ? "连接中..." : "💳 连接钱包" })
|
|
512
|
-
})
|
|
513
|
-
}),
|
|
514
|
-
/* @__PURE__ */ jsx("div", {
|
|
515
|
-
className: "_cppay-section",
|
|
516
|
-
children: /* @__PURE__ */ jsx("button", {
|
|
517
|
-
onClick: ke,
|
|
518
|
-
disabled: y,
|
|
519
|
-
className: "_cppay-btn _cppay-btn-primary",
|
|
520
|
-
children: y ? "检查中..." : "我已完成支付"
|
|
521
|
-
})
|
|
522
|
-
}),
|
|
523
|
-
/* @__PURE__ */ jsx("div", {
|
|
524
|
-
className: "_cppay-section",
|
|
525
|
-
children: /* @__PURE__ */ jsx("button", {
|
|
526
|
-
onClick: () => g("select"),
|
|
527
|
-
disabled: _ || y,
|
|
528
|
-
className: "_cppay-btn _cppay-btn-text",
|
|
529
|
-
children: "更改支付方式"
|
|
530
|
-
})
|
|
531
|
-
})
|
|
532
|
-
] })
|
|
603
|
+
}), /* @__PURE__ */ jsx(PaymentContent_default, {
|
|
604
|
+
apikey: i,
|
|
605
|
+
ott: n,
|
|
606
|
+
plain: a,
|
|
607
|
+
orderId: o,
|
|
608
|
+
amount: s,
|
|
609
|
+
intervalDays: c,
|
|
610
|
+
locale: l,
|
|
611
|
+
onSuccess: u,
|
|
612
|
+
onExpired: se,
|
|
613
|
+
onFailed: ce,
|
|
614
|
+
onError: le,
|
|
615
|
+
Slots: ue,
|
|
616
|
+
paymentStep: d,
|
|
617
|
+
onPaymentStepChange: de,
|
|
618
|
+
loading: f,
|
|
619
|
+
isCheckingPayment: p,
|
|
620
|
+
error: me,
|
|
621
|
+
onErrorChange: he
|
|
533
622
|
})]
|
|
534
623
|
})
|
|
535
624
|
}) : null;
|
|
536
|
-
}
|
|
625
|
+
}, CppayContext = createContext(null);
|
|
537
626
|
const CppayProvider = ({ apikey: e, children: t }) => {
|
|
538
|
-
let [n, r] = useState(!1), [i,
|
|
539
|
-
|
|
540
|
-
}, []),
|
|
627
|
+
let [n, r] = useState(!1), [i, a] = useState(null), o = useCallback((e) => {
|
|
628
|
+
a(e), r(!0);
|
|
629
|
+
}, []), s = useCallback(() => {
|
|
630
|
+
r(!1);
|
|
631
|
+
}, []), c = useCallback(() => {
|
|
541
632
|
r(!1);
|
|
542
|
-
}, []),
|
|
543
|
-
i?.onSuccess?.(e), r(!1);
|
|
544
|
-
}, [i]),
|
|
633
|
+
}, []), l = useCallback((e) => {
|
|
634
|
+
i?.onSuccess?.(e), setTimeout(() => r(!1), 1e3);
|
|
635
|
+
}, [i]), se = useCallback((e) => {
|
|
636
|
+
i?.onExpired?.(e);
|
|
637
|
+
}, [i]), u = useCallback((e) => {
|
|
638
|
+
i?.onFailed?.(e);
|
|
639
|
+
}, [i]), ce = useCallback((e) => {
|
|
545
640
|
i?.onError?.(e);
|
|
546
641
|
}, [i]);
|
|
547
|
-
return
|
|
548
|
-
|
|
642
|
+
return useEffect(() => {
|
|
643
|
+
if (!n) return;
|
|
644
|
+
let e = (e) => {
|
|
645
|
+
e.key === "Escape" && c();
|
|
646
|
+
};
|
|
647
|
+
return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
|
|
648
|
+
}, [n, c]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
|
|
649
|
+
value: {
|
|
650
|
+
showPayment: o,
|
|
651
|
+
closePayment: s
|
|
652
|
+
},
|
|
549
653
|
children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
|
|
550
654
|
open: n,
|
|
551
|
-
onClose:
|
|
655
|
+
onClose: c,
|
|
552
656
|
apikey: e,
|
|
553
657
|
plain: i.plain,
|
|
554
658
|
orderId: i.orderId,
|
|
555
659
|
amount: i.amount,
|
|
556
660
|
intervalDays: i.intervalDays,
|
|
557
|
-
onSuccess:
|
|
558
|
-
|
|
661
|
+
onSuccess: l,
|
|
662
|
+
onExpired: se,
|
|
663
|
+
onFailed: u,
|
|
664
|
+
onError: ce
|
|
559
665
|
})]
|
|
560
666
|
});
|
|
561
667
|
}, useCppayPayment = () => {
|
|
@@ -564,4 +670,4 @@ const CppayProvider = ({ apikey: e, children: t }) => {
|
|
|
564
670
|
return e;
|
|
565
671
|
};
|
|
566
672
|
injectStyle(payment_dialog_default);
|
|
567
|
-
export { CppayProvider, PaymentDialog_default as PaymentDialog, useCppayPayment };
|
|
673
|
+
export { CppayProvider, PaymentContent_default as PaymentContent, PaymentDialog_default as PaymentDialog, useCppayPayment };
|