Skip to content

Commit

Permalink
Revert V20230106_0 (binary-com#7334)
Browse files Browse the repository at this point in the history
* Revert "fix: summary panel flickering (binary-com#7321)"

This reverts commit b134c88.

* Revert "translations: 📚 sync translations with crowdin (binary-com#7316)"

This reverts commit 37266a2.

* Revert "fix: dbot performance issue -- unified websocket connection and moved… (binary-com#7103)"

This reverts commit 1abb7de.
  • Loading branch information
carolsachdeva committed Jan 9, 2023
1 parent b134c88 commit 69825d3
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 298 deletions.
2 changes: 0 additions & 2 deletions packages/bot-skeleton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
"immutable": "^3.8.2",
"localforage": "^1.9.0",
"lz-string": "^1.4.4",
"mobx": "^6.6.1",
"mobx-react": "^7.5.1",
"redux": "^4.0.1",
"redux-thunk": "^2.2.0",
"scratch-blocks": "0.1.0-prerelease.20200917235131",
Expand Down
8 changes: 0 additions & 8 deletions packages/bot-skeleton/src/scratch/dbot-store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { reaction } from 'mobx';
import { api_base } from '../services/api/api-base';

class DBotStoreInterface {
// TODO here we are suppose to define an interface and implement fields of DBotStore.
handleFileChange = () => {
Expand Down Expand Up @@ -30,11 +27,6 @@ class DBotStore extends DBotStoreInterface {
this.handleFileChange = store.handleFileChange;
this.startLoading = store.startLoading;
this.endLoading = store.endLoading;

reaction(
() => this.client.loginid,
() => api_base.createNewInstance(this.client.loginid)
);
}

static setInstance(store) {
Expand Down
10 changes: 2 additions & 8 deletions packages/bot-skeleton/src/scratch/dbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { observer as globalObserver } from '../utils/observer';
import ApiHelpers from '../services/api/api-helpers';
import Interpreter from '../services/tradeEngine/utils/interpreter';
import { setColors } from './hooks/colours';
import { api_base } from '../services/api/api-base';

class DBot {
constructor() {
Expand Down Expand Up @@ -98,7 +97,7 @@ class DBot {
window.dispatchEvent(new Event('resize'));
window.addEventListener('dragover', DBot.handleDragOver);
window.addEventListener('drop', e => DBot.handleDropOver(e, handleFileChange));
api_base.init();

// disable overflow
el_scratch_div.parentNode.style.overflow = 'hidden';
resolve();
Expand Down Expand Up @@ -135,7 +134,7 @@ class DBot {
}

this.interpreter = Interpreter();
api_base.setIsRunning(true);

this.interpreter.run(code).catch(error => {
globalObserver.emit('Error', error);
this.stopBot();
Expand Down Expand Up @@ -227,7 +226,6 @@ class DBot {
* that trade will be completed first to reflect correct contract status in UI.
*/
stopBot() {
api_base.setIsRunning(false);
if (this.interpreter) {
this.interpreter.stop();
}
Expand All @@ -243,10 +241,6 @@ class DBot {
}
}

terminateConnection = () => {
api_base.terminate();
};

/**
* Unselects any selected block before running the bot.
*/
Expand Down
123 changes: 0 additions & 123 deletions packages/bot-skeleton/src/services/api/api-base.js

This file was deleted.

16 changes: 0 additions & 16 deletions packages/bot-skeleton/src/services/api/appId.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,3 @@ export const generateDerivApiInstance = () => {
});
return deriv_api;
};

export const getLoginId = () => {
const login_id = localStorage.getItem('active_loginid');
if (login_id && login_id !== 'null') return login_id;
return null;
};

export const getToken = () => {
const active_loginid = getLoginId();
const client_accounts = JSON.parse(localStorage.getItem('client.accounts')) || undefined;
const active_account = (client_accounts && client_accounts[active_loginid]) || {};
return {
token: active_account?.token || undefined,
account_id: active_loginid || undefined,
};
};
48 changes: 18 additions & 30 deletions packages/bot-skeleton/src/services/api/ticks_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Map } from 'immutable';
import { historyToTicks, getLast } from 'binary-utils';
import { doUntilDone, getUUID } from '../tradeEngine/utils/helpers';
import { observer as globalObserver } from '../../utils/observer';
import { api_base } from './api-base';

const parseTick = tick => ({
epoch: +tick.epoch,
Expand Down Expand Up @@ -40,7 +39,8 @@ const updateCandles = (candles, ohlc) => {
const getType = isCandle => (isCandle ? 'candles' : 'ticks');

export default class TicksService {
constructor() {
constructor(api) {
this.api = api;
this.ticks = new Map();
this.candles = new Map();
this.tickListeners = new Map();
Expand All @@ -60,13 +60,23 @@ export default class TicksService {

if (!this.active_symbols_promise) {
this.active_symbols_promise = new Promise(resolve => {
this.pipSizes = api_base.pip_sizes;
resolve(this.pipSizes);
this.getActiveSymbols().then(active_symbols => {
this.pipSizes = active_symbols
.reduce((s, i) => s.set(i.symbol, +(+i.pip).toExponential().substring(3)), new Map())
.toObject();
resolve(this.pipSizes);
});
});
}
return this.active_symbols_promise;
}

getActiveSymbols = async () => {
await this.api.expectResponse('authorize');
const active_symbols = await this.api.send({ active_symbols: 'brief' });
return active_symbols.active_symbols;
};

request(options) {
const { symbol, granularity } = options;

Expand All @@ -79,6 +89,7 @@ export default class TicksService {
if (style === 'candles' && this.candles.hasIn([symbol, Number(granularity)])) {
return Promise.resolve(this.candles.getIn([symbol, Number(granularity)]));
}

return this.requestStream({ ...options, style });
}

Expand Down Expand Up @@ -152,7 +163,7 @@ export default class TicksService {
...(tickSubscription || []),
];

Promise.all(subscription.map(id => doUntilDone(() => api_base.api.forget(id))));
Promise.all(subscription.map(id => doUntilDone(() => this.api.forget(id))));

this.subscriptions = new Map();
}
Expand Down Expand Up @@ -184,7 +195,7 @@ export default class TicksService {
}

observe() {
api_base.api.onMessage().subscribe(({ data }) => {
this.api.onMessage().subscribe(({ data }) => {
if (data.msg_type === 'tick') {
const { tick } = data;
const { symbol, id } = tick;
Expand Down Expand Up @@ -249,7 +260,7 @@ export default class TicksService {
style,
};
return new Promise((resolve, reject) => {
doUntilDone(() => api_base.api.send(request_object), [], api_base)
doUntilDone(() => this.api.send(request_object))
.then(r => {
if (style === 'ticks') {
const ticks = historyToTicks(r.history);
Expand All @@ -267,27 +278,4 @@ export default class TicksService {
.catch(reject);
});
}

forget = subscription_id => {
if (subscription_id) {
api_base.api.forget(subscription_id);
}
};

unsubscribeFromTicksService() {
if (this.ticks_history_promise) {
const { stringified_options } = this.ticks_history_promise;
const { symbol = '' } = JSON.parse(stringified_options);
if (symbol) {
this.forget(this.subscriptions.getIn(['tick', symbol]));
}
}
if (this.candles_promise) {
const { stringified_options } = this.candles_promise;
const { symbol = '' } = JSON.parse(stringified_options);
if (symbol) {
this.forget(this.subscriptions.getIn(['candle', symbol]));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { getFormattedText } from '@deriv/shared';
import { info } from '../utils/broadcast';
import DBotStore from '../../../scratch/dbot-store';
import { api_base } from '../../api/api-base';

let balance_string = '';

export default Engine =>
class Balance extends Engine {
observeBalance() {
const subscription = api_base.api.onMessage().subscribe(({ data }) => {
this.api.onMessage().subscribe(({ data }) => {
if (data.msg_type === 'balance') {
const {
balance: { balance: b, currency },
Expand All @@ -19,7 +18,6 @@ export default Engine =>
info({ accountID: this.accountInfo.loginid, balance: balance_string });
}
});
api_base.pushSubscription(subscription);
}

// eslint-disable-next-line class-methods-use-this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import { sell, openContractReceived } from './state/actions';
import { contractStatus, contract as broadcastContract } from '../utils/broadcast';
import { doUntilDone } from '../utils/helpers';
import DBotStore from '../../../scratch/dbot-store';
import { api_base } from '../../api/api-base';

export default Engine =>
class OpenContract extends Engine {
observeOpenContract() {
const subscription = api_base.api.onMessage().subscribe(({ data }) => {
this.api.onMessage().subscribe(({ data }) => {
if (data.msg_type === 'proposal_open_contract') {
const contract = data.proposal_open_contract;

Expand Down Expand Up @@ -42,7 +41,6 @@ export default Engine =>
}
}
});
api_base.pushSubscription(subscription);
}

waitForAfter() {
Expand All @@ -53,21 +51,15 @@ export default Engine =>

subscribeToOpenContract(contract_id = this.contractId) {
this.contractId = contract_id;
const request_object = {
proposal_open_contract: 1,
contract_id,
subscribe: 1,
};

doUntilDone(() => api_base.api.send(request_object))
doUntilDone(() => this.api.send({ proposal_open_contract: 1, contract_id, subscribe: 1 }))
.then(data => {
const { populateConfig } = DBotStore.instance;
populateConfig(data.proposal_open_contract);
this.openContractId = data.proposal_open_contract.id;
})
.catch(error => {
if (error.error.code !== 'AlreadySubscribed') {
doUntilDone(() => api_base.api.send(request_object)).then(
doUntilDone(() => this.api.send({ proposal_open_contract: 1, contract_id, subscribe: 1 })).then(
response => (this.openContractId = response.proposal_open_contract.id)
);
}
Expand Down
Loading

0 comments on commit 69825d3

Please sign in to comment.