Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function (e) {
try {
blockly.mainWorkspace.clear();
var xml = blockly.Xml.textToDom(e.target.result);
blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
botUtils.addPurchaseOptions();
blockly.mainWorkspace.clearUndo();
blockly.mainWorkspace.zoomToFit();
setBlockColors();
botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
} catch (err) {
botUtils.showError(err);
}
};
})(f);
return function (e) {
try {
blockly.mainWorkspace.clear();
var xml = blockly.Xml.textToDom(e.target.result);
blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
botUtils.addPurchaseOptions();
blockly.mainWorkspace.clearUndo();
blockly.mainWorkspace.zoomToFit();
setBlockColors();
botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
} catch (err) {
botUtils.showError(err);
}
};
})(f);
return function (e) {
try {
blockly.mainWorkspace.clear();
var xml = blockly.Xml.textToDom(e.target.result);
blockly.Xml.domToWorkspace(xml, blockly.mainWorkspace);
botUtils.addPurchaseOptions();
var tokenList = storageManager.getTokenList();
if (tokenList.length !== 0) {
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setValue(tokenList[0].token);
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setText(tokenList[0].account_name);
}
blockly.mainWorkspace.clearUndo();
blockly.mainWorkspace.zoomToFit();
botUtils.log(i18n._('Blocks are loaded successfully'), 'success');
} catch (err) {
var saveXml = function saveXml(showOnly) {
var xmlDom = blockly.Xml.workspaceToDom(blockly.mainWorkspace);
Array.prototype.slice.apply(xmlDom.getElementsByTagName('field'))
.forEach(function (field) {
if (field.getAttribute('name') === 'ACCOUNT_LIST') {
if (field.childNodes.length >= 1) {
field.childNodes[0].nodeValue = '';
}
}
});
Array.prototype.slice.apply(xmlDom.getElementsByTagName('block'))
.forEach(function (block) {
switch (block.getAttribute('type')) {
case 'trade':
block.setAttribute('id', 'trade');
break;
case 'on_strategy':
block.setAttribute('id', 'strategy');
$.get('xml/main.xml', function (main) {
blockly.Xml.domToWorkspace(main.getElementsByTagName('xml')[0], workspace);
blockly.mainWorkspace.getBlockById('trade')
.setDeletable(false);
blockly.mainWorkspace.getBlockById('strategy')
.setDeletable(false);
blockly.mainWorkspace.getBlockById('finish')
.setDeletable(false);
view.updateTokenList();
view.addPurchaseOptions();
blockly.mainWorkspace.clearUndo();
view.initTours();
});
});
var updateTokenList = function updateTokenList(tokenToAdd) {
var tokenList = storageManager.getTokenList();
blockly.WidgetDiv.hideIfOwner(blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST'));
if (tokenList.length === 0) {
$('#addAccount')
.text('Login');
$('#logout')
.hide();
globals.lists.accounts = [
[i18n._('Please add a token first'), '']
];
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setValue('');
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setText(i18n._('Please add a token first'));
} else {
})
.text('Add Token');
$('#logout')
.show();
global.lists.accounts = [];
tokenList.forEach(function (tokenInfo) {
global.lists.accounts.push([tokenInfo.account_name, tokenInfo.token]);
});
var tokenInfoToAdd = tokenList[0];
if (tokenToAdd !== undefined) {
var tokenInfoIndex = storageManager.findToken(tokenToAdd);
if (tokenInfoIndex >= 0) {
tokenInfoToAdd = tokenList[tokenInfoIndex];
}
}
if (blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.getValue() !== tokenInfoToAdd.token) {
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setValue(tokenInfoToAdd.token);
}
if (blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.getText() !== tokenInfoToAdd.account_name) {
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setText(tokenInfoToAdd.account_name);
}
}
};
if (tokenList.length === 0) {
$('#addAccount')
.unbind('.addAccount')
.bind('click.login', function(e){
appId.redirectOauth();
})
.text('Login');
$('#logout')
.hide();
global.lists.accounts = [
[i18n._('Please add a token first'), '']
];
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setValue('');
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setText(i18n._('Please add a token first'));
} else {
$('#addAccount')
.unbind('.login')
.bind('click.addAccount', function(e){
addAccount();
})
.text('Add Token');
$('#logout')
.show();
global.lists.accounts = [];
tokenList.forEach(function (tokenInfo) {
global.lists.accounts.push([tokenInfo.account_name, tokenInfo.token]);
});
var tokenInfoToAdd = tokenList[0];
var updateTokenList = function updateTokenList(tokenToAdd) {
var tokenList = storageManager.getTokenList();
blockly.WidgetDiv.hideIfOwner(blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST'));
if (tokenList.length === 0) {
$('#addAccount')
.unbind('.addAccount')
.bind('click.login', function(e){
appId.redirectOauth();
})
.text('Login');
$('#logout')
.hide();
global.lists.accounts = [
[i18n._('Please add a token first'), '']
];
blockly.mainWorkspace.getBlockById('trade')
.getField('ACCOUNT_LIST')
.setValue('');