Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(billing): 完善订单 ID 复制交互

liugaowei8e7391e89f1c
diff --git a/apps/desktop/src/renderer/features/billing/BillingPage.tsx b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
index 1126c0197c..c93dd4c462 100644
--- a/apps/desktop/src/renderer/features/billing/BillingPage.tsx
+++ b/apps/desktop/src/renderer/features/billing/BillingPage.tsx
@@ -144,8 +144,8 @@ function isAwaitingPaymentOrder(order: BillingPaymentOrder): boolean {
/** 订单号展示保留首尾用于对单,中段固定脱敏;复制仍使用服务端返回的完整原值。 */
function maskedOrderId(orderId: string): string {
- const visibleEdgeLength = 8;
- if (orderId.length <= visibleEdgeLength * 2) return orderId;
+ if (orderId.length <= 2) return '*'.repeat(orderId.length);
+ const visibleEdgeLength = Math.min(8, Math.floor((orderId.length - 1) / 2));
return `${orderId.slice(0, visibleEdgeLength)}****${orderId.slice(-visibleEdgeLength)}`;
}
@@ -1800,15 +1800,17 @@ function OrderHistoryCard({
<button
type="button"
onClick={() => void copyOrderId(order.orderId)}
- aria-label={t('billing.orders.copy.action')}
+ aria-label={t('billing.orders.copy.action', {
+ id: maskedOrderId(order.orderId),
+ })}
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',
+ '-ml-1.5 mt-0.5 inline-flex max-w-full 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)]',
)}
>
- <span className="whitespace-nowrap">
+ <span className="min-w-0 break-all">
{t('billing.orders.orderId', { id: maskedOrderId(order.orderId) })}
</span>
<Copy aria-hidden="true" size={11} className="shrink-0" />
diff --git a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
index 10fd6739e4..f7108b89b8 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
@@ -2788,7 +2788,9 @@ describe('BillingPage order history', () => {
expect(screen.getByText('billing.orders.count:{"count":1}')).toBeTruthy();
expect(screen.getByText('billing.orders.description')).toBeTruthy();
// 展示首尾并固定脱敏中段,不把完整订单号写进可见文本或原生 title。
- const orderIdButton = screen.getByRole('button', { name: 'billing.orders.copy.action' });
+ const orderIdButton = screen.getByRole('button', {
+ name: 'billing.orders.copy.action:{"id":"c2309a98****51f13c7f"}',
+ });
expect(
within(orderIdButton).getByText('billing.orders.orderId:{"id":"c2309a98****51f13c7f"}'),
).toBeTruthy();
@@ -2810,7 +2812,7 @@ describe('BillingPage order history', () => {
render(<BillingPage />);
const orderIdButton = await screen.findByRole('button', {
- name: 'billing.orders.copy.action',
+ name: 'billing.orders.copy.action:{"id":"c2309a98****51f13c7f"}',
});
const maskedText = within(orderIdButton).getByText(
'billing.orders.orderId:{"id":"c2309a98****51f13c7f"}',
@@ -2827,12 +2829,38 @@ describe('BillingPage order history', () => {
await waitFor(() => expect(uiMocks.clipboardWriteText).toHaveBeenCalledWith(fullOrderId));
});
+ it('masks short ids, distinguishes copy targets and keeps the control shrinkable', async () => {
+ const shortOrderId = 'ord_8f21c4de9a';
+ const otherOrderId = '1234567890abcdefghi';
+ install([order({ orderId: shortOrderId }), order({ orderId: otherOrderId })]);
+
+ render(<BillingPage />);
+
+ const shortOrderButton = await screen.findByRole('button', {
+ name: 'billing.orders.copy.action:{"id":"ord_8f****c4de9a"}',
+ });
+ expect(
+ within(shortOrderButton).getByText('billing.orders.orderId:{"id":"ord_8f****c4de9a"}'),
+ ).toBeTruthy();
+ expect(
+ screen.getByRole('button', {
+ name: 'billing.orders.copy.action:{"id":"12345678****bcdefghi"}',
+ }),
+ ).toBeTruthy();
+ expect(shortOrderButton.className).toContain('max-w-full');
+ expect(shortOrderButton.querySelector('span')?.className).toContain('break-all');
+ });
+
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' }));
+ fireEvent.click(
+ await screen.findByRole('button', {
+ name: 'billing.orders.copy.action:{"id":"ord_8f****c4de9a"}',
+ }),
+ );
await waitFor(() =>
expect(uiMocks.toastError).toHaveBeenCalledWith('billing.orders.copy.failed'),
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 970de87635..048705a93a 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -10671,7 +10671,7 @@
"incomplete": "There are many order records. Only the latest {{count}} are shown.",
"orderId": "NO. {{id}}",
"copy": {
- "action": "Copy Order ID",
+ "action": "Copy Order ID {{id}}",
"success": "Order ID copied",
"failed": "Order ID wasn’t copied — try again"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index f48ff009ba..52acc3f6a6 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -10657,7 +10657,7 @@
"incomplete": "注文履歴が多いため、最新の{{count}}件のみ表示しています。",
"orderId": "NO. {{id}}",
"copy": {
- "action": "注文 ID をコピー",
+ "action": "注文 ID {{id}} をコピー",
"success": "注文 ID をコピーしました",
"failed": "注文 ID をコピーできませんでした。もう一度お試しください。"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 6373ade023..c616971be0 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -10657,7 +10657,7 @@
"incomplete": "주문 내역이 많아 최근 {{count}}건만 표시합니다.",
"orderId": "NO. {{id}}",
"copy": {
- "action": "주문 ID 복사",
+ "action": "주문 ID {{id}} 복사",
"success": "주문 ID를 복사했습니다",
"failed": "주문 ID를 복사하지 못했습니다. 다시 시도해 주세요."
},
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index df55d6b4bf..e29966097a 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -10649,7 +10649,7 @@
"incomplete": "订单记录较多,当前仅显示最近的 {{count}} 笔。",
"orderId": "NO. {{id}}",
"copy": {
- "action": "复制订单 ID",
+ "action": "复制订单 ID {{id}}",
"success": "订单 ID 已复制",
"failed": "复制订单 ID 失败,请重试"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 35d09857a2..28439fee0a 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -10649,7 +10649,7 @@
"incomplete": "訂單記錄較多,當前僅顯示最近的 {{count}} 筆。",
"orderId": "NO. {{id}}",
"copy": {
- "action": "複製訂單 ID",
+ "action": "複製訂單 ID {{id}}",
"success": "訂單 ID 已複製",
"failed": "複製訂單 ID 失敗,請再試一次"
},