cppay-sdk 0.0.2-beta.28 → 0.0.2-beta.29

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