cppay-sdk 0.0.2-beta.35 → 0.0.2-beta.37

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-DGvDecya.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,10 +9,10 @@ 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: _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);
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
- typeof window < "u" && !U.current && (U.current = createAppKit({
15
+ typeof window < "u" && !H.current && (H.current = createAppKit({
16
16
  debug: !1,
17
17
  enableNetworkSwitch: !1,
18
18
  adapters: [new EthersAdapter()],
@@ -33,22 +33,22 @@ 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
- }), 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) => {
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
+ }), H.current.subscribeProviders((e) => {
39
39
  let t = e?.eip155;
40
- z(t);
40
+ R(t);
41
41
  }));
42
- }, []);
43
- let Ee = async () => {
42
+ }, []), useEffect(() => {
43
+ Ce?.(b);
44
+ }, [b]);
45
+ let ke = async () => {
44
46
  try {
45
- L(!0), w?.(void 0), U.current && await U.current.open();
47
+ I(!0), E(void 0), H.current && await H.current.open();
46
48
  } catch (e) {
47
- console.error("钱包连接失败:", e);
48
- let t = e instanceof Error ? e.message : E.walletConnectionFailed;
49
- w?.(t), v?.(e);
49
+ console.error("钱包连接失败:", e), E(e instanceof Error ? e.message : y.walletConnectionFailed), _?.(e);
50
50
  } finally {
51
- L(!1);
51
+ I(!1);
52
52
  }
53
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) => [
54
54
  "USDT",
@@ -61,93 +61,105 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
61
61
  ].includes(e.toUpperCase()) ? 2 : 6, X = (e, t) => {
62
62
  let n = parseFloat(e);
63
63
  return isNaN(n) ? "0" : n.toFixed(t).replace(/\.?0+$/, "");
64
- }, De = (e) => {
65
- if (e <= 0) return E.expired;
64
+ }, Ae = (e) => {
65
+ if (e <= 0) return y.expired;
66
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);
67
+ return t > 0 ? `${t}${y.hours}${n}${y.minutes}${r}${y.seconds}` : `${n}${y.minutes}${r}${y.seconds}`;
68
+ }, je = (e) => {
69
+ W.current && clearInterval(W.current);
70
70
  let t = () => {
71
+ if (b === "checking") {
72
+ Z();
73
+ return;
74
+ }
71
75
  let t = e - Math.floor(Date.now() / 1e3);
72
- Ce(De(t)), t <= 0 && (b("expired"), ke());
76
+ Ee(Ae(t)), t <= 0 && (x("expired"), Z());
73
77
  };
74
- t(), G.current = setInterval(t, 1e3);
75
- }, ke = () => {
76
- G.current &&= (clearInterval(G.current), null);
77
- }, Z = useMemo(() => {
78
+ t(), W.current = setInterval(t, 1e3);
79
+ }, Z = () => {
80
+ W.current &&= (clearInterval(W.current), null);
81
+ }, Q = useMemo(() => {
78
82
  if (!A || !J) return "0";
79
83
  let e = parseFloat(J.price);
80
84
  if (isNaN(e) || e === 0) return "0";
81
85
  let t = Y(A);
82
- return X((parseFloat(_) / e).toFixed(t), t);
86
+ return X((parseFloat(h) / e).toFixed(t), t);
83
87
  }, [
84
- _,
88
+ h,
85
89
  A,
86
90
  J
87
- ]), Ae = async () => {
91
+ ]), Me = async () => {
88
92
  try {
89
- w?.(void 0);
90
- let e = await T.getSupportedChains();
91
- Se(e), e.length > 0 && k(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);
92
96
  } catch (e) {
93
- let t = e instanceof Error ? e.message : E.loadPaymentNetworkFailed;
94
- w?.(t), v?.(e);
97
+ E(e instanceof Error ? e.message : y.loadPaymentNetworkFailed), _?.(e);
98
+ } finally {
99
+ w(!1);
95
100
  }
96
- }, je = async (e) => {
97
- if (R) try {
98
- await R.request({
101
+ }, Ne = async (e) => {
102
+ if (L) try {
103
+ await L.request({
99
104
  method: "wallet_switchEthereumChain",
100
105
  params: [{ chainId: `0x${e.toString(16)}` }]
101
106
  });
102
107
  } catch (e) {
103
- throw e.code === 4902 ? Error(E.pleaseAddNetwork) : e;
108
+ throw e.code === 4902 ? Error(y.pleaseAddNetwork) : e;
104
109
  }
105
- }, Me = async () => {
106
- if (!(!P || !R || !Q.current || !J || !K)) try {
107
- let e = Q.current;
108
- await je(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);
109
115
  let t = createWalletClient({
110
- account: P,
111
- transport: custom(R)
116
+ account: N,
117
+ transport: custom(L)
112
118
  });
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"
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" }]
125
134
  }],
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);
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");
136
149
  } catch (e) {
137
- console.error("钱包支付失败:", e);
138
- let t = e instanceof Error ? e.message : E.walletPaymentFailed;
139
- w?.(t), v?.(e);
150
+ console.error("钱包支付失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), _?.(e), w(!1);
140
151
  }
141
- }, Ne = async () => {
142
- if (!(!P || !R || !Q.current || !J || !K)) try {
143
- let e = Q.current;
144
- await je(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);
145
157
  let t = createWalletClient({
146
- account: P,
147
- transport: custom(R)
158
+ account: N,
159
+ transport: custom(L)
148
160
  });
149
- if (!J.address) throw Error(E.subscriptionDoesNotSupportNative);
150
- await t.writeContract({
161
+ if (!J.address) throw Error(y.subscriptionDoesNotSupportNative);
162
+ let n = await t.writeContract({
151
163
  address: J.address,
152
164
  abi: [{
153
165
  name: "approve",
@@ -165,69 +177,71 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
165
177
  functionName: "approve",
166
178
  args: [e.spenderAddress, parseUnits(e.approveAmount, J.decimals)],
167
179
  chain: null
168
- }), N(void 0);
180
+ });
181
+ console.log("授权交易哈希:", n), w(!1), x("checking");
169
182
  } catch (e) {
170
- console.error("钱包授权失败:", e);
171
- let t = e instanceof Error ? e.message : E.walletPaymentFailed;
172
- w?.(t), v?.(e);
183
+ console.error("钱包授权失败:", e), E(e instanceof Error ? e.message : y.walletPaymentFailed), _?.(e), w(!1);
173
184
  }
174
- }, Pe = async () => {
175
- if (!P) {
176
- let e = E.pleaseConnectWallet;
177
- w?.(e), v?.(Error(e));
185
+ }, Ie = async () => {
186
+ if (!N) {
187
+ let e = y.pleaseConnectWallet;
188
+ E(e), _?.(Error(e));
178
189
  return;
179
190
  }
180
- h === "one-time" ? await Me() : h === "subscription" && await Ne();
181
- }, Q = useRef(null), Fe = async () => {
191
+ p === "instant" ? await Pe() : p === "subscription" && await Fe();
192
+ }, Le = async () => {
182
193
  if (!(!O || !A)) try {
183
- w?.(void 0);
194
+ w(!0), E(void 0);
184
195
  let e = "";
185
- h === "one-time" ? (Q.current = await T.createOnetimePayment({
196
+ p === "instant" ? (G.current = await v.createOnetimePayment({
186
197
  paymentChain: O,
187
198
  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({
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({
191
202
  paymentChain: O,
192
203
  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, {
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, {
197
208
  width: 200,
198
209
  margin: 2,
199
210
  errorCorrectionLevel: "H"
200
211
  }));
201
212
  } catch (e) {
202
- let t = e instanceof Error ? e.message : E.createPaymentFailed;
203
- w?.(t), v?.(e);
213
+ E(e instanceof Error ? e.message : y.createPaymentFailed), _?.(e);
214
+ } finally {
215
+ w(!1);
204
216
  }
217
+ }, Re = () => {
218
+ G.current && (x("checking"), E(void 0));
205
219
  }, $ = (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));
220
+ U.current?.unsubscribe();
221
+ let t = () => defer(() => p === "subscription" ? v.checkSubscriptionPaymentStatus(e) : v.checkOnetimePaymentStatus(e)).pipe(timeout(15e3), retry({ delay: 2e3 }));
222
+ U.current = t().pipe(expand((e) => e.status === "pending" ? timer(2e3).pipe(switchMap(() => t())) : EMPTY), tap((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));
210
224
  })).subscribe({
211
225
  error: (e) => {
212
- if (Q.current) {
213
- let t = e instanceof Error ? e.message : E.checkPaymentStatusFailed;
214
- b("error"), w?.(t), v?.(e);
226
+ if (G.current) {
227
+ let t = e instanceof Error ? e.message : y.checkPaymentStatusFailed;
228
+ x("error"), E(t), _?.(e);
215
229
  }
216
230
  },
217
231
  complete: () => {
218
- W.current?.unsubscribe();
232
+ U.current?.unsubscribe();
219
233
  }
220
234
  });
221
235
  };
222
236
  return useEffect(() => {
223
- D.length === 0 && Ae();
237
+ D.length === 0 && Me();
224
238
  }, []), useEffect(() => {
225
239
  q.length > 0 && j(q[0].symbol);
226
- }, [q]), useEffect(() => (g && $({ orderId: g }), () => {
227
- W.current?.unsubscribe(), ke();
228
- }), [g]), /* @__PURE__ */ jsx("div", {
240
+ }, [q]), useEffect(() => (m && $({ orderId: m }), () => {
241
+ U.current?.unsubscribe(), Z();
242
+ }), [m]), /* @__PURE__ */ jsx("div", {
229
243
  className: "_cppay-content",
230
- children: y === "success" ? /* @__PURE__ */ jsxs("div", {
244
+ children: b === "success" ? /* @__PURE__ */ jsxs("div", {
231
245
  className: "_cppay-state-container",
232
246
  children: [
233
247
  /* @__PURE__ */ jsx("div", {
@@ -236,14 +250,14 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
236
250
  }),
237
251
  /* @__PURE__ */ jsx("h3", {
238
252
  className: "_cppay-state-title",
239
- children: h === "subscription" ? E.authorizationSuccess : E.paymentSuccess
253
+ children: p === "subscription" ? y.authorizationSuccess : y.paymentSuccess
240
254
  }),
241
255
  /* @__PURE__ */ jsx("p", {
242
256
  className: "_cppay-state-message",
243
- children: h === "subscription" ? E.subscriptionActivated : E.transactionCompleted
257
+ children: p === "subscription" ? y.subscriptionActivated : y.transactionCompleted
244
258
  })
245
259
  ]
246
- }) : y === "expired" ? /* @__PURE__ */ jsxs("div", {
260
+ }) : b === "expired" ? /* @__PURE__ */ jsxs("div", {
247
261
  className: "_cppay-state-container",
248
262
  children: [
249
263
  /* @__PURE__ */ jsx("div", {
@@ -252,40 +266,40 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
252
266
  }),
253
267
  /* @__PURE__ */ jsx("h3", {
254
268
  className: "_cppay-state-title",
255
- children: E.paymentExpired
269
+ children: y.paymentExpired
256
270
  }),
257
271
  /* @__PURE__ */ jsx("button", {
258
- onClick: () => b("select"),
259
- disabled: x || S,
272
+ onClick: () => x("select"),
273
+ disabled: C || S,
260
274
  className: "_cppay-btn _cppay-btn-text",
261
- children: E.returnButton
275
+ children: y.returnButton
262
276
  })
263
277
  ]
264
- }) : y === "error" ? /* @__PURE__ */ jsxs("div", {
278
+ }) : b === "error" ? /* @__PURE__ */ jsxs("div", {
265
279
  className: "_cppay-state-container",
266
280
  children: [/* @__PURE__ */ jsx("div", {
267
281
  className: "_cppay-state-icon",
268
282
  children: "❌"
269
283
  }), /* @__PURE__ */ jsx("h3", {
270
284
  className: "_cppay-state-title",
271
- children: C || E.error
285
+ children: T || y.error
272
286
  })]
273
- }) : y === "failed" ? /* @__PURE__ */ jsxs("div", {
287
+ }) : b === "failed" ? /* @__PURE__ */ jsxs("div", {
274
288
  className: "_cppay-state-container",
275
289
  children: [/* @__PURE__ */ jsx("div", {
276
290
  className: "_cppay-state-icon",
277
291
  children: "❌"
278
292
  }), /* @__PURE__ */ jsx("h3", {
279
293
  className: "_cppay-state-title",
280
- children: E.paymentFailed
294
+ children: y.paymentFailed
281
295
  })]
282
- }) : y === "select" ? /* @__PURE__ */ jsxs("div", { children: [
283
- xe?.ChooseTop,
296
+ }) : b === "select" ? /* @__PURE__ */ jsxs("div", { children: [
297
+ Se?.ChooseTop,
284
298
  /* @__PURE__ */ jsxs("div", {
285
299
  className: "_cppay-section",
286
300
  children: [/* @__PURE__ */ jsx("label", {
287
301
  className: "_cppay-label",
288
- children: E.paymentNetwork
302
+ children: y.paymentNetwork
289
303
  }), /* @__PURE__ */ jsx("div", {
290
304
  className: "_cppay-grid",
291
305
  children: D.map((e) => /* @__PURE__ */ jsxs("button", {
@@ -302,7 +316,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
302
316
  className: "_cppay-section",
303
317
  children: [/* @__PURE__ */ jsx("label", {
304
318
  className: "_cppay-label",
305
- children: E.paymentToken
319
+ children: y.paymentToken
306
320
  }), /* @__PURE__ */ jsx("div", {
307
321
  className: "_cppay-grid",
308
322
  children: q.map((e) => /* @__PURE__ */ jsxs("button", {
@@ -315,7 +329,7 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
315
329
  }, e.symbol))
316
330
  })]
317
331
  }),
318
- xe?.ChooseBottom,
332
+ Se?.ChooseBottom,
319
333
  /* @__PURE__ */ jsx("div", {
320
334
  className: "_cppay-section",
321
335
  children: /* @__PURE__ */ jsx("div", {
@@ -324,19 +338,19 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
324
338
  className: "_cppay-price-row",
325
339
  children: [/* @__PURE__ */ jsx("span", {
326
340
  className: "_cppay-price-label",
327
- children: E.paymentAmount
341
+ children: y.paymentAmount
328
342
  }), /* @__PURE__ */ jsxs("div", {
329
343
  className: "_cppay-price-amount",
330
344
  children: [/* @__PURE__ */ jsxs("div", {
331
345
  className: "_cppay-price-main",
332
346
  children: [
333
- Z ?? "-",
347
+ Q ?? "-",
334
348
  " ",
335
349
  A ?? ""
336
350
  ]
337
351
  }), /* @__PURE__ */ jsxs("div", {
338
352
  className: "_cppay-price-sub",
339
- children: ["≈ $", _]
353
+ children: ["≈ $", h]
340
354
  })]
341
355
  })]
342
356
  })
@@ -344,10 +358,10 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
344
358
  }),
345
359
  /* @__PURE__ */ jsxs("div", {
346
360
  className: "_cppay-section",
347
- children: [C && /* @__PURE__ */ jsxs("div", {
361
+ children: [T && /* @__PURE__ */ jsxs("div", {
348
362
  className: "_cppay-error-tooltip-wrapper",
349
- onMouseEnter: () => H(!0),
350
- onMouseLeave: () => H(!1),
363
+ onMouseEnter: () => V(!0),
364
+ onMouseLeave: () => V(!1),
351
365
  children: [/* @__PURE__ */ jsxs("div", {
352
366
  className: "_cppay-error-tooltip",
353
367
  children: [/* @__PURE__ */ jsx("svg", {
@@ -358,16 +372,16 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
358
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",
359
373
  clipRule: "evenodd"
360
374
  })
361
- }), /* @__PURE__ */ jsx("span", { children: C })]
362
- }), Te && /* @__PURE__ */ jsx("div", {
375
+ }), /* @__PURE__ */ jsx("span", { children: T })]
376
+ }), Oe && /* @__PURE__ */ jsx("div", {
363
377
  className: "_cppay-error-tooltip-full",
364
- children: C
378
+ children: T
365
379
  })]
366
380
  }), /* @__PURE__ */ jsx("button", {
367
- onClick: Fe,
368
- disabled: !O || !A || x,
381
+ onClick: Le,
382
+ disabled: !O || !A || C,
369
383
  className: "_cppay-btn _cppay-btn-primary",
370
- children: x ? E.processing : E.continuePayment
384
+ children: C ? y.processing : y.continuePayment
371
385
  })]
372
386
  })
373
387
  ] }) : /* @__PURE__ */ jsxs("div", { children: [
@@ -393,10 +407,10 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
393
407
  className: "_cppay-info-flex-child",
394
408
  children: [/* @__PURE__ */ jsx("div", {
395
409
  className: "_cppay-info-label",
396
- children: h === "subscription" ? E.authorizationAmount : E.paymentAmount
410
+ children: p === "subscription" ? y.authorizationAmount : y.paymentAmount
397
411
  }), /* @__PURE__ */ jsxs("div", {
398
412
  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: ["≈ $", _] })]
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] })]
400
414
  })]
401
415
  })
402
416
  })
@@ -407,27 +421,27 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
407
421
  className: "_cppay-info-flex-child",
408
422
  children: [/* @__PURE__ */ jsxs("div", {
409
423
  className: "_cppay-info-label _cppay-info-label-flex",
410
- children: [/* @__PURE__ */ jsx("span", { children: h === "subscription" ? E.authorizationContractAddress : E.paymentAddress }), B && /* @__PURE__ */ jsxs("span", {
424
+ children: [/* @__PURE__ */ jsx("span", { children: p === "subscription" ? y.authorizationContractAddress : y.paymentAddress }), z && /* @__PURE__ */ jsxs("span", {
411
425
  className: "_cppay-countdown",
412
- children: ["⏰ ", B]
426
+ children: ["⏰ ", z]
413
427
  })]
414
428
  }), /* @__PURE__ */ jsxs("div", {
415
429
  className: "_cppay-address-row",
416
- 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", {
417
431
  onClick: async () => {
418
- if (!Q.current) return;
419
- 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;
420
434
  if (e) try {
421
- await navigator.clipboard.writeText(e), we(!0), setTimeout(() => {
422
- we(!1);
435
+ await navigator.clipboard.writeText(e), De(!0), setTimeout(() => {
436
+ De(!1);
423
437
  }, 2e3);
424
438
  } catch (e) {
425
439
  console.error("复制失败:", e);
426
440
  }
427
441
  },
428
- className: `_cppay-copy-btn ${V ? "_cppay-copy-success" : ""}`,
429
- title: V ? E.copied : E.copyAddress,
430
- children: V ? /* @__PURE__ */ jsx("svg", {
442
+ className: `_cppay-copy-btn ${B ? "_cppay-copy-success" : ""}`,
443
+ title: B ? y.copied : y.copyAddress,
444
+ children: B ? /* @__PURE__ */ jsx("svg", {
431
445
  className: "_cppay-copy-icon",
432
446
  viewBox: "0 0 24 24",
433
447
  fill: "currentColor",
@@ -451,22 +465,22 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
451
465
  })]
452
466
  })
453
467
  }),
454
- h === "subscription" && /* @__PURE__ */ jsxs("div", {
468
+ p === "subscription" && /* @__PURE__ */ jsxs("div", {
455
469
  className: "_cppay-info-box _cppay-subscription-box",
456
470
  children: [/* @__PURE__ */ jsx("div", {
457
471
  className: "_cppay-info-label _cppay-subscription-label",
458
- children: E.subscriptionNotice
472
+ children: y.subscriptionNotice
459
473
  }), /* @__PURE__ */ jsx("div", {
460
474
  className: "_cppay-info-value _cppay-subscription-message",
461
- children: E.subscriptionNoticeMessage
475
+ children: y.subscriptionNoticeMessage
462
476
  })]
463
477
  })
464
478
  ]
465
479
  }),
466
- C && /* @__PURE__ */ jsxs("div", {
480
+ T && /* @__PURE__ */ jsxs("div", {
467
481
  className: "_cppay-error-tooltip-wrapper",
468
- onMouseEnter: () => H(!0),
469
- onMouseLeave: () => H(!1),
482
+ onMouseEnter: () => V(!0),
483
+ onMouseLeave: () => V(!1),
470
484
  children: [/* @__PURE__ */ jsxs("div", {
471
485
  className: "_cppay-error-tooltip",
472
486
  children: [/* @__PURE__ */ jsx("svg", {
@@ -477,30 +491,30 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
477
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",
478
492
  clipRule: "evenodd"
479
493
  })
480
- }), /* @__PURE__ */ jsx("span", { children: C })]
481
- }), Te && /* @__PURE__ */ jsx("div", {
494
+ }), /* @__PURE__ */ jsx("span", { children: T })]
495
+ }), Oe && /* @__PURE__ */ jsx("div", {
482
496
  className: "_cppay-error-tooltip-full",
483
- children: C
497
+ children: T
484
498
  })]
485
499
  }),
486
500
  !S && /* @__PURE__ */ jsx("div", {
487
501
  className: "_cppay-section",
488
- children: P ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
489
- onClick: Pe,
490
- disabled: x,
502
+ children: N ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
503
+ onClick: Ie,
504
+ disabled: C,
491
505
  className: "_cppay-btn _cppay-btn-primary",
492
- children: x ? h === "subscription" ? E.authorizing : E.processing : h === "subscription" ? `💳 ${E.connectWallet}` : `💳 ${E.walletPay}`
506
+ children: C ? p === "subscription" ? y.authorizing : y.processing : p === "subscription" ? `💳 ${y.connectWallet}` : `💳 ${y.walletPay}`
493
507
  }), /* @__PURE__ */ jsxs("button", {
494
- onClick: Ee,
495
- disabled: x,
508
+ onClick: ke,
509
+ disabled: C,
496
510
  className: "_cppay-btn _cppay-wallet-address-btn",
497
- title: E.clickToModifyWallet,
511
+ title: y.clickToModifyWallet,
498
512
  children: [/* @__PURE__ */ jsxs("span", {
499
513
  className: "_cppay-wallet-address-text",
500
514
  children: [
501
- P.slice(0, 10),
515
+ N.slice(0, 10),
502
516
  "...",
503
- P.slice(-4)
517
+ N.slice(-4)
504
518
  ]
505
519
  }), /* @__PURE__ */ jsx("svg", {
506
520
  className: "_cppay-wallet-arrow",
@@ -511,63 +525,50 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
511
525
  children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" })
512
526
  })]
513
527
  })] }) : /* @__PURE__ */ jsx("button", {
514
- onClick: Ee,
515
- disabled: I,
528
+ onClick: ke,
529
+ disabled: F,
516
530
  className: "_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn",
517
- children: /* @__PURE__ */ jsx("span", { children: I ? E.processing : `💳 ${E.connectWallet}` })
531
+ children: /* @__PURE__ */ jsx("span", { children: F ? y.processing : `💳 ${y.connectWallet}` })
518
532
  })
519
533
  }),
520
534
  /* @__PURE__ */ jsx("div", {
521
535
  className: "_cppay-section",
522
536
  children: /* @__PURE__ */ jsx("button", {
523
- onClick: () => {
524
- b("payment");
525
- },
537
+ onClick: Re,
526
538
  disabled: S,
527
539
  className: "_cppay-btn _cppay-btn-primary",
528
- children: S ? E.checking : E.completedPayment
540
+ children: S ? y.checking : y.completedPayment
529
541
  })
530
542
  }),
531
543
  /* @__PURE__ */ jsx("hr", { className: "_cppay-divider" }),
532
544
  /* @__PURE__ */ jsx("div", {
533
545
  className: "_cppay-section",
534
546
  children: /* @__PURE__ */ jsx("button", {
535
- onClick: () => b("select"),
536
- disabled: x || S,
547
+ onClick: () => x("select"),
548
+ disabled: C || S,
537
549
  className: "_cppay-btn _cppay-btn-text",
538
- children: E.changePaymentMethod
550
+ children: y.changePaymentMethod
539
551
  })
540
552
  })
541
553
  ] })
542
554
  });
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();
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]);
545
557
  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));
558
+ e || l("select");
554
559
  }, [e]), useEffect(() => {
555
560
  if (!e) return;
556
561
  let t = (e) => {
557
- e.key === "Escape" && !f && !p && m();
562
+ e.key === "Escape" && u && d();
558
563
  };
559
564
  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]);
565
+ }, [e, u]);
566
+ let d = () => {
567
+ u && t();
568
+ }, f = useMemo(() => getLocaleMessages(o), [o]);
568
569
  return e ? /* @__PURE__ */ jsx("div", {
569
570
  className: "_cppay-overlay",
570
- onClick: (e) => e.target === e.currentTarget && !f && !p && m(),
571
+ onClick: (e) => e.target === e.currentTarget && d(),
571
572
  children: /* @__PURE__ */ jsxs("div", {
572
573
  className: "_cppay-dialog",
573
574
  children: [/* @__PURE__ */ jsxs("div", {
@@ -575,18 +576,19 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
575
576
  children: [/* @__PURE__ */ jsx("h2", {
576
577
  className: "_cppay-title",
577
578
  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;
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;
585
587
  }
586
588
  })()
587
589
  }), /* @__PURE__ */ jsx("button", {
588
- onClick: m,
589
- disabled: f || p,
590
+ onClick: d,
591
+ disabled: !u,
590
592
  className: "_cppay-close-btn",
591
593
  children: /* @__PURE__ */ jsx("svg", {
592
594
  fill: "none",
@@ -603,65 +605,60 @@ var PaymentContent_default = ({ apikey: t, ott: n, plain: h, orderId: g, amount:
603
605
  }), /* @__PURE__ */ jsx(PaymentContent_default, {
604
606
  apikey: i,
605
607
  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
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, a] = useState(null), o = useCallback((e) => {
628
- a(e), r(!0);
629
- }, []), s = 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
- }, []), c = useCallback(() => {
628
+ }, []), a = useCallback(() => {
632
629
  r(!1);
633
- }, []), l = useCallback((e) => {
630
+ }, []), o = useCallback((e) => {
634
631
  i?.onSuccess?.(e), setTimeout(() => r(!1), 1e3);
635
- }, [i]), se = useCallback((e) => {
632
+ }, [i]), me = useCallback((e) => {
636
633
  i?.onExpired?.(e);
637
- }, [i]), u = useCallback((e) => {
634
+ }, [i]), he = useCallback((e) => {
638
635
  i?.onFailed?.(e);
639
- }, [i]), ce = 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" && c();
642
+ e.key === "Escape" && a();
646
643
  };
647
644
  return document.addEventListener("keydown", e), () => document.removeEventListener("keydown", e);
648
- }, [n, c]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
645
+ }, [n, a]), /* @__PURE__ */ jsxs(CppayContext.Provider, {
649
646
  value: {
650
- showPayment: o,
651
- closePayment: s
647
+ showPayment: fe,
648
+ closePayment: pe
652
649
  },
653
650
  children: [t, i && /* @__PURE__ */ jsx(PaymentDialog_default, {
654
651
  open: n,
655
- onClose: c,
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: l,
662
- onExpired: se,
663
- onFailed: u,
664
- onError: ce
658
+ onSuccess: o,
659
+ onExpired: me,
660
+ onFailed: he,
661
+ onError: s
665
662
  })]
666
663
  });
667
664
  }, useCppayPayment = () => {