-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validations to the auction / marketplace
- Loading branch information
Samuel Sramko
committed
Sep 1, 2021
1 parent
e534a0d
commit a8e889b
Showing
10 changed files
with
91 additions
and
11 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
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
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 @@ | ||
import {BigNumber} from 'bignumber.js'; | ||
import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface} from 'class-validator'; | ||
|
||
@ValidatorConstraint({name: 'amountDecimalValidator', async: false}) | ||
export class AmountDecimalValidator implements ValidatorConstraintInterface { | ||
public defaultMessage(validationArguments?: ValidationArguments) { | ||
return 'amount can\'t have more then 0 decimals.'; | ||
} | ||
|
||
public validate(value: any, validationArguments?: ValidationArguments) { | ||
return new BigNumber(value.amount || 0).decimalPlaces() == 18; | ||
} | ||
|
||
} |
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,13 @@ | ||
import {BigNumber} from 'bignumber.js'; | ||
import {buildMessage, ValidateBy, ValidationOptions} from 'class-validator'; | ||
|
||
export function HasDecimalPlaces(decimals: number, validationOptions?: ValidationOptions) { | ||
return ValidateBy({ | ||
name: 'hasDecimalPlaces', | ||
constraints: [decimals], | ||
validator: { | ||
validate: (value) => new BigNumber(value).decimalPlaces() <= decimals, | ||
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must have less than $constraint1 decimals', validationOptions), | ||
} | ||
}, validationOptions); | ||
} |
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,17 @@ | ||
import {BigNumber} from 'bignumber.js'; | ||
import {ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface} from 'class-validator'; | ||
|
||
@ValidatorConstraint({name: 'priceDecimalValidator', async: false}) | ||
export class PriceDecimalValidator implements ValidatorConstraintInterface { | ||
public defaultMessage(validationArguments?: ValidationArguments) { | ||
return 'price can\'t have more then 18 decimals.'; | ||
} | ||
|
||
public validate(value: any, validationArguments?: ValidationArguments) { | ||
if (value.erc20Address) { | ||
return new BigNumber(value.price || 0).decimalPlaces() <= 18; | ||
} | ||
return true; | ||
} | ||
|
||
} |
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