2020-08-11 09:30:17 +02:00
|
|
|
import { Decimal } from 'decimal.js'
|
2020-05-07 08:03:30 +02:00
|
|
|
|
2021-10-13 18:48:59 +02:00
|
|
|
export function isValidNumber(value: any): boolean {
|
|
|
|
const isUndefinedValue = typeof value === 'undefined'
|
|
|
|
const isNullValue = value === null
|
|
|
|
const isNaNValue = isNaN(Number(value))
|
|
|
|
const isEmptyString = value === ''
|
|
|
|
|
|
|
|
return !isUndefinedValue && !isNullValue && !isNaNValue && !isEmptyString
|
|
|
|
}
|
|
|
|
|
2020-08-11 09:30:17 +02:00
|
|
|
// Run decimal.js comparison
|
|
|
|
// http://mikemcl.github.io/decimal.js/#cmp
|
2021-10-13 18:48:59 +02:00
|
|
|
export function compareAsBN(balance: string, price: string): boolean {
|
2020-08-11 09:30:17 +02:00
|
|
|
const aBN = new Decimal(balance)
|
|
|
|
const bBN = new Decimal(price)
|
|
|
|
const compare = aBN.comparedTo(bBN)
|
2020-05-07 08:03:30 +02:00
|
|
|
|
2020-08-11 09:30:17 +02:00
|
|
|
switch (compare) {
|
2021-08-11 11:45:05 +02:00
|
|
|
case 1: // balance is greater than price
|
|
|
|
case 0: // balance is equal to price
|
2020-08-11 09:30:17 +02:00
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2020-05-07 08:03:30 +02:00
|
|
|
}
|