Skip to content

Commit

Permalink
TransferRequiredInputTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Aug 29, 2024
1 parent 473f237 commit ef38a5a
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1008,28 +1008,29 @@ open class TradingStateMachine(
price = null, // priceOverwrite(markets),
configs = null, // This is used to get the IMF.. with "null" the default value 0.05 will be used
)
}
this.marketsSummary?.let { marketsSummary ->
val periods = if (this.input != null) {
setOf(
CalculationPeriod.current,
CalculationPeriod.post,
CalculationPeriod.settled,
)
} else {
setOf(CalculationPeriod.current)
}
} else {
this.marketsSummary?.let { marketsSummary ->
val periods = if (this.input != null) {
setOf(
CalculationPeriod.current,
CalculationPeriod.post,
CalculationPeriod.settled,
)
} else {
setOf(CalculationPeriod.current)
}

parser.asNativeMap(marketsSummary["markets"])?.let { markets ->
val modifiedAccount = accountCalculator.calculate(
account = account,
subaccountNumbers = subaccountNumbers,
configs = null,
markets = markets,
price = priceOverwrite(markets),
periods = periods,
)
this.account = modifiedAccount
parser.asNativeMap(marketsSummary["markets"])?.let { markets ->
val modifiedAccount = accountCalculator.calculate(
account = account,
subaccountNumbers = subaccountNumbers,
configs = null,
markets = markets,
price = priceOverwrite(markets),
periods = periods,
)
this.account = modifiedAccount
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ internal class TransferFieldsValidator(
val transfer = internalState.input.transfer
val type = transfer.type ?: return null
when (type) {
TransferType.deposit, TransferType.withdrawal -> {
TransferType.deposit -> {
val usdcSize = parser.asDouble(transfer.size?.usdcSize) ?: 0.0
if (usdcSize <= 0.0) {
errors.add(
required(
errorCode = "REQUIRED_SIZE",
field = "size.usdcSize",
actionStringKey = "APP.TRADE.ENTER_AMOUNT",
),
)
}
}
TransferType.withdrawal -> {
val usdcSize = parser.asDouble(transfer.size?.usdcSize) ?: 0.0
if (usdcSize <= 0.0) {
errors.add(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package exchange.dydx.abacus.validator.transfer

import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.output.input.TransferType
import exchange.dydx.abacus.output.input.ValidationError
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.abacus.protocols.ParserProtocol
Expand All @@ -22,7 +24,23 @@ internal class TransferOutValidator(
restricted: Boolean,
environment: V4Environment?
): List<ValidationError>? {
return null
val transfer = internalState.input.transfer ?: return null
val address = transfer.address
val type = transfer.type
if (type == TransferType.transferOut && !address.isNullOrEmpty() && !address.isAddressValid()) {
return listOf(
error(
type = ErrorType.error,
errorCode = "INVALID_ADDRESS",
fields = listOf("address"),
actionStringKey = "APP.DIRECT_TRANSFER_MODAL.ADDRESS_FIELD",
titleStringKey = "APP.DIRECT_TRANSFER_MODAL.INVALID_ADDRESS_TITLE",
textStringKey = "APP.DIRECT_TRANSFER_MODAL.INVALID_ADDRESS_BODY",
),
)
} else {
return null
}
}

override fun validateTransferDeprecated(
Expand Down
Loading

0 comments on commit ef38a5a

Please sign in to comment.