Skip to content

Commit

Permalink
client: hide order form if asset version is not supported
Browse files Browse the repository at this point in the history
This shows "{asset} (v{version}) not supported" on the order form as needed.

---------

Co-authored-by: Brian Stafford <buck54321@gmail.com>
  • Loading branch information
vctt94 and buck54321 authored Feb 8, 2023
1 parent 40205c0 commit adc816d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions client/webserver/site/src/js/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const ID_SHOW_ADDITIONAL_SETTINGS = 'ID_SHOW_ADDITIONAL_SETTINGS'
export const ID_BUY = 'ID_BUY'
export const ID_SELL = 'ID_SELL'
export const ID_NOT_SUPPORTED = 'ID_NOT_SUPPORTED'
export const ID_VERSION_NOT_SUPPORTED = 'ID_VERSION_NOT_SUPPORTED'
export const ID_CONNECTION_FAILED = 'ID_CONNECTION_FAILED'
export const ID_ORDER_PREVIEW = 'ID_ORDER_PREVIEW'
export const ID_CALCULATING = 'ID_CALCULATING'
Expand Down Expand Up @@ -123,6 +124,7 @@ export const enUS: Locale = {
[ID_BUY]: 'Buy',
[ID_SELL]: 'Sell',
[ID_NOT_SUPPORTED]: '{{ asset }} is not supported',
[ID_VERSION_NOT_SUPPORTED]: '{{ asset }} (v{{version}}) is not supported',
[ID_CONNECTION_FAILED]: 'Connection to dex server failed. You can close dexc and try again later or wait for it to reconnect.',
[ID_ORDER_PREVIEW]: 'Total: {{ total }} {{ asset }}',
[ID_CALCULATING]: 'calculating...',
Expand Down
40 changes: 32 additions & 8 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,33 @@ export default class MarketsPage extends BasePage {
/* assetsAreSupported is true if all the assets of the current market are
* supported
*/
assetsAreSupported () {
const [b, q] = [this.market.base, this.market.quote]
return b && q
assetsAreSupported (): {
isSupported: boolean;
text: string;
} {
const { market: { base, quote, baseCfg, quoteCfg } } = this
if (!base || !quote) {
const symbol = base ? quoteCfg.symbol : baseCfg.symbol
return {
isSupported: false,
text: intl.prep(intl.ID_NOT_SUPPORTED, { asset: symbol.toUpperCase() })
}
}
// check if versions are supported. If asset is a token, we check if its
// parent supports the version.
const bVers = (base.token ? app().assets[base.token.parentID].info?.versions : base.info?.versions) as number[]
const qVers = (quote.token ? app().assets[quote.token.parentID].info?.versions : quote.info?.versions) as number[]
// if none them are token, just check if own asset is supported.
let text = ''
if (!bVers.includes(baseCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: base.symbol.toUpperCase(), version: baseCfg.version + '' })
} else if (!qVers.includes(quoteCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: quote.symbol.toUpperCase(), version: quoteCfg.version + '' })
}
return {
isSupported: bVers.includes(baseCfg.version) && qVers.includes(quoteCfg.version),
text
}
}

/*
Expand Down Expand Up @@ -639,7 +663,7 @@ export default class MarketsPage extends BasePage {
// and ready for trading the form should show up.
Doc.hide(page.orderForm, page.orderTypeBttns)
const feePaid = !this.hasFeePending()
const assetsAreSupported = this.assetsAreSupported()
const assetsAreSupported = this.assetsAreSupported().isSupported
const { base, quote } = this.market
const hasWallets = base && app().assets[base.id].wallet && quote && app().assets[quote.id].wallet

Expand All @@ -652,15 +676,15 @@ export default class MarketsPage extends BasePage {
* supported
*/
setLoaderMsgVisibility () {
const { page, market } = this
const { page } = this

if (this.assetsAreSupported()) {
const { isSupported, text } = this.assetsAreSupported()
if (isSupported) {
// make sure to hide the loader msg
Doc.hide(page.loaderMsg)
return
}
const symbol = market.base ? market.quoteCfg.symbol : market.baseCfg.symbol
page.loaderMsg.textContent = intl.prep(intl.ID_NOT_SUPPORTED, { asset: symbol.toUpperCase() })
page.loaderMsg.textContent = text
Doc.show(page.loaderMsg)
Doc.hide(page.noWallet)
}
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 @@ -191,6 +191,7 @@ export interface WalletInfo {
name: string
version: number
availablewallets: WalletDefinition[]
versions: number[]
emptyidx: number
unitinfo: UnitInfo
}
Expand Down

0 comments on commit adc816d

Please sign in to comment.