From 2d88e4a204a667d8158639043cf21ef55ddca1e4 Mon Sep 17 00:00:00 2001 From: JiaJun <2394389886@qq.com> Date: Fri, 10 Jul 2026 14:34:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(withdraw):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E6=8F=90=E7=8E=B0=E9=87=91=E9=A2=9D=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入舍入单位计算,避免小额差值导致的选项过多问题 - 实现最小最大钻石数量的舍入处理 - 重构快速提现金额生成算法,提高计算精度 - 使用索引映射方式重新实现金额选项生成 - 更新项目索引统计信息,反映代码结构变化 --- AGENTS.md | 2 +- CLAUDE.md | 2 +- src/hooks/use-withdraw-vm.ts | 30 +++++++++++++++++++++--------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 9da77e7..3f61447 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,7 @@ # GitNexus — Code Intelligence -This project is indexed by GitNexus as **36-character-flower** (3095 symbols, 6119 relationships, 264 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. +This project is indexed by GitNexus as **36-character-flower** (3365 symbols, 6609 relationships, 288 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. > If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first. diff --git a/CLAUDE.md b/CLAUDE.md index 9da77e7..3f61447 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,7 +1,7 @@ # GitNexus — Code Intelligence -This project is indexed by GitNexus as **36-character-flower** (3095 symbols, 6119 relationships, 264 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. +This project is indexed by GitNexus as **36-character-flower** (3365 symbols, 6609 relationships, 288 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. > If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first. diff --git a/src/hooks/use-withdraw-vm.ts b/src/hooks/use-withdraw-vm.ts index 9a73f1b..5a5e862 100644 --- a/src/hooks/use-withdraw-vm.ts +++ b/src/hooks/use-withdraw-vm.ts @@ -58,27 +58,39 @@ function getWithdrawDiamondBounds( function getQuickWithdrawAmounts(bounds: WithdrawDiamondBounds) { const { maximumDiamonds, minimumDiamonds } = bounds - const availableOptionCount = maximumDiamonds - minimumDiamonds + 1 + const roundingUnit = + 10 ** Math.max(0, Math.floor(Math.log10(maximumDiamonds)) - 1) + const roundedMinimumDiamonds = + Math.ceil(minimumDiamonds / roundingUnit) * roundingUnit + const roundedMaximumDiamonds = + Math.floor(maximumDiamonds / roundingUnit) * roundingUnit + + if (roundedMinimumDiamonds > roundedMaximumDiamonds) { + return [] + } + + const availableOptionCount = + (roundedMaximumDiamonds - roundedMinimumDiamonds) / roundingUnit + 1 if (availableOptionCount <= QUICK_WITHDRAW_OPTION_COUNT) { return Array.from( { length: availableOptionCount }, - (_, index) => minimumDiamonds + index, + (_, index) => roundedMinimumDiamonds + index * roundingUnit, ) } - const amounts = new Set([minimumDiamonds, maximumDiamonds]) - const span = maximumDiamonds - minimumDiamonds + const lastOptionIndex = availableOptionCount - 1 + const optionIndexes = new Set([0, lastOptionIndex]) for (let index = 1; index < QUICK_WITHDRAW_OPTION_COUNT - 1; index += 1) { - amounts.add( - Math.round( - minimumDiamonds + (span * index) / (QUICK_WITHDRAW_OPTION_COUNT - 1), - ), + optionIndexes.add( + Math.round((lastOptionIndex * index) / (QUICK_WITHDRAW_OPTION_COUNT - 1)), ) } - return [...amounts].sort((left, right) => left - right) + return [...optionIndexes] + .sort((left, right) => left - right) + .map((index) => roundedMinimumDiamonds + index * roundingUnit) } function getCurrencyExchangeRate(