Skip to content

Commit

Permalink
check for uninitialized this.market in note handlers
Browse files Browse the repository at this point in the history
- This fixes an issue where the `markets` page receives certain notes
  before `this.market` is initialized. These notes are sent when a user
  reconnects to the internet and the market page has not been refreshed.
Signed-off-by: Philemon Ukane <[email protected]>
  • Loading branch information
ukane-philemon committed Apr 10, 2023
1 parent d1c4581 commit 5e5b87a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 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 || 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 @@ -2023,6 +2023,7 @@ export default class MarketsPage extends BasePage {
* handlePriceUpdate is the handler for the 'spots' notification.
*/
handlePriceUpdate (note: SpotPriceNote) {
if (!this.market) return // This note can arrive before the market is set.
if (note.host === this.market.dex.host && note.spots[this.market.cfg.name]) {
this.setCurrMarketPrice()
}
Expand All @@ -2035,6 +2036,7 @@ export default class MarketsPage extends BasePage {
*/
async handleBondUpdate (note: BondNote) {
const dexAddr = note.dex
if (!this.market) return // This note can arrive before the market is set.
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.
Expand Down Expand Up @@ -2085,6 +2087,7 @@ export default class MarketsPage extends BasePage {
*/
handleEpochNote (note: EpochNote) {
app().log('book', 'handleEpochNote:', note)
if (!this.market) return // This note can arrive before the market is set.
if (note.host !== this.market.dex.host || note.marketID !== this.market.sid) return
if (this.book) {
this.book.setEpoch(note.epoch)
Expand Down

0 comments on commit 5e5b87a

Please sign in to comment.