Skip to content

Commit

Permalink
Merge pull request #30 from deriv-com/sandeep/bot-1694/self-exclusion…
Browse files Browse the repository at this point in the history
…-fix

fix: 🔥 fixed the auth flow for bot application
  • Loading branch information
sandeep-deriv authored Jul 24, 2024
2 parents 0b20250 + 6ded83b commit a826080
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
4 changes: 4 additions & 0 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';

const path = require('path');

export default defineConfig({
Expand Down Expand Up @@ -52,6 +53,9 @@ export default defineConfig({
html: {
template: './index.html',
},
server: {
port: 8443,
},
tools: {
rspack: {
plugins: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { observer as globalObserver } from '../../utils/observer';
import { doUntilDone, socket_state } from '../tradeEngine/utils/helpers';
import { generateDerivApiInstance, getLoginId, getToken } from './appId';
import { generateDerivApiInstance, V2GetActiveClientId, V2GetActiveToken } from './appId';
import chart_api from './chart-api';

class APIBase {
Expand Down Expand Up @@ -30,7 +30,7 @@ class APIBase {
this.time_interval = null;
this.getTime();

if (getLoginId()) {
if (V2GetActiveToken()) {
await this.authorizeAndSubscribe();
}
chart_api.init();
Expand Down Expand Up @@ -74,26 +74,34 @@ class APIBase {
};

async authorizeAndSubscribe() {
const { token, account_id } = getToken();
const token = V2GetActiveToken();
if (token) {
this.token = token;
this.account_id = account_id;
this.api.authorize(this.token);
this.account_id = V2GetActiveClientId();
try {
const { authorize } = await this.api.expectResponse('authorize');
const { authorize, error } = await this.api.authorize(this.token);
console.log(authorize, error, 'authorize authorize');
if (error) return error;

if (this.has_active_symbols) {
this.toggleRunButton(false);
} else {
this.active_symbols_promise = this.getActiveSymbols();
}
await this.subscribe();
this.account_info = authorize;
this.subscribe();
this.getSelfExclusion();
} catch (e) {
globalObserver.emit('Error', e);
}
}
}

async getSelfExclusion() {
const data = await this.api.getSelfExclusion();
console.log(data, 'data data');
}

async subscribe() {
await Promise.all([
doUntilDone(() => this.api.send({ balance: 1, subscribe: 1 })),
Expand Down
18 changes: 18 additions & 0 deletions src/external/bot-skeleton/services/api/appId.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ export const getLoginId = () => {
return null;
};

export const V2GetActiveToken = () => {
const token = localStorage.getItem('authToken');
if (token && token !== 'null') return token;
return null;
};

export const V2GetActiveClientId = () => {
const token = V2GetActiveToken();

if (!token) return null;
const account_list = JSON.parse(localStorage.getItem('accountsList'));
if (account_list && account_list !== 'null') {
const active_clientId = Object.keys(account_list).find(key => account_list[key] === token);
return active_clientId;
}
return null;
};

export const getToken = () => {
const active_loginid = getLoginId();
const client_accounts = JSON.parse(localStorage.getItem('client.accounts')) || undefined;
Expand Down

0 comments on commit a826080

Please sign in to comment.