Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sandeep/65842/unifiy-websocket -- using the same websocket instance from the core … #6555

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(generateDerivApiInstance());
const ticksService = new TicksService(WS.get());

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

Expand Down
12 changes: 0 additions & 12 deletions packages/bot-skeleton/src/services/api/appId.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ 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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why accountInfo gets null here? If it gets null meybe there are some problems ... because it doea not seem reasonable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In DBot there is a problem.
With every request such as if we request for tick, then in the response there will be a tick object or error in worst case.
So here we are checking for the msg_type === 'authorize' and setting the whole data (response) object in the accountInfo which I think is incorrect.

bot-skeleton>src>services>tradeEngine>trade>index.js loginAndGetBalance()

Screenshot 2022-09-23 at 12 10 12 PM

This is the response object of authorize.
the whole object is data.

Screenshot 2022-09-23 at 12 18 21 PM

Now the places where we are using this.accountInfo.loginId it will always give error or undefined because the data object doesn't contain loginid but authorize inside data does.

and here you can see the result of console which I added inside trade>balance.js

Screenshot 2022-09-23 at 12 24 39 PM

and this all is happening in master branch.

So I just corrected the assignment of object in trade>index.js file. And it works fine now
@sara-fs

}
});
}
Expand Down
18 changes: 15 additions & 3 deletions packages/bot-skeleton/src/services/tradeEngine/trade/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ 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 @@ -130,19 +133,28 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
}, 1500);
}
if (data.msg_type === 'authorize') {
this.accountInfo = data;
const { authorize = {} } = data;
this.accountInfo = authorize;
this.token = token;

// Only subscribe to balance in browser, not for tests.
if (document) {
doUntilDone(() => this.api.send({ balance: 1, subscribe: 1 })).then(r => {
doUntilDone(() => this.api.send({ balance: 1 })).then(r => {
this.balance = Number(r.balance.balance);
resolve();
});
sandeep-deriv marked this conversation as resolved.
Show resolved Hide resolved
} else {
resolve();
}
doUntilDone(() => this.api.send({ transaction: 1, subscribe: 1 }));
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);
});
}
}
});
});
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 { generateDerivApiInstance } from '../../api/appId';
import { WS } from '@deriv/shared';

export const createScope = () => {
const observer = new Observer();
const api = generateDerivApiInstance();
const api = WS.get();
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,13 +180,6 @@ 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: 2 additions & 1 deletion 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 } from '@deriv/shared';
import { LocalStore, setWebsocket } from '@deriv/shared';
import { MobxContentProvider } from 'Stores/connect';
import RootStore from 'Stores';
import GTM from 'Utils/gtm';
Expand All @@ -31,6 +31,7 @@ const App = ({ passthrough }) => {
const { onMount, onUnmount, showDigitalOptionsMaltainvestError } = app;

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