diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1fe4aefe1..4043f6e4a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,4 +3,4 @@ # More info: https://help.github.com/articles/about-codeowners/ # -* @binary-com/write-admin-smartcharts \ No newline at end of file +* @binary-com/write-admin-smartcharts diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7b2ee3a62..a276517bb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,7 @@ updates: directory: "/" schedule: interval: daily + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/generate_preview_link.yml b/.github/workflows/generate_preview_link.yml index 3c108eaad..a0217a087 100644 --- a/.github/workflows/generate_preview_link.yml +++ b/.github/workflows/generate_preview_link.yml @@ -4,26 +4,23 @@ on: pull_request_target: types: [opened, synchronize] -env: - HEAD_REF: ${{ github.head_ref }} - concurrency: - group: cloudflare-pages-build-"$HEAD_REF" + group: cloudflare-pages-build-${{ github.head_ref }} cancel-in-progress: true jobs: build_and_deploy_preview_link: - if: github.event.pull_request.user.login == 'ahmadtaimoor-deriv' runs-on: Ubuntu-latest permissions: checks: write pull-requests: write steps: - # - name: Verify user - # uses: "deriv-com/shared-actions/.github/actions/verify_user_in_organization@v1" - # with: - # username: ${{github.event.pull_request.user.login}} - # token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + - name: Verify user + uses: "deriv-com/shared-actions/.github/actions/verify_user_in_organization@v1" + with: + username: ${{github.event.pull_request.user.login}} + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + - name: Post preview build comment id: post_preview_build_comment uses: 'deriv-com/shared-actions/.github/actions/post_preview_build_comment@v1' @@ -32,7 +29,7 @@ jobs: head_sha: ${{github.event.pull_request.head.sha}} - name: Checkout SmartCharts - uses: 'ahmadtaimoor-deriv/SmartCharts/.github/actions/checkout@master' + uses: 'binary-com/SmartCharts/.github/actions/checkout@master' with: repository: ${{github.event.pull_request.user.login}}/SmartCharts path: SmartCharts @@ -41,7 +38,8 @@ jobs: alternate_ref: master - name: Checkout deriv-app - uses: 'ahmadtaimoor-deriv/SmartCharts/.github/actions/checkout@master' + id: deriv_app + uses: 'binary-com/SmartCharts/.github/actions/checkout@master' with: repository: ${{github.event.pull_request.user.login}}/deriv-app path: deriv-app @@ -50,9 +48,10 @@ jobs: alternate_ref: master - name: Custom flutter-chart - uses: 'ahmadtaimoor-deriv/SmartCharts/.github/actions/checkout@master' + id: flutter_chart + uses: 'binary-com/SmartCharts/.github/actions/checkout@master' with: - repository: ${{github.event.pull_request.user.login}}/flutter-chartz + repository: ${{github.event.pull_request.user.login}}/flutter-chart path: flutter-chart ref: ${{github.head_ref}} alternate_repository: 'regentmarkets/flutter-chart' @@ -116,7 +115,7 @@ jobs: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_TEST_LINKS_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_TEST_LINKS_ACCOUNT_ID }} project_name: 'smartcharts-preview' - branch_name: 'pr-${{github.event.number}}' + branch_name: pr-${{github.event.number}}${{ steps.deriv_app.outputs.ref_exists == true && '-dtra' || ''}}${{ steps.flutter_chart.outputs.ref_exists == true && '-flutt' || ''}} output_dir: deriv-app/packages/core/dist - name: 'Generate preview link comment' @@ -126,4 +125,4 @@ jobs: issue_number: ${{github.event.number}} check_run_id: ${{steps.post_preview_build_comment.outputs.check_run_id}} preview_url: ${{steps.publish_to_pages_branch.outputs.cf_pages_url}} - status: ${{job.status}} \ No newline at end of file + status: ${{job.status}} 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/sass/components/_barrier.scss b/sass/components/_barrier.scss index ecadd37db..eae07585c 100644 --- a/sass/components/_barrier.scss +++ b/sass/components/_barrier.scss @@ -205,7 +205,6 @@ right: 0; height: 120px !important; opacity: 0.3; - transition: all 0.1s ease-out; } /* css gradients are only partially supported in Safari, but will work here since colors are not premultiplied */ 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(); diff --git a/src/store/BarrierStore.ts b/src/store/BarrierStore.ts index 5f7d7ae6e..d2462ac05 100644 --- a/src/store/BarrierStore.ts +++ b/src/store/BarrierStore.ts @@ -113,6 +113,8 @@ export default class BarrierStore { () => [this.mainStore.chartAdapter.epochBounds, this.mainStore.chartAdapter.quoteBounds], this._drawShadedArea ); + + this.mainStore.chartAdapter.painter.registerCallback(this._drawShadedArea); }; init(): void { @@ -195,6 +197,9 @@ export default class BarrierStore { this.disposeDrawReaction?.(); + this.mainStore.chartAdapter.painter.unregisterCallback(this._drawShadedArea); + + const i = this.mainStore.chart._barriers.findIndex((b: BarrierStore) => b === this); if (i !== -1) { this.mainStore.chart._barriers.splice(i, 1); diff --git a/src/store/TimeperiodStore.ts b/src/store/TimeperiodStore.ts index 572f14c81..ac85a54cd 100644 --- a/src/store/TimeperiodStore.ts +++ b/src/store/TimeperiodStore.ts @@ -118,7 +118,7 @@ export default class TimeperiodStore { if (dataSegmentClose && dataSegmentClose.length) { const currentQuote = dataSegmentClose[dataSegmentClose.length - 1]; if (currentQuote.DT) { - const now = this._serverTime.getLocalDate().getTime(); + const now = this._serverTime?.getLocalDate()?.getTime(); const diff = now - currentQuote.DT.getTime(); const granularity = this.mainStore.chart.granularity; diff --git a/src/utils/ServerTime.ts b/src/utils/ServerTime.ts index b95860be2..4ab03e893 100644 --- a/src/utils/ServerTime.ts +++ b/src/utils/ServerTime.ts @@ -84,8 +84,7 @@ class ServerTime { if (this.serverTimeAtResponse) { return this.serverTimeAtResponse; } - - throw new Error('Server time is undefined!'); + return getUTCEpoch(new Date()); } getLocalDate() {