Refactor code structure for improved readability and maintainability

This commit is contained in:
2025-12-30 21:27:20 +07:00
parent 391acd574b
commit f35f281cb6
3 changed files with 984 additions and 983 deletions

View File

@@ -9,6 +9,10 @@ const { updateProfile } = useUserStore();
const platform = usePlatform();
const { checkAndPromptUpdate } = useAppUpdate();
onBeforeMount(() => {
loadSavedLanguage();
});
onMounted(() => {
if (!isAuthenticated.value)
return;
@@ -26,10 +30,6 @@ onMounted(() => {
}
});
onBeforeMount(() => {
loadSavedLanguage();
});
watch(locale, (newLocale) => {
document.querySelector("html")?.setAttribute("lang", newLocale);
}, { immediate: true });

View File

@@ -136,6 +136,6 @@ export const TradingViewChart = defineComponent({
}, 0);
});
return () => <div ref={el} class="w-full" style={styles.value} />;
return () => h("div", { ref: el, class: "w-full", style: styles.value });
},
});

View File

@@ -9,7 +9,7 @@ export declare const enum SearchInitiationPoint {
SymbolSearch = "symbolSearch",
Watchlist = "watchlist",
Compare = "compare",
IndicatorInputs = "indicatorInputs"
IndicatorInputs = "indicatorInputs",
}
/**
* This is the generic type useful for declaring a nominal type,
@@ -24,14 +24,15 @@ export declare const enum SearchInitiationPoint {
* @example
* type TagName = Nominal<string, 'TagName'>;
*/
export declare type Nominal<T, Name extends string> = T & { /* eslint-disable-next-line jsdoc/require-jsdoc */
export declare type Nominal<T, Name extends string> = T & {
[Symbol.species]: Name;
};
/**
* Bar data point
*/
export interface Bar {
/** Bar time.
/**
* Bar time.
* Amount of **milliseconds** since Unix epoch start in **UTC** timezone.
* `time` for daily, weekly, and monthly bars is expected to be a trading day (not session start day) at 00:00 UTC.
* The library adjusts time according to `session` from {@link LibrarySymbolInfo}.
@@ -273,7 +274,7 @@ export interface IDatafeedChartApi {
* @param onDataCallback Callback function containing an array of marks
* @param resolution Resolution of the symbol
*/
getMarks?(symbolInfo: LibrarySymbolInfo, from: number, to: number, onDataCallback: GetMarksCallback<Mark>, resolution: ResolutionString): void;
getMarks?: (symbolInfo: LibrarySymbolInfo, from: number, to: number, onDataCallback: GetMarksCallback<Mark>, resolution: ResolutionString) => void;
/**
* The library calls this function to get timescale marks for visible bars range.
* The library assumes that you will call `onDataCallback` only once per `getTimescaleMarks` call.
@@ -286,7 +287,7 @@ export interface IDatafeedChartApi {
* @param onDataCallback Callback function containing an array of marks
* @param resolution Resolution of the symbol
*/
getTimescaleMarks?(symbolInfo: LibrarySymbolInfo, from: number, to: number, onDataCallback: GetMarksCallback<TimescaleMark>, resolution: ResolutionString): void;
getTimescaleMarks?: (symbolInfo: LibrarySymbolInfo, from: number, to: number, onDataCallback: GetMarksCallback<TimescaleMark>, resolution: ResolutionString) => void;
/**
* This function is called if the `supports_time` configuration flag is `true` when the chart needs to know the server time.
* The library expects a callback to be called once.
@@ -295,7 +296,7 @@ export interface IDatafeedChartApi {
* `getServerTime` is used to display countdown on the price scale.
* Note that the countdown can be displayed only for [intraday](https://www.tradingview.com/charting-library-docs/latest/core_concepts/Resolution#resolution-in-minutes-intraday) resolutions.
*/
getServerTime?(callback: ServerTimeCallback): void;
getServerTime?: (callback: ServerTimeCallback) => void;
/**
* Provides a list of symbols that match the user's search query.
*
@@ -305,7 +306,7 @@ export interface IDatafeedChartApi {
* @param onResult Callback function that returns an array of results ({@link SearchSymbolResultItem}) or empty array if no symbols found
* @param searchSource The source of the search ({@link SearchInitiationPoint}).
*/
searchSymbols(userInput: string, exchange: string, symbolType: string, onResult: SearchSymbolsCallback, searchSource?: SearchInitiationPoint): void;
searchSymbols: (userInput: string, exchange: string, symbolType: string, onResult: SearchSymbolsCallback, searchSource?: SearchInitiationPoint) => void;
/**
* The library will call this function when it needs to get SymbolInfo by symbol name.
*
@@ -314,7 +315,7 @@ export interface IDatafeedChartApi {
* @param onError Callback function whose only argument is a text error message
* @param extension An optional object with additional parameters
*/
resolveSymbol(symbolName: string, onResolve: ResolveCallback, onError: DatafeedErrorCallback, extension?: SymbolResolveExtension): void;
resolveSymbol: (symbolName: string, onResolve: ResolveCallback, onError: DatafeedErrorCallback, extension?: SymbolResolveExtension) => void;
/**
* This function is called when the chart needs a history fragment defined by dates range.
*
@@ -324,7 +325,7 @@ export interface IDatafeedChartApi {
* @param onResult Callback function for historical data
* @param onError Callback function whose only argument is a text error message. If using special characters, please consider `encodeURIComponent`.
*/
getBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, periodParams: PeriodParams, onResult: HistoryCallback, onError: DatafeedErrorCallback): void;
getBars: (symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, periodParams: PeriodParams, onResult: HistoryCallback, onError: DatafeedErrorCallback) => void;
/**
* The library calls this function when it wants to receive real-time updates for a symbol.
* The library assumes that you will call the callback provided by the `onTick` parameter every time you want to update the most recent bar or to add a new one.
@@ -335,13 +336,13 @@ export interface IDatafeedChartApi {
* @param listenerGuid
* @param onResetCacheNeededCallback Function to be executed when bar data has changed
*/
subscribeBars(symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void): void;
subscribeBars: (symbolInfo: LibrarySymbolInfo, resolution: ResolutionString, onTick: SubscribeBarsCallback, listenerGuid: string, onResetCacheNeededCallback: () => void) => void;
/**
* The library calls this function when it doesn't want to receive updates anymore.
*
* @param listenerGuid id to unsubscribe from
*/
unsubscribeBars(listenerGuid: string): void;
unsubscribeBars: (listenerGuid: string) => void;
/**
* The library calls this function when it wants to receive real-time symbol data in the [Depth of Market](https://www.tradingview.com/charting-library-docs/latest/trading_terminal/depth-of-market) (DOM) widget.
* Note that you should set the {@link BrokerConfigFlags.supportLevel2Data} configuration flag to `true`.
@@ -350,14 +351,14 @@ export interface IDatafeedChartApi {
* @param callback A function returning an object to update DOM data
* @returns A unique identifier that will be used to unsubscribe from the data
*/
subscribeDepth?(symbol: string, callback: DOMCallback): string;
subscribeDepth?: (symbol: string, callback: DOMCallback) => string;
/**
* The library calls this function to stop receiving real-time updates for the [Depth of Market](https://www.tradingview.com/charting-library-docs/latest/trading_terminal/depth-of-market) listener.
* Note that you should set the {@link BrokerConfigFlags.supportLevel2Data} configuration flag to `true`.
*
* @param subscriberUID A string returned by `subscribeDepth`
*/
unsubscribeDepth?(subscriberUID: string): void;
unsubscribeDepth?: (subscriberUID: string) => void;
/**
* The library calls this function to get the resolution that will be used to calculate the Volume Profile Visible Range indicator.
*
@@ -371,7 +372,7 @@ export interface IDatafeedChartApi {
* @param symbolInfo A Symbol object
* @returns A resolution
*/
getVolumeProfileResolutionForPeriod?(currentResolution: ResolutionString, from: number, to: number, symbolInfo: LibrarySymbolInfo): ResolutionString;
getVolumeProfileResolutionForPeriod?: (currentResolution: ResolutionString, from: number, to: number, symbolInfo: LibrarySymbolInfo) => ResolutionString;
}
/** Quotes datafeed API */
export interface IDatafeedQuotesApi {
@@ -382,7 +383,7 @@ export interface IDatafeedQuotesApi {
* @param {QuotesCallback} onDataCallback - callback to return the requested data.
* @param {QuotesErrorCallback} onErrorCallback - callback for responding with an error.
*/
getQuotes(symbols: string[], onDataCallback: QuotesCallback, onErrorCallback: QuotesErrorCallback): void;
getQuotes: (symbols: string[], onDataCallback: QuotesCallback, onErrorCallback: QuotesErrorCallback) => void;
/**
* Trading Platform calls this function when it wants to receive real-time quotes for a symbol.
* The library assumes that you will call `onRealtimeCallback` every time you want to update the quotes.
@@ -391,13 +392,13 @@ export interface IDatafeedQuotesApi {
* @param {QuotesCallback} onRealtimeCallback - callback to send realtime quote data updates
* @param {string} listenerGUID - unique identifier of the listener
*/
subscribeQuotes(symbols: string[], fastSymbols: string[], onRealtimeCallback: QuotesCallback, listenerGUID: string): void;
subscribeQuotes: (symbols: string[], fastSymbols: string[], onRealtimeCallback: QuotesCallback, listenerGUID: string) => void;
/**
* Trading Platform calls this function when it doesn't want to receive updates for this listener anymore.
* `listenerGUID` will be the same object that the Library passed to `subscribeQuotes` before.
* @param {string} listenerGUID - unique identifier of the listener
*/
unsubscribeQuotes(listenerGUID: string): void;
unsubscribeQuotes: (listenerGUID: string) => void;
}
export interface IExternalDatafeed {
/**
@@ -406,7 +407,7 @@ export interface IExternalDatafeed {
*
* @param {OnReadyCallback} callback - callback to return your datafeed configuration ({@link DatafeedConfiguration}) to the library.
*/
onReady(callback: OnReadyCallback): void;
onReady: (callback: OnReadyCallback) => void;
}
export interface LibrarySubsessionInfo {
/**
@@ -414,15 +415,15 @@ export interface LibrarySubsessionInfo {
*
* @example "Regular Trading Hours"
*/
description: string;
"description": string;
/**
* Subsession ID.
*/
id: LibrarySessionId;
"id": LibrarySessionId;
/**
* Session string. See {@link LibrarySymbolInfo.session}.
*/
session: string;
"session": string;
/**
* Session corrections string. See {@link LibrarySymbolInfo.corrections}.
*/
@@ -659,9 +660,9 @@ export interface LibrarySymbolInfo {
/**
* The boolean value showing whether or not seconds bars for this symbol can be built from ticks. Only available in Trading Platform.
*
* * {@link LibrarySymbolInfo.has_seconds} must also be `true`
* * {@link LibrarySymbolInfo.has_ticks} must also be `true`
* * {@link LibrarySymbolInfo.seconds_multipliers} must be an empty array or only contain multipliers that the datafeed provides itself
* {@link LibrarySymbolInfo.has_seconds} must also be `true`
* {@link LibrarySymbolInfo.has_ticks} must also be `true`
* {@link LibrarySymbolInfo.seconds_multipliers} must be an empty array or only contain multipliers that the datafeed provides itself
*
* The library builds resolutions from ticks only if there are no seconds resolutions from the datafeed or the provided resolutions are larger then the required one. For example, the datafeed provides `3S` resolution. In this case, the library can build only `1S` or `2S` resolutions from ticks. Resolutions such as `15S` will be build with seconds bars.
* @default false
@@ -827,10 +828,10 @@ export interface LibrarySymbolInfo {
* - `data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4...`
*/
logo_urls?: [
string
string,
] | [
string,
string
string,
];
/**
* URL of image to be displayed as the logo for the exchange. The `show_exchange_logos` featureset needs to be enabled for this to be visible in the UI.
@@ -1000,10 +1001,10 @@ export interface SearchSymbolResultItem {
* - `data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAASABIAAD/4...`
*/
logo_urls?: [
string
string,
] | [
string,
string
string,
];
/**
* URL of image to be displayed as the logo for the exchange. The `show_exchange_logos` featureset needs to be enabled for this to be visible in the UI.