@aixnn/aixautots 0.6.17 → 0.6.21
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/{automation-queue-DO8fOG6l.d.ts → automation-queue-GhfQtZLm.d.ts} +2 -2
- package/dist/{chunk-TJ2QIP5M.js → chunk-4NRIEM5Z.js} +249 -33
- package/dist/chunk-6IH74UX6.js +1693 -0
- package/dist/{chunk-WOPEKCVC.js → chunk-DAU3FVCV.js} +2 -2
- package/dist/chunk-DTXXQPOU.js +693 -0
- package/dist/{chunk-7BJPVSEZ.js → chunk-ED6CB3B4.js} +222 -12
- package/dist/{chunk-NIEGPH3E.js → chunk-FJKMRWYC.js} +55 -23
- package/dist/{chunk-ZDCTHR7D.js → chunk-H7KZUU67.js} +2 -2
- package/dist/{chunk-FJPIY4YI.js → chunk-HQ2L4NQ2.js} +262 -10
- package/dist/{chunk-LOKPZ677.js → chunk-JQBSGFAR.js} +2 -2
- package/dist/{chunk-2KPZSPV6.js → chunk-OJK35AQD.js} +105 -17
- package/dist/{chunk-KASSYUGM.js → chunk-RFOJSDYI.js} +2 -2
- package/dist/{chunk-QEK25NUA.js → chunk-UEZVXYGP.js} +12 -5
- package/dist/{config-CBUhr4Gl.d.ts → config-C79rcedl.d.ts} +52 -10
- package/dist/core/index.d.ts +13 -9
- package/dist/core/index.js +2 -2
- package/dist/core/network-adb-node.d.ts +23 -0
- package/dist/core/network-adb-node.js +171 -0
- package/dist/{script-debugger-DoT02din.d.ts → device-channel-OiZwAqNQ.d.ts} +41 -55
- package/dist/{device-normalize-Vl5JYbAI.d.ts → device-normalize-ODrxJb-a.d.ts} +1 -1
- package/dist/device-session-PVHD6PNR.js +1 -0
- package/dist/i18n/index.js +1 -1
- package/dist/{mirror-session-Y1InpkUY.d.ts → mirror-session-DifANocH.d.ts} +2 -2
- package/dist/react/index.d.ts +19 -12
- package/dist/react/index.js +3 -3
- package/dist/script-debugger-DjxpvdaN.d.ts +56 -0
- package/dist/{task-agent-runner-Cl2ickJ1.d.ts → task-agent-runner-CAt-z8gr.d.ts} +3 -3
- package/dist/{types-Cp1ohbTb.d.ts → types-CBI5SIH5.d.ts} +102 -4
- package/dist/ui/billing.d.ts +43 -6
- package/dist/ui/billing.js +190 -309
- package/dist/ui/device-create.d.ts +1 -1
- package/dist/ui/device-create.js +7 -7
- package/dist/ui/device-mirror.js +5 -5
- package/dist/ui/devices.d.ts +5 -5
- package/dist/ui/devices.js +9 -9
- package/dist/ui/editor.d.ts +2 -2
- package/dist/ui/editor.js +5 -5
- package/dist/ui/index.d.ts +6 -4
- package/dist/ui/index.js +13 -492
- package/dist/ui/inspector.js +4 -4
- package/dist/ui/ip-commerce.d.ts +2 -2
- package/dist/ui/ip-commerce.js +5 -5
- package/dist/ui/market.js +4 -4
- package/dist/ui/mirror.d.ts +3 -3
- package/dist/ui/script-studio.js +4 -4
- package/dist/ui/scripts.d.ts +1 -1
- package/dist/ui/scripts.js +4 -4
- package/dist/ui/settings.d.ts +164 -0
- package/dist/ui/settings.js +10 -0
- package/dist/ui/tasks.js +9 -9
- package/package.json +9 -1
- package/dist/device-session-3XK2SZDF.js +0 -1
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
import { Button, cn, Badge } from './chunk-7RQTSTR6.js';
|
|
2
|
+
import { useAixT } from './chunk-HQ2L4NQ2.js';
|
|
3
|
+
import { useClient, useQuery, useBilling } from './chunk-UEZVXYGP.js';
|
|
4
|
+
import { SlidersHorizontal, Globe, ArrowUpCircle, Server, CalendarClock, Smartphone, ArrowDownCircle, RefreshCw, ExternalLink, CreditCard, HeadphonesIcon, Wallet, X } from 'lucide-react';
|
|
5
|
+
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
6
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
var TABLE = {
|
|
9
|
+
topup: { icon: ArrowUpCircle, i18nKey: "billing.kind.topup", sign: "credit" },
|
|
10
|
+
platform_session: { icon: Smartphone, i18nKey: "billing.kind.platform_session", sign: "debit" },
|
|
11
|
+
subscription: { icon: CalendarClock, i18nKey: "billing.kind.subscription", sign: "debit" },
|
|
12
|
+
own_node_daily: { icon: Server, i18nKey: "billing.kind.own_node_daily", sign: "debit" },
|
|
13
|
+
proxy_purchase: { icon: Globe, i18nKey: "billing.kind.proxy_purchase", sign: "debit" },
|
|
14
|
+
proxy_refund: { icon: ArrowUpCircle, i18nKey: "billing.kind.proxy_refund", sign: "credit" },
|
|
15
|
+
ip_hold: { icon: Globe, i18nKey: "billing.kind.ip_hold", sign: "debit" },
|
|
16
|
+
ip_hold_release: { icon: ArrowUpCircle, i18nKey: "billing.kind.ip_hold_release", sign: "credit" },
|
|
17
|
+
ip_purchase: { icon: Globe, i18nKey: "billing.kind.ip_purchase", sign: "debit" },
|
|
18
|
+
ip_usage: { icon: Globe, i18nKey: "billing.kind.ip_usage", sign: "debit" },
|
|
19
|
+
adjust: { icon: SlidersHorizontal, i18nKey: "billing.kind.adjust", sign: "debit" }
|
|
20
|
+
};
|
|
21
|
+
var FALLBACK = {
|
|
22
|
+
icon: ArrowDownCircle,
|
|
23
|
+
i18nKey: "billing.kind.adjust",
|
|
24
|
+
sign: "debit"
|
|
25
|
+
};
|
|
26
|
+
function ledgerKindMeta(kind, amount) {
|
|
27
|
+
const base = TABLE[kind] ?? FALLBACK;
|
|
28
|
+
if (kind === "adjust" && amount !== void 0) {
|
|
29
|
+
return { ...base, sign: amount >= 0 ? "credit" : "debit" };
|
|
30
|
+
}
|
|
31
|
+
return base;
|
|
32
|
+
}
|
|
33
|
+
var DEFAULT_PACKS_CENTS = [500, 1e3, 2e3, 5e3, 1e4];
|
|
34
|
+
var DEFAULT_MIN_CENTS = 500;
|
|
35
|
+
var DEFAULT_MAX_CENTS = 5e4;
|
|
36
|
+
var POLL_INTERVAL_MS = 4e3;
|
|
37
|
+
var MAX_POLL_ATTEMPTS = 90;
|
|
38
|
+
function StripeTopupPanel({
|
|
39
|
+
refreshBalance,
|
|
40
|
+
channel,
|
|
41
|
+
returnUrl,
|
|
42
|
+
cancelUrl,
|
|
43
|
+
openExternalUrl,
|
|
44
|
+
onTopupCompleted
|
|
45
|
+
}) {
|
|
46
|
+
const client = useClient();
|
|
47
|
+
const t = useAixT();
|
|
48
|
+
const {
|
|
49
|
+
data: methods,
|
|
50
|
+
error: methodsError,
|
|
51
|
+
loading: methodsLoading
|
|
52
|
+
} = useQuery(
|
|
53
|
+
() => client ? client.billing.topupMethods() : Promise.resolve({
|
|
54
|
+
currency: "USD",
|
|
55
|
+
project_id: "",
|
|
56
|
+
channel: "direct",
|
|
57
|
+
stripe: {
|
|
58
|
+
enabled: true,
|
|
59
|
+
min_cents: DEFAULT_MIN_CENTS,
|
|
60
|
+
max_cents: DEFAULT_MAX_CENTS,
|
|
61
|
+
packs_cents: DEFAULT_PACKS_CENTS
|
|
62
|
+
},
|
|
63
|
+
wise: { enabled: false }
|
|
64
|
+
}),
|
|
65
|
+
[client]
|
|
66
|
+
);
|
|
67
|
+
const stripeCfg = methods?.stripe;
|
|
68
|
+
const enabled = stripeCfg ? stripeCfg.enabled : !methodsLoading && !methodsError;
|
|
69
|
+
const minCents = stripeCfg?.min_cents ?? DEFAULT_MIN_CENTS;
|
|
70
|
+
const maxCents = stripeCfg?.max_cents ?? DEFAULT_MAX_CENTS;
|
|
71
|
+
const minDollars = Math.ceil(minCents / 100);
|
|
72
|
+
const maxDollars = Math.floor(maxCents / 100);
|
|
73
|
+
const packsCents = stripeCfg?.packs_cents && stripeCfg.packs_cents.length > 0 ? stripeCfg.packs_cents : DEFAULT_PACKS_CENTS;
|
|
74
|
+
const [amountDollars, setAmountDollars] = useState("10");
|
|
75
|
+
const [submitting, setSubmitting] = useState(false);
|
|
76
|
+
const [checking, setChecking] = useState(false);
|
|
77
|
+
const [pendingSession, setPendingSession] = useState(null);
|
|
78
|
+
const [completed, setCompleted] = useState(null);
|
|
79
|
+
const [pendingNote, setPendingNote] = useState(false);
|
|
80
|
+
const [failed, setFailed] = useState(false);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!stripeCfg?.packs_cents?.length) return;
|
|
83
|
+
setAmountDollars((curr) => {
|
|
84
|
+
const n = Number(curr);
|
|
85
|
+
if (/^\d+$/.test(curr) && n * 100 >= minCents && n * 100 <= maxCents) return curr;
|
|
86
|
+
const preferred = stripeCfg.packs_cents.includes(1e3) ? 1e3 : stripeCfg.packs_cents[0] ?? DEFAULT_MIN_CENTS;
|
|
87
|
+
return String(Math.round(preferred / 100));
|
|
88
|
+
});
|
|
89
|
+
}, [stripeCfg, minCents, maxCents]);
|
|
90
|
+
const trimmed = amountDollars.trim();
|
|
91
|
+
const parsedDollars = /^\d+$/.test(trimmed) ? Number(trimmed) : NaN;
|
|
92
|
+
const cents = parsedDollars * 100;
|
|
93
|
+
const valid = Number.isSafeInteger(cents) && cents >= minCents && cents <= maxCents && cents % 100 === 0;
|
|
94
|
+
const verifyingRef = useRef(false);
|
|
95
|
+
const verifySession = useCallback(
|
|
96
|
+
async (sessionId, manual) => {
|
|
97
|
+
if (!client || verifyingRef.current) return;
|
|
98
|
+
verifyingRef.current = true;
|
|
99
|
+
if (manual) {
|
|
100
|
+
setChecking(true);
|
|
101
|
+
setFailed(false);
|
|
102
|
+
setPendingNote(false);
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const res = await client.billing.reconcileStripeCheckout(sessionId);
|
|
106
|
+
if (res.reconciled) {
|
|
107
|
+
setPendingSession(null);
|
|
108
|
+
setPendingNote(false);
|
|
109
|
+
setCompleted(res);
|
|
110
|
+
await refreshBalance();
|
|
111
|
+
await onTopupCompleted?.(res);
|
|
112
|
+
} else if (manual) {
|
|
113
|
+
setPendingNote(true);
|
|
114
|
+
}
|
|
115
|
+
} catch {
|
|
116
|
+
if (manual) setFailed(true);
|
|
117
|
+
} finally {
|
|
118
|
+
verifyingRef.current = false;
|
|
119
|
+
if (manual) setChecking(false);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
[client, refreshBalance, onTopupCompleted]
|
|
123
|
+
);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (!pendingSession) return;
|
|
126
|
+
let attempts = 0;
|
|
127
|
+
const sid = pendingSession.sessionId;
|
|
128
|
+
const resume = () => {
|
|
129
|
+
if (document.visibilityState === "visible") {
|
|
130
|
+
void verifySession(sid, false);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
window.addEventListener("focus", resume);
|
|
134
|
+
document.addEventListener("visibilitychange", resume);
|
|
135
|
+
const timer = window.setInterval(() => {
|
|
136
|
+
attempts += 1;
|
|
137
|
+
if (attempts > MAX_POLL_ATTEMPTS) {
|
|
138
|
+
window.clearInterval(timer);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
void verifySession(sid, false);
|
|
142
|
+
}, POLL_INTERVAL_MS);
|
|
143
|
+
return () => {
|
|
144
|
+
window.removeEventListener("focus", resume);
|
|
145
|
+
document.removeEventListener("visibilitychange", resume);
|
|
146
|
+
window.clearInterval(timer);
|
|
147
|
+
};
|
|
148
|
+
}, [pendingSession, verifySession]);
|
|
149
|
+
async function handleSubmit(e) {
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
if (!client || !valid || submitting || !enabled) return;
|
|
152
|
+
setSubmitting(true);
|
|
153
|
+
setFailed(false);
|
|
154
|
+
setPendingNote(false);
|
|
155
|
+
setCompleted(null);
|
|
156
|
+
try {
|
|
157
|
+
const checkout = await client.billing.createStripeCheckout({
|
|
158
|
+
amount_cents: cents,
|
|
159
|
+
channel: channel?.trim() || void 0,
|
|
160
|
+
return_url: returnUrl,
|
|
161
|
+
cancel_url: cancelUrl
|
|
162
|
+
});
|
|
163
|
+
setPendingSession({ sessionId: checkout.session_id, url: checkout.url });
|
|
164
|
+
if (openExternalUrl) {
|
|
165
|
+
await openExternalUrl(checkout.url);
|
|
166
|
+
} else if (typeof window !== "undefined" && typeof window.open === "function") {
|
|
167
|
+
window.open(checkout.url, "_blank", "noopener,noreferrer");
|
|
168
|
+
}
|
|
169
|
+
} catch {
|
|
170
|
+
setFailed(true);
|
|
171
|
+
} finally {
|
|
172
|
+
setSubmitting(false);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (methods && !methods.stripe.enabled) {
|
|
176
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-xs text-muted-foreground", children: [
|
|
177
|
+
/* @__PURE__ */ jsx("p", { children: t("stripe.subtitle") }),
|
|
178
|
+
/* @__PURE__ */ jsx("p", { children: t("stripe.disabled") })
|
|
179
|
+
] });
|
|
180
|
+
}
|
|
181
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-3 text-xs", children: [
|
|
182
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("stripe.subtitle") }),
|
|
183
|
+
/* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-3", children: [
|
|
184
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
185
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1.5 text-[11px] font-medium text-muted-foreground", children: t("stripe.preset") }),
|
|
186
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: packsCents.map((packCents) => {
|
|
187
|
+
const dollars = String(Math.round(packCents / 100));
|
|
188
|
+
const active = trimmed === dollars;
|
|
189
|
+
return /* @__PURE__ */ jsxs(
|
|
190
|
+
Button,
|
|
191
|
+
{
|
|
192
|
+
type: "button",
|
|
193
|
+
size: "sm",
|
|
194
|
+
variant: active ? "primary" : "secondary",
|
|
195
|
+
"aria-pressed": active,
|
|
196
|
+
onClick: () => setAmountDollars(dollars),
|
|
197
|
+
children: [
|
|
198
|
+
"$",
|
|
199
|
+
dollars
|
|
200
|
+
]
|
|
201
|
+
},
|
|
202
|
+
packCents
|
|
203
|
+
);
|
|
204
|
+
}) })
|
|
205
|
+
] }),
|
|
206
|
+
/* @__PURE__ */ jsxs("label", { className: "grid gap-1", children: [
|
|
207
|
+
/* @__PURE__ */ jsx("span", { className: "text-[11px] font-medium text-muted-foreground", children: t("stripe.custom") }),
|
|
208
|
+
/* @__PURE__ */ jsx(
|
|
209
|
+
"input",
|
|
210
|
+
{
|
|
211
|
+
type: "text",
|
|
212
|
+
inputMode: "numeric",
|
|
213
|
+
"aria-label": t("stripe.custom"),
|
|
214
|
+
"aria-invalid": Boolean(trimmed) && !valid,
|
|
215
|
+
placeholder: String(minDollars),
|
|
216
|
+
value: amountDollars,
|
|
217
|
+
onChange: (e) => setAmountDollars(e.target.value),
|
|
218
|
+
className: "min-h-10 w-40 rounded border border-border bg-background px-2.5 text-sm tabular-nums text-foreground"
|
|
219
|
+
}
|
|
220
|
+
),
|
|
221
|
+
trimmed && !valid && /* @__PURE__ */ jsx("span", { className: "text-destructive", children: t("stripe.range", { min: minDollars, max: maxDollars }) })
|
|
222
|
+
] }),
|
|
223
|
+
/* @__PURE__ */ jsx(
|
|
224
|
+
Button,
|
|
225
|
+
{
|
|
226
|
+
type: "submit",
|
|
227
|
+
className: "min-h-10 w-full",
|
|
228
|
+
disabled: !valid || submitting || methodsLoading || !!methodsError,
|
|
229
|
+
children: submitting ? t("stripe.creating") : t("stripe.submit", { amount: valid ? parsedDollars : 0 })
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
] }),
|
|
233
|
+
pendingSession && /* @__PURE__ */ jsxs("div", { className: "space-y-2 rounded-md border border-border/80 bg-secondary/20 p-2.5", children: [
|
|
234
|
+
/* @__PURE__ */ jsx("p", { className: "text-foreground", children: t("stripe.opening") }),
|
|
235
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
236
|
+
/* @__PURE__ */ jsxs(
|
|
237
|
+
Button,
|
|
238
|
+
{
|
|
239
|
+
type: "button",
|
|
240
|
+
size: "sm",
|
|
241
|
+
variant: "secondary",
|
|
242
|
+
disabled: checking,
|
|
243
|
+
onClick: () => void verifySession(pendingSession.sessionId, true),
|
|
244
|
+
children: [
|
|
245
|
+
/* @__PURE__ */ jsx(RefreshCw, { className: cn("h-3.5 w-3.5", checking && "animate-spin") }),
|
|
246
|
+
t("stripe.checkNow")
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
),
|
|
250
|
+
/* @__PURE__ */ jsxs(
|
|
251
|
+
"a",
|
|
252
|
+
{
|
|
253
|
+
href: pendingSession.url,
|
|
254
|
+
target: "_blank",
|
|
255
|
+
rel: "noopener noreferrer",
|
|
256
|
+
className: "inline-flex items-center gap-1 text-xs font-medium text-primary underline-offset-2 hover:underline",
|
|
257
|
+
children: [
|
|
258
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "h-3 w-3" }),
|
|
259
|
+
"Stripe"
|
|
260
|
+
]
|
|
261
|
+
}
|
|
262
|
+
)
|
|
263
|
+
] }),
|
|
264
|
+
pendingNote && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: t("stripe.pending") })
|
|
265
|
+
] }),
|
|
266
|
+
completed && completed.balance !== null && /* @__PURE__ */ jsx(
|
|
267
|
+
"p",
|
|
268
|
+
{
|
|
269
|
+
role: "status",
|
|
270
|
+
className: "rounded-md bg-green-500/10 px-2.5 py-2 font-medium text-green-600 dark:text-green-400",
|
|
271
|
+
children: t("stripe.paid", {
|
|
272
|
+
balance: String(completed.balance),
|
|
273
|
+
currency: completed.currency
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
),
|
|
277
|
+
(methodsError || failed) && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: t("stripe.failed") })
|
|
278
|
+
] });
|
|
279
|
+
}
|
|
280
|
+
function WiseOrdersPanel({
|
|
281
|
+
refreshBalance,
|
|
282
|
+
channel
|
|
283
|
+
}) {
|
|
284
|
+
const client = useClient();
|
|
285
|
+
const t = useAixT();
|
|
286
|
+
const { data, error, loading, refetch, setData } = useQuery(() => client.billing.wiseOrders(), [client]);
|
|
287
|
+
const [amount, setAmount] = useState("");
|
|
288
|
+
const [creating, setCreating] = useState(false);
|
|
289
|
+
const [failed, setFailed] = useState(false);
|
|
290
|
+
const [units, fraction = ""] = amount.split(".");
|
|
291
|
+
const cents = Number(units) * 100 + Number(fraction.padEnd(2, "0"));
|
|
292
|
+
const valid = /^\d+(\.\d{1,2})?$/.test(amount) && Number.isSafeInteger(cents) && cents > 0 && cents <= 1e8;
|
|
293
|
+
const busy = creating || loading;
|
|
294
|
+
const [clock, setClock] = useState(Date.now);
|
|
295
|
+
const now = Math.max(clock, Date.now());
|
|
296
|
+
useEffect(() => {
|
|
297
|
+
const deadline = Math.min(...(data?.orders ?? []).filter((o) => o.status === "pending").map((o) => Date.parse(o.expires_at)).filter((expires) => expires > now));
|
|
298
|
+
if (!Number.isFinite(deadline)) return;
|
|
299
|
+
const timer = window.setTimeout(() => setClock(Date.now()), Math.min(2147483647, Math.max(0, deadline - Date.now())));
|
|
300
|
+
return () => window.clearTimeout(timer);
|
|
301
|
+
}, [data, now]);
|
|
302
|
+
const checking = useRef(false);
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
const resume = () => {
|
|
305
|
+
if (document.visibilityState !== "visible") return;
|
|
306
|
+
setClock(Date.now());
|
|
307
|
+
if (busy || checking.current) return;
|
|
308
|
+
checking.current = true;
|
|
309
|
+
void refetch().finally(() => {
|
|
310
|
+
checking.current = false;
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
window.addEventListener("focus", resume);
|
|
314
|
+
document.addEventListener("visibilitychange", resume);
|
|
315
|
+
return () => {
|
|
316
|
+
window.removeEventListener("focus", resume);
|
|
317
|
+
document.removeEventListener("visibilitychange", resume);
|
|
318
|
+
};
|
|
319
|
+
}, [busy, refetch]);
|
|
320
|
+
async function create(e) {
|
|
321
|
+
e.preventDefault();
|
|
322
|
+
if (!valid || busy || failed || !data?.enabled) return;
|
|
323
|
+
setCreating(true);
|
|
324
|
+
try {
|
|
325
|
+
const order = await client.billing.createWiseOrder(cents, channel ? { channel } : void 0);
|
|
326
|
+
setData((prev) => prev && { ...prev, orders: [order, ...prev.orders.filter((o) => o.id !== order.id)] });
|
|
327
|
+
setAmount("");
|
|
328
|
+
} catch {
|
|
329
|
+
setFailed(true);
|
|
330
|
+
} finally {
|
|
331
|
+
setCreating(false);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return /* @__PURE__ */ jsxs("section", { className: "mb-4 space-y-3 rounded-lg border border-border p-3 text-sm", "aria-busy": busy, children: [
|
|
335
|
+
data?.enabled && /* @__PURE__ */ jsxs("form", { onSubmit: create, className: "flex flex-wrap items-end gap-2", children: [
|
|
336
|
+
/* @__PURE__ */ jsxs("label", { className: "grid gap-1", children: [
|
|
337
|
+
t("wise.amount"),
|
|
338
|
+
/* @__PURE__ */ jsx("input", { className: "min-h-11 w-36 rounded border border-border bg-background px-2", "aria-invalid": Boolean(amount) && !valid, inputMode: "decimal", placeholder: "10.00", value: amount, onChange: (e) => setAmount(e.target.value) }),
|
|
339
|
+
amount && !valid && /* @__PURE__ */ jsx("span", { className: "text-xs text-destructive", children: t("wise.range") })
|
|
340
|
+
] }),
|
|
341
|
+
/* @__PURE__ */ jsx(Button, { className: "min-h-11", disabled: !valid || busy || failed || !!error, children: t("wise.create") })
|
|
342
|
+
] }),
|
|
343
|
+
data && !data.enabled && /* @__PURE__ */ jsx("p", { children: t("wise.disabled") }),
|
|
344
|
+
(error || failed) && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: t("wise.failed") }),
|
|
345
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", className: "min-h-11", disabled: busy, onClick: () => {
|
|
346
|
+
setFailed(false);
|
|
347
|
+
void refetch();
|
|
348
|
+
void refreshBalance();
|
|
349
|
+
}, children: busy ? t("wise.busy") : t("wise.refresh") }),
|
|
350
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2", "aria-live": "polite", children: [
|
|
351
|
+
data?.orders.length === 0 && data.enabled && /* @__PURE__ */ jsx("p", { children: t("wise.empty") }),
|
|
352
|
+
data?.orders.map((order) => /* @__PURE__ */ jsxs("article", { className: "space-y-1 rounded border border-border p-3", children: [
|
|
353
|
+
/* @__PURE__ */ jsxs("p", { className: "font-semibold tabular-nums", children: [
|
|
354
|
+
(order.amount_cents / 100).toFixed(2),
|
|
355
|
+
" USD \xB7 ",
|
|
356
|
+
t(order.status === "pending" && Date.parse(order.expires_at) <= now ? "wise.windowClosed" : `wise.${order.status}`)
|
|
357
|
+
] }),
|
|
358
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
359
|
+
t("wise.reference"),
|
|
360
|
+
": ",
|
|
361
|
+
/* @__PURE__ */ jsx("code", { className: "select-all break-all", children: order.reference })
|
|
362
|
+
] }),
|
|
363
|
+
order.status === "pending" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
364
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
365
|
+
t("wise.expires"),
|
|
366
|
+
": ",
|
|
367
|
+
/* @__PURE__ */ jsx("time", { dateTime: order.expires_at, children: new Date(order.expires_at).toLocaleString() })
|
|
368
|
+
] }),
|
|
369
|
+
data.enabled && !loading && !error && !failed && Date.parse(order.expires_at) > now && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
370
|
+
/* @__PURE__ */ jsx("p", { children: t("wise.hint") }),
|
|
371
|
+
/* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: order.payment_instructions })
|
|
372
|
+
] })
|
|
373
|
+
] })
|
|
374
|
+
] }, order.id))
|
|
375
|
+
] })
|
|
376
|
+
] });
|
|
377
|
+
}
|
|
378
|
+
function RechargeMethods({
|
|
379
|
+
refreshBalance,
|
|
380
|
+
channel,
|
|
381
|
+
returnUrl,
|
|
382
|
+
cancelUrl,
|
|
383
|
+
openExternalUrl,
|
|
384
|
+
onTopupCompleted
|
|
385
|
+
}) {
|
|
386
|
+
const [wiseOpen, setWiseOpen] = useState(false);
|
|
387
|
+
const t = useAixT();
|
|
388
|
+
const channels = [
|
|
389
|
+
{
|
|
390
|
+
key: "wechat",
|
|
391
|
+
label: t("recharge.wechat"),
|
|
392
|
+
icon: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", className: "h-5 w-5 fill-current", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.295.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-3.898-6.348-7.601-6.348zM5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178 1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18zm5.34 2.867c-1.797-.052-3.746.512-5.28 1.786-1.72 1.428-2.687 3.72-1.78 6.22.942 2.453 3.666 4.229 6.884 4.229.826 0 1.622-.12 2.361-.336a.722.722 0 0 1 .598.082l1.584.926a.272.272 0 0 0 .14.047c.134 0 .24-.111.24-.247 0-.06-.023-.12-.038-.177l-.327-1.233a.582.582 0 0 1-.023-.156.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-7.063-6.122zm-3.494 3.096c.529 0 .957.44.957.983a.97.97 0 0 1-.957.981.97.97 0 0 1-.957-.981c0-.544.429-.983.957-.983zm4.976 0c.529 0 .957.44.957.983a.97.97 0 0 1-.957.981.97.97 0 0 1-.957-.981c0-.544.428-.983.957-.983z" }) }),
|
|
393
|
+
color: "text-green-500",
|
|
394
|
+
bg: "bg-green-500/10"
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
key: "alipay",
|
|
398
|
+
label: t("recharge.alipay"),
|
|
399
|
+
icon: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", className: "h-5 w-5 fill-current", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M21.422 15.358c-3.83-1.153-6.055-1.84-6.055-1.84s1.485-3.37 1.822-5.51H13.5V6.85h4.5V5.768H13.5V3h-2.723v2.768H6.234v1.082h4.543v1.158H7.09v1.056h8.35c-.217 1.115-.672 2.514-1.207 3.528-1.983-.53-4.084-.946-5.873-.622-3.586.646-4.783 3.204-4.5 5.084.295 1.95 2.156 3.603 5.019 3.603 2.85 0 5.535-1.61 7.534-4.477 1.91.853 4.286 1.805 6.586 2.56L24 16.74c0-.001-.887-.864-2.578-1.382zm-12.27 2.936c-2.064 0-3.357-1.025-3.52-2.137-.186-1.25.814-2.477 2.658-2.797 1.016-.18 2.357.04 3.82.59-1.366 2.78-2.91 4.344-4.958 4.344z" }) }),
|
|
400
|
+
color: "text-blue-500",
|
|
401
|
+
bg: "bg-blue-500/10"
|
|
402
|
+
}
|
|
403
|
+
];
|
|
404
|
+
return /* @__PURE__ */ jsxs("section", { children: [
|
|
405
|
+
/* @__PURE__ */ jsx("h3", { className: "mb-1 text-xs font-semibold text-foreground", children: t("recharge.methods") }),
|
|
406
|
+
/* @__PURE__ */ jsx("p", { className: "mb-3 text-xs text-muted-foreground", children: t("recharge.desc") }),
|
|
407
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-3 rounded-lg border border-border p-3", children: [
|
|
408
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center gap-2", children: [
|
|
409
|
+
/* @__PURE__ */ jsx(CreditCard, { className: "h-4 w-4 text-primary" }),
|
|
410
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-foreground", children: t("stripe.title") })
|
|
411
|
+
] }),
|
|
412
|
+
/* @__PURE__ */ jsx(
|
|
413
|
+
StripeTopupPanel,
|
|
414
|
+
{
|
|
415
|
+
refreshBalance,
|
|
416
|
+
channel,
|
|
417
|
+
returnUrl,
|
|
418
|
+
cancelUrl,
|
|
419
|
+
openExternalUrl,
|
|
420
|
+
onTopupCompleted
|
|
421
|
+
}
|
|
422
|
+
)
|
|
423
|
+
] }),
|
|
424
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "secondary", className: "mb-2 min-h-11", "aria-expanded": wiseOpen, onClick: () => setWiseOpen(!wiseOpen), children: t("wise.title") }),
|
|
425
|
+
wiseOpen && /* @__PURE__ */ jsx(WiseOrdersPanel, { refreshBalance, channel }),
|
|
426
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-2 sm:grid-cols-2", children: [
|
|
427
|
+
channels.map((ch) => /* @__PURE__ */ jsxs(
|
|
428
|
+
"div",
|
|
429
|
+
{
|
|
430
|
+
className: "flex cursor-default items-center gap-2.5 rounded-md border border-border px-3 py-2.5 transition-colors hover:bg-secondary/40",
|
|
431
|
+
title: t("recharge.comingSoon"),
|
|
432
|
+
children: [
|
|
433
|
+
/* @__PURE__ */ jsx("span", { className: cn("flex h-8 w-8 shrink-0 items-center justify-center rounded-full", ch.bg, ch.color), children: ch.icon }),
|
|
434
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
435
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-foreground", children: ch.label }),
|
|
436
|
+
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: t("recharge.comingSoon") })
|
|
437
|
+
] })
|
|
438
|
+
]
|
|
439
|
+
},
|
|
440
|
+
ch.key
|
|
441
|
+
)),
|
|
442
|
+
/* @__PURE__ */ jsxs("div", { className: "flex cursor-default items-center gap-2.5 rounded-md border border-border px-3 py-2.5 transition-colors hover:bg-secondary/40", children: [
|
|
443
|
+
/* @__PURE__ */ jsx("span", { className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-muted/40 text-muted-foreground", children: /* @__PURE__ */ jsx(HeadphonesIcon, { className: "h-4 w-4" }) }),
|
|
444
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
445
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-foreground", children: t("recharge.contact") }),
|
|
446
|
+
/* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground", children: t("recharge.contactDesc") })
|
|
447
|
+
] })
|
|
448
|
+
] })
|
|
449
|
+
] })
|
|
450
|
+
] });
|
|
451
|
+
}
|
|
452
|
+
function RechargeDrawer({
|
|
453
|
+
open,
|
|
454
|
+
onClose,
|
|
455
|
+
channel,
|
|
456
|
+
returnUrl,
|
|
457
|
+
cancelUrl,
|
|
458
|
+
openExternalUrl,
|
|
459
|
+
onTopupCompleted
|
|
460
|
+
}) {
|
|
461
|
+
const t = useAixT();
|
|
462
|
+
const { data: balance, loading, refetch: refresh } = useBilling();
|
|
463
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
464
|
+
/* @__PURE__ */ jsx(
|
|
465
|
+
"div",
|
|
466
|
+
{
|
|
467
|
+
className: cn(
|
|
468
|
+
"fixed inset-0 z-30 bg-black/40 transition-opacity duration-300",
|
|
469
|
+
open ? "opacity-100" : "pointer-events-none opacity-0"
|
|
470
|
+
),
|
|
471
|
+
onClick: onClose
|
|
472
|
+
}
|
|
473
|
+
),
|
|
474
|
+
/* @__PURE__ */ jsxs(
|
|
475
|
+
"div",
|
|
476
|
+
{
|
|
477
|
+
className: cn(
|
|
478
|
+
"fixed right-0 top-0 z-40 flex h-full w-full max-w-md flex-col border-l border-border bg-card transition-transform duration-300 ease-in-out",
|
|
479
|
+
open ? "translate-x-0" : "translate-x-full"
|
|
480
|
+
),
|
|
481
|
+
role: "dialog",
|
|
482
|
+
"aria-label": t("recharge.title"),
|
|
483
|
+
children: [
|
|
484
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-4 py-3", children: [
|
|
485
|
+
/* @__PURE__ */ jsxs("h2", { className: "flex items-center gap-2 text-body-md font-semibold text-foreground", children: [
|
|
486
|
+
/* @__PURE__ */ jsx(Wallet, { className: "h-4 w-4" }),
|
|
487
|
+
t("recharge.title")
|
|
488
|
+
] }),
|
|
489
|
+
/* @__PURE__ */ jsx(
|
|
490
|
+
"button",
|
|
491
|
+
{
|
|
492
|
+
type: "button",
|
|
493
|
+
"aria-label": t("common.close"),
|
|
494
|
+
onClick: onClose,
|
|
495
|
+
className: "rounded p-1 text-muted-foreground hover:bg-secondary hover:text-foreground",
|
|
496
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
|
|
497
|
+
}
|
|
498
|
+
)
|
|
499
|
+
] }),
|
|
500
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-4 overflow-y-auto p-4", children: [
|
|
501
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-lg border border-border bg-card p-4", children: [
|
|
502
|
+
/* @__PURE__ */ jsx("div", { className: "flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary", children: /* @__PURE__ */ jsx(Wallet, { className: "h-5 w-5" }) }),
|
|
503
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
504
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("billing.balance") }),
|
|
505
|
+
/* @__PURE__ */ jsx("p", { className: "text-lg font-semibold text-foreground", children: balance ? `${balance.balance} ${balance.currency}` : loading ? t("billing.loading") : "\u2014" })
|
|
506
|
+
] })
|
|
507
|
+
] }),
|
|
508
|
+
/* @__PURE__ */ jsx(
|
|
509
|
+
RechargeMethods,
|
|
510
|
+
{
|
|
511
|
+
refreshBalance: refresh,
|
|
512
|
+
channel,
|
|
513
|
+
returnUrl,
|
|
514
|
+
cancelUrl,
|
|
515
|
+
openExternalUrl,
|
|
516
|
+
onTopupCompleted
|
|
517
|
+
},
|
|
518
|
+
String(open)
|
|
519
|
+
)
|
|
520
|
+
] })
|
|
521
|
+
]
|
|
522
|
+
}
|
|
523
|
+
)
|
|
524
|
+
] });
|
|
525
|
+
}
|
|
526
|
+
function BillingPage({
|
|
527
|
+
channel,
|
|
528
|
+
returnUrl,
|
|
529
|
+
cancelUrl,
|
|
530
|
+
openExternalUrl,
|
|
531
|
+
onTopupCompleted
|
|
532
|
+
} = {}) {
|
|
533
|
+
const t = useAixT();
|
|
534
|
+
const client = useClient();
|
|
535
|
+
const { data: balance, loading, error, refetch: refresh } = useBilling();
|
|
536
|
+
const [subs, setSubs] = useState([]);
|
|
537
|
+
const [charges, setCharges] = useState([]);
|
|
538
|
+
const [rechargeOpen, setRechargeOpen] = useState(false);
|
|
539
|
+
useEffect(() => {
|
|
540
|
+
let cancelled = false;
|
|
541
|
+
(async () => {
|
|
542
|
+
try {
|
|
543
|
+
const [s, c] = await Promise.all([
|
|
544
|
+
client.billing.subscriptions().catch(() => []),
|
|
545
|
+
client.billing.ownNodeCharges().catch(() => [])
|
|
546
|
+
]);
|
|
547
|
+
if (!cancelled) {
|
|
548
|
+
setSubs(s);
|
|
549
|
+
setCharges(c);
|
|
550
|
+
}
|
|
551
|
+
} catch {
|
|
552
|
+
}
|
|
553
|
+
})();
|
|
554
|
+
return () => {
|
|
555
|
+
cancelled = true;
|
|
556
|
+
};
|
|
557
|
+
}, [client]);
|
|
558
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col", children: [
|
|
559
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-3 py-2 sm:px-6", children: [
|
|
560
|
+
/* @__PURE__ */ jsx("h1", { className: "text-body-md font-semibold text-foreground", children: t("billing.title") }),
|
|
561
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
562
|
+
/* @__PURE__ */ jsxs(Button, { variant: "secondary", size: "sm", onClick: () => void refresh(), disabled: loading, children: [
|
|
563
|
+
/* @__PURE__ */ jsx(RefreshCw, { className: cn("h-3.5 w-3.5", loading && "animate-spin") }),
|
|
564
|
+
t("billing.refresh")
|
|
565
|
+
] }),
|
|
566
|
+
/* @__PURE__ */ jsxs(Button, { variant: "primary", size: "sm", onClick: () => setRechargeOpen(true), children: [
|
|
567
|
+
/* @__PURE__ */ jsx(Wallet, { className: "h-3.5 w-3.5" }),
|
|
568
|
+
t("recharge.title")
|
|
569
|
+
] })
|
|
570
|
+
] })
|
|
571
|
+
] }),
|
|
572
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 space-y-4 overflow-auto p-3 sm:p-6", children: [
|
|
573
|
+
error && /* @__PURE__ */ jsx("p", { className: "text-xs text-destructive", children: error.message }),
|
|
574
|
+
/* @__PURE__ */ jsx(LedgerSection, { rows: balance?.recent ?? [], loading, t }),
|
|
575
|
+
/* @__PURE__ */ jsx(SubsSection, { subs, t }),
|
|
576
|
+
/* @__PURE__ */ jsx(OwnNodeSection, { charges, t })
|
|
577
|
+
] }),
|
|
578
|
+
/* @__PURE__ */ jsx(
|
|
579
|
+
RechargeDrawer,
|
|
580
|
+
{
|
|
581
|
+
open: rechargeOpen,
|
|
582
|
+
onClose: () => setRechargeOpen(false),
|
|
583
|
+
channel,
|
|
584
|
+
returnUrl,
|
|
585
|
+
cancelUrl,
|
|
586
|
+
openExternalUrl,
|
|
587
|
+
onTopupCompleted
|
|
588
|
+
}
|
|
589
|
+
)
|
|
590
|
+
] });
|
|
591
|
+
}
|
|
592
|
+
function LedgerSection({ rows, loading, t }) {
|
|
593
|
+
return /* @__PURE__ */ jsxs("section", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: [
|
|
594
|
+
/* @__PURE__ */ jsx("h2", { className: "mb-2 text-xs font-semibold text-foreground", children: t("billing.ledger") }),
|
|
595
|
+
rows.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-6 text-center text-xs text-muted-foreground", children: loading ? t("common.loading") : t("billing.ledger.empty") }) : /* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-xs", children: [
|
|
596
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-border text-left text-muted-foreground", children: [
|
|
597
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 font-medium", children: t("billing.col.kind") }),
|
|
598
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.col.amount") }),
|
|
599
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.col.balanceAfter") }),
|
|
600
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 font-medium", children: t("billing.col.ref") }),
|
|
601
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 font-medium", children: t("billing.col.time") })
|
|
602
|
+
] }) }),
|
|
603
|
+
/* @__PURE__ */ jsx("tbody", { children: rows.map((r) => {
|
|
604
|
+
const meta = ledgerKindMeta(r.kind, Number(r.amount));
|
|
605
|
+
const Icon = meta.icon;
|
|
606
|
+
const credit = meta.sign === "credit";
|
|
607
|
+
return /* @__PURE__ */ jsxs("tr", { className: "border-b border-border/50", children: [
|
|
608
|
+
/* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2", children: /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1.5 text-foreground", children: [
|
|
609
|
+
/* @__PURE__ */ jsx(
|
|
610
|
+
Icon,
|
|
611
|
+
{
|
|
612
|
+
className: cn("h-3.5 w-3.5", credit ? "text-green-500" : "text-muted-foreground")
|
|
613
|
+
}
|
|
614
|
+
),
|
|
615
|
+
t(meta.i18nKey)
|
|
616
|
+
] }) }),
|
|
617
|
+
/* @__PURE__ */ jsxs(
|
|
618
|
+
"td",
|
|
619
|
+
{
|
|
620
|
+
className: cn(
|
|
621
|
+
"py-1.5 pr-2 text-right font-mono",
|
|
622
|
+
credit ? "text-green-500" : "text-destructive"
|
|
623
|
+
),
|
|
624
|
+
children: [
|
|
625
|
+
credit ? "+" : "-",
|
|
626
|
+
String(r.amount).replace(/^[-+]/, "")
|
|
627
|
+
]
|
|
628
|
+
}
|
|
629
|
+
),
|
|
630
|
+
/* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-right font-mono text-muted-foreground", children: String(r.balance_after) }),
|
|
631
|
+
/* @__PURE__ */ jsx("td", { className: "max-w-[12rem] truncate py-1.5 pr-2 text-muted-foreground", title: r.ref, children: r.ref }),
|
|
632
|
+
/* @__PURE__ */ jsx("td", { className: "py-1.5 text-muted-foreground", children: new Date(r.created_at).toLocaleString() })
|
|
633
|
+
] }, r.id);
|
|
634
|
+
}) })
|
|
635
|
+
] }) })
|
|
636
|
+
] });
|
|
637
|
+
}
|
|
638
|
+
function SubsSection({ subs, t }) {
|
|
639
|
+
return /* @__PURE__ */ jsxs("section", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: [
|
|
640
|
+
/* @__PURE__ */ jsx("h2", { className: "mb-2 text-xs font-semibold text-foreground", children: t("billing.subs") }),
|
|
641
|
+
subs.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-xs text-muted-foreground", children: t("billing.subs.empty") }) : /* @__PURE__ */ jsx("div", { className: "space-y-1.5", children: subs.map((s) => /* @__PURE__ */ jsxs(
|
|
642
|
+
"div",
|
|
643
|
+
{
|
|
644
|
+
className: "flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md border border-border/60 px-2.5 py-1.5 text-xs",
|
|
645
|
+
children: [
|
|
646
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: s.tier }),
|
|
647
|
+
/* @__PURE__ */ jsx(Badge, { variant: s.status === "active" ? "success" : "muted", children: s.status }),
|
|
648
|
+
s.remaining_hours != null && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
|
|
649
|
+
t("billing.subs.remaining"),
|
|
650
|
+
": ",
|
|
651
|
+
String(s.remaining_hours)
|
|
652
|
+
] }),
|
|
653
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
|
|
654
|
+
t("billing.subs.expires"),
|
|
655
|
+
": ",
|
|
656
|
+
new Date(s.expires_at).toLocaleDateString()
|
|
657
|
+
] }),
|
|
658
|
+
s.bound_device_id && /* @__PURE__ */ jsxs("span", { className: "truncate font-mono text-muted-foreground", title: s.bound_device_id, children: [
|
|
659
|
+
t("billing.subs.boundDevice"),
|
|
660
|
+
": ",
|
|
661
|
+
s.bound_device_id.slice(0, 8)
|
|
662
|
+
] })
|
|
663
|
+
]
|
|
664
|
+
},
|
|
665
|
+
s.id
|
|
666
|
+
)) })
|
|
667
|
+
] });
|
|
668
|
+
}
|
|
669
|
+
function OwnNodeSection({ charges, t }) {
|
|
670
|
+
return /* @__PURE__ */ jsxs("section", { className: "rounded-lg border border-border bg-card p-3 sm:p-4", children: [
|
|
671
|
+
/* @__PURE__ */ jsx("h2", { className: "mb-2 text-xs font-semibold text-foreground", children: t("billing.ownNode") }),
|
|
672
|
+
charges.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-4 text-center text-xs text-muted-foreground", children: t("billing.ownNode.empty") }) : /* @__PURE__ */ jsx("div", { className: "overflow-x-auto", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-xs", children: [
|
|
673
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b border-border text-left text-muted-foreground", children: [
|
|
674
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 font-medium", children: t("billing.ownNode.day") }),
|
|
675
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.ownNode.devices") }),
|
|
676
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 pr-2 text-right font-medium", children: t("billing.ownNode.billable") }),
|
|
677
|
+
/* @__PURE__ */ jsx("th", { className: "py-1.5 text-right font-medium", children: t("billing.ownNode.amount") })
|
|
678
|
+
] }) }),
|
|
679
|
+
/* @__PURE__ */ jsx("tbody", { children: charges.map((c) => /* @__PURE__ */ jsxs("tr", { className: "border-b border-border/50", children: [
|
|
680
|
+
/* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-foreground", children: c.day }),
|
|
681
|
+
/* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-right text-muted-foreground", children: c.device_count }),
|
|
682
|
+
/* @__PURE__ */ jsx("td", { className: "py-1.5 pr-2 text-right text-muted-foreground", children: c.billable }),
|
|
683
|
+
/* @__PURE__ */ jsxs("td", { className: "py-1.5 text-right font-mono text-foreground", children: [
|
|
684
|
+
String(c.amount),
|
|
685
|
+
" ",
|
|
686
|
+
c.currency
|
|
687
|
+
] })
|
|
688
|
+
] }, c.id)) })
|
|
689
|
+
] }) })
|
|
690
|
+
] });
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
export { BillingPage, RechargeDrawer, RechargeMethods, StripeTopupPanel, ledgerKindMeta };
|