cppay-sdk 0.0.2-beta.36 → 0.0.2-beta.38

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