Skip to content

Commit 2d71292

Browse files
committed
feat: add validation utilities
1 parent 1a617ef commit 2d71292

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/utils/validation.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function isValidAddress(address: string): boolean {
2+
return /^S[PM][0-9A-Z]{38,39}$/.test(address)
3+
}
4+
5+
export function isPositiveNumber(value: string): boolean {
6+
const n = parseFloat(value)
7+
return !isNaN(n) && n > 0
8+
}
9+
10+
export function isValidLockBlocks(blocks: number): boolean {
11+
return [0, 525, 1050, 2100].includes(blocks)
12+
}
13+
14+
export function validateStakeInput(amount: string, balance: number): string | null {
15+
if (!isPositiveNumber(amount)) return 'Enter a valid amount'
16+
if (parseFloat(amount) > balance) return 'Insufficient balance'
17+
return null
18+
}

0 commit comments

Comments
 (0)