Browse Source

Merge #331

331: Fix default quantity in UI r=bonomat a=bonomat

`@thomaseizinger` : I'm not sure if I understand it correctly. Can I do ed2ec8eb49 or is this not allowed because I change the variable independent of what is in the state? 

Alternative solution is the second commit ac8d6e191c

resolves #330 

Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
refactor/no-log-handler
bors[bot] 3 years ago
committed by GitHub
parent
commit
5d461702d4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      daemon/src/maker_cfd.rs
  2. 10
      frontend/src/TakerApp.tsx

6
daemon/src/maker_cfd.rs

@ -507,6 +507,12 @@ impl Actor {
// 2. check if order has acceptable amounts
if quantity < current_order.min_quantity || quantity > current_order.max_quantity {
tracing::warn!(
"Order rejected because quantity {} was out of bounds. It was either <{} or >{}",
quantity,
current_order.min_quantity,
current_order.max_quantity
);
self.takers
.do_send_async(maker_inc_connections::TakerMessage {
taker_id,

10
frontend/src/TakerApp.tsx

@ -73,7 +73,7 @@ export default function App() {
let [margin, setMargin] = useState("0");
let [userHasEdited, setUserHasEdited] = useState(false);
let quantityToShow = userHasEdited ? quantity : (order?.min_quantity.toString() || "0");
let effectiveQuantity = userHasEdited ? quantity : (order?.min_quantity.toString() || "0");
let { run: calculateMargin } = useAsync({
deferFn: async ([payload]: any[]) => {
@ -98,7 +98,7 @@ export default function App() {
if (!order) {
return;
}
let quantity = quantityToShow ? Number.parseFloat(quantityToShow) : 0;
let quantity = effectiveQuantity ? Number.parseFloat(effectiveQuantity) : 0;
let payload: MarginRequestPayload = {
leverage: order.leverage,
price: order.price,
@ -109,7 +109,7 @@ export default function App() {
// We don't want that as we will end up in an endless loop. It is safe to ignore `calculateMargin` because
// nothing in `calculateMargin` depends on outside values, i.e. is guaranteed to be stable.
// eslint-disable-next-line react-hooks/exhaustive-deps
[margin, quantityToShow, order]);
[margin, effectiveQuantity, order]);
const format = (val: any) => `$` + val;
const parse = (val: any) => val.replace(/^\$/, "");
@ -169,7 +169,7 @@ export default function App() {
};
calculateMargin(payload);
}}
value={format(quantityToShow)}
value={format(effectiveQuantity)}
min={order?.min_quantity}
max={order?.max_quantity}
/>
@ -197,7 +197,7 @@ export default function App() {
onClick={() => {
let payload: CfdOrderRequestPayload = {
order_id: order!.id,
quantity: Number.parseFloat(quantity),
quantity: Number.parseFloat(effectiveQuantity),
};
makeNewOrderRequest(payload);
}}

Loading…
Cancel
Save