diff --git a/chart_app/lib/src/models/indicators.dart b/chart_app/lib/src/models/indicators.dart index 9797f9447..5d6df46cd 100644 --- a/chart_app/lib/src/models/indicators.dart +++ b/chart_app/lib/src/models/indicators.dart @@ -309,7 +309,7 @@ class IndicatorsModel { values: values, )); } else if (item is AlligatorSeries) { - //TODO : enable offset after fixing in the flutter charts + //TO DO : enable offset after fixing in the flutter charts tooltipContent.add(JsIndicatorTooltip( name: AlligatorIndicatorConfig.name, values: [ @@ -368,6 +368,16 @@ class IndicatorsModel { double y, int bottomIndicatorIndex, ) { + /// Called to get epoch from x position + int? _getClosestEpoch(int? x, int granularity) { + try { + return getClosestEpoch?.call(x, granularity); + // ignore: avoid_catches_without_on_clauses + } catch (_) { + return null; + } + } + int configIndex = 0; Series? bottomItemIndicator; final List sortedSeriesList = [...seriesList]; @@ -388,9 +398,11 @@ class IndicatorsModel { final Offset target = Offset(x, y); final int? epoch = - getClosestEpoch?.call(controller.getEpochFromX(x), granularity); + _getClosestEpoch(controller.getEpochFromX(x), granularity); - if (bottomItemIndicator != null && bottomIndicatorIndex != null) { + if (bottomItemIndicator != null && + bottomIndicatorIndex > -1 && + epoch != null) { if (bottomItemIndicator is AwesomeOscillatorSeries) { final List aoEntries = bottomItemIndicator.entries ?? []; @@ -816,11 +828,11 @@ class IndicatorsModel { } } } else if (item is AlligatorSeries) { - final List teethEntries = item.teethSeries!.entries ?? []; + final List teethEntries = item.teethSeries?.entries ?? []; - final List jawEntries = item.jawSeries!.entries ?? []; + final List jawEntries = item.jawSeries?.entries ?? []; - final List lipEntries = item.lipsSeries!.entries ?? []; + final List lipEntries = item.lipsSeries?.entries ?? []; if (isPointOnIndicator( teethEntries, @@ -864,7 +876,7 @@ class IndicatorsModel { if (index != null) { final int quoteIndex = index - offset; - if (quoteIndex <= entries.length - 1) { + if (quoteIndex <= entries.length - 1 && quoteIndex > 0) { final Tick prevIndex = entries[quoteIndex - 1]; final Tick currIndex = entries[quoteIndex]; diff --git a/package-lock.json b/package-lock.json index b02e38538..9aa65d7bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@deriv/deriv-charts", - "version": "2.0.2", + "version": "2.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@deriv/deriv-charts", - "version": "2.0.2", + "version": "2.0.3", "license": "ISC", "dependencies": { "@types/lodash.set": "^4.3.7", diff --git a/package.json b/package.json index d0451cf0e..98b45849f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@deriv/deriv-charts", - "version": "2.0.2", + "version": "2.0.3", "main": "dist/smartcharts.js", "author": "amin@binary.com", "contributors": [ diff --git a/src/feed/Feed.ts b/src/feed/Feed.ts index 0eca8d6cd..142c7a0f8 100644 --- a/src/feed/Feed.ts +++ b/src/feed/Feed.ts @@ -362,6 +362,10 @@ class Feed { end: number, callback: TPaginationCallback ) { + if (this._mainStore.state.hasReachedEndOfData) { + return; + } + const isMainChart = true; // TODO There is no need to get historical data before startTime if (this.startEpoch /* && start < this.startEpoch */ || (this.endEpoch && end > this.endEpoch)) { @@ -407,6 +411,12 @@ class Feed { callback({ moreAvailable: false, quotes: [] }); this.setHasReachedEndOfData(true); } + + if (result.quotes?.length && result.quotes.length < count) { + callback({ moreAvailable: false, quotes: result.quotes }); + this.setHasReachedEndOfData(true); + return; + } } catch (err) { console.error(err); result = { error: err }; diff --git a/src/flutter-chart/index.ts b/src/flutter-chart/index.ts index 98412020d..0739db138 100644 --- a/src/flutter-chart/index.ts +++ b/src/flutter-chart/index.ts @@ -12,6 +12,8 @@ export const createChartElement = ({ onChartLoad }: TCreateChartElementProps) => return; } + setupListeners(); + const flutterChartElement = document.createElement('div'); flutterChartElement.classList.add('flutter-chart'); @@ -42,6 +44,19 @@ export const createChartElement = ({ onChartLoad }: TCreateChartElementProps) => return flutterChartElement; }; +const setupListeners = () => { + const listener = (ev: KeyboardEvent) => { + // To fix a trackjs issue caused by some keyboard events that don't contain `key` or `code` props. + // https://github.com/flutter/engine/blob/f20657354d8b53baafcec55650830ead89adf3e9/lib/web_ui/lib/src/engine/keyboard_binding.dart#L386 + if (!ev.key || !ev.code) { + ev.stopImmediatePropagation(); + } + }; + + window.addEventListener('keydown', listener, true); + window.addEventListener('keyup', listener, true); +}; + export const runChartApp = () => { if (window._flutter.initState.isMounted) { window._flutter.appRunner?.runApp();