Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: hide order form if asset version is not supported #2054

Merged
merged 2 commits into from Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/webserver/site/src/js/locales.ts
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
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
Expand Up @@ -191,6 +191,7 @@ export interface WalletInfo {
name: string
version: number
availablewallets: WalletDefinition[]
versions: number[]
emptyidx: number
unitinfo: UnitInfo
}
Expand Down