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(desktop): 优化支付宝二维码展示 (#948)

GaoWei Liu0d3bd4673dcb
diff --git a/apps/desktop/src/renderer/features/billing/BillingCheckoutDialog.tsx b/apps/desktop/src/renderer/features/billing/BillingCheckoutDialog.tsx
index 3f44afb472..4406adca9b 100644
--- a/apps/desktop/src/renderer/features/billing/BillingCheckoutDialog.tsx
+++ b/apps/desktop/src/renderer/features/billing/BillingCheckoutDialog.tsx
@@ -4,6 +4,7 @@ import * as QRCode from 'qrcode';
import { Check, CircleAlert, ExternalLink, LoaderCircle, RotateCcw, X } from 'lucide-react';
import { useTranslation } from 'react-i18next';
+import cindyIconUrl from '@/../../resources/icon.png?url';
import { Spinner } from '@/components/ui/spinner';
import { cn } from '@/lib/utils';
import { billingApi } from './api';
@@ -49,7 +50,8 @@ export function BillingCheckoutDialog({
setQrDataUrl(null);
if (action?.type === 'QR_CODE') {
void QRCode.toDataURL(action.value, {
- width: 1024,
+ errorCorrectionLevel: 'H',
+ width: 320,
margin: 4,
})
.then((dataUrl) => {
@@ -180,14 +182,22 @@ export function BillingCheckoutDialog({
{state.phase === 'AWAITING_PAYMENT' && !actionExpired && action?.type === 'QR_CODE' && (
<>
<div
- className="grid place-items-center rounded-xl border border-[var(--border-default)] bg-white p-2"
+ className="relative grid place-items-center rounded-xl border border-[var(--border-default)] bg-white p-2"
style={{
- width: 'min(512px, calc(100vw - 96px), calc(100vh - 260px))',
- height: 'min(512px, calc(100vw - 96px), calc(100vh - 260px))',
+ width: 'min(280px, calc(100vw - 96px), calc(100vh - 260px))',
+ height: 'min(280px, calc(100vw - 96px), calc(100vh - 260px))',
}}
>
{qrDataUrl ? (
- <img src={qrDataUrl} className="size-full" alt={t('billing.checkout.qrAlt')} />
+ <>
+ <img src={qrDataUrl} className="size-full" alt={t('billing.checkout.qrAlt')} />
+ <span
+ aria-hidden="true"
+ className="pointer-events-none absolute grid size-10 place-items-center rounded-lg bg-white p-1"
+ >
+ <img src={cindyIconUrl} className="size-8 rounded-md" alt="" />
+ </span>
+ </>
) : (
<Spinner size={24} className="text-[var(--text-secondary)]" />
)}
diff --git a/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx b/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx
index 37cc8d8067..6105385d9b 100644
--- a/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx
+++ b/apps/desktop/src/renderer/features/billing/PlanChangeDialog.tsx
@@ -14,6 +14,7 @@ import {
} from 'lucide-react';
import { useTranslation } from 'react-i18next';
+import cindyIconUrl from '@/../../resources/icon.png?url';
import { Spinner } from '@/components/ui/spinner';
import { cn } from '@/lib/utils';
import type {
@@ -257,7 +258,11 @@ export function PlanChangeStatusDialog({
let active = true;
setQrDataUrl(null);
if (action?.type === 'QR_CODE') {
- void QRCode.toDataURL(action.value, { width: 1024, margin: 4 })
+ void QRCode.toDataURL(action.value, {
+ errorCorrectionLevel: 'H',
+ width: 320,
+ margin: 4,
+ })
.then((dataUrl) => {
if (active) setQrDataUrl(dataUrl);
})
@@ -411,14 +416,22 @@ export function PlanChangeStatusDialog({
{state.phase === 'AWAITING_PAYMENT' && action?.type === 'QR_CODE' && (
<>
<div
- className="grid place-items-center rounded-xl border border-[var(--border-default)] bg-white p-2"
+ className="relative grid place-items-center rounded-xl border border-[var(--border-default)] bg-white p-2"
style={{
- width: 'min(440px, calc(100vw - 96px), calc(100vh - 280px))',
- height: 'min(440px, calc(100vw - 96px), calc(100vh - 280px))',
+ width: 'min(280px, calc(100vw - 96px), calc(100vh - 280px))',
+ height: 'min(280px, calc(100vw - 96px), calc(100vh - 280px))',
}}
>
{qrDataUrl ? (
- <img src={qrDataUrl} className="size-full" alt={t('billing.checkout.qrAlt')} />
+ <>
+ <img src={qrDataUrl} className="size-full" alt={t('billing.checkout.qrAlt')} />
+ <span
+ aria-hidden="true"
+ className="pointer-events-none absolute grid size-10 place-items-center rounded-lg bg-white p-1"
+ >
+ <img src={cindyIconUrl} className="size-8 rounded-md" alt="" />
+ </span>
+ </>
) : (
<Spinner size={24} className="text-[var(--text-secondary)]" />
)}
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 cdeb2a3112..1908229bc9 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/BillingPage.test.tsx
@@ -76,6 +76,7 @@ vi.mock('qrcode', () => ({
}));
import { BillingPage } from '../BillingPage';
+import * as QRCode from 'qrcode';
beforeEach(() => {
uiMocks.confirm.mockReset().mockResolvedValue(false);
@@ -706,7 +707,12 @@ describe('BillingPage remote catalog rendering', () => {
const view = render(<BillingPage />);
// 服务端仍下发的动作以服务端为准展示,不用本地时钟提前藏码。
- expect(await screen.findByAltText('billing.checkout.qrAlt')).toBeTruthy();
+ const qrCode = await screen.findByAltText('billing.checkout.qrAlt');
+ expect(qrCode.parentElement?.querySelectorAll('img')).toHaveLength(2);
+ expect(vi.mocked(QRCode.toDataURL)).toHaveBeenCalledWith(
+ order.paymentAction.value,
+ expect.objectContaining({ errorCorrectionLevel: 'H', margin: 4, width: 320 }),
+ );
expect(screen.queryByText('billing.checkout.actionExpiredBody')).toBeNull();
// 服务端判定过期后轮询响应把动作置空:切换为过期提示,不再显示二维码。
diff --git a/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx b/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx
index 6135fc3124..29657cb057 100644
--- a/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx
+++ b/apps/desktop/src/renderer/features/billing/__tests__/PlanChangeDialog.test.tsx
@@ -15,6 +15,7 @@ vi.mock('qrcode', () => ({
}));
import { PlanChangeStatusDialog } from '../PlanChangeDialog';
+import * as QRCode from 'qrcode';
import type { PlanChangeState } from '../usePlanChange';
function quoteReadyState(overrides: Partial<PlanChangeState> = {}): PlanChangeState {
@@ -40,6 +41,36 @@ function quoteReadyState(overrides: Partial<PlanChangeState> = {}): PlanChangeSt
}
describe('PlanChangeStatusDialog stale snapshot handling', () => {
+ it('renders a logo QR code with high error correction while awaiting Alipay payment', async () => {
+ const paymentAction = {
+ type: 'QR_CODE' as const,
+ value: 'https://u.alipay.cn/fixture',
+ expiresAt: '2099-01-01T00:00:00.000Z',
+ };
+ const quoted = quoteReadyState().planChange!;
+ render(
+ <PlanChangeStatusDialog
+ state={quoteReadyState({
+ phase: 'AWAITING_PAYMENT',
+ planChange: { ...quoted, status: 'AWAITING_PAYMENT', paymentAction },
+ })}
+ targetName={null}
+ onClose={vi.fn()}
+ onConfirm={vi.fn()}
+ onRefresh={vi.fn()}
+ onReselect={vi.fn()}
+ onAbandon={vi.fn()}
+ />,
+ );
+
+ const qrCode = await screen.findByAltText('billing.checkout.qrAlt');
+ expect(qrCode.parentElement?.querySelectorAll('img')).toHaveLength(2);
+ expect(vi.mocked(QRCode.toDataURL)).toHaveBeenCalledWith(
+ paymentAction.value,
+ expect.objectContaining({ errorCorrectionLevel: 'H', margin: 4, width: 320 }),
+ );
+ });
+
it('lets a fresh quote be confirmed or abandoned', () => {
render(
<PlanChangeStatusDialog
diff --git a/apps/desktop/src/renderer/types/qrcode.d.ts b/apps/desktop/src/renderer/types/qrcode.d.ts
index 5d588b5c57..63e31e5fe6 100644
--- a/apps/desktop/src/renderer/types/qrcode.d.ts
+++ b/apps/desktop/src/renderer/types/qrcode.d.ts
@@ -1,5 +1,6 @@
declare module 'qrcode' {
interface QRCodeOptions {
+ errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H';
margin?: number;
width?: number;
color?: {
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 2fbfc25988..c9a58999f1 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -678,6 +678,13 @@ The splash wordmark is a separate asset pair (`assets/splash/wordmark.png`, whit
- **Scope boundary**: this dialog only. Other working-UI surfaces keep the neutral treatment; a new brand surface needs a new entry here. Contract test: `mobileDownloadDialog.test.tsx` → `keeps the QR card flat with no brand edge`.
- **Reference renders** (light theme, zh-CN, @2x — `assets/mobile-download-dialog/`): [local mode](assets/mobile-download-dialog/guest-local.webp) (QR only — no account, so no permission card) · [signed in, no linked mobile](assets/mobile-download-dialog/onboarding.webp) (228px QR + permission card) · [signed in, mobile linked](assets/mobile-download-dialog/linked.webp) (132px QR + device list). Re-shoot these when the dialog's layout changes. **Stale as of 2026-07-25**: all three still show the retired brand edge around the QR — read them for layout only, not for the card's treatment.
+**Sanctioned brand surface — Alipay payment QR (approved 2026-07-29).**
+
+- **Where**: `features/billing/BillingCheckoutDialog.tsx` and `PlanChangeDialog.tsx` (`PlanChangeStatusDialog`) only. The 40px white center plate may show the 32px official `resources/icon.png` only after a QR payment payload successfully encodes at H error correction.
+- **Payload / rollout**: this surface accepts only the server-issued Alipay short link. Desktop rollout is gated on the server being fully deployed and all pre-deployment QR actions having exceeded their 5-minute TTL; do not add a legacy long-Scheme or lower-error-correction fallback.
+- **Constraints**: the white QR background is a scanner-contrast requirement, not a general brand panel. Do not add a border, edge, shadow, motion or other decoration to the code.
+- **Scope boundary**: this approval covers the current Alipay QR payment paths only. `BillingPaymentAction` currently does not carry a provider; any future non-Alipay `QR_CODE` channel must first add provider-aware rendering rather than inheriting this mark by default.
+
### 15.8 status-badge-fg
- The orange badge (bg `status-bar-accent` `#EA6B17`) has its own foreground token `status-badge-fg`: **default mirrors `accent-pure-cta-fg`** (light white / dark black — zero change for the 9 existing themes); **CINDY overrides both modes to `#1F1F1F`** (near-black), contrast × `#EA6B17` = **5.19:1 ≥ 4.5** (user-approved; darken toward `#000000` if a future orange fails 4.5).