-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: cap input quantity, truncate rfq card qty #2344
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
|
||
import { HIGHLIGHT_ROW_FLASH_TIME } from "@/client/constants" | ||
import { | ||
applyMaximum, | ||
DECIMAL_SEPARATOR, | ||
DECIMAL_SEPARATOR_REGEXP, | ||
invertDirection, | ||
|
@@ -216,8 +217,10 @@ export const [usePrice, price$] = bind( | |
|
||
const truncated = formatter(inputQuantityAsNumber) | ||
|
||
const value = Number( | ||
truncated.replace(filterRegExp, "").replace(decimalRegExp, "."), | ||
const value = applyMaximum( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion re above: some could be extracted to util module (e.g. |
||
Number( | ||
truncated.replace(filterRegExp, "").replace(decimalRegExp, "."), | ||
), | ||
) | ||
|
||
return { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,3 +230,8 @@ export const parseQuantity = (rawValue: string): number => | |
Number(rawValue.replace(filterRegExp, "").replace(decimalRegExp, ".")) | ||
|
||
export const adjustUserCreditQuantity = (value: number): number => value * 1000 | ||
|
||
const MAX_INPUT_VALUE = 100000000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: 100 mill, but hard to read, I always use underscores .. |
||
|
||
export const applyMaximum = (value: number): number => | ||
Math.min(value, MAX_INPUT_VALUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion(/later): I would put this whole thing in the util function, or create a new one, and could perhaps simplify If
parseQuantity()
returnsNaN
, which it can, then we really catch it as early as possible.Also, a near dup of code in
formatNotional
, but that has noMath.trunc()
..