<commit_before>'use strict';
import logger from './logger';
import TradeInfo from './tradeInfo';
import account from 'binary-common-utils/account';
import Observer from 'binary-common-utils/observer';
import _Blockly from './blockly';
import storageManager from 'binary-common-utils/storageManager';
import Translator from 'translator';
import Bot from '../bot';
import Introduction from './tours/introduction';
import Welcome from './tours/welcome';
import {PlainChart as Chart} from 'binary-charts';
import lzString from 'lz-string';
import _ from 'underscore';


var View = function View(){
	if ( View.instance ) {
		return View.instance;
	}
	this.observer = new Observer();
	View.instance = this;
	this.tours = {};
	this.translator = new Translator();
	this.tradeInfo = new TradeInfo();
	this.addTranslationToUi();
	this.errorAndLogHandling();
	var that = this;
	this.bot = new Bot();
	this.initPromise = new Promise(function(resolve, reject){
		that.updateTokenList();
		that.blockly = new _Blockly();
		that.blockly.initPromise.then(function(){
			that.setElementActions();
			that.initTours();
			resolve();
		});
	});
};

View.prototype = Object.create(null, {
	updateTokenList: {
		value: function updateTokenList() {
			var tokenList = storageManager.getTokenList();
			if (tokenList.length === 0) {
				$('#login').css('display', 'inline-block');
				$('#accountSelect').css('display', 'none');
				$('#logout').css('display', 'none');
			} else {
				$('#login').css('display', 'none');
				$('#accountSelect').css('display', 'inline-block');
				$('#logout').css('display', 'inline-block');
				tokenList.forEach(function (tokenInfo) {
					var str;
					if ( tokenInfo.hasOwnProperty('isVirtual') ) {
						str = (tokenInfo.isVirtual) ? 'Virtual Account' : 'Real Account';
					} else {
						str = '';
					}
					$('#accountSelect').append('<option value="' + tokenInfo.token + '">'+str + ' (' + tokenInfo.account_name+ ') ' + '</option>');
				});
			}
		}
	},
	addTranslationToUi: {
		value: function addTranslationToUi(){
			var that = this;
			$('[data-i18n-text]')
				.each(function() {
						var contents = $(this).contents();
						if (contents.length > 0) {
								if (contents.get(0).nodeType == Node.TEXT_NODE) {
										$(this).text(that.translator.translateText($(this)
								.attr('data-i18n-text')))
								.append(contents.slice(1));
								}
						} else {
						$(this)
							.text(that.translator.translateText($(this)
								.attr('data-i18n-text')));
					}
				});
		}
	},
	initTours: {
		value: function initTours() {
			this.tours.introduction = new Introduction();
			this.tours.welcome = new Welcome();
		}
	},
	startTour: {
		value: function startTour() {
			var that = this;
			$('#tours').on('change', function(e) {
					var value = $(this).val();
					if (value === '') return;
					if (that.activeTour) {
						that.activeTour.stop();
					}
					that.activeTour = that.tours[value];
					that.activeTour.start(function(){
						that.activeTour = null;
					});
			});
		}
	},
	errorAndLogHandling: {
		value: function errorAndLogHandling(){

			var that = this;

			this.observer.register('ui.error', function showError(error) {
				var api = true;
				if (error.stack) {
					api = false;
					if (logger.isDebug()) {
						console.log('%c' + error.stack, 'color: red');
					} else {
						logger.addLogToQueue('%c' + error.stack, 'color: red');
					}
				}
				console.error({
					api: api,
					0: error.message,
					1: lzString.compressToBase64(JSON.stringify(error.stack)),
					2: lzString.compressToBase64(that.blockly.generatedJs),
					3: lzString.compressToBase64(that.blockly.blocksXmlStr)
				});
				var message = error.message;
				$.notify(message, {
					position: 'bottom right',
					className: 'error',
				});
				if (logger.isDebug()) {
					console.log('%cError: ' + message, 'color: red');
				} else {
					logger.addLogToQueue('%cError: ' + message, 'color: red');
				}
			});

			var observeForLog = function observeForLog(type, position) {
				var subtype = ( position === 'left' )? '.left' : '';
				that.observer.register('ui.log.' + type + subtype , function(message){
					if ( type === 'warn' ) {
						console.warn(message);
					}
					$.notify(message, {
						position: 'bottom ' + position,
						className: type,
					});
					if (logger.isDebug()) {
						console.log(message);
					} else {
						logger.addLogToQueue(message);
					}
				});
			};

			["success", "info", "warn", "error"].forEach(function(type){
				observeForLog(type, 'right');
				observeForLog(type, 'left');
			});<commit_msg>Added better information for trackjs<commit_after>'use strict';
import logger from './logger';
import TradeInfo from './tradeInfo';
import account from 'binary-common-utils/account';
import Observer from 'binary-common-utils/observer';
import _Blockly from './blockly';
import storageManager from 'binary-common-utils/storageManager';
import Translator from 'translator';
import Bot from '../bot';
import Introduction from './tours/introduction';
import Welcome from './tours/welcome';
import {PlainChart as Chart} from 'binary-charts';
import lzString from 'lz-string';
import _ from 'underscore';


var View = function View(){
	if ( View.instance ) {
		return View.instance;
	}
	this.observer = new Observer();
	View.instance = this;
	this.tours = {};
	this.translator = new Translator();
	this.tradeInfo = new TradeInfo();
	this.addTranslationToUi();
	this.errorAndLogHandling();
	var that = this;
	this.bot = new Bot();
	this.initPromise = new Promise(function(resolve, reject){
		that.updateTokenList();
		that.blockly = new _Blockly();
		that.blockly.initPromise.then(function(){
			that.setElementActions();
			that.initTours();
			resolve();
		});
	});
};

View.prototype = Object.create(null, {
	updateTokenList: {
		value: function updateTokenList() {
			var tokenList = storageManager.getTokenList();
			if (tokenList.length === 0) {
				$('#login').css('display', 'inline-block');
				$('#accountSelect').css('display', 'none');
				$('#logout').css('display', 'none');
			} else {
				$('#login').css('display', 'none');
				$('#accountSelect').css('display', 'inline-block');
				$('#logout').css('display', 'inline-block');
				tokenList.forEach(function (tokenInfo) {
					var str;
					if ( tokenInfo.hasOwnProperty('isVirtual') ) {
						str = (tokenInfo.isVirtual) ? 'Virtual Account' : 'Real Account';
					} else {
						str = '';
					}
					$('#accountSelect').append('<option value="' + tokenInfo.token + '">'+str + ' (' + tokenInfo.account_name+ ') ' + '</option>');
				});
			}
		}
	},
	addTranslationToUi: {
		value: function addTranslationToUi(){
			var that = this;
			$('[data-i18n-text]')
				.each(function() {
						var contents = $(this).contents();
						if (contents.length > 0) {
								if (contents.get(0).nodeType == Node.TEXT_NODE) {
										$(this).text(that.translator.translateText($(this)
								.attr('data-i18n-text')))
								.append(contents.slice(1));
								}
						} else {
						$(this)
							.text(that.translator.translateText($(this)
								.attr('data-i18n-text')));
					}
				});
		}
	},
	initTours: {
		value: function initTours() {
			this.tours.introduction = new Introduction();
			this.tours.welcome = new Welcome();
		}
	},
	startTour: {
		value: function startTour() {
			var that = this;
			$('#tours').on('change', function(e) {
					var value = $(this).val();
					if (value === '') return;
					if (that.activeTour) {
						that.activeTour.stop();
					}
					that.activeTour = that.tours[value];
					that.activeTour.start(function(){
						that.activeTour = null;
					});
			});
		}
	},
	errorAndLogHandling: {
		value: function errorAndLogHandling(){

			var that = this;

			this.observer.register('ui.error', function showError(error) {
				var api = true;
				if (error.stack) {
					api = false;
					if (logger.isDebug()) {
						console.log('%c' + error.stack, 'color: red');
					} else {
						logger.addLogToQueue('%c' + error.stack, 'color: red');
					}
				}
				var message = error.message;
				$.notify(message, {
					position: 'bottom right',
					className: 'error',
				});
				if (logger.isDebug()) {
					console.log('%cError: ' + message, 'color: red');
				} else {
					logger.addLogToQueue('%cError: ' + message, 'color: red');
				}
				var customError = new Error(JSON.stringify({
					api: api,
					0: error.message,
					1: lzString.compressToBase64(that.blockly.generatedJs),
					2: lzString.compressToBase64(that.blockly.blocksXmlStr)
				}));
				customError.stack = error.stack;
				trackJs.track(customError);
			});

			var observeForLog = function observeForLog(type, position) {
				var subtype = ( position === 'left' )? '.left' : '';
				that.observer.register('ui.log.' + type + subtype , function(message){
					if ( type === 'warn' ) {
						console.warn(message);
					}
					$.notify(message, {
						position: 'bottom ' + position,
						className: type,
					});
					if (logger.isDebug()) {
						console.log(message);
					} else {
						logger.addLogToQueue(message);
					}
				});
			};

			["success", "info", "warn", "error"].forEach(function(type){
				observeForLog(type, 'right');
				observeForLog(type, 'left');
			});
{'fraction_non_alphanumeric': 0.17861771058315334, 'fraction_numerical': 0.003995680345572354, 'mean_word_length': 3.1566427289048473, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1174682', 'n_tokens_mistral': 3799, 'n_tokens_neox': 2959, 'n_words': 596}