Skip to content

Commit

Permalink
Revert "sandeep/65842/unifiy-websocket -- using the same websocket in…
Browse files Browse the repository at this point in the history
…stance from the core … (binary-com#6555)" (binary-com#6623)

This reverts commit e2b3d2e.
  • Loading branch information
carolsachdeva committed Sep 28, 2022
1 parent 6c95773 commit 4f3ffcc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-unused-expressions */
import { generateDerivApiInstance } from '../appId';
import TicksService from '../ticks_service';
import { WS } from '@deriv/shared';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;

const ticksService = new TicksService(WS.get());
const ticksService = new TicksService(generateDerivApiInstance());

const isTick = t => Number.isInteger(t.epoch) && Number.isFinite(t.quote);

Expand Down
12 changes: 12 additions & 0 deletions packages/bot-skeleton/src/services/api/appId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import DerivAPIBasic from '@deriv/deriv-api/dist/DerivAPIBasic';
import { getAppId, getSocketURL, website_name } from '@deriv/shared';
import { getLanguage } from '@deriv/translations';

export const generateDerivApiInstance = () => {
const socket_url = `wss://${getSocketURL()}/websockets/v3?app_id=${getAppId()}&l=${getLanguage()}&brand=${website_name.toLowerCase()}`;
const deriv_socket = new WebSocket(socket_url);
const deriv_api = new DerivAPIBasic({
connection: deriv_socket,
});
return deriv_api;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default Engine =>
} = data;

balance_string = getFormattedText(b, currency);
info({ accountID: this.accountInfo?.loginid, balance: balance_string });

info({ accountID: this.accountInfo.loginid, balance: balance_string });
}
});
}
Expand Down
18 changes: 3 additions & 15 deletions packages/bot-skeleton/src/services/tradeEngine/trade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
forget_proposal_ids: [],
};
this.store = createStore(rootReducer, applyMiddleware(thunk));
this.api.connection.onclose = () => {
globalObserver.setState({ transaction_subscription_id: null });
};
}

init(...args) {
Expand Down Expand Up @@ -133,28 +130,19 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
}, 1500);
}
if (data.msg_type === 'authorize') {
const { authorize = {} } = data;
this.accountInfo = authorize;
this.accountInfo = data;
this.token = token;

// Only subscribe to balance in browser, not for tests.
if (document) {
doUntilDone(() => this.api.send({ balance: 1 })).then(r => {
doUntilDone(() => this.api.send({ balance: 1, subscribe: 1 })).then(r => {
this.balance = Number(r.balance.balance);
resolve();
});
} else {
resolve();
}
if (!globalObserver.getState('transaction_subscription_id')) {
doUntilDone(() => this.api.send({ transaction: 1, subscribe: 1 }))
.then(({ transaction }) => {
globalObserver.setState({ transaction_subscription_id: transaction.id });
})
.catch(err => {
this.$scope.observer.emit('Error', err);
});
}
doUntilDone(() => this.api.send({ transaction: 1, subscribe: 1 }));
}
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import TicksService from '../../api/ticks_service';
import Observer from '../../../utils/observer';
import { WS } from '@deriv/shared';
import { generateDerivApiInstance } from '../../api/appId';

export const createScope = () => {
const observer = new Observer();
const api = WS.get();
const api = generateDerivApiInstance();
const ticksService = new TicksService(api);
const stopped = false;
return { observer, api, ticksService, stopped };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ const Interpreter = () => {
}

function terminateSession() {
const { connection } = $scope.api;
if (connection.readyState === 0) {
connection.addEventListener('open', () => connection.close());
} else if (connection.readyState === 1) {
connection.close();
}

$scope.stopped = true;
$scope.is_error_triggered = false;
globalObserver.emit('bot.stop');
Expand Down
3 changes: 1 addition & 2 deletions packages/bot-web-ui/src/app/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Toolbar,
NetworkToastPopup,
} from 'Components';
import { LocalStore, setWebsocket } from '@deriv/shared';
import { LocalStore } from '@deriv/shared';
import { MobxContentProvider } from 'Stores/connect';
import RootStore from 'Stores';
import GTM from 'Utils/gtm';
Expand All @@ -31,7 +31,6 @@ const App = ({ passthrough }) => {
const { onMount, onUnmount, showDigitalOptionsMaltainvestError } = app;

React.useEffect(() => {
setWebsocket(WS);
/**
* Inject: External Script Hotjar - for DBot only
*/
Expand Down

0 comments on commit 4f3ffcc

Please sign in to comment.