Skip to content
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

add price rate to browser title #1117

Merged
merged 4 commits into from
Jul 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client/webserver/site/src/js/markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default class MarketsPage extends BasePage {
this.ordersSortKey = 'stamp'
// 1 if sorting ascendingly, -1 if sorting descendingly.
this.ordersSortDirection = 1
// store original title so we can re-append it when updating market value.
this.ogTitle = document.title

const reporters = {
click: p => { this.reportClick(p) },
Expand Down Expand Up @@ -956,6 +958,23 @@ export default class MarketsPage extends BasePage {
if (this.book) this.chart.draw()
}

/* updateTitle update the browser title based on the midgap value and the
* selected assets.
*/
updateTitle () {
// gets first price value from buy or from sell, so we can show it on
// title.
const midGapValue = this.midGap()
if (!midGapValue) return

chappjc marked this conversation as resolved.
Show resolved Hide resolved
const market = this.market
const [b, q] = [market.baseCfg, market.quoteCfg]
const baseSymb = b.symbol.toUpperCase()
const quoteSymb = q.symbol.toUpperCase()
// more than 6 numbers it gets too big for the title.
document.title = `${midGapValue.toFixed(6)} | ${baseSymb}${quoteSymb} | ${this.ogTitle}`
}

/* handleBookRoute is the handler for the 'book' notification, which is sent
* in response to a new market subscription. The data received will contain
* the entire order book.
Expand All @@ -970,6 +989,7 @@ export default class MarketsPage extends BasePage {
if (mktBook.base !== b.id || mktBook.quote !== q.id) return
this.refreshActiveOrders()
this.handleBook(mktBook)
this.updateTitle()
page.marketLoader.classList.add('d-none')
this.marketList.select(host, b.id, q.id)

Expand Down Expand Up @@ -1002,6 +1022,7 @@ export default class MarketsPage extends BasePage {
const order = data.payload
if (order.rate > 0) this.book.add(order)
this.addTableOrder(order)
this.updateTitle()
this.chart.draw()
}

Expand All @@ -1012,6 +1033,7 @@ export default class MarketsPage extends BasePage {
const order = data.payload
this.book.remove(order.token)
this.removeTableOrder(order)
this.updateTitle()
this.chart.draw()
}

Expand Down