fix market ranking display fallbacks
This commit is contained in:
@@ -26,18 +26,21 @@ class MarketRankingTableRequestClient extends TableRequestClient {
|
||||
private requestParams: string;
|
||||
private fieldIds: number[];
|
||||
private sortId: number;
|
||||
private fallbackNames: Map<string, string>;
|
||||
private listener: MarketRankingCardDataListener;
|
||||
|
||||
constructor(
|
||||
requestParams: string,
|
||||
fieldIds: number[],
|
||||
sortId: number,
|
||||
fallbackNames: Map<string, string>,
|
||||
listener: MarketRankingCardDataListener,
|
||||
) {
|
||||
super(FRAME_ID, PAGE_ID, [], null, undefined);
|
||||
this.requestParams = requestParams;
|
||||
this.fieldIds = fieldIds;
|
||||
this.sortId = sortId;
|
||||
this.fallbackNames = fallbackNames;
|
||||
this.listener = listener;
|
||||
this.setSubscribeIds(fieldIds);
|
||||
}
|
||||
@@ -67,7 +70,7 @@ class MarketRankingTableRequestClient extends TableRequestClient {
|
||||
const item: RankItem = {
|
||||
code: `${codeValue}`,
|
||||
market: `${marketValue}`,
|
||||
name: this.getString(row, TableConstants.DATA_ID_NAME),
|
||||
name: this.getContractName(row, `${codeValue}`, `${marketValue}`),
|
||||
};
|
||||
item.price = this.getNumber(row, TableConstants.DATA_ID_PRICE);
|
||||
item.price_chg = this.getNumber(row, TableConstants.DATA_ID_ZF);
|
||||
@@ -90,6 +93,14 @@ class MarketRankingTableRequestClient extends TableRequestClient {
|
||||
return value === undefined ? '' : `${value}`;
|
||||
}
|
||||
|
||||
private getContractName(row: RowData, code: string, market: string): string {
|
||||
const hqName: string = this.getString(row, TableConstants.DATA_ID_NAME);
|
||||
if (hqName !== '' && hqName !== '--') {
|
||||
return hqName;
|
||||
}
|
||||
return this.fallbackNames.get(`${market}_${code}`) ?? '';
|
||||
}
|
||||
|
||||
private getNumber(row: RowData, fieldId: number): number | undefined {
|
||||
const value = row.originalData.get(fieldId);
|
||||
if (typeof value === 'number') {
|
||||
@@ -145,10 +156,15 @@ export class MarketRankingHqRequestClient {
|
||||
|
||||
const requestParams: string =
|
||||
this.buildRequestParams(contracts, primaryIdx, sortId, fieldIds);
|
||||
const fallbackNames: Map<string, string> = new Map();
|
||||
contracts.forEach((contract: RecommendFuturesItem): void => {
|
||||
fallbackNames.set(`${contract.market}_${contract.contract_code}`, contract.contract_name);
|
||||
});
|
||||
const requestClient = new MarketRankingTableRequestClient(
|
||||
requestParams,
|
||||
fieldIds,
|
||||
sortId,
|
||||
fallbackNames,
|
||||
listener,
|
||||
);
|
||||
requestClient.request(0, contracts.length);
|
||||
|
||||
Reference in New Issue
Block a user