Skip to content

Commit

Permalink
ui: fix unsupported asset bugs on markets view (#2548)
Browse files Browse the repository at this point in the history
* fix unsupported asset bugs on markets view
  • Loading branch information
buck54321 authored Oct 17, 2023
1 parent 7a30549 commit 312d42a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
12 changes: 7 additions & 5 deletions client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1489,12 +1489,14 @@ func (s *WebServer) actuallyLogin(w http.ResponseWriter, r *http.Request, login
func (s *WebServer) apiUser(w http.ResponseWriter, r *http.Request) {
response := struct {
*core.User
Authed bool `json:"authed"`
OK bool `json:"ok"`
Authed bool `json:"authed"`
OK bool `json:"ok"`
Experimental bool `json:"experimental"`
}{
User: s.core.User(),
Authed: s.isAuthed(r),
OK: true,
User: s.core.User(),
Authed: s.isAuthed(r),
OK: true,
Experimental: s.experimental,
}
writeJSON(w, response, s.indent)
}
Expand Down
12 changes: 11 additions & 1 deletion client/webserver/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ func mkSupportedAsset(symbol string, state *core.WalletState) *core.SupportedAss

func mkDexAsset(symbol string) *dex.Asset {
assetID, _ := dex.BipSymbolID(symbol)
ui, err := asset.UnitInfo(assetID)
if err != nil /* unknown asset*/ {
ui = dex.UnitInfo{
AtomicUnit: "Sats",
Conventional: dex.Denomination{
ConversionFactor: 1e8,
Unit: strings.ToUpper(symbol),
},
}
}
a := &dex.Asset{
ID: assetID,
Symbol: symbol,
Expand All @@ -237,7 +247,7 @@ func mkDexAsset(symbol string) *dex.Asset {
SwapSize: uint64(rand.Intn(150) + 150),
SwapSizeBase: uint64(rand.Intn(150) + 15),
SwapConf: uint32(rand.Intn(5) + 2),
UnitInfo: dex.UnitInfo{Conventional: dex.Denomination{ConversionFactor: 1e8}},
UnitInfo: ui,
}
return a
}
Expand Down
22 changes: 15 additions & 7 deletions client/webserver/site/src/js/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import {
UnitInfo,
LayoutMetrics,
WalletState,
PageElement,
SupportedAsset
PageElement
} from './registry'
import { RateEncodingFactor } from './orderutil'

// Symbolizer is satisfied by both dex.Asset and core.SupportedAsset. Used by
// Doc.symbolize.
interface Symbolizer {
symbol: string
unitInfo: UnitInfo
}

const parser = new window.DOMParser()

const FPS = 30
Expand Down Expand Up @@ -353,12 +359,14 @@ export default class Doc {
* non-token assets, this is simply a <span>SYMBOL</span>. For tokens, it'll
* be <span><span>SYMBOL</span><sup>PARENT</sup></span>.
*/
static symbolize (asset: SupportedAsset, useLogo?: boolean): PageElement {
const symbol = asset.unitInfo.conventional.unit
static symbolize (asset: Symbolizer, useLogo?: boolean): PageElement {
const ticker = asset.unitInfo.conventional.unit
const symbolSpan = document.createElement('span')
symbolSpan.textContent = symbol.toUpperCase()
if (!asset.token) return symbolSpan
const parentSymbol = asset.symbol.split('.')[1]
symbolSpan.textContent = ticker.toUpperCase()
const parts = asset.symbol.split('.')
const isToken = parts.length === 2
if (!isToken) return symbolSpan
const parentSymbol = parts[1]
const span = document.createElement('span')
span.appendChild(symbolSpan)
if (useLogo) {
Expand Down
14 changes: 7 additions & 7 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export default class MarketsPage extends BasePage {
bind(row.node, 'click', () => {
// return early if the market is already set
const { quoteid: quoteID, baseid: baseID, xc: { host } } = row.mkt
if (this.market && this.market.base.id === baseID && this.market.quote.id === quoteID) return
if (this.market?.base?.id === baseID && this.market?.quote?.id === quoteID) return
this.startLoadingAnimations()
this.setMarket(host, baseID, quoteID)
})
Expand Down Expand Up @@ -613,7 +613,7 @@ export default class MarketsPage extends BasePage {
setMarketDetails () {
if (!this.market) return
for (const s of this.stats) {
const [ba, qa] = [app().assets[this.market.base.id], app().assets[this.market.quote.id]]
const { baseCfg: ba, quoteCfg: qa } = this.market
s.tmpl.baseIcon.src = Doc.logoPath(ba.symbol)
s.tmpl.quoteIcon.src = Doc.logoPath(qa.symbol)
Doc.empty(s.tmpl.baseSymbol, s.tmpl.quoteSymbol)
Expand Down Expand Up @@ -741,7 +741,7 @@ export default class MarketsPage extends BasePage {

Doc.setVis(await showOrderForm(), page.orderForm, page.orderTypeBttns)

if (this.mmRunning === undefined) {
if (app().user.experimental && this.mmRunning === undefined) {
const marketMakingStatus = await app().getMarketMakingStatus()
this.mmRunning = marketMakingStatus.running
}
Expand Down Expand Up @@ -1097,7 +1097,7 @@ export default class MarketsPage extends BasePage {
page.lotSize.textContent = Doc.formatCoinValue(mkt.cfg.lotsize, mkt.baseUnitInfo)
page.rateStep.textContent = Doc.formatCoinValue(mkt.cfg.ratestep / rateConversionFactor)

if ((!baseAsset && !quoteAsset) || (!baseAsset.wallet && !quoteAsset.wallet)) Doc.setVis(true, page.noWallet)
if (!baseAsset?.wallet || !quoteAsset?.wallet) Doc.setVis(true, page.noWallet)
else this.balanceWgt.setWallets(host, base, quote)
this.setMarketDetails()
this.setCurrMarketPrice()
Expand Down Expand Up @@ -1742,7 +1742,7 @@ export default class MarketsPage extends BasePage {
handleBookRoute (note: BookUpdate) {
app().log('book', 'handleBookRoute:', note)
const mktBook = note.payload
const [b, q] = [app().assets[this.market.base.id], app().assets[this.market.quote.id]]
const { baseCfg: b, quoteCfg: q } = this.market
if (mktBook.base !== b.id || mktBook.quote !== q.id) return // user already changed markets
this.handleBook(mktBook)
this.updateTitle()
Expand Down Expand Up @@ -3033,8 +3033,8 @@ class MarketRow {
const tmpl = this.tmpl = Doc.parseTemplate(this.node)
tmpl.baseIcon.src = Doc.logoPath(mkt.basesymbol)
tmpl.quoteIcon.src = Doc.logoPath(mkt.quotesymbol)
tmpl.baseSymbol.appendChild(Doc.symbolize(app().assets[mkt.baseid], true))
tmpl.quoteSymbol.appendChild(Doc.symbolize(app().assets[mkt.quoteid], true))
tmpl.baseSymbol.appendChild(Doc.symbolize(mkt.xc.assets[mkt.baseid], true))
tmpl.quoteSymbol.appendChild(Doc.symbolize(mkt.xc.assets[mkt.quoteid], true))
tmpl.baseName.textContent = mkt.baseName
tmpl.host.textContent = mkt.xc.host
tmpl.host.style.color = hostColor(mkt.xc.host)
Expand Down
1 change: 1 addition & 0 deletions client/webserver/site/src/js/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export interface User {
bots: BotReport[]
net: number
extensionModeConfig: ExtensionModeConfig
experimental: boolean
}

export interface CoreNote {
Expand Down
6 changes: 4 additions & 2 deletions client/webserver/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package webserver

import (
"bytes"
"encoding/hex"
"fmt"
"html/template"
"io/fs"
Expand All @@ -14,6 +15,7 @@ import (
"runtime/debug"

"decred.org/dcrdex/client/webserver/locales"
"decred.org/dcrdex/dex/encode"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down Expand Up @@ -188,13 +190,13 @@ func (t *templates) exec(name string, data any) (string, error) {
var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
if setting.Key == "vcs.revision" && len(setting.Value) >= 8 {
return setting.Value
}
}
}

return ""
return hex.EncodeToString(encode.RandomBytes(4))
}()

// templateFuncs are able to be called during template execution.
Expand Down

0 comments on commit 312d42a

Please sign in to comment.