@ -112,9 +112,11 @@ export default function Trade({
const quantityTooHigh = maxQuantity < parse ( quantity ) ;
const quantityTooHigh = maxQuantity < parse ( quantity ) ;
const quantityTooLow = minQuantity > parse ( quantity ) ;
const quantityTooLow = minQuantity > parse ( quantity ) ;
const quantityGreaterZero = parse ( quantity ) > 0 ;
const quantityGreaterZero = parse ( quantity ) > 0 ;
const quantityIncrement = 100 ;
const quantityIsEvenlyDivisibleByIncrement = isEvenlyDivisible ( parse ( quantity ) , quantityIncrement ) ;
const canSubmit = orderId && ! isLongSubmitting && ! balanceTooLow
const canSubmit = orderId && ! isLongSubmitting && ! balanceTooLow
&& ! quantityTooHigh && ! quantityTooLow && quantityGreaterZero ;
&& ! quantityTooHigh && ! quantityTooLow && quantityGreaterZero && quantityIsEvenlyDivisibleByIncrement ;
let alertBox ;
let alertBox ;
@ -130,6 +132,12 @@ export default function Trade({
description = { "Please deposit more into you wallet." }
description = { "Please deposit more into you wallet." }
/ > ;
/ > ;
}
}
if ( ! quantityIsEvenlyDivisibleByIncrement ) {
alertBox = < AlertBox
title = { ` Quantity is not in increments of ${ quantityIncrement } ! ` }
description = { ` Increment is ${ quantityIncrement } ` }
/ > ;
}
if ( quantityTooHigh ) {
if ( quantityTooHigh ) {
alertBox = < AlertBox
alertBox = < AlertBox
title = { "Quantity too high!" }
title = { "Quantity too high!" }
@ -184,7 +192,13 @@ export default function Trade({
< / Center >
< / Center >
< / GridItem >
< / GridItem >
< GridItem colSpan = { 1 } >
< GridItem colSpan = { 1 } >
< Quantity min = { minQuantity } max = { maxQuantity } quantity = { quantity } onChange = { onQuantityChange } / >
< Quantity
min = { minQuantity }
max = { maxQuantity }
quantity = { quantity }
onChange = { onQuantityChange }
quantityIncrement = { quantityIncrement }
/ >
< / GridItem >
< / GridItem >
< GridItem colSpan = { 1 } >
< GridItem colSpan = { 1 } >
< Leverage leverage = { leverage } / >
< Leverage leverage = { leverage } / >
@ -276,10 +290,11 @@ interface QuantityProps {
min : number ;
min : number ;
max : number ;
max : number ;
quantity : string ;
quantity : string ;
quantityIncrement : number ;
onChange : any ;
onChange : any ;
}
}
function Quantity ( { min , max , onChange , quantity } : QuantityProps ) {
function Quantity ( { min , max , onChange , quantity , quantityIncrement } : QuantityProps ) {
return (
return (
< FormControl id = "quantity" >
< FormControl id = "quantity" >
< FormLabel > Quantity < / FormLabel >
< FormLabel > Quantity < / FormLabel >
@ -289,6 +304,7 @@ function Quantity({ min, max, onChange, quantity }: QuantityProps) {
min = { min }
min = { min }
max = { max }
max = { max }
default = { min }
default = { min }
step = { quantityIncrement }
onChange = { onChange }
onChange = { onChange }
value = { quantity }
value = { quantity }
>
>
@ -345,3 +361,7 @@ function Margin({ margin }: MarginProps) {
< / VStack >
< / VStack >
) ;
) ;
}
}
export function isEvenlyDivisible ( numerator : number , divisor : number ) : boolean {
return ( numerator % divisor === 0.0 ) ;
}