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
check if assets are token

Add ID_VERSION_NOT_SUPPORTED message on loaderMsg when version not supported

lint

change text message
  • Loading branch information
vctt94 committed Feb 8, 2023
1 parent 7603ead commit 894f8a4
Show file tree
Hide file tree
Showing 3 changed files with 76 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
81 changes: 73 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,74 @@ 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 } = this
const [base, quote] = [market.base, market.quote]
if (!base || !quote) {
const symbol = market.base ? market.quoteCfg.symbol : market.baseCfg.symbol
return {
isSupported: false,
text: intl.prep(intl.ID_NOT_SUPPORTED, { asset: symbol.toUpperCase() })
}
}
const { baseCfg, quoteCfg } = this.market
// check if versions are supported. If asset is a token, we check if its
// parent supports the version.
let text = ''
if (base.token && quote.token) {
const bParent = app().assets[base.token.parentID]
const qParent = app().assets[quote.token.parentID]
if (!bParent.info?.versions.includes(baseCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: bParent.symbol.toUpperCase(), version: baseCfg.version + '' })
}
if (!qParent.info?.versions.includes(quoteCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: qParent.symbol.toUpperCase(), version: quoteCfg.version + '' })
}
return {
isSupported: !!qParent.info?.versions.includes(quoteCfg.version) && !!bParent.info?.versions.includes(baseCfg.version),
text
}
}
if (base.token) {
const bParent = app().assets[base.token.parentID]
if (!bParent.info?.versions.includes(baseCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: bParent.symbol.toUpperCase(), version: baseCfg.version + '' })
}
if (!quote.info?.versions.includes(quoteCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: quote.symbol.toUpperCase(), version: quoteCfg.version + '' })
}
return {
isSupported: !!quote.info?.versions.includes(quoteCfg.version) && !!bParent.info?.versions.includes(baseCfg.version),
text
}
}
if (quote.token) {
const qParent = app().assets[quote.token.parentID]
if (!base.info?.versions.includes(baseCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: base.symbol.toUpperCase(), version: baseCfg.version + '' })
}
if (!qParent.info?.versions.includes(quoteCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: quote.symbol.toUpperCase(), version: quoteCfg.version + '' })
}
return {
isSupported: !!base.info?.versions.includes(baseCfg.version) && !!qParent.info?.versions.includes(quoteCfg.version),
text
}
}
// if none them are token, just check if own asset is supported.
if (!base.info?.versions.includes(baseCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: base.symbol.toUpperCase(), version: baseCfg.version + '' })
}
if (!quote.info?.versions.includes(quoteCfg.version)) {
text = intl.prep(intl.ID_VERSION_NOT_SUPPORTED, { asset: quote.symbol.toUpperCase(), version: quoteCfg.version + '' })
}
return {
isSupported: !!base.info?.versions.includes(baseCfg.version) && !!quote.info?.versions.includes(quoteCfg.version),
text
}
}

/*
Expand Down Expand Up @@ -639,7 +704,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 +717,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 894f8a4

Please sign in to comment.