Skip to content

Commit

Permalink
fix: 🔥 removed core ws and fixing chart
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeep-deriv committed Jun 24, 2024
1 parent 1702a71 commit b5186d9
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 42 deletions.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"start": "vite",
"start:dev": "vite-live-preview --reload --port=8443",
"start:dev": "vite-live-preview --reload --port=8444",
"build": "vite build",
"preview": "vite preview",
"test:lint": "prettier --log-level silent --write . && eslint \"./src/**/*.?(js|jsx|ts|tsx)\"",
Expand Down Expand Up @@ -113,6 +113,7 @@
"ts-jest": "^29.1.2",
"typescript": "^5.2.2",
"vite-live-preview": "^0.1.6",
"vite-plugin-static-copy": "^1.0.5",
"vite-plugin-svgr": "^4.2.0",
"vite-require": "^0.2.3",
"vite-tsconfig-paths": "^4.3.2",
Expand Down
6 changes: 6 additions & 0 deletions src/app/app-content.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { ToastContainer } from 'react-toastify';

import { setSmartChartsPublicPath } from '@deriv/deriv-charts';
import { Loader } from '@deriv-com/ui';

import { getUrlBase } from '@/components/shared';
import TransactionDetailsModal from '@/components/transaction-details';
import { api_base, ApiHelpers, ServerTime } from '@/external/bot-skeleton';
import { useStore } from '@/hooks/useStore';
Expand Down Expand Up @@ -57,6 +59,10 @@ const AppContent = () => {
}
};

React.useEffect(() => {
setSmartChartsPublicPath(getUrlBase('/js/smartcharts/'));
}, []);

React.useEffect(() => {
// Listen for proposal open contract messages to check
// if there is any active contract from bot still running
Expand Down
7 changes: 3 additions & 4 deletions src/components/trade-animation/trade-animation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ const TradeAnimation = observer(({ className, should_show_overlay }: TTradeAnima
onStopBotClick,
performSelfExclusionCheck,
} = run_panel;
const { account_status } = client;
const { account_status, is_logged_in } = client;
const cashier_validation = account_status?.cashier_validation;
const [shouldDisable, setShouldDisable] = React.useState(false);
const is_unavailable_for_payment_agent = cashier_validation?.includes('WithdrawServiceUnavailableForPA');

// perform self-exclusion checks which will be stored under the self-exclusion-store
React.useEffect(() => {
performSelfExclusionCheck();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (is_logged_in) performSelfExclusionCheck();
}, [is_logged_in, performSelfExclusionCheck]);

React.useEffect(() => {
if (shouldDisable) {
Expand Down
2 changes: 1 addition & 1 deletion src/external/bot-skeleton/services/api/active-symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ActiveSymbols {

this.is_initialised = true;

if (api_base.has_activeSymbols) {
if (api_base.has_active_symbols) {
this.active_symbols = api_base?.active_symbols ?? [];
} else {
await api_base.active_symbols_promise;
Expand Down
52 changes: 27 additions & 25 deletions src/external/bot-skeleton/services/api/api-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@ class APIBase {
is_running = false;
subscriptions = [];
time_interval = null;
has_activeSymbols = false;
has_active_symbols = false;
is_stopping = false;
active_symbols = [];

active_symbols_promise = null;

async init(force_update = false) {
this.toggleRunButton(true);
if (force_update) this.terminate();
this.api = generateDerivApiInstance();
if (!this.has_active_symbols) {
this.active_symbols_promise = this.getActiveSymbols();
}
this.initEventListeners();
if (this.time_interval) clearInterval(this.time_interval);
this.time_interval = null;
this.getTime();

if (getLoginId()) {
this.toggleRunButton(true);
if (force_update) this.terminate();
this.api = generateDerivApiInstance();
this.initEventListeners();
await this.authorizeAndSubscribe();
if (this.time_interval) clearInterval(this.time_interval);
this.time_interval = null;
this.getTime();
} else {
this.api = generateDerivApiInstance();
if (!this.has_activeSymbols) {
this.active_symbols_promise = this.getActiveSymbols();
}
}
}

Expand Down Expand Up @@ -81,10 +80,10 @@ class APIBase {
this.api.authorize(this.token);
try {
const { authorize } = await this.api.expectResponse('authorize');
if (this.has_activeSymbols) {
if (this.has_active_symbols) {
this.toggleRunButton(false);
} else {
this.getActiveSymbols = this.getActiveSymbols();
this.active_symbols_promise = this.getActiveSymbols();
}
await this.subscribe();
this.account_info = authorize;
Expand All @@ -103,16 +102,19 @@ class APIBase {
}

getActiveSymbols = async () => {
await doUntilDone(() => this.api.send({ active_symbols: 'brief' })).then(({ active_symbols = [] }) => {
const pip_sizes = {};
if (active_symbols.length) this.has_activeSymbols = true;
active_symbols.forEach(({ symbol, pip }) => {
pip_sizes[symbol] = +(+pip).toExponential().substring(3);
});
this.pip_sizes = pip_sizes;
this.toggleRunButton(false);
this.active_symbols = active_symbols;
});
await doUntilDone(() => this.api.send({ active_symbols: 'brief' })).then(
({ active_symbols = [], error = {} }) => {
const pip_sizes = {};
if (active_symbols.length) this.has_active_symbols = true;
active_symbols.forEach(({ symbol, pip }) => {
pip_sizes[symbol] = +(+pip).toExponential().substring(3);
});
this.pip_sizes = pip_sizes;
this.toggleRunButton(false);
this.active_symbols = active_symbols;
return active_symbols || error;
}
);
};

toggleRunButton = toggle => {
Expand Down
4 changes: 3 additions & 1 deletion src/external/bot-skeleton/services/api/contracts-for.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { config } from '../../constants/config';
import PendingPromise from '../../utils/pending-promise';

import { api_base } from './api-base';

export default class ContractsFor {
constructor({ ws, server_time }) {
this.cache_age_in_min = 10;
Expand Down Expand Up @@ -196,7 +198,7 @@ export default class ContractsFor {
}

this.retrieving_contracts_for[symbol] = new PendingPromise();
const response = await this.ws.send({ contracts_for: symbol });
const response = await api_base.api.send({ contracts_for: symbol });

if (response.error) {
return [];
Expand Down
10 changes: 6 additions & 4 deletions src/pages/chart/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { useEffect } from 'react';
import classNames from 'classnames';
import { observer } from 'mobx-react-lite';

import { ChartTitle, setSmartChartsPublicPath, SmartChart } from '@deriv/deriv-charts';
import { ChartTitle, SmartChart } from '@deriv/deriv-charts';

import { getUrlBase } from '@/components/shared';
import { useStore } from '@/hooks/useStore';

import ToolbarWidgets from './toolbar-widgets';
Expand All @@ -27,6 +26,7 @@ const Chart = observer(({ show_digits_stats }: { show_digits_stats: boolean }) =
wsForgetStream,
wsSendRequest,
wsSubscribe,
updateSymbol,
} = chart_store;
const {
ui: { is_mobile, is_desktop },
Expand All @@ -44,8 +44,10 @@ const Chart = observer(({ show_digits_stats }: { show_digits_stats: boolean }) =
};

useEffect(() => {
setSmartChartsPublicPath(getUrlBase('/js/smartcharts/'));
}, []);
updateSymbol();
}, [updateSymbol]);

if (!symbol) return null;

return (
<div
Expand Down
2 changes: 1 addition & 1 deletion src/stores/load-modal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default class LoadModalStore implements ILoadModalStore {

get selected_strategy(): TStrategy {
return (
this.dashboard_strategies.find((ws: { id: string }) => ws.id === this.selected_strategy_id) ??
this.dashboard_strategies.find((workspace: { id: string }) => workspace.id === this.selected_strategy_id) ??
this.dashboard_strategies[0]
);
}
Expand Down
1 change: 0 additions & 1 deletion src/stores/root-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default class RootStore {
public data_collection_store: DataCollectionStore;

core = {};
ws = null;

constructor(dbot: unknown) {
this.dbot = dbot;
Expand Down
4 changes: 2 additions & 2 deletions src/stores/self-exclusion-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export default class SelfExclusionStore {

async checkRestriction() {
if (api_base.api) {
api_base.api.getSelfExclusion().then(response => {
const { max_losses: maxLosses } = response.get_self_exclusion;
api_base.api.getSelfExclusion().then(({ get_self_exclusion }) => {
const { max_losses: maxLosses } = get_self_exclusion;
if (maxLosses) {
this.setApiMaxLosses(maxLosses);
}
Expand Down
3 changes: 2 additions & 1 deletion src/stores/summary-card-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getIndicativePrice, isEqualObject, isMultiplierContract } from '@/compo
import { TContractInfo } from '@/components/summary/summary-card.types';
import { getValidationRules, TValidationRuleIndex, TValidationRules } from '@/constants/contract';
import { contract_stages } from '@/constants/contract-stage';
import { api_base } from '@/external/bot-skeleton';
import { getContractUpdateConfig } from '@/utils/multiplier';
import Validator from '@/utils/tmp/validator';

Expand Down Expand Up @@ -212,7 +213,7 @@ export default class SummaryCardStore {
const limit_order = this.getLimitOrder();

if (this.contract_info?.contract_id) {
this.root_store.ws.contractUpdate(this.contract_info?.contract_id, limit_order).then(response => {
api_base.api.contractUpdate(this.contract_info?.contract_id, limit_order).then(response => {
if (response.error) {
this.root_store.run_panel.showContractUpdateErrorDialog(response.error.message);
return;
Expand Down
11 changes: 10 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import svgr from 'vite-plugin-svgr';
import { viteRequire } from 'vite-require';
import tsconfigPaths from 'vite-tsconfig-paths';
Expand Down Expand Up @@ -28,6 +29,14 @@ export default defineConfig({
}
},
},
viteStaticCopy({
targets: [
{
src: 'node_modules/@deriv/deriv-charts/dist/*',
dest: 'js/smartcharts',
},
],
}),
],
css: {
preprocessorOptions: {
Expand All @@ -47,6 +56,6 @@ export default defineConfig({
},
},
server: {
port: 8443,
port: 8444,
},
});

0 comments on commit b5186d9

Please sign in to comment.