use null check for missing fields

This commit is contained in:
Omar Khan
2022-08-18 23:11:24 -04:00
parent e64a668ef6
commit 35fef6512f
2 changed files with 11 additions and 11 deletions

View File

@@ -61,7 +61,7 @@ export interface AMMDeposit extends BaseTransaction {
export function validateAMMDeposit(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.AMMID === undefined) {
if (tx.AMMID == null) {
throw new ValidationError('AMMDeposit: missing field AMMID')
}
@@ -69,31 +69,31 @@ export function validateAMMDeposit(tx: Record<string, unknown>): void {
throw new ValidationError('AMMDeposit: AMMID must be a string')
}
if (tx.Asset2In !== undefined && tx.Asset1In === undefined) {
if (tx.Asset2In != null && tx.Asset1In == null) {
throw new ValidationError('AMMDeposit: must set Asset1In with Asset2In')
} else if (tx.EPrice !== undefined && tx.Asset1In === undefined) {
} else if (tx.EPrice != null && tx.Asset1In == null) {
throw new ValidationError('AMMDeposit: must set Asset1In with EPrice')
} else if (tx.LPToken === undefined && tx.Asset1In === undefined) {
} else if (tx.LPToken == null && tx.Asset1In == null) {
throw new ValidationError(
'AMMDeposit: must set either or both LPToken with Asset1In',
)
}
if (tx.LPToken !== undefined && !isIssuedCurrency(tx.LPToken)) {
if (tx.LPToken != null && !isIssuedCurrency(tx.LPToken)) {
throw new ValidationError(
'AMMDeposit: LPToken must be an IssuedCurrencyAmount',
)
}
if (tx.Asset1In !== undefined && !isAmount(tx.Asset1In)) {
if (tx.Asset1In != null && !isAmount(tx.Asset1In)) {
throw new ValidationError('AMMDeposit: Asset1In must be an Amount')
}
if (tx.Asset2In !== undefined && !isAmount(tx.Asset2In)) {
if (tx.Asset2In != null && !isAmount(tx.Asset2In)) {
throw new ValidationError('AMMDeposit: Asset2In must be an Amount')
}
if (tx.EPrice !== undefined && typeof tx.EPrice !== 'string') {
if (tx.EPrice != null && typeof tx.EPrice !== 'string') {
throw new ValidationError('AMMDeposit: EPrice must be a string')
}
}

View File

@@ -44,7 +44,7 @@ export interface AMMInstanceCreate extends BaseTransaction {
export function validateAMMInstanceCreate(tx: Record<string, unknown>): void {
validateBaseTransaction(tx)
if (tx.Asset1 === undefined) {
if (tx.Asset1 == null) {
throw new ValidationError('AMMInstanceCreate: missing field Asset1')
}
@@ -52,7 +52,7 @@ export function validateAMMInstanceCreate(tx: Record<string, unknown>): void {
throw new ValidationError('AMMInstanceCreate: Asset1 must be an Amount')
}
if (tx.Asset2 === undefined) {
if (tx.Asset2 == null) {
throw new ValidationError('AMMInstanceCreate: missing field Asset2')
}
@@ -60,7 +60,7 @@ export function validateAMMInstanceCreate(tx: Record<string, unknown>): void {
throw new ValidationError('AMMInstanceCreate: Asset2 must be an Amount')
}
if (tx.TradingFee === undefined) {
if (tx.TradingFee == null) {
throw new ValidationError('AMMInstanceCreate: missing field TradingFee')
}