Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(billing): 支持脱敏展示和复制订单 ID
liugaoweib4927e05baa8
diff --git a/apps/desktop/src/renderer/features/billing/BillingPage.tsx b/apps/desktop/src/renderer/features/billing/BillingPage.tsxindex fc90d9d4ef..1126c0197c 100644--- a/apps/desktop/src/renderer/features/billing/BillingPage.tsx+++ b/apps/desktop/src/renderer/features/billing/BillingPage.tsx@@ -7,6 +7,7 @@ import {ChevronRight,ChevronUp,CircleDollarSign,+ Copy,CreditCard,ExternalLink,PackageOpen,@@ -141,12 +142,11 @@ function isAwaitingPaymentOrder(order: BillingPaymentOrder): boolean {return phaseForOrder(order) === 'AWAITING_PAYMENT';}-/**- * 订单号在界面上只做「认得出是哪一单」用,全长展示会把左列挤没 —— 截断展示、完整值- * 挂 title。截断取头部:服务端订单号带随机前缀,头 8 位已足够区分。- */-function shortOrderId(orderId: string): string {- return orderId.length > 8 ? orderId.slice(0, 8) : orderId;+/** 订单号展示保留首尾用于对单,中段固定脱敏;复制仍使用服务端返回的完整原值。 */+function maskedOrderId(orderId: string): string {+ const visibleEdgeLength = 8;+ if (orderId.length <= visibleEdgeLength * 2) return orderId;+ return `${orderId.slice(0, visibleEdgeLength)}****${orderId.slice(-visibleEdgeLength)}`;}function decimalParts(value: string): { value: bigint; scale: number } | null {@@ -1752,6 +1752,14 @@ function OrderHistoryCard({}) {const { t, i18n } = useTranslation();const billingLocale = i18n.resolvedLanguage ?? i18n.language;+ const copyOrderId = async (orderId: string) => {+ try {+ await navigator.clipboard.writeText(orderId);+ toast.success(t('billing.orders.copy.success'));+ } catch {+ toast.error(t('billing.orders.copy.failed'));+ }+ };/*** 支付方式只有在服务端还带着本单的支付动作时才知道 —— 订单投影(shared/billing.ts 的* BillingPaymentOrder)里没有收单渠道字段,终态订单通常也不再带 paymentAction。整批都@@ -1788,13 +1796,23 @@ function OrderHistoryCard({<p className="truncate text-12 font-medium tabular-nums text-[var(--text-primary)]">{formatLedgerTimestamp(order.createdAt, billingLocale)}</p>- {/* 订单号只用来对单,截断展示、完整值挂 title(客服场景要能复制全长)。 */}- <p- title={order.orderId}- className="mt-1 truncate font-mono text-10 text-[var(--text-tertiary)]"+ {/* 可见值只露首尾;整块按钮含 Copy 图标,点击任一位置都复制完整订单号。 */}+ <button+ type="button"+ onClick={() => void copyOrderId(order.orderId)}+ aria-label={t('billing.orders.copy.action')}+ className={cn(+ '-ml-1.5 mt-0.5 inline-flex cursor-pointer select-none items-center gap-1 rounded-full px-1.5 py-0.5 text-left',+ 'font-mono text-10 text-[var(--text-tertiary)] transition-colors',+ 'hover:bg-[var(--surface-hover-soft)] hover:text-[var(--text-secondary)]',+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring-soft)]',+ )}>- {t('billing.orders.orderId', { id: shortOrderId(order.orderId) })}- </p>+ <span className="whitespace-nowrap">+ {t('billing.orders.orderId', { id: maskedOrderId(order.orderId) })}+ </span>+ <Copy aria-hidden="true" size={11} className="shrink-0" />+ </button></div><p className="min-w-0 truncate text-right text-12 font-medium tabular-nums text-[var(--text-primary)]">{formatMoney(order.amount, order.currency, billingLocale)}diff --git a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsxindex e4accaf279..10fd6739e4 100644--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx@@ -14,6 +14,7 @@ const i18n = {};const uiMocks = vi.hoisted(() => ({+ clipboardWriteText: vi.fn(),confirm: vi.fn(),toastError: vi.fn(),toastSuccess: vi.fn(),@@ -103,6 +104,11 @@ import { BillingPage } from '../BillingPage';import * as QRCode from 'qrcode';beforeEach(() => {+ Object.defineProperty(navigator, 'clipboard', {+ configurable: true,+ value: { writeText: uiMocks.clipboardWriteText },+ });+ uiMocks.clipboardWriteText.mockReset().mockResolvedValue(undefined);uiMocks.confirm.mockReset().mockResolvedValue(false);uiMocks.toastError.mockReset();uiMocks.toastSuccess.mockReset();@@ -2772,24 +2778,67 @@ describe('BillingPage order history', () => {return listOrders;};- it('lists the most recent orders with amount, id and status', async () => {- install([order()]);+ it('lists the most recent orders with amount, masked id and status', async () => {+ const fullOrderId = 'c2309a98-d776-4ad9-99b3-418951f13c7f';+ install([order({ orderId: fullOrderId })]);render(<BillingPage />);expect(await screen.findByText('billing.orders.title')).toBeTruthy();expect(screen.getByText('billing.orders.count:{"count":1}')).toBeTruthy();expect(screen.getByText('billing.orders.description')).toBeTruthy();- // 订单号截断展示、完整值挂 title(客服场景要能复制全长)。- expect(screen.getByText('billing.orders.orderId:{"id":"ord_8f21"}').title).toBe(- 'ord_8f21c4de9a',- );+ // 展示首尾并固定脱敏中段,不把完整订单号写进可见文本或原生 title。+ const orderIdButton = screen.getByRole('button', { name: 'billing.orders.copy.action' });expect(- screen.getByText(new Intl.NumberFormat('en', { style: 'currency', currency: 'CNY' }).format(33)),+ within(orderIdButton).getByText('billing.orders.orderId:{"id":"c2309a98****51f13c7f"}'),+ ).toBeTruthy();+ expect(orderIdButton.getAttribute('title')).toBeNull();+ expect(screen.queryByText(`billing.orders.orderId:{"id":"${fullOrderId}"}`)).toBeNull();+ expect(orderIdButton.querySelector('svg')).toBeTruthy();+ expect(+ screen.getByText(+ new Intl.NumberFormat('en', { style: 'currency', currency: 'CNY' }).format(33),+ ),).toBeTruthy();expect(screen.getByText('billing.orders.states.completed')).toBeTruthy();});+ it('copies the complete order id from both the id text and copy icon', async () => {+ const fullOrderId = 'c2309a98-d776-4ad9-99b3-418951f13c7f';+ install([order({ orderId: fullOrderId })]);++ render(<BillingPage />);++ const orderIdButton = await screen.findByRole('button', {+ name: 'billing.orders.copy.action',+ });+ const maskedText = within(orderIdButton).getByText(+ 'billing.orders.orderId:{"id":"c2309a98****51f13c7f"}',+ );+ const copyIcon = orderIdButton.querySelector('svg');+ expect(copyIcon).toBeTruthy();++ fireEvent.click(maskedText);+ await waitFor(() => expect(uiMocks.clipboardWriteText).toHaveBeenCalledWith(fullOrderId));+ expect(uiMocks.toastSuccess).toHaveBeenCalledWith('billing.orders.copy.success');++ uiMocks.clipboardWriteText.mockClear();+ fireEvent.click(copyIcon!);+ await waitFor(() => expect(uiMocks.clipboardWriteText).toHaveBeenCalledWith(fullOrderId));+ });++ it('explains how to recover when copying an order id fails', async () => {+ uiMocks.clipboardWriteText.mockRejectedValueOnce(new Error('clipboard denied'));+ install([order()]);++ render(<BillingPage />);+ fireEvent.click(await screen.findByRole('button', { name: 'billing.orders.copy.action' }));++ await waitFor(() =>+ expect(uiMocks.toastError).toHaveBeenCalledWith('billing.orders.copy.failed'),+ );+ });+it('asks the server for exactly the ten most recent orders', async () => {const listOrders = install([order()]);diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 3a4341e1bc..970de87635 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -10670,6 +10670,11 @@"count": "{{count}} orders","incomplete": "There are many order records. Only the latest {{count}} are shown.","orderId": "NO. {{id}}",+ "copy": {+ "action": "Copy Order ID",+ "success": "Order ID copied",+ "failed": "Order ID wasn’t copied — try again"+ },"states": {"completed": "Completed","awaitingPayment": "Awaiting payment",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex d4acd6d1bc..f48ff009ba 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -10656,6 +10656,11 @@"count": "{{count}}件","incomplete": "注文履歴が多いため、最新の{{count}}件のみ表示しています。","orderId": "NO. {{id}}",+ "copy": {+ "action": "注文 ID をコピー",+ "success": "注文 ID をコピーしました",+ "failed": "注文 ID をコピーできませんでした。もう一度お試しください。"+ },"states": {"completed": "完了","awaitingPayment": "支払い待ち",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 8c7f860132..6373ade023 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -10656,6 +10656,11 @@"count": "{{count}}건","incomplete": "주문 내역이 많아 최근 {{count}}건만 표시합니다.","orderId": "NO. {{id}}",+ "copy": {+ "action": "주문 ID 복사",+ "success": "주문 ID를 복사했습니다",+ "failed": "주문 ID를 복사하지 못했습니다. 다시 시도해 주세요."+ },"states": {"completed": "완료","awaitingPayment": "결제 대기",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 337a19b9bc..df55d6b4bf 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -10648,6 +10648,11 @@"count": "{{count}} 笔","incomplete": "订单记录较多,当前仅显示最近的 {{count}} 笔。","orderId": "NO. {{id}}",+ "copy": {+ "action": "复制订单 ID",+ "success": "订单 ID 已复制",+ "failed": "复制订单 ID 失败,请重试"+ },"states": {"completed": "已完成","awaitingPayment": "待支付",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 5780c71dd7..35d09857a2 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -10648,6 +10648,11 @@"count": "{{count}} 筆","incomplete": "訂單記錄較多,當前僅顯示最近的 {{count}} 筆。","orderId": "NO. {{id}}",+ "copy": {+ "action": "複製訂單 ID",+ "success": "訂單 ID 已複製",+ "failed": "複製訂單 ID 失敗,請再試一次"+ },"states": {"completed": "已完成","awaitingPayment": "待支付",