Skip to content

Commit

Permalink
refresh user orders for new match note and minor improvement
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
  • Loading branch information
ukane-philemon committed Aug 8, 2023
1 parent 95fdaf9 commit 61072ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 7 additions & 2 deletions client/core/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,20 @@ func (ord *OrderReader) RateString() string {
// AverageRateString returns a formatting string containing the average rate of
// the matches that have been filled in an order.
func (ord *OrderReader) AverageRateString() string {
if len(ord.Matches) == 0 {
nMatch := len(ord.Matches)
if nMatch == 0 {
return "0"
}
var baseQty, rateProduct uint64
for _, match := range ord.Matches {
baseQty += match.Qty
rateProduct += match.Rate * match.Qty // order ~ 1e16
}
return "~ " + ord.formatRate(rateProduct/baseQty)
rateStr := ord.formatRate(rateProduct / baseQty)
if nMatch > 1 {
rateStr = "~ " + rateStr // "~" only makes sense if the order has more than one match.
}
return rateStr
}

// SwapFeesString is a formatted string of the paid swap fees.
Expand Down
7 changes: 4 additions & 3 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1484,9 +1484,10 @@ export default class MarketsPage extends BasePage {
details.qty.textContent = header.qty.textContent = Doc.formatCoinValue(ord.qty, market.baseUnitInfo)
let rate = ord.rate
let ratePrefix = ''
if (ord.type === OrderUtil.Market && ord.matches?.length > 0) {
ratePrefix = '~ '
const nMatch = ord.matches?.length
if (ord.type === OrderUtil.Market && nMatch > 0) {
rate = OrderUtil.averageRate(ord)
if (nMatch > 1) ratePrefix = '~ ' // ~ only makes sense if the order has more than one match
}
details.rate.textContent = header.rate.textContent = ratePrefix + Doc.formatRateFullPrecision(rate, market.baseUnitInfo, market.quoteUnitInfo, cfg.ratestep)
header.baseSymbol.textContent = ord.baseSymbol.toUpperCase()
Expand Down Expand Up @@ -2257,7 +2258,7 @@ export default class MarketsPage extends BasePage {

handleMatchNote (note: MatchNote) {
const mord = this.metaOrders[note.orderID]
if (!mord) return this.refreshActiveOrders()
if (!mord || note.match.status === OrderUtil.NewlyMatched) return this.refreshActiveOrders()
if (app().canAccelerateOrder(mord.ord)) Doc.show(mord.details.accelerateBttn)
else Doc.hide(mord.details.accelerateBttn)
}
Expand Down
7 changes: 5 additions & 2 deletions client/webserver/site/src/js/orderutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ export function settled (order: Order) {
/* averageRateString returns a formatting string containing the average rate of
the matches that have been filled in an order. */
export function averageRateString (ord: Order): string {
if (ord.matches?.length === 0) return '0'
return '~ ' + Doc.formatCoinValue(app().conventionalRate(ord.baseID, ord.quoteID, averageRate(ord)))
const nMatch = ord.matches?.length
if (nMatch === 0) return '0'
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.
return rateStr
}

/* averageRate returns a the average rate of the matches that have been filled
Expand Down

0 comments on commit 61072ef

Please sign in to comment.