Skip to content

Commit

Permalink
ui: filter out injected non-existent language (#2930)
Browse files Browse the repository at this point in the history
* filter out injected non-existent language

* npm audit fix
  • Loading branch information
buck54321 committed Aug 23, 2024
1 parent da30f52 commit 32d88bc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
16 changes: 8 additions & 8 deletions client/webserver/site/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions client/webserver/site/src/js/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
PageElement
} from './registry'
import State from './state'
import { RateEncodingFactor } from './orderutil'

// Symbolizer is satisfied by both dex.Asset and core.SupportedAsset. Used by
// Doc.symbolize.
Expand Down Expand Up @@ -51,11 +50,15 @@ const BipSymbolIDs: Record<string, number> = {};

const BipSymbols = Object.values(BipIDs)

const RateEncodingFactor = 1e8 // same as value defined in ./orderutil

const log10RateEncodingFactor = Math.round(Math.log10(RateEncodingFactor))

const intFormatter = new Intl.NumberFormat(navigator.languages as string[], { maximumFractionDigits: 0 })
const languages = navigator.languages.filter((locale: string) => locale !== 'c')

const intFormatter = new Intl.NumberFormat(languages, { maximumFractionDigits: 0 })

const fourSigFigs = new Intl.NumberFormat((navigator.languages as string[]), {
const fourSigFigs = new Intl.NumberFormat(languages, {
minimumSignificantDigits: 4,
maximumSignificantDigits: 4
})
Expand Down Expand Up @@ -90,7 +93,7 @@ function formatter (formatters: Record<string, Intl.NumberFormat>, min: number,
const k = `${min}-${max}`
let fmt = formatters[k]
if (!fmt) {
fmt = new Intl.NumberFormat(locales || navigator.languages as string[], {
fmt = new Intl.NumberFormat(locales ?? languages, {
minimumFractionDigits: min,
maximumFractionDigits: max
})
Expand Down Expand Up @@ -365,6 +368,10 @@ export default class Doc {
return fullPrecisionFormatter(prec).format(value)
}

static languages (): string[] {
return languages
}

static formatFiatValue (value: number): string {
return fullPrecisionFormatter(2).format(value)
}
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const sellBtnClass = 'sellred-bg'
const fiveMinBinKey = '5m'
const oneHrBinKey = '1h'

const percentFormatter = new Intl.NumberFormat(document.documentElement.lang, {
const percentFormatter = new Intl.NumberFormat(Doc.languages(), {
minimumFractionDigits: 1,
maximumFractionDigits: 2
})
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function setOptionTemplates (page: Record<string, PageElement>): void {
[booleanOptTmpl, rangeOptTmpl, orderOptTmpl] = [page.booleanOptTmpl, page.rangeOptTmpl, page.orderOptTmpl]
}

const threeSigFigs = new Intl.NumberFormat((navigator.languages as string[]), {
const threeSigFigs = new Intl.NumberFormat(Doc.languages(), {
minimumSignificantDigits: 3,
maximumSignificantDigits: 3
})
Expand Down
4 changes: 2 additions & 2 deletions client/webserver/site/src/js/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class OrderPage extends BasePage {
tmpl.matchID.textContent = match.matchID

const time = new Date(match.stamp)
tmpl.matchTime.textContent = time.toLocaleTimeString(navigator.languages as string[], {
tmpl.matchTime.textContent = time.toLocaleTimeString(Doc.languages(), {
year: 'numeric',
month: 'short',
day: 'numeric'
Expand Down Expand Up @@ -287,7 +287,7 @@ export default class OrderPage extends BasePage {
const refundAfter = new Date(m.stamp + lockTime)
if (Date.now() > refundAfter.getTime()) tmpl.refundPending.textContent = intl.prep(intl.ID_REFUND_IMMINENT)
else {
const refundAfterStr = refundAfter.toLocaleTimeString(navigator.languages as string[], {
const refundAfterStr = refundAfter.toLocaleTimeString(Doc.languages(), {
year: 'numeric',
month: 'short',
day: 'numeric'
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ export default class WalletsPage extends BasePage {
Doc.show(page.purchaserErr)
return
}
this.showSuccess(intl.prep(intl.ID_TICKETS_PURCHASED, { n: n.toLocaleString(navigator.languages) }))
this.showSuccess(intl.prep(intl.ID_TICKETS_PURCHASED, { n: n.toLocaleString(Doc.languages()) }))
}

processTicketPurchaseUpdate (walletNote: CustomWalletNote) {
Expand Down

0 comments on commit 32d88bc

Please sign in to comment.