Skip to content

Commit

Permalink
use javascript optional chaining in note handlers
Browse files Browse the repository at this point in the history
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Apr 7, 2023
1 parent 7b94d01 commit 5fb99e5
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ export default class MarketsPage extends BasePage {

if (!this.assetsAreSupported().isSupported) return // assets not supported

if (this.market.dex.tier < 1) return // acct suspended or not registered
if (!this.market?.dex || this.market.dex.tier < 1) return // acct suspended or not registered

const { base, quote } = this.market
const hasWallets = base && app().assets[base.id].wallet && quote && app().assets[quote.id].wallet
Expand Down Expand Up @@ -909,8 +909,8 @@ export default class MarketsPage extends BasePage {
}

/*
* reportDepthMouse accepts informations about the mouse position on the
* chart area.
* reportDepthMouse accepts information about the mouse position on the chart
* area.
*/
reportDepthMouse (r: MouseReport) {
while (this.hovers.length) (this.hovers.shift() as HTMLElement).classList.remove('hover')
Expand All @@ -937,9 +937,9 @@ export default class MarketsPage extends BasePage {
}

/*
* reportDepthZoom accepts informations about the current depth chart zoom level.
* This information is saved to disk so that the zoom level can be maintained
* across reloads.
* reportDepthZoom accepts information about the current depth chart zoom
* level. This information is saved to disk so that the zoom level can be
* maintained across reloads.
*/
reportDepthZoom (zoom: number) {
State.storeLocal(State.depthZoomLK, zoom)
Expand Down Expand Up @@ -1398,6 +1398,7 @@ export default class MarketsPage extends BasePage {
app().log('book', 'handleBookRoute:', note)
const mktBook = note.payload
const market = this.market
if (!market?.dex) return
const page = this.page
const host = market.dex.host
const [b, q] = [market.baseCfg, market.quoteCfg]
Expand Down Expand Up @@ -1431,7 +1432,7 @@ export default class MarketsPage extends BasePage {
/* handleBookOrderRoute is the handler for 'book_order' notifications. */
handleBookOrderRoute (data: BookUpdate) {
app().log('book', 'handleBookOrderRoute:', data)
if (data.host !== this.market.dex.host || data.marketID !== this.market.sid) return
if (data.host !== this.market?.dex?.host || data.marketID !== this.market?.sid) return
const order = data.payload as MiniOrder
if (order.rate > 0) this.book.add(order)
this.addTableOrder(order)
Expand All @@ -1442,7 +1443,7 @@ export default class MarketsPage extends BasePage {
/* handleUnbookOrderRoute is the handler for 'unbook_order' notifications. */
handleUnbookOrderRoute (data: BookUpdate) {
app().log('book', 'handleUnbookOrderRoute:', data)
if (data.host !== this.market.dex.host || data.marketID !== this.market.sid) return
if (data.host !== this.market?.dex?.host || data.marketID !== this.market?.sid) return
const order = data.payload
this.book.remove(order.token)
this.removeTableOrder(order)
Expand All @@ -1456,7 +1457,7 @@ export default class MarketsPage extends BasePage {
*/
handleUpdateRemainingRoute (data: BookUpdate) {
app().log('book', 'handleUpdateRemainingRoute:', data)
if (data.host !== this.market.dex.host || data.marketID !== this.market.sid) return
if (data.host !== this.market?.dex?.host || data.marketID !== this.market?.sid) return
const update = data.payload
this.book.updateRemaining(update.token, update.qty, update.qtyAtomic)
this.updateTableOrder(update)
Expand All @@ -1466,7 +1467,7 @@ export default class MarketsPage extends BasePage {
/* handleEpochOrderRoute is the handler for 'epoch_order' notifications. */
handleEpochOrderRoute (data: BookUpdate) {
app().log('book', 'handleEpochOrderRoute:', data)
if (data.host !== this.market.dex.host || data.marketID !== this.market.sid) return
if (data.host !== this.market?.dex?.host || data.marketID !== this.market?.sid) return
const order = data.payload
if (order.msgRate > 0) this.book.add(order) // No cancels or market orders
if (order.qtyAtomic > 0) this.addTableOrder(order) // No cancel orders
Expand All @@ -1480,7 +1481,7 @@ export default class MarketsPage extends BasePage {
this.candlesLoading.loaded()
this.candlesLoading = null
}
if (data.host !== this.market.dex.host || data.marketID !== this.market.cfg.name) return
if (data.host !== this.market?.dex?.host || data.marketID !== this.market?.cfg.name) return
const dur = data.payload.dur
this.market.candleCaches[dur] = data.payload
this.setHighLow()
Expand All @@ -1497,7 +1498,7 @@ export default class MarketsPage extends BasePage {

/* handleCandleUpdateRoute is the handler for 'candle_update' notifications. */
handleCandleUpdateRoute (data: BookUpdate) {
if (data.host !== this.market.dex.host) return
if (data.host !== this.market?.dex?.host) return
const { dur, candle } = data.payload
const cache = this.market.candleCaches[dur]
if (!cache) return // must not have seen the 'candles' notification yet?
Expand Down Expand Up @@ -2023,7 +2024,7 @@ export default class MarketsPage extends BasePage {
* handlePriceUpdate is the handler for the 'spots' notification.
*/
handlePriceUpdate (note: SpotPriceNote) {
if (note.host === this.market.dex.host && note.spots[this.market.cfg.name]) {
if (note.host === this.market?.dex?.host && note.spots[this.market?.cfg.name]) {
this.setCurrMarketPrice()
}
this.marketList.updateSpots(note)
Expand All @@ -2035,7 +2036,7 @@ export default class MarketsPage extends BasePage {
*/
async handleBondUpdate (note: BondNote) {
const dexAddr = note.dex
if (dexAddr !== this.market.dex.host) return
if (dexAddr !== this.market?.dex?.host) return
// If we just finished legacy registration, we need to update the Exchange.
// TODO: Use tier change notification once available.
if (note.topic === 'AccountRegistered') await app().fetchUser()
Expand Down Expand Up @@ -2085,7 +2086,7 @@ export default class MarketsPage extends BasePage {
*/
handleEpochNote (note: EpochNote) {
app().log('book', 'handleEpochNote:', note)
if (note.host !== this.market.dex.host || note.marketID !== this.market.sid) return
if (note.host !== this.market?.dex?.host || note.marketID !== this.market?.sid) return
if (this.book) {
this.book.setEpoch(note.epoch)
this.depthChart.draw()
Expand Down

0 comments on commit 5fb99e5

Please sign in to comment.