Skip to content

fix(web): require positive integers for recharge presets - #8495

Open
ningjiang233 wants to merge 1 commit into
QuantumNous:mainfrom
ningjiang233:fix/recharge-preset-integers
Open

ningjiang233 wants to merge 1 commit into
QuantumNous:mainfrom
ningjiang233:fix/recharge-preset-integers

Conversation

@ningjiang233

@ningjiang233 ningjiang233 commented Nov 28, 2026 •

Copy link
Copy Markdown

Agent: Codex unknown · gpt-6.2-sol · Windows desktop · 2026-11-28 UTC

Related: none

Request summary

修复管理员能在充值预设中添加小数档位的问题,使可视化编辑和 JSON 保存都符合现有后端配置类型。

本 PR 的代码与回归测试使用 AI 辅助编写。

Summary

两个编辑入口共用正安全整数校验,并在保存 payment_setting.amount_options 时将合法数值规范化为整数数组。

可视化编辑 → 添加档位时校验 ┐
                          ├→ [10,25,50] → PUT /api/option/
JSON 编辑  → 保存前逐项校验 ┘

Evidence

  • Before: 在官方 v1.0.0-rc.52(04dfcbb)打开 /system-settings/billing/payment,输入 12.5 后点击添加,可以得到 $12.5 档位。JSON 编辑器只检查顶层是否为数组,而后端将该配置声明为 []int。另一个回归用例确认,原有数组中的 null 会被显示为 $0。
  • After: 可视化编辑器通过按钮或回车均无法添加 12.5,仍可添加 25。原列表中的 null 不再显示为档位,有效档位保留。JSON 编辑器拒绝 [10,12.5],接受 [10,2.5e1,50] 并按 [10,25,50] 保存。
  • 浏览器复核使用包含此补丁的本地组合构建,Chrome 158.0.8127.37、浅色主题。非法数组产生 0 次配置写入,合法数组向本地配置接口写入 1 次,刷新后仍显示 $25。付款请求为 0。本改动仅影响管理员编辑预设档位,充值汇率、折扣与订单应付金额沿用原逻辑。

浏览器复核使用本地接口替身。组合构建的控制台记录了一次隔离策略拦截,未记录页面运行时异常。

Merge Danger

Door: two-way

Blast Radius: frontend

Summary by CodeRabbit

  • Bug Fixes
    • Recharge presets now accept only positive whole-number amounts, and fractional or invalid values can’t be added or saved.
    • Valid presets appear in numeric order without duplicates. Empty or null entries no longer appear as a $0 option or prevent other valid presets from displaying.
    • Valid numeric values, including values entered in exponent notation, are saved as canonical integers.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Recharge amount validation now accepts only positive safe integers. The visual editor filters and sorts valid presets. Payment settings rejects invalid JSON amount options and normalizes valid values before submission.

Changes

Recharge Amount Validation

Layer / File(s) Summary
Validate visual editor amounts
web/src/features/system-settings/integrations/recharge-amount.ts, web/src/features/system-settings/integrations/amount-options-visual-editor.tsx, web/src/features/system-settings/integrations/__tests__/amount-options-visual-editor.test.tsx
A shared type guard accepts positive safe integers. The visual editor filters, deduplicates, and sorts presets, and disables Add for invalid values. Tests cover fractional input and null placeholders.
Validate and save JSON amount options
web/src/features/system-settings/integrations/payment-settings-section.tsx, web/src/features/system-settings/integrations/__tests__/epay-sign-settings.test.tsx
Payment settings accepts JSON amount arrays only when every element is a positive safe integer. Submitted JSON is normalized. Tests cover rejected fractional values and canonicalized integer values.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: t0ng7u, calcium-ion

Merge Risk: Minimal · up to b8903

This change stops administrators from saving fractional recharge presets in either the visual or JSON editor, and it normalizes valid JSON values to integers. It has a narrow blast radius and tests for the changed behavior. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: recharge presets now require positive integers. The raw summary confirms that the visual editor, the JSON save path, and the new isPositiveRechargeAmount guard all enf…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: recharge presets now require positive integers. The raw summary confirms that the visual editor, the JSON save path, and the new isPositiveRechargeAmount guard all enforce this rule. The title uses the conventional fix(web) prefix and stays concise. The PR objectives describe the same goal of rejecting fractional presets in both editors.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each amount with care,
Fractions leave the list behind.
Whole numbers line up in order,
Safe and positive, neatly aligned.
“Presets saved!” the rabbit cheers,
Then hops away with sorted ears.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c3b1694a-6022-46ed-ad6d-c5f6d7fddf8e
Commits

Reviewing files that changed from the base of the PR and between 04dfcbb and b890338.

Files selected for processing: 5

  • web/src/features/system-settings/integrations/__tests__/amount-options-visual-editor.test.tsx
  • web/src/features/system-settings/integrations/__tests__/epay-sign-settings.test.tsx
  • web/src/features/system-settings/integrations/amount-options-visual-editor.tsx
  • web/src/features/system-settings/integrations/payment-settings-section.tsx
  • web/src/features/system-settings/integrations/recharge-amount.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant