Skip to content

Commit

Permalink
Clean up updateOrderBttnState
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Oct 11, 2023
1 parent bd778aa commit 0487795
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,58 +1038,51 @@ export default class MarketsPage extends BasePage {
const orderQty = order.qty
const orderRate = order.rate
const baseWallet = app().assets[this.market.base.id].wallet
const quoteWallet = app().assets[mkt.quote.id].wallet
if (!baseWallet || !quoteWallet) return

if (orderQty <= 0) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_QTY_ERROR))
return
}

// market orders
// Market orders
if (!order.isLimit) {
if (orderQty <= 0) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_QTY_ERROR))
return
}
if (order.sell) {
this.setOrderBttnEnabled(orderQty <= baseWallet.balance.available, intl.prep(intl.ID_ORDER_BUTTON_SELL_BALANCE_ERROR))
return
} else {
this.setOrderBttnEnabled(orderQty <= quoteWallet.balance.available, intl.prep(intl.ID_ORDER_BUTTON_BUY_BALANCE_ERROR))
}
return
}

if (orderQty <= 0 || !orderRate) {
if (!orderRate) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_QTY_RATE_ERROR))
return
}

// Limit sell
if (order.sell) {
const baseWallet = app().assets[mkt.base.id].wallet

if (baseWallet.balance.available < mkt.cfg.lotsize) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_SELL_BALANCE_ERROR))
return
}

if (mkt.maxSell) {
if (orderQty > mkt.maxSell.swap.value) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_SELL_BALANCE_ERROR))
return
}
this.setOrderBttnEnabled(true)
}
} else {
const quoteWallet = app().assets[mkt.quote.id].wallet
if (!quoteWallet) return

const rate = this.adjustedRate()
const aLot = mkt.cfg.lotsize * (rate / OrderUtil.RateEncodingFactor)

if (quoteWallet.balance.available < aLot) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_BUY_BALANCE_ERROR))
return
this.setOrderBttnEnabled(orderQty <= mkt.maxSell.swap.value, intl.prep(intl.ID_ORDER_BUTTON_SELL_BALANCE_ERROR))
}
return
}

if (mkt.maxBuys[rate]) {
if (orderQty > mkt.maxBuys[rate].swap.lots * mkt.cfg.lotsize) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_BUY_BALANCE_ERROR))
return
}
this.setOrderBttnEnabled(true)
}
// Limit buy
const rate = this.adjustedRate()
const aLot = mkt.cfg.lotsize * (rate / OrderUtil.RateEncodingFactor)
if (quoteWallet.balance.available < aLot) {
this.setOrderBttnEnabled(false, intl.prep(intl.ID_ORDER_BUTTON_BUY_BALANCE_ERROR))
return
}
if (mkt.maxBuys[rate]) {
const enable = orderQty <= mkt.maxBuys[rate].swap.lots * mkt.cfg.lotsize
this.setOrderBttnEnabled(enable, intl.prep(intl.ID_ORDER_BUTTON_BUY_BALANCE_ERROR))
}
}

Expand Down

0 comments on commit 0487795

Please sign in to comment.