-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: invalidation of negative amounts and too many decimal points (#135)
- Loading branch information
Showing
7 changed files
with
105 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import utils from '../../utils'; | ||
|
||
const {afterDecimal, isNegative, isZero} = utils.number; | ||
|
||
describe('afterDecimal', () => { | ||
it.only('should return number of decimals places', () => { | ||
expect(afterDecimal('')).toEqual(0); | ||
expect(afterDecimal(0)).toEqual(0); | ||
expect(afterDecimal('0')).toEqual(0); | ||
expect(afterDecimal(0.1)).toEqual(1); | ||
expect(afterDecimal('0.1')).toEqual(1); | ||
expect(afterDecimal(0.00001)).toEqual(5); | ||
expect(afterDecimal('0.00000001')).toEqual(8); | ||
}); | ||
}); | ||
|
||
describe('isZero', () => { | ||
it('should return true for zero numbers', () => { | ||
expect(isZero(0.0)).toBeTruthy(); | ||
expect(isZero(-0.0)).toBeTruthy(); | ||
expect(isZero(0)).toBeTruthy(); | ||
expect(isZero('0')).toBeTruthy(); | ||
expect(isZero(0.1)).toBeFalsy(); | ||
expect(isZero(0.000001)).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('isNegative', () => { | ||
it('should return true for negative numbers', () => { | ||
expect(isNegative(0)).toBeFalsy(); | ||
expect(isNegative(-1)).toBeTruthy(); | ||
expect(isNegative(-0.1)).toBeTruthy(); | ||
expect(isNegative('-0.1')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import utils from '../../../utils'; | ||
|
||
export const INSUFFICIENT_BALANCE_ERROR_MSG = utils.getTranslation( | ||
'menus.transfer.insufficient_balance_error_msg' | ||
); | ||
|
||
export const MAX_DEPOSIT_ERROR_MSG = utils.getTranslation('menus.transfer.max_deposit_error_msg'); | ||
export const { | ||
insufficient_balance_error_msg: INSUFFICIENT_BALANCE_ERROR_MSG, | ||
max_deposit_error_msg: MAX_DEPOSIT_ERROR_MSG, | ||
too_many_digits_error_msg: TOO_MANY_DIGITS_ERROR_MSG, | ||
negative_value_error_msg: NEGATIVE_VALUE_ERROR_MSG | ||
} = utils.getTranslation('menus.transfer'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const afterDecimal = num => { | ||
if (Number.isInteger(Number(num))) { | ||
return 0; | ||
} | ||
return num.toString().split('.')[1]?.length; | ||
}; | ||
|
||
export const isZero = num => { | ||
return Math.sign(num) === 0; | ||
}; | ||
|
||
export const isNegative = num => { | ||
return Math.sign(num) === -1; | ||
}; |