Skip to content

Commit

Permalink
site: simplify empty order match check and set the correct header rat…
Browse files Browse the repository at this point in the history
…e HTMLElement

Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Aug 28, 2023
1 parent 6de25cb commit 7d5c826
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/webserver/site/src/html/bodybuilder.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{{end}}

{{define "bottom"}}
<script src="/js/entry.js?v=dedee09b|9193c67a"></script>
<script src="/js/entry.js?v=c8e99f90|57d459a0"></script>
</body>
</html>
{{end}}
10 changes: 3 additions & 7 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1568,10 +1568,9 @@ export default class MarketsPage extends BasePage {
market order rate.
*/
marketOrderRateString (ord: Order, mkt: CurrentMarket) :string {
const nMatch = ord.matches?.length
if (nMatch === 0) return intl.prep(intl.ID_MARKET_ORDER)
if (!ord.matches) return intl.prep(intl.ID_MARKET_ORDER)
let rateStr = Doc.formatRateFullPrecision(OrderUtil.averageRate(ord), mkt.baseUnitInfo, mkt.quoteUnitInfo, mkt.cfg.ratestep)
if (nMatch > 1) rateStr = '~ ' + rateStr // ~ only makes sense if the order has more than one match
if (ord.matches.length > 1) rateStr = '~ ' + rateStr // ~ only makes sense if the order has more than one match
return rateStr
}

Expand Down Expand Up @@ -2280,10 +2279,7 @@ export default class MarketsPage extends BasePage {
else if (mord.ord.type === OrderUtil.Market && note.match.status === OrderUtil.NewlyMatched) { // Update the average market rate display.
// Fetch and use the updated order.
const ord = app().order(note.orderID)
if (ord) {
const rateStr = this.marketOrderRateString(ord, this.market)
mord.details.rate.textContent = mord.details.header.textContent = rateStr
}
if (ord) mord.details.rate.textContent = mord.header.rate.textContent = this.marketOrderRateString(ord, this.market)
}
if (app().canAccelerateOrder(mord.ord)) Doc.show(mord.details.accelerateBttn)
else Doc.hide(mord.details.accelerateBttn)
Expand Down
11 changes: 5 additions & 6 deletions client/webserver/site/src/js/orderutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,22 @@ export function settled (order: Order) {
/* averageRateString returns a formatting string containing the average rate of
the matches that have been filled for a market order. */
export function averageMarketOrderRateString (ord: Order): string {
const nMatch = ord.matches?.length
if (nMatch === 0) return intl.prep(intl.ID_MARKET_ORDER)
if (!ord.matches) return intl.prep(intl.ID_MARKET_ORDER)
let rateStr = Doc.formatCoinValue(app().conventionalRate(ord.baseID, ord.quoteID, averageRate(ord)))
if (nMatch > 1) rateStr = '~ ' + rateStr // "~" only makes sense if the order has more than one match.
if (ord.matches.length > 1) rateStr = '~ ' + rateStr // "~" only makes sense if the order has more than one match.
return rateStr
}

/* averageRate returns a the average rate of the matches that have been filled
in an order. */
export function averageRate (ord: Order): number {
if (ord.matches?.length === 0) return 0
if (!ord.matches) return 0
let rateProduct = 0
let baseQty = 0
ord.matches.forEach((m) => {
for (const m of ord.matches) {
baseQty += m.qty
rateProduct += (m.rate * m.qty) // order ~ 1e16
})
}
return rateProduct / baseQty
}

Expand Down

0 comments on commit 7d5c826

Please sign in to comment.