jean 1 月之前
父节点
当前提交
c38423bc9e
共有 1 个文件被更改,包括 11 次插入12 次删除
  1. 11 12
      code/src/utils/stakingDisplay.ts

+ 11 - 12
code/src/utils/stakingDisplay.ts

@@ -1,24 +1,23 @@
 import type { StakingConfig } from '@/api/staking'
 
-/** 锁定月数(按 30 天/月向上取整,至少 1) */
+const DAYS_PER_MONTH = 30
+
+/** 天数转展示月数(30 天/月截断取整,不足 1 个月显示 1) */
+export function daysToDisplayMonths(days: number): number {
+  return Math.max(1, Math.floor(days / DAYS_PER_MONTH))
+}
+
+/** 锁定月数(lockDays 为天数) */
 export function lockMonthsFromConfig(config: StakingConfig): number {
-  const days = config.lockDays ?? 0
-  return Math.max(1, Math.ceil(days / 30))
+  return daysToDisplayMonths(config.lockDays ?? 0)
 }
 
-/** 分批释放总月数;一次性释放返回 0 */
+/** 释放月数(releasePeriod 为天数);一次性释放返回 0 */
 export function releaseMonthsFromConfig(config: StakingConfig): number {
   if (config.releaseType !== 1) {
     return 0
   }
-  const rate = Number(config.releaseRate)
-  const periodDays = config.releasePeriod ?? 1
-  if (!rate || rate <= 0) {
-    return Math.max(1, Math.ceil(periodDays / 30))
-  }
-  const batches = Math.ceil(1 / rate)
-  const totalDays = batches * periodDays
-  return Math.max(1, Math.ceil(totalDays / 30))
+  return daysToDisplayMonths(config.releasePeriod ?? 0)
 }
 
 /** 预计开始释放时间 = 当前时间 + lockDays */