decred.org/dcrdex@v1.0.5/client/webserver/site/src/js/mmarchives.ts (about)

     1  import {
     2    app,
     3    PageElement,
     4    MarketWithHost
     5  } from './registry'
     6  import { getJSON } from './http'
     7  import Doc from './doc'
     8  import BasePage from './basepage'
     9  import { setMarketElements } from './mmutil'
    10  
    11  interface MarketMakingRun {
    12    startTime: number
    13    market: MarketWithHost
    14  }
    15  
    16  export default class MarketMakerArchivesPage extends BasePage {
    17    page: Record<string, PageElement>
    18    base: number
    19    quote: number
    20    host: string
    21  
    22    constructor (main: HTMLElement) {
    23      super()
    24      const page = this.page = Doc.idDescendants(main)
    25      Doc.cleanTemplates(page.runTableRowTmpl)
    26      Doc.bind(page.backButton, 'click', () => { app().loadPage('mm') })
    27      this.setup()
    28    }
    29  
    30    async setup () {
    31      const res = await getJSON('/api/archivedmmruns')
    32      if (!app().checkResponse(res)) {
    33        console.error('failed to get archived mm runs', res)
    34        // TODO: show error
    35        return
    36      }
    37  
    38      const runs : MarketMakingRun[] = res.runs
    39  
    40      for (let i = 0; i < runs.length; i++) {
    41        const { startTime, market: { baseID, quoteID, host } } = runs[i]
    42        const row = this.page.runTableRowTmpl.cloneNode(true) as HTMLElement
    43        const tmpl = Doc.parseTemplate(row)
    44        tmpl.startTime.textContent = new Date(startTime * 1000).toLocaleString()
    45        setMarketElements(row, baseID, quoteID, host)
    46  
    47        Doc.bind(tmpl.logs, 'click', () => {
    48          app().loadPage('mmlogs', { baseID, quoteID, host, startTime, returnPage: 'mmarchives' })
    49        })
    50  
    51        Doc.bind(tmpl.settings, 'click', () => {
    52          app().loadPage('mmsettings', { host, baseID, quoteID })
    53        })
    54  
    55        this.page.runTableBody.appendChild(row)
    56      }
    57    }
    58  }