Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
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
132 changes: 66 additions & 66 deletions src/navigation/navigation.es6
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import $ from 'jquery';
import moment from 'moment';
import _ from 'lodash';
import liveapi from '../websockets/binary_websockets';
import rv from '../common/rivetsExtra';
import $navHtml from 'text!./navigation.html';
import $ from 'jquery';
import moment from 'moment';
import _ from 'lodash';
import liveapi from '../websockets/binary_websockets';
import rv from '../common/rivetsExtra';
import $navHtml from 'text!./navigation.html';
import workspace from '../workspace/workspace.js';
import '../common/util';
import 'css!navigation/navigation.css';
Expand All @@ -12,22 +12,23 @@ const menu_selectors = [
'.trade',
'.instruments',
'.resources',
'.workspace',
]
'.workspace'
];

const getType = (acc) => {
let id = acc.loginid || acc.id;
if(!acc || !id) return;
const type = {
MLT:"Gaming",
MF:"Investment",
VRTC:"Virtual",
REAL:(acc.currency || '').toUpperCase() || 'Real'
MLT:'Gaming',
MF:'Investment',
VRTC:'Virtual',
REAL:(acc.currency || '').toUpperCase() || 'Real',
};
id = id.match(/^(MLT|MF|VRTC)/i) ? id.match(/^(MLT|MF|VRTC)/i)[0] : "REAL";
return type[id]+" Account";
};

id = id.match(/^(MLT|MF|VRTC)/i) ? id.match(/^(MLT|MF|VRTC)/i)[0] : 'REAL';

return type[id] + ' Account';
};

const initLoginButton = (root) => {
const account_menu = root.find('.account-menu');
Expand All @@ -38,11 +39,11 @@ const initLoginButton = (root) => {
currency: '',
logout_disabled: false,
account: {
show:false,
type:'',
id:'',
show: false,
type: '',
id: '',
balance: '',
is_virtual:0
is_virtual: 0,
},
show_submenu: false,
show_new_account_link: false,
Expand All @@ -52,18 +53,19 @@ const initLoginButton = (root) => {
},
openFinancialAccountMF: () => {
const financial_account_binary_url = getBinaryUrl('new_account/maltainvestws');
window.open(financial_account_binary_url, '_blank')
window.open(financial_account_binary_url, '_blank');
}
};
const destroy_windows = (data_attribute) => {
$(`.webtrader-dialog[${data_attribute}]`).each((inx, elm) => {
const dlg = $(elm);
dlg.dialog('close');
dlg.one('dialogclose', () => {
_.defer(() => dlg.dialog('instance') && dlg.dialog('destroy') && dlg.remove());
});
});
}

const destroy_windows = (data_attribute) => {
$(`.webtrader-dialog[${data_attribute}]`).each((inx, elm) => {
const dlg = $(elm);
dlg.dialog('close');
dlg.one('dialogclose', () => {
_.defer(() => dlg.dialog('instance') && dlg.dialog('destroy') && dlg.remove());
});
});
}

state.oauth = local_storage.get('oauth') || [];
state.oauth = state.oauth.map((e) => {
Expand Down Expand Up @@ -91,10 +93,9 @@ const destroy_windows = (data_attribute) => {
destroy_windows('data-account-specific=true');
liveapi.switch_account(id)
.catch((err) => {
$.growl.error({message: err.message});
$.growl.error({ message: err.message });
// logout user if he decided to self exclude himself.
if(err.code==="SelfExclusion"){
console.log("logging out because of self exclude");
if (err.code === 'SelfExclusion') {
liveapi.invalidate();
}
});
Expand All @@ -105,8 +106,8 @@ const destroy_windows = (data_attribute) => {
const update_balance = (data) => {
if (!state.currency) {
/* We're not going to set currency automatically, since the user might select a different currency */
if (local_storage.get("currency")){
state.currency = local_storage.get("currency");
if (local_storage.get('currency')){
state.currency = local_storage.get('currency');
} else
return;
}
Expand All @@ -133,7 +134,7 @@ const destroy_windows = (data_attribute) => {
state.account.type = '';
state.currency = '';

local_storage.remove("currency");
local_storage.remove('currency');
});

liveapi.events.on('login', (data) => {
Expand All @@ -151,35 +152,35 @@ const destroy_windows = (data_attribute) => {
state.account.type = getType(data.authorize);

state.currency = data.authorize.currency;
local_storage.set("currency", state.currency);
local_storage.set('currency', state.currency);
update_balance(data);
const is_current_account_real = data.authorize.is_virtual === 0;

getLandingCompany().then((what_todo) => {
state.show_financial_link = (what_todo === 'upgrade-mf');
state.show_realaccount_link = (what_todo === 'upgrade-mlt');
const loginIds = loginids();
state.has_real_account = _.some(loginIds, {is_real: true});
state.has_mf_or_mlt = _.some(loginIds, {is_mf: true}) || _.some(loginIds, {is_mlt: true});
state.has_real_account = _.some(loginIds, { is_real: true });
state.has_mf_or_mlt = _.some(loginIds, { is_mf: true }) || _.some(loginIds, { is_mlt: true });
state.show_new_account_link = what_todo === 'new-account';
state.has_disabled_account = _.some(loginIds, {is_disabled: true});
state.has_disabled_account = _.some(loginIds, { is_disabled: true });
// https://trello.com/c/9PCHncnx/5146-8-raunak-accountlistordering
// https://trello.com/c/fNZ1Zkbb/2529-negar-accountlistauthorize
if(_.some(oAuthLoginIds(), {is_disabled: true})) {
const lockedIds = _.filter(loginIds, {is_disabled:true}).map(acc => acc.id).join(',');
if(_.some(oAuthLoginIds(), { is_disabled: true })) {
const lockedIds = _.filter(loginIds, { s_disabled:true }).map(acc => acc.id).join(',');
$.growl.error({
fixed: true,
message:`<a href='${getBinaryUrl('contact.html')}' target='_blank'>
${"Your account (%) is locked, please contact customer support for more info.".i18n().replace('%', lockedIds)}
${'Your account (%) is locked, please contact customer support for more info.'.i18n().replace('%', lockedIds)}
</a>`
});
}
});
});

// Restore login-button in case of login-error
$('.login').on("login-error", (e) => {
console.log("Encountered login error");
$('.login').on('login-error', (e) => {
console.log('Encountered login error');
state.show_login = true;
});

Expand Down Expand Up @@ -218,20 +219,20 @@ const initLang = (root) => {

state.onclick = (value) => {
state.confirm.visible = false;
const lang = _.find(state.languages, {value: value});
const lang = _.find(state.languages, { value: value });
if(lang && state.lang && lang.value == state.lang.value)
return;

local_storage.set('i18n', {value: lang.value});
local_storage.set('i18n', { value: lang.value });
window.location.reload();
};

state.toggleVisibility = (visible) => {
state.confirm.visible = visible;
}

const lang = (local_storage.get('i18n') || {value: 'en'}).value;
state.lang = _.find(state.languages, {value: lang}); // set the initial state.
const lang = (local_storage.get('i18n') || { value: 'en' }).value;
state.lang = _.find(state.languages, { value: lang }); // set the initial state.

const contact_us_el = document.getElementById('contact-us');
const logo_container = document.getElementById('logo-container');
Expand All @@ -247,15 +248,14 @@ const initLang = (root) => {
.send({website_status: 1})
.then((data) => {
let supported_languages = (data.website_status || {}).supported_languages || [];
supported_languages = _.map(supported_languages, (m) => ({value: m.toLowerCase()}));
supported_languages = _.map(supported_languages, (m) => ({ value: m.toLowerCase() }));
const newList = _.intersectionBy(state.languages, supported_languages, 'value') || [];
state.languages.length = 0;
newList.forEach(
(e) => state.languages.push(e)
);
})
.catch(console.error)

.catch(console.error);
}

/*
Expand Down Expand Up @@ -287,8 +287,8 @@ const initLang = (root) => {
export const getLandingCompany = () => {
return liveapi.cached.authorize().then((data) => {
return Promise.all([
liveapi.cached.send({landing_company: data.authorize.country }),
liveapi.cached.send({landing_company_details: data.authorize.landing_company_name})
liveapi.cached.send({ landing_company: data.authorize.country }),
liveapi.cached.send({ landing_company_details: data.authorize.landing_company_name })
])
.then((results) => {
const data = results[0];
Expand All @@ -298,29 +298,29 @@ export const getLandingCompany = () => {
const financial = data.landing_company.financial_company;
const gaming = data.landing_company.gaming_company;
const loginIds = loginids();
const curr_login = local_storage.get("oauth")[0];
const curr_login = local_storage.get('oauth')[0];
curr_login.is_mlt = /MLT/.test(curr_login.id);
if (gaming && financial && financial.shortcode === 'maltainvest') { // 1:
if (_.some(loginIds, {is_mlt: true}) && (_.some(loginIds, {is_mf: true}) || !curr_login.is_mlt)) // 1-c
if (_.some(loginIds, { is_mlt: true }) && (_.some(loginIds, { is_mf: true }) || !curr_login.is_mlt)) // 1-c
return 'do-nothing';
if (_.some(loginIds, {is_mlt: true})) // 1-b
if (_.some(loginIds, { is_mlt: true })) // 1-b
return 'upgrade-mf';
return 'upgrade-mlt'; // 1-a
}
if (financial && financial.shortcode === 'maltainvest' && !gaming) { // 2:
if (_.some(loginIds, {is_mf: true})) // 2-b
if (_.some(loginIds, { is_mf: true })) // 2-b
return 'do-nothing';
return 'upgrade-mf'; // 2-a
}
// 3:
if (_.some(loginIds, {is_mlt: true}) || _.some(loginIds, {is_mx: true}))
if (_.some(loginIds, { is_mlt: true }) || _.some(loginIds, { is_mx: true }))
return 'do-nothing'; // 3-b
// 4: never happens, japan accounts are not able to log into webtrader.
// 5:
const cr_accts = _.filter(loginIds, {is_cr: true});
const cr_accts = _.filter(loginIds, { is_cr: true });
if( cr_accts.length && landing_company_details.legal_allowed_currencies) {
const currencies_config = local_storage.get("currencies_config") || {};
const has_fiat = _.some(cr_accts, {type: 'fiat'});
const currencies_config = local_storage.get('currencies_config') || {};
const has_fiat = _.some(cr_accts, { type: 'fiat' });
const crypto_currencies = _.difference(
landing_company_details.legal_allowed_currencies.filter((curr) => {
return currencies_config[curr].type === 'crypto';
Expand All @@ -343,7 +343,7 @@ export const getLandingCompany = () => {

export const init = (callback) => {
const root = $($navHtml).i18n();
$("body").prepend(root);
$('body').prepend(root);

initLoginButton(root);
initLang(root);
Expand All @@ -355,12 +355,12 @@ export const init = (callback) => {
workspace.init($('#nav-menu .workspace'));

if (callback) {
callback($("#nav-menu"));
callback($('#nav-menu'));
}

//Show config <LI> if its production and not BETA
if (is_beta()) {
root.find("a.config").closest('li').show();
root.find('a.config').closest('li').show();
}

// Handle click navigation to show menu dialog
Expand All @@ -370,12 +370,12 @@ export const init = (callback) => {
const current_selector = `${nav_selector} ${selector}`;
const visible = {
'visibility': 'visible',
'opacity': 1
'opacity': 1,
};
$(current_selector).click((e) => {
$(dialog_selector).toggle('fast',
() => {
$(dialog_selector).css(visible)
$(dialog_selector).css(visible);
}
);
});
Expand Down