From 502c18a1a2228efa0dfac60d31c0b6cd9fd7e4d2 Mon Sep 17 00:00:00 2001 From: dev-warrior777 <> Date: Tue, 29 Oct 2024 23:48:40 +0800 Subject: [PATCH] webserver/site: refactor order type processing 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 --- client/webserver/jsintl.go | 5 +++++ client/webserver/site/src/js/locales.ts | 1 + client/webserver/site/src/js/markets.ts | 17 +---------------- client/webserver/site/src/js/orderutil.ts | 11 +++++++++++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/client/webserver/jsintl.go b/client/webserver/jsintl.go index 733be59e2e..1a433f514c 100644 --- a/client/webserver/jsintl.go +++ b/client/webserver/jsintl.go @@ -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" @@ -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"}, @@ -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{ diff --git a/client/webserver/site/src/js/locales.ts b/client/webserver/site/src/js/locales.ts index 1dd2ee7ddf..afd93e9047 100644 --- a/client/webserver/site/src/js/locales.ts +++ b/client/webserver/site/src/js/locales.ts @@ -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' diff --git a/client/webserver/site/src/js/markets.ts b/client/webserver/site/src/js/markets.ts index 5dfb02bcec..bf9c414e49 100644 --- a/client/webserver/site/src/js/markets.ts +++ b/client/webserver/site/src/js/markets.ts @@ -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', () => { diff --git a/client/webserver/site/src/js/orderutil.ts b/client/webserver/site/src/js/orderutil.ts index eb5d99c016..c136704617 100644 --- a/client/webserver/site/src/js/orderutil.ts +++ b/client/webserver/site/src/js/orderutil.ts @@ -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) + } +}