refactor(withdraw): 优化快速提现金额计算逻辑
- 引入舍入单位计算,避免小额差值导致的选项过多问题 - 实现最小最大钻石数量的舍入处理 - 重构快速提现金额生成算法,提高计算精度 - 使用索引映射方式重新实现金额选项生成 - 更新项目索引统计信息,反映代码结构变化
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<!-- gitnexus:start -->
|
<!-- gitnexus:start -->
|
||||||
# GitNexus — Code Intelligence
|
# 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.
|
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!-- gitnexus:start -->
|
<!-- gitnexus:start -->
|
||||||
# GitNexus — Code Intelligence
|
# 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.
|
> If any GitNexus tool warns the index is stale, run `npx gitnexus analyze` in terminal first.
|
||||||
|
|
||||||
|
|||||||
@@ -58,27 +58,39 @@ function getWithdrawDiamondBounds(
|
|||||||
|
|
||||||
function getQuickWithdrawAmounts(bounds: WithdrawDiamondBounds) {
|
function getQuickWithdrawAmounts(bounds: WithdrawDiamondBounds) {
|
||||||
const { maximumDiamonds, minimumDiamonds } = bounds
|
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) {
|
if (availableOptionCount <= QUICK_WITHDRAW_OPTION_COUNT) {
|
||||||
return Array.from(
|
return Array.from(
|
||||||
{ length: availableOptionCount },
|
{ length: availableOptionCount },
|
||||||
(_, index) => minimumDiamonds + index,
|
(_, index) => roundedMinimumDiamonds + index * roundingUnit,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const amounts = new Set<number>([minimumDiamonds, maximumDiamonds])
|
const lastOptionIndex = availableOptionCount - 1
|
||||||
const span = maximumDiamonds - minimumDiamonds
|
const optionIndexes = new Set<number>([0, lastOptionIndex])
|
||||||
|
|
||||||
for (let index = 1; index < QUICK_WITHDRAW_OPTION_COUNT - 1; index += 1) {
|
for (let index = 1; index < QUICK_WITHDRAW_OPTION_COUNT - 1; index += 1) {
|
||||||
amounts.add(
|
optionIndexes.add(
|
||||||
Math.round(
|
Math.round((lastOptionIndex * index) / (QUICK_WITHDRAW_OPTION_COUNT - 1)),
|
||||||
minimumDiamonds + (span * 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(
|
function getCurrencyExchangeRate(
|
||||||
|
|||||||
Reference in New Issue
Block a user