Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 15 additions & 13 deletions src/botPage/common/symbolApi/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ActiveSymbols from './activeSymbols';
import config from '../../common/const';
import { getObjectValue } from '../../../common/utils/tools';
import { getTokenList } from '../../../common/utils/storageManager';
import { getTokenList, removeAllTokens } from '../../../common/utils/storageManager';

const noop = () => {};

Expand Down Expand Up @@ -44,7 +44,7 @@ export default class _Symbol {
constructor(api) {
this.api = api;
this.initPromise = new Promise(resolve => {
const getActiveSymbolsPromise = () => {
const getActiveSymbolsLogic = () => {
this.api.getActiveSymbolsBrief().then(r => {
this.activeSymbols = new ActiveSymbols(r.active_symbols);
this.api.getAssetIndex().then(r2 => {
Expand All @@ -53,17 +53,19 @@ export default class _Symbol {
}, noop);
}, noop);
};
// Authorize when possible for accurate offered symbols, assetindex
const getAuthorisePromise = () => {
const tokenList = getTokenList();
if (tokenList.length) {
return this.api.authorize(tokenList[0].token);
}
return new Promise(r => r());
};
getAuthorisePromise()
.then(() => getActiveSymbolsPromise(), noop)
.catch(() => getActiveSymbolsPromise(), noop);
// Authorize the WS connection when possible for accurate offered Symbols & AssetIndex
const tokenList = getTokenList();
if (tokenList.length) {
this.api
.authorize(tokenList[0].token)
.then(getActiveSymbolsLogic())
.catch(() => {
removeAllTokens();
getActiveSymbolsLogic();
});
} else {
getActiveSymbolsLogic();
}
});
}
/* eslint-disable class-methods-use-this */
Expand Down
20 changes: 15 additions & 5 deletions src/botPage/view/blockly/blocks/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { symbolApi } from '../../shared';
import config from '../../../common/const';
import { generateLiveApiInstance } from '../../../../common/appId';
import { translate } from '../../../../common/i18n';
import { get as getStorage, set as setStorage, getTokenList } from '../../../../common/utils/storageManager';
import {
get as getStorage,
set as setStorage,
getTokenList,
removeAllTokens,
} from '../../../../common/utils/storageManager';

let purchaseChoices = [[translate('Click to select'), '']];

Expand Down Expand Up @@ -136,21 +141,27 @@ export const dependentFieldMapping = {

export const getAvailableDurations = (symbol, selectedContractType) => {
const contractsForStore = JSON.parse(getStorage('contractsForStore') || '[]');
const tokenList = getTokenList();
let tokenList = getTokenList();
const defaultDurations = [
[translate('Ticks'), 't'],
[translate('Seconds'), 's'],
[translate('Minutes'), 'm'],
[translate('Hours'), 'h'],
[translate('Days'), 'd'],
];

const getContractsForSymbolFromApi = async underlyingSymbol => {
// Refactor this when reducing WS connections
let api = generateLiveApiInstance();
const api = generateLiveApiInstance();

// Try to authorize for accurate contracts response
if (tokenList.length) {
await api.authorize(tokenList[0].token);
try {
await api.authorize(tokenList[0].token);
} catch (e) {
removeAllTokens();
tokenList = [];
}
}

const response = await api.getContractsForSymbol(underlyingSymbol);
Expand All @@ -176,7 +187,6 @@ export const getAvailableDurations = (symbol, selectedContractType) => {
setStorage('contractsForStore', JSON.stringify(contractsForStore));
}
api.disconnect();
api = null;
return contractsForSymbol;
};
const getDurationsForContract = contractsForSymbol => {
Expand Down
2 changes: 1 addition & 1 deletion src/botPage/view/blockly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ Blockly.ContextMenu.show = (e, menuOptions, rtl) => {
if (window._elev) {
menuOptions.some(option => {
if (option.text === Blockly.Msg.HELP) {
option.callback = () => window._elev.open(); // eslint-disable-line no-param-reassign, no-underscore-dangle
option.callback = () => window._elev.openHome(); // eslint-disable-line no-param-reassign, no-underscore-dangle
return true;
}
return false;
Expand Down