11import { parseUnits , formatUnits } from 'viem' ;
2+
3+ import type { TimePeriod } from '../core/types' ;
24import {
35 convertReadableDateToTimestamp ,
46 getStartOfTodayUTC ,
57 TIME_PERIOD_TO_SECONDS ,
68} from '../utils/time' ;
7- import { TimePeriod } from '../core/types' ;
89
9- export interface ValidationErrors {
10+ export type ValidationErrors = {
1011 [ key : string ] : string ;
11- }
12+ } ;
1213
1314/**
14- * Validates and parses a token amount string to BigInt
15- * @param amount - The amount string to validate
16- * @param decimals - Token decimals
17- * @param fieldName - Name of the field for error messages
18- * @param allowZero - Whether zero values are allowed (default: false)
19- * @returns Object containing the parsed amount and any validation error
15+ * Validates and parses a token amount string to BigInt.
16+ * @param amount - The amount string to validate.
17+ * @param decimals - Token decimals.
18+ * @param fieldName - Name of the field for error messages.
19+ * @param allowZero - Whether zero values are allowed (default: false).
20+ * @returns Object containing the parsed amount and any validation error.
2021 */
2122export function validateAndParseAmount (
2223 amount : string | undefined ,
@@ -49,9 +50,9 @@ export function validateAndParseAmount(
4950}
5051
5152/**
52- * Validates a start time to ensure it's today or later
53- * @param startTime - The start time string to validate
54- * @returns Validation error message or undefined if valid
53+ * Validates a start time to ensure it's today or later.
54+ * @param startTime - The start time string to validate.
55+ * @returns Validation error message or undefined if valid.
5556 */
5657export function validateStartTime ( startTime : string ) : string | undefined {
5758 try {
@@ -66,9 +67,9 @@ export function validateStartTime(startTime: string): string | undefined {
6667}
6768
6869/**
69- * Validates an expiry time to ensure it's in the future
70- * @param expiry - The expiry time string to validate
71- * @returns Validation error message or undefined if valid
70+ * Validates an expiry time to ensure it's in the future.
71+ * @param expiry - The expiry time string to validate.
72+ * @returns Validation error message or undefined if valid.
7273 */
7374export function validateExpiry ( expiry : string ) : string | undefined {
7475 try {
@@ -84,10 +85,10 @@ export function validateExpiry(expiry: string): string | undefined {
8485}
8586
8687/**
87- * Validates that max amount is greater than initial amount
88- * @param maxAmount - The maximum amount as BigInt
89- * @param initialAmount - The initial amount as BigInt
90- * @returns Validation error message or undefined if valid
88+ * Validates that max amount is greater than initial amount.
89+ * @param maxAmount - The maximum amount as BigInt.
90+ * @param initialAmount - The initial amount as BigInt.
91+ * @returns Validation error message or undefined if valid.
9192 */
9293export function validateMaxAmountVsInitialAmount (
9394 maxAmount : bigint | undefined ,
@@ -104,11 +105,11 @@ export function validateMaxAmountVsInitialAmount(
104105}
105106
106107/**
107- * Calculates amount per second from amount per period
108- * @param amountPerPeriod - The amount per period as BigInt
109- * @param timePeriod - The time period
110- * @param decimals - Token decimals
111- * @returns Formatted amount per second string
108+ * Calculates amount per second from amount per period.
109+ * @param amountPerPeriod - The amount per period as BigInt.
110+ * @param timePeriod - The time period.
111+ * @param decimals - Token decimals.
112+ * @returns Formatted amount per second string.
112113 */
113114export function calculateAmountPerSecond (
114115 amountPerPeriod : bigint ,
@@ -122,9 +123,9 @@ export function calculateAmountPerSecond(
122123}
123124
124125/**
125- * Validates a period duration (for periodic permissions)
126- * @param periodDuration - The period duration string to validate
127- * @returns Object containing parsed duration and any validation error
126+ * Validates a period duration (for periodic permissions).
127+ * @param periodDuration - The period duration string to validate.
128+ * @returns Object containing parsed duration and any validation error.
128129 */
129130export function validatePeriodDuration ( periodDuration : string ) : {
130131 duration : number | undefined ;
0 commit comments