Skip to content

Commit

Permalink
webserver/site: refactor order type processing
Browse files Browse the repository at this point in the history
	Make a new fn 'orderTypeText' in orderutil.ts
	that returns the translated text representation
	for order types:
	  - limit
	  - market
	  - cancel

	Also added simplified chinese translations for
	these 3 order types in jsintl.go
  • Loading branch information
dev-warrior777 committed Oct 29, 2024
1 parent e67e78b commit 502c18a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
5 changes: 5 additions & 0 deletions client/webserver/jsintl.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const (
limitOrderID = "LIMIT_ORDER"
limitOrderImmediateTifID = "LIMIT_ORDER_IMMEDIATE_TIF"
marketOrderID = "MARKET_ORDER"
cancelOrderID = "CANCEL_ORDER"
matchStatusNewlyMatchedID = "MATCH_STATUS_NEWLY_MATCHED"
matchStatusMakerSwapCastID = "MATCH_STATUS_MAKER_SWAP_CAST"
matchStatusTakerSwapCastID = "MATCH_STATUS_TAKER_SWAP_CAST"
Expand Down Expand Up @@ -286,6 +287,7 @@ var enUS = map[string]*intl.Translation{
limitOrderID: {T: "limit"},
limitOrderImmediateTifID: {T: "limit (i)", Notes: "i = immediate"},
marketOrderID: {T: "market"},
cancelOrderID: {T: "cancel"},
matchStatusNewlyMatchedID: {T: "Newly Matched"},
matchStatusMakerSwapCastID: {T: "Maker Swap Sent"},
matchStatusTakerSwapCastID: {T: "Taker Swap Sent"},
Expand Down Expand Up @@ -489,6 +491,9 @@ var zhCN = map[string]*intl.Translation{
createID: {T: "创建"},
availableID: {T: "可用"},
immatureID: {T: "不成"},
limitOrderID: {T: "限价单"},
marketOrderID: {T: "市价单"},
cancelOrderID: {T: "取消单"},
}

var plPL = map[string]*intl.Translation{
Expand Down
1 change: 1 addition & 0 deletions client/webserver/site/src/js/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const ID_UNSUPPORTED_ASSET_INFO_ERR_MSG = 'UNSUPPORTED_ASSET_INFO_ERR_MSG
export const ID_LIMIT_ORDER = 'LIMIT_ORDER'
export const ID_LIMIT_ORDER_IMMEDIATE_TIF = 'LIMIT_ORDER_IMMEDIATE_TIF'
export const ID_MARKET_ORDER = 'MARKET_ORDER'
export const ID_CANCEL_ORDER = 'CANCEL_ORDER'
export const ID_MATCH_STATUS_NEWLY_MATCHED = 'MATCH_STATUS_NEWLY_MATCHED'
export const ID_MATCH_STATUS_MAKER_SWAP_CAST = 'MATCH_STATUS_MAKER_SWAP_CAST'
export const ID_MATCH_STATUS_TAKER_SWAP_CAST = 'MATCH_STATUS_TAKER_SWAP_CAST'
Expand Down
17 changes: 1 addition & 16 deletions client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1703,22 +1703,7 @@ export default class MarketsPage extends BasePage {
else rateStr = Doc.formatRateFullPrecision(ord.rate, market.baseUnitInfo, market.quoteUnitInfo, cfg.ratestep)
details.rate.textContent = mord.header.rate.textContent = rateStr
header.baseSymbol.textContent = market.baseUnitInfo.conventional.unit
let ordType = ''
switch (ord.type) {
case OrderUtil.OrderTypeLimit:{
ordType = intl.prep(intl.ID_LIMIT_ORDER)
break
}
case OrderUtil.OrderTypeMarket:{
ordType = intl.prep(intl.ID_MARKET_ORDER)
break
}
case OrderUtil.OrderTypeCancel:{
ordType = 'cancel' // currently no translation
break
}
}
details.type.textContent = ordType
details.type.textContent = OrderUtil.orderTypeText(ord.type)
this.updateMetaOrder(mord)

Doc.bind(div, 'mouseenter', () => {
Expand Down
11 changes: 11 additions & 0 deletions client/webserver/site/src/js/orderutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,14 @@ function dexAssetSymbol (host: string, assetID: number): string {
export function isCancellable (ord: Order): boolean {
return ord.type === Limit && ord.tif === StandingTiF && ord.status < StatusExecuted
}

export function orderTypeText (ordType: number): string {
switch (ordType) {
case OrderTypeLimit:
return intl.prep(intl.ID_LIMIT_ORDER)
case OrderTypeMarket:
return intl.prep(intl.ID_MARKET_ORDER)
default: // OrderTypeCancel
return intl.prep(intl.ID_CANCEL_ORDER)
}
}

0 comments on commit 502c18a

Please sign in to comment.