complete store refactor; moved form inputs into store; refactored components out of TimedOrderEntry
This commit is contained in:
21
src/misc.js
21
src/misc.js
@@ -58,3 +58,24 @@ export function routeInverted(route) {
|
||||
const s = useStore()
|
||||
return route && (route.token0 === s.tokenA) === s.inverted
|
||||
}
|
||||
|
||||
export function isEmpty(v) {
|
||||
return v === null || typeof v === 'string' && v.trim() === ''
|
||||
}
|
||||
|
||||
export function validateRequired(v) {
|
||||
if (isEmpty(v))
|
||||
return 'Required'
|
||||
return true
|
||||
}
|
||||
|
||||
export function validateAmount(v) {
|
||||
if (isEmpty(v))
|
||||
return true
|
||||
const floatRegex = /^-?\d*(?:[.,]\d*?)?$/
|
||||
if (!floatRegex.test(v))
|
||||
return 'Amount must be a number'
|
||||
if (parseFloat(v) <= 0)
|
||||
return 'Amount must be positive'
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user