text:
<repo_name>ptyx11/dICOApp<file_sep>/gui/js/coin_select_options.js

var coin_select_options = '';

coin_select_options = `<optgroup label="Crytpo Coins">
      <option data-content=" Komodo (KMD)" data-tokens="kmd komodo ">KMD</option>
      <option data-content=" Bitcoin (BTC)" data-tokens="btc bitcoin ">BTC</option>
    </optgroup>`;

$('.trading_pair_coin').html(coin_select_options);

<file_sep>/gui/js/ipc-actions.js
var CheckMM_Interval = null;

// In renderer process (web page).
const {ipcRenderer} = require('electron')

ShepherdIPC = function(data) {
	/*ipcRenderer.on('shepherd-reply', (event, arg) => {
		console.log(arg) // prints "pong"
	})
	ipcRenderer.sendSync('shepherd-command', data)*/

	// USING SYNCHRONOUS METHOD TO SEND AND RECIVE IPC COMMANDS/REPLIES
	//console.log(ipcRenderer.sendSync('shepherd-commandSync', 'ping')) // prints "pong"
	let shepherdreply = ipcRenderer.sendSync('shepherd-command', data);
	//console.log(shepherdreply);
	return shepherdreply;
}

$('.dexlogout-btn').click(function(e) {
	e.preventDefault();
	var shepherdresult = ShepherdIPC({"command":"logout"});
	$('.mainbody').fadeOut();
	$('.loginbody').fadeIn();
	//CheckOrderBookFn(false);

	//CheckPortfolioFn(false);
	CheckOrderBookFn(false);
	check_swap_status(false);
	check_bot_list(false);
	check_my_prices(false);
	bot_screen_coin_balance(false);
	bot_screen_sellcoin_balance(false);

	//check_coin_balance(false);
	sessionStorage.clear();
});

$('.login-btn').click(function(e) {
	e.preventDefault();
	var passphrase = $('.loginPassphrase').val();
	var shepherdresult = ShepherdIPC({"command":"login","passphrase":passphrase});
	$('.loginPassphrase').val('');
	$('.mainbody').hide();
	$('.loginbody').hide();
	CheckMM_Interval = setInterval(CheckMMStatus,1000);
	$('.loadingbody').fadeIn();
});

CheckMMStatus = function(sig) {
	if (sig == false) {
		clearInterval(CheckMM_Interval);
	} else {
		console.log('Checking MarketMaker Status');
	}

	var mmstatus = ShepherdIPC({"command":"mmstatus"});
	if (mmstatus !== 'closed') {
		$('.mainbody').fadeIn();
		$('.loginbody').fadeOut();
		$('.loadingbody').hide();
		/*var refresh_data = {"coin":" ", "status": "enable"};
		enable_disable_coin(refresh_data);
		get_myprices();
		CheckOrderbook_Interval = setInterval(CheckOrderBookFn,3000);*/
		//check_coin_balance_Interval = setInterval(check_coin_balance,3000);

//---- dICO App Settings START ----//
		//CheckPortfolio_Interval = setInterval(CheckPortfolioFn,60000);

		selected_coin = {}
		selected_coin.coin = 'MNZ';
		selected_coin.coin_name = 'Monaize';
		console.log(selected_coin);
		sessionStorage.setItem('mm_selectedcoin', JSON.stringify(selected_coin));

		$('.screen-portfolio').hide();
		$('.screen-coindashboard').hide()
		$('.screen-exchange').show();
		$('.coin_ticker').html('MNZ');
		$.each($('.coinexchange[data-coin]'), function(index, value) {
			$('.coinexchange[data-coin]').data('coin', 'MNZ');
		});

		check_coin_balance(false);
		CheckOrderbook_Interval = setInterval(CheckOrderBookFn,3000);
		check_swap_status_Internal = setInterval(check_swap_status,10000);
		check_swap_status();
		check_bot_list_Internal = setInterval(check_bot_list, 60000);
		check_bot_list();
		check_my_prices_Internal = setInterval(check_my_prices, 60000);
		check_my_prices();
		bot_screen_coin_balance_Internal = setInterval(bot_screen_coin_balance, 30000);
		bot_screen_coin_balance();
		bot_screen_sellcoin_balance_Internal = setInterval(bot_screen_sellcoin_balance, 30000);
		bot_screen_sellcoin_balance();

//---- dICO App Settings END ----//

		clearInterval(CheckMM_Interval);
	} else {
		$('.mainbody').fadeOut();
		$('.loginbody').fadeOut();
		$('.loadingbody').fadeIn();
	}
}<file_sep>/gui/js/simpledexactions.js
/*** Simple GUI JS ***/

var CheckOrderbook_Interval = null;
var CheckPortfolio_Interval = null;
var check_coin_balance_Interval = null;
var check_swap_status_Internal = null;
var check_my_prices_Internal = null;
var check_bot_list_Internal = null;
var bot_screen_coin_balance_Internal = null;
var bot_screen_sellcoin_balance_Internal = null;

$(document).ready(function() {
	var mmstatus = ShepherdIPC({"command":"mmstatus"});
	if (mmstatus !== 'closed') {
		$('.mainbody').show();
		$('.loginbody').hide();

		//check_coin_balance_Interval = setInterval(check_coin_balance,3000);
		//check_coin_balance();

//---- dICO App Settings START ----//
		//CheckPortfolio_Interval = setInterval(CheckPortfolioFn,60000);
		//CheckPortfolioFn();

		selected_coin = {}
		selected_coin.coin = 'MNZ';
		selected_coin.coin_name = 'Monaize';
		console.log(selected_coin);
		sessionStorage.setItem('mm_selectedcoin', JSON.stringify(selected_coin));

		$('.screen-portfolio').hide();
		$('.screen-coindashboard').hide()
		$('.screen-exchange').show();
		$('.coin_ticker').html('MNZ');
		$.each($('.coinexchange[data-coin]'), function(index, value) {
			$('.coinexchange[data-coin]').data('coin', 'MNZ');
		});

		check_coin_balance(false);
		CheckOrderbook_Interval = setInterval(CheckOrderBookFn,3000);
		check_swap_status_Internal = setInterval(check_swap_status,10000);
		check_swap_status();
		check_bot_list_Internal = setInterval(check_bot_list, 60000);
		check_bot_list();
		check_my_prices_Internal = setInterval(check_my_prices, 60000);
		check_my_prices();
		bot_screen_coin_balance_Internal = setInterval(bot_screen_coin_balance, 30000);
		bot_screen_coin_balance();
		bot_screen_sellcoin_balance_Internal = setInterval(bot_screen_sellcoin_balance, 30000);
		bot_screen_sellcoin_balance();
		get_coin_info('MNZ');

//---- dICO App Settings END ----//

		$('.relvol_basevol_coin').html($('.trading_pair_coin').selectpicker('val'));

	} else {
		$('.mainbody').hide();
		$('.loginbody').show();
	}
	//$('.set_goal_label_portfolio').html($('.sell_coin_p').selectpicker('val'));
});

$('.porfolio_coins_list tbody').on('click', '.btn-portfoliogo', function() {
	console.log('portfolio coin button clicked')
	console.log($(this).data());
	console.log($(this).data('coin'));
	$('.screen-portfolio').hide();
	$('.screen-coindashboard').show()

	coin = $(this).data('coin');
	$.each($('.coindashboard[data-coin]'), function(index, value) {
		$('.coindashboard[data-coin]').attr('data-coin', coin);
	});

	$.each($('.coinexchange[data-coin]'), function(index, value) {
		//$('.coinexchange[data-coin]').attr('data-coin', coin);
		$('.coinexchange[data-coin]').data('coin', coin);
	});

	selected_coin = {}
	selected_coin.coin = $(this).data('coin');
	selected_coin.coin_name = $(this).data('coinname');
	selected_coin.addr = $(this).data('addr');
	selected_coin.balance = $(this).data('balance');
	console.log(selected_coin);
	sessionStorage.setItem('mm_selectedcoin', JSON.stringify(selected_coin));

	CheckPortfolioFn(false);
	check_coin_balance_Interval = setInterval(check_coin_balance($(this).data()),3000);
});

$('.btn-activatecoins').click(function(e){
	e.preventDefault();
	console.log('btn-activatecoins clicked');
	console.log($(this).data());

	addcoins_dialog();

	//$('.screen-portfolio').hide();
	//$('.screen-addcoins').show();

	//CheckPortfolioFn(false);
	//get_coins_list();

})

/*$('.btn-addcoinsclose').click(function(e){
	e.preventDefault();
	console.log('btn-addcoinsclose clicked');
	console.log($(this).data());

	$('.screen-portfolio').show();
	$('.screen-addcoins').hide();

	CheckPortfolioFn();
	CheckPortfolio_Interval = setInterval(CheckPortfolioFn,60000);
});

$('.btn-addcoinsrefresh').click(function(e){
	e.preventDefault();
	console.log('btn-addcoinsrefresh clicked');
	console.log($(this).data());

	get_coins_list()
});*/

$('.addcoins_tbl tbody').on('click', '.addcoins_tbl_disable_btn', function() {
	console.log('Disable this coin:' + $(this).data('coin'));
	var refresh_data = {"coin":$(this).data('coin'), "status": "disable"};
	//enable_disable_coin(refresh_data)
	//$('.selectpicker option').filter(function () { return $(this).html() == $(this).data('coin'); }).attr("disabled","disabled");
	//$('.selectpicker').selectpicker('refresh');

});

$('.addcoins_tbl tbody').on('click', '.addcoins_tbl_enable_btn', function() {
	console.log('Enable this coin:' + $(this).data('coin'));
	var refresh_data = {"coin":$(this).data('coin'), "status": "enable"};
	//enable_disable_coin(refresh_data)
	//$('.selectpicker option').filter(function () { return $(this).html() == $(this).data('coin'); }).removeAttr('disabled');
	//$('.selectpicker').selectpicker('refresh');
});

$('.btn_coindashboard_back').click(function(){
	console.log('btn_coindashboard_back clicked');
	console.log($(this).data());

	$('.screen-portfolio').show();
	$('.screen-coindashboard').hide()

	check_coin_balance(false);
	CheckPortfolioFn();
	CheckPortfolio_Interval = setInterval(CheckPortfolioFn,60000);
});

$('.btn_coindashboard_receive').click(function() {
	console.log('btn-receive clicked');
	console.log($(this).data());
	coin = $(this).data('coin');

	var coin_name = return_coin_name(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"getcoin","coin": coin};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		}

		bootbox.dialog({
		    //title: 'A custom dialog with init',
			message: '

'+data.coin.smartaddress+'

'
		});

		var qrcode = new QRCode("receive_addr_qrcode");
		qrcode.makeCode(data.coin.smartaddress); // make another code.
		$('#receive_addr_qrcode > img').removeAttr('style');
		$('#receive_addr_qrcode > img').css('display', 'initial');
		$('#receive_addr_qrcode > img').css('border', '9px solid #f1f1f1','border-radius','5px','margin', '5px');
		$('#receive_addr_qrcode > img').css('border-radius','5px');
		$('#receive_addr_qrcode > img').css('margin', '5px');

	}).fail(function(jqXHR, textStatus, errorThrown) {
		// If fail
		console.log(textStatus + ': ' + errorThrown);
	});
})

$('.btn_coindashboard_enable').click(function() {
	console.log('btn-enable clicked');
	//console.log($(this).data());

	var electrum_option = $('#coindashboard-toggle').prop('checked');

	//console.log(electrum_option);

	var enable_data = $(this).data();
	enable_data['electrum'] = electrum_option;
	//console.log(enable_data);

	enable_disable_coin(enable_data);
});

$('.btn_coindashboard_disable').click(function() {
	console.log('btn-disable clicked');
	//console.log($(this).data());

	var electrum_option = $('#coindashboard-toggle').prop('checked');

	//console.log(electrum_option);

	var enable_data = $(this).data();
	enable_data['electrum'] = electrum_option;
	//console.log(enable_data);

	enable_disable_coin(enable_data);
});

$('.btn_coindashboard_send').click(function(e) {
	e.preventDefault();
	console.log('btn-send clicked');
	console.log($(this).data());
	$('.screen-coindashboard').hide()
	$('.screen-sendcoin').show();
	check_coin_balance(false);
	$('.sendcoin-title').html('Send ('+$('.coindashboard-balance').html()+' '+$(this).data('coin')+')');
	$('.sendcoin-title').data('coin', $(this).data('coin'));
});

$('.btn-sendcoin').click(function(e){
	e.preventDefault();
	console.log('btn-sendcoin clicked');
	//console.log($(this).data());

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	console.log(coin);

	var to_addr = $('#send-toaddr').val();
	var send_amount = $('#send-amount').val();
	//console.log(to_addr);
	//console.log(send_amount);

	var output_data = {};
	output_data[to_addr] = send_amount;
	//console.log(output_data);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"withdraw","coin": coin, "outputs": [output_data]};
	var url = "http://127.0.0.1:7783";

	console.log(ajax_data);

	var a1 = $.ajax({
			async: true,
			data: JSON.stringify(ajax_data),
			dataType: 'json',
			type: 'POST',
			url: url
		}),
		a2 = a1.then(function(data) {
			// .then() returns a new promise
			console.log(data);
			if (data.complete == false) {
				toastr.error('Uncessful Transaction. Please try again.','Tansaction info');
			}
			if (data.complete == true) {
				bootbox.confirm({
					message: `<b>Send</b>: `+send_amount+` `+ajax_data.coin+`

									To: `+to_addr+`
`,
					buttons: {
						confirm: {
							label: 'Confirm',
							className: 'btn-primary'
						},
						cancel: {
							label: 'Cancel',
							className: 'btn-default'
						}
					},
					callback: function (result) {
						console.log('This was logged in the callback: ' + result);

						if (result == true) {
							var ajax_data2 = {"userpass":<PASSWORD>pass,"method":"sendrawtransaction","coin": coin, "signedtx": data.hex};
							console.log(ajax_data2);

							toastr.info('Transaction Executed', 'Transaction Status');

							$.ajax({
									async: true,
									data: JSON.stringify(ajax_data2),
									dataType: 'json',
									type: 'POST',
									url: url
								})
						} else {
							console.log('Sending Transaction operation canceled.');
							return {'output': 'canceled'};
						}
					}
				});
			}
	});

	a2.done(function(data) {
		console.log(data);
	});
});

$('.btn-sendcoinclose').click(function(e) {
	e.preventDefault();
	console.log('btn-sendcoinclose clicked');
	console.log($(this).data());
	$('.screen-coindashboard').show()
	$('.screen-sendcoin').hide();
	$('#send-toaddr').val('');
	$('#send-amount').val('');
	check_coin_balance_Interval = setInterval(check_coin_balance,3000);
});

$('.btn_coindashboard_inventory').click(function(e) {
	e.preventDefault();
	console.log('btn-inventory clicked');
	console.log($(this).data());

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	console.log(coin);

	$('.screen-coindashboard').hide()
	$('.screen-inventory').show();
	check_coin_balance(false);
	$('.inventory-title').html('Manage Inventory ('+$('.coindashboard-balance').html()+' '+coin+')');
	$('.inventory-title').data('coin', coin);
	$('.coininventory[data-coin]').attr('data-coin', coin);
	//$('.coininventory[data-coin]').attr('data-pair', $(this).data('pair'));
	$('.coininventory[data-coin]').attr('data-addr', selected_coin.addr);
	$('.inventory-sliderTotalCoin').html(' '+coin);

	$('.dex_showinv_alice_tbl tbody').html('
Loading...
	');
	$('.dex_showlist_unspents_tbl tbody').html('
Loading...
	');

	check_coin_inventory(coin);
	check_coin_listunspent($(this).data());

	calc_data = {"coin": coin, "balance": $('.coindashboard-balance').html()};
	clac_coin_inventory(calc_data);
});

/*$('.btn-inventoryclose').click(function(e) {
	e.preventDefault();
	console.log('btn-inventoryclose clicked');
	//console.log($(this).data());
	$('.screen-coindashboard').show()
	$('.screen-inventory').hide();
	$('.dex_showinv_alice_tbl tbody').empty();
	$('.dex_showlist_unspents_tbl tbody').empty();
	$('.RawJSONInventory-output').empty();
	check_coin_balance_Interval = setInterval(check_coin_balance,3000);
});*/

$('.btn-inventoryclose').click(function(e) {
	e.preventDefault();
	console.log('btn-inventoryclose clicked');
	//console.log($(this).data());
	$('.screen-exchange').show()
	$('.screen-inventory').hide();
	$('.dex_showinv_alice_tbl tbody').empty();
	$('.dex_showlist_unspents_tbl tbody').empty();
	$('.RawJSONInventory-output').empty();
	$('.coin_ticker').html('MNZ');
	$.each($('.coinexchange[data-coin]'), function(index, value) {
		$('.coinexchange[data-coin]').data('coin', 'MNZ');
	});

	check_coin_balance(false);
	CheckOrderbook_Interval = setInterval(CheckOrderBookFn,3000);
	check_swap_status_Internal = setInterval(check_swap_status,10000);
	check_swap_status();
	check_bot_list_Internal = setInterval(check_bot_list, 60000);
	check_bot_list();
	check_my_prices_Internal = setInterval(check_my_prices, 60000);
	check_my_prices();
	bot_screen_coin_balance_Internal = setInterval(bot_screen_coin_balance, 30000);
	bot_screen_coin_balance();
	bot_screen_sellcoin_balance_Internal = setInterval(bot_screen_sellcoin_balance, 30000);
	bot_screen_sellcoin_balance();
	get_coin_info('MNZ');
});

$('.btn-inventoryrefresh').click(function(e) {
	e.preventDefault();
	console.log('btn-inventoryrefresh clicked');
	console.log($(this).data());
	$('.dex_showinv_alice_tbl tbody').html('
Loading...
	');
	$('.dex_showlist_unspents_tbl tbody').html('
Loading...
	');

	check_coin_inventory($(this).data('coin'));
	check_coin_listunspent($(this).data());
});

$('.dex_showinv_alice_tbl tbody').on('click', '.btn_coiniventory_detail', function() {
	//console.log($(this).data());
	var index = $(this).data('index');
	var coininventory = sessionStorage.getItem('mm_coininventory');
	coininventory = JSON.parse(coininventory);
	console.log(coininventory.alice[index]);

	bootbox.dialog({
		message: `

					` + index + `
					method
					` + coininventory.alice[index].method + `

					gui
					` + coininventory.alice[index].gui + `

					coin
					` + coininventory.alice[index].coin + `

					iambob
					` + coininventory.alice[index].iambob + `

					address
					` + coininventory.alice[index].address + `

					txid
					` + coininventory.alice[index].txid + `

					vout
					` + coininventory.alice[index].vout + `

					value
					` + (parseFloat(coininventory.alice[index].value)/100000000).toFixed(8) + ` ` + coininventory.alice[index].coin + `

					satoshis
					` + coininventory.alice[index].satoshis + `

					txid2
					` + coininventory.alice[index].txid2 + `

					vout2
					` + coininventory.alice[index].vout2 + `

					value2
					` + (parseFloat(coininventory.alice[index].value2)/100000000).toFixed(8) + ` ` + coininventory.alice[index].coin + `

					desthash
					` + coininventory.alice[index].desthash + `

`,
		closeButton: true,
		size: 'large'
	});
});

$('.btn-makeinventory').click(function(e) {
	e.preventDefault();
	console.log('btn-makeinventory clicked');
	//console.log($(this).data());

	utxo_input1 = $("#inventory_slider_input1").val();
	utxo_input2 = $("#inventory_slider_input2").val();
	utxo_input3 = $("#inventory_slider_input3").val();
	//console.log(utxo_input1);
	//console.log(utxo_input2);
	//console.log(utxo_input3);

	var slider_input1 = $('#inventory-slider1').val();
	var slider_input2 = $('#inventory-slider2').val();
	var slider_input3 = $('#inventory-slider3').val();
	//console.log(slider_input1);
	//console.log(slider_input2);
	//console.log(slider_input3);

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin_addr = selected_coin.addr;
	console.log(coin_addr);

	var withdraw_outputs = []

	for(var i=0; i < slider_input1; i++){
		var tmp_json = {}
		tmp_json[coin_addr] = utxo_input1
		//console.log(tmp_json)
		withdraw_outputs.push(tmp_json)
	}
	for(var i=0; i < slider_input2; i++){
		var tmp_json = {}
		tmp_json[coin_addr] = utxo_input2
		withdraw_outputs.push(tmp_json)
	}
	for(var i=0; i < slider_input3; i++){
		var tmp_json = {}
		tmp_json[coin_addr] = utxo_input3
		withdraw_outputs.push(tmp_json)
	}
	//console.log(withdraw_outputs);

	inventory_data = {};
	inventory_data['coin'] = $(this).data('coin');
	inventory_data['outputs'] = withdraw_outputs;
	console.log(inventory_data);
	make_inventory_withdraw(inventory_data);

});

$('.btn_coindashboard_exchange').click(function(e) {
	e.preventDefault();
	console.log('btn_coindashboard_exchange clicked');
	console.log($(this).data());

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	console.log(selected_coin);
	var coin = selected_coin.coin;

	$('.screen-coindashboard').hide()
	$('.screen-exchange').show();
	$('.coin_ticker').html(coin);

	$.each($('.coinexchange[data-coin]'), function(index, value) {
		//$('.coinexchange[data-coin]').attr('data-coin', coin);
		$('.coinexchange[data-coin]').data('coin', coin);
	});

	/*$('.btn-exchangeclose').attr('data-coin', coin);
	$('.btn-exchangerefresh').attr('data-coin', coin);
	$('.btn-myordersrefresh').attr('data-coin', coin);
	$('.btn-botlistrefresh').attr('data-coin', coin);
	$('.btn-refreshtrading_pair').attr('data-coin', coin);*/
	check_coin_balance(false);
	CheckOrderbook_Interval = setInterval(CheckOrderBookFn,3000);
	check_swap_status_Internal = setInterval(check_swap_status,10000);
	check_swap_status();
	check_bot_list_Internal = setInterval(check_bot_list, 60000);
	check_bot_list();
	check_my_prices_Internal = setInterval(check_my_prices, 60000);
	check_my_prices();
	bot_screen_coin_balance_Internal = setInterval(bot_screen_coin_balance, 30000);
	bot_screen_coin_balance();
	bot_screen_sellcoin_balance_Internal = setInterval(bot_screen_sellcoin_balance, 30000);
	bot_screen_sellcoin_balance();
});

$('.btn-exchangeclose').click(function(e){
	e.preventDefault();
	console.log('btn-exchangeclose clicked');
	console.log($(this).data());

	$('.screen-coindashboard').show()
	$('.screen-exchange').hide();
	CheckOrderBookFn(false);
	check_swap_status(false);
	check_bot_list(false);
	check_my_prices(false);
	bot_screen_coin_balance(false);
	bot_screen_sellcoin_balance(false);
	check_coin_balance_Interval = setInterval(check_coin_balance(),3000);
	check_coin_balance();
});

$('.btn-exchangerefresh').click(function(e){
	e.preventDefault();
	console.log('btn-exchangerefresh clicked');
	console.log($(this).data());

	CheckOrderBookFn();
});

$('.btn-myordersrefresh').click(function(e){
	e.preventDefault();
	console.log('btn-myordersrefresh clicked');
	console.log($(this).data());

	check_my_prices();
});

$('.btn-botlistrefresh').click(function(e){
	e.preventDefault();
	console.log('btn-botlistrefresh clicked');
	console.log($(this).data());

	check_bot_list();
});

$('.btn-bot_action').click(function(e){
	e.preventDefault();
	console.log('btn-botlistrefresh clicked');
	console.log($(this).data());
	console.log($(this).data('action'));

	pair_price = $('.trading_pair_coin_price').val();

	base_volume = $('.trading_pair_coin_volume').val();

	pair_volume = pair_price * base_volume;

	$('.relvol_basevol').html(pair_volume.toFixed(8));

	bot_data = {}
	bot_data.price = pair_price;
	bot_data.volume = pair_volume;
	bot_data.action = $(this).data('action');

	console.log(bot_data);

	bot_buy_sell(bot_data);
});

$('.trading_pair_coin_price').keyup(function(){
	pair_price = $('.trading_pair_coin_price').val();

	base_volume = $('.trading_pair_coin_volume').val();

	pair_volume = pair_price * base_volume;

	$('.relvol_basevol').html(pair_volume.toFixed(8));
});

$('.trading_pair_coin_volume').keyup(function(){
	pair_price = $('.trading_pair_coin_price').val();

	base_volume = $('.trading_pair_coin_volume').val();

	pair_volume = pair_price * base_volume;

	$('.relvol_basevol').html(pair_volume.toFixed(8));
});

$('.exchange_bot_list_tbl tbody').on('click', '.btn_bot_status', function() {
	console.log('bot status button clicked')
	console.log($(this).data());

	bot_status($(this).data());
});

$('.exchange_bot_list_tbl tbody').on('click', '.btn_bot_resume', function() {
	console.log('bot resume button clicked')
	console.log($(this).data());

	bot_stop_pause_resume($(this).data());
});

$('.exchange_bot_list_tbl tbody').on('click', '.btn_bot_pause', function() {
	console.log('bot pause button clicked')
	console.log($(this).data());

	bot_stop_pause_resume($(this).data());
});

$('.exchange_bot_list_tbl tbody').on('click', '.btn_bot_stop', function() {
	console.log('bot stop button clicked')
	console.log($(this).data());

	bot_stop_pause_resume($(this).data());
});

$('.btn-trading_coin_balance_refresh').click(function(e){
	e.preventDefault();
	console.log('btn-trading_coin_balance_refresh clicked');
	console.log($(this).data());

	bot_screen_sellcoin_balance();
	bot_screen_coin_balance();
})

function check_coin_balance(coin_data) {
	console.log(coin_data);
	if (coin_data == false) {
		clearInterval(check_coin_balance_Interval);
		console.log('checking coin balance stopped.')
		return
	} else {
		console.log('checking coin balance');
	}

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	console.log(selected_coin);
	var coin = selected_coin.coin;
	console.log(coin);

	//if (((coin_data == null) ? coin : coin_data.coin) == 'BTC') {
	if (coin == 'BTC') {
		$('#coindashboard-toggle').bootstrapToggle('enable');
	} else {
		$('#coindashboard-toggle').bootstrapToggle('disable');
	}

	$('.coindashboard-title').empty();
	$('.coindashboard-coin').empty();
	$('.coindashboard-balance').empty();
	$('.coindashboard-address[data-coin="' + coin + '"]').empty();
	$(".coindashboard-coinicon").attr("src","img/cryptologo/" + coin.toLowerCase() + ".png");

	var coin_name = return_coin_name(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"getcoin","coin": coin};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		//console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		}

		if (!data.error === false && data.error == 'coin is disabled') {
			console.log(data.coin);
			console.log('coin '+ data.coin.coin + ' is disabled');
			$('.btn_coindashboard_send[data-coin="' + data.coin.coin + '"]').hide();
			$('.btn_coindashboard_receive[data-coin="' + data.coin.coin + '"]').hide();
			$('.btn_coindashboard_exchange[data-coin="' + data.coin.coin + '"]').hide();
			$('.btn_coindashboard_inventory[data-coin="' + data.coin.coin + '"]').hide();
			$('.btn_coindashboard_enable[data-coin="' + data.coin.coin + '"]').show();
			$('.btn_coindashboard_disable[data-coin="' + data.coin.coin + '"]').hide();

			$('.coindashboard-balance').html('Coin is disabled.
Please enable before trading ')
			$('.coindashboard-balance').css( "font-size", "35px" );

		} else {
			//console.log(data);
			console.log(data.coin);
			//console.log(data.coin.smartaddress);
			//console.log(val);

			$('.btn_coindashboard_send[data-coin="' + data.coin.coin + '"]').show();
			$('.btn_coindashboard_receive[data-coin="' + data.coin.coin + '"]').show();
			$('.btn_coindashboard_exchange[data-coin="' + data.coin.coin + '"]').show();
			$('.btn_coindashboard_inventory[data-coin="' + data.coin.coin + '"]').show();
			$('.btn_coindashboard_enable[data-coin="' + data.coin.coin + '"]').hide();
			$('.btn_coindashboard_disable[data-coin="' + data.coin.coin + '"]').show();
			$('.coindashboard-address[data-coin="' + data.coin.coin + '"]').html(data.coin.smartaddress);
			$('.coindashboard-title').html(coin_name + ' (' + data.coin.coin + ')');
			$('.coindashboard-coin').html(data.coin.coin);

			$('.coindashboard-balance').css( "font-size", "55px" );
			$('.coindashboard-balance').html(data.coin.balance);
			$('.coindashboard-height').html(data.coin.height);
			$('.coindashboard-kmdvalue').html(data.coin.KMDvalue);
			$('.btn_coindashboard_inventory[data-addr]').attr('data-addr', data.coin.smartaddress);
		}

		//if (data.error == 'coin is disabled') {
			//console.log('coin '+ val + ' is disabled');
		//}
	}).fail(function(jqXHR, textStatus, errorThrown) {
		// If fail
		console.log(textStatus + ': ' + errorThrown);
	});

}

function get_coin_info(coin) {

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"getcoin","coin":coin};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
	    // If successful
	   console.log(data);
	   if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		}

		if (!data.error == true) {
			selected_coin = {}
			selected_coin.coin = coin;
			selected_coin.coin_name = return_coin_name(coin);
			selected_coin.addr = data.coin.smartaddress;
			selected_coin.balance = data.coin.balance;
			console.log(selected_coin);
			sessionStorage.setItem('mm_selectedcoin', JSON.stringify(selected_coin));
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function get_coins() {
	//console.log(data);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"getcoins"};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
	    // If successful
	   console.log(data);

		$.each(data, function(index, val) {
			//console.log(index);
			//console.log(val);
			if (val.status == 'active') {
				console.log(index);
				console.log(val);
			}
		});
	   if (!data.userpass === false) {
				console.log('first marketmaker api call execution after marketmaker started.')
				sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
				sessionStorage.setItem('mm_userpass', data.userpass);
				sessionStorage.setItem('mm_mypubkey', data.mypubkey);
				get_coin_info('MNZ');
			}
	   //toastr.success('Auto goal setup executed!', 'Portfolio Info')
	   //$('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function enable_disable_coin(data) {
	console.log(data);

	var electrum_option = data.electrum //If 'false', electrum option selected
	var userpass = sessionStorage.getItem('mm_userpass');
	var url = "http://127.0.0.1:7783";

	if (electrum_option == false) {
		console.log(electrum_option);
		console.log("electrum selected for " + data.coin);
		//var rand_electrum_srv = get_random_electrum_server(data.coin);
		$.each(electrum_servers_list[data.coin], function(index,val){
			var ipaddr = _.keys(val);
			var return_data_ipaddr = ipaddr[0];
			var return_data_port = val[ipaddr[0]];
			console.log(return_data_ipaddr);
			console.log(return_data_port);

			var ajax_data = {"userpass":userpass,"method":"electrum","coin":data.coin,"ipaddr":return_data_ipaddr,"port":return_data_port};

			$.ajax({
				async: true,
				data: JSON.stringify(ajax_data),
				dataType: 'json',
				type: 'POST',
				url: url
			}).done(function(data) {
				// If successful
				console.log(data);
				if (!data.userpass === false) {
					console.log('first marketmaker api call execution after marketmaker started.')
					sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
					sessionStorage.setItem('mm_userpass', data.userpass);
					sessionStorage.setItem('mm_mypubkey', data.mypubkey);
					get_coin_info('MNZ');

					if (ajax_data.status === 'enable') {
						toastr.success(ajax_data.coin+' Enabled','Coin Status');
					}
					if (ajax_data.status === 'disable') {
						toastr.success(ajax_data.coin+' Disabled','Coin Status');
					}
					//get_coins_list(data.coins);
				} else {
					//get_coins_list(data);
					if (electrum_option == false) {
						//get_coins_list('');
						//$('.refresh_dex_balances').trigger('click');
					} else {
						//get_coins_list(data);
					}
				}

				if (!data.error === false) {
					//console.log(data.error);
					if (data.error == 'coin cant be activated till synced') { //{error: "couldnt find coin locally installed", coin: "BTC"}
						toastr.info("Coin can't be acviated till synced.
Try in a moment.",'Coin Status');
					}
					if (data.error == 'couldnt find coin locally installed') { //{error: "couldnt find coin locally installed", coin: "BTC"}
						bootbox.alert({
							title: "Couldn't find "+data.coin+" locally installed",
							message: `<p>It seems you don't have `+data.coin+` wallet installed on your OS. Please check these following points to make sure you have your wallet setup properly:

Make sure your wallet is installed properly.

Make sure your wallet is running and synced to network.

Make sure your wallet has proper RPC settings configured in it's configuration file.

If you have all the above covered properly, please logout and then login back and try activating the coin again.

If you still having issues activating the your wallet, please get in touch with our support desk.

https://support.supernet.org

`,
							size: 'large'
						});
					}
				}
			}).fail(function(jqXHR, textStatus, errorThrown) {
			    // If fail
			    console.log(textStatus + ': ' + errorThrown);
			});
		});
	} else {
		console.log(electrum_option);
		console.log("native selected for " + data.coin);
		var ajax_data = {"userpass":userpass,"method":data.method,"coin":data.coin};

		console.log(ajax_data);

		$.ajax({
			async: true,
		    data: JSON.stringify(ajax_data),
		    dataType: 'json',
		    type: 'POST',
		    url: url
		}).done(function(data) {
			// If successful
			console.log(data);
			if (!data.userpass === false) {
				console.log('first marketmaker api call execution after marketmaker started.')
				sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
				sessionStorage.setItem('mm_userpass', data.userpass);
				sessionStorage.setItem('mm_mypubkey', data.mypubkey);
				get_coin_info('MNZ');

				if (ajax_data.status === 'enable') {
					toastr.success(ajax_data.coin+' Enabled','Coin Status');
				}
				if (ajax_data.status === 'disable') {
					toastr.success(ajax_data.coin+' Disabled','Coin Status');
				}
				//get_coins_list(data.coins);
			} else {
				//get_coins_list(data);
				if (electrum_option == false) {
					//get_coins_list('');
					//$('.refresh_dex_balances').trigger('click');
				} else {
					//get_coins_list(data);
				}
			}

			if (!data.error === false) {
				//console.log(data.error);
				if (data.error == 'coin cant be activated till synced') { //{error: "couldnt find coin locally installed", coin: "BTC"}
					toastr.info("Coin can't be acviated till synced.
Try in a moment.",'Coin Status');
				}
				if (data.error == 'couldnt find coin locally installed') { //{error: "couldnt find coin locally installed", coin: "BTC"}
					bootbox.alert({
						title: "Couldn't find "+data.coin+" locally installed",
						message: `<p>It seems you don't have `+data.coin+` wallet installed on your OS. Please check these following points to make sure you have your wallet setup properly:

Make sure your wallet is installed properly.

Make sure your wallet is running and synced to network.

Make sure your wallet has proper RPC settings configured in it's configuration file.

If you have all the above covered properly, please logout and then login back and try activating the coin again.

If you still having issues activating the your wallet, please get in touch with our support desk.

https://support.supernet.org

`,
						size: 'large'
					});
				}
			}
		}).fail(function(jqXHR, textStatus, errorThrown) {
		    // If fail
		    console.log(textStatus + ': ' + errorThrown);
		});
	}

	return
}

function check_coin_inventory(coin) {
	console.log(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":userpass,"method":"inventory","coin":coin};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
			//get_coins_list(data.coins);
			//$( ".inv_btn[data-coin='"+ coin +"']" ).trigger( "click" );
		} else {
			sessionStorage.setItem('mm_coininventory', JSON.stringify(data));
			$('.RawJSONInventory-output').html(JSON.stringify(data, null, 2));
			$('.dex_showinv_alice_tbl tbody').empty();
			$.each(data.alice, function(index, val) {
				//console.log(index);
				//console.log(val);
				var inv_alice_table_tr = '';
				inv_alice_table_tr += '
';
					inv_alice_table_tr += '' + index + '	';
					inv_alice_table_tr += 'coin	';
					inv_alice_table_tr += 'vout1	';
					inv_alice_table_tr += 'value1	';
					inv_alice_table_tr += 'vout2	';
					inv_alice_table_tr += 'value2	';
					inv_alice_table_tr += '	';
				inv_alice_table_tr += '
';
				inv_alice_table_tr += '
';
					inv_alice_table_tr += '' + val.coin + '	';
					inv_alice_table_tr += '' + val.vout + '	';
					inv_alice_table_tr += '' + (parseFloat(val.value)/100000000).toFixed(8) + ' ' + val.coin + '	';
					inv_alice_table_tr += '' + val.vout2 + '	';
					inv_alice_table_tr += '' + (parseFloat(val.value2)/100000000).toFixed(8) + ' ' + val.coin + '	';
					inv_alice_table_tr += '<button class="btn btn-default btn_coiniventory_detail" data-invof="alice" data-index="' + index + '">Detail</button>	';
				inv_alice_table_tr += '
';

				$('.dex_showinv_alice_tbl tbody').append(inv_alice_table_tr);
			})

		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function check_coin_listunspent(coin_data) {
	console.log(coin_data);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":userpass,"method":"listunspent","coin":coin_data.coin,"address":coin_data.addr};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		//console.log(data);

		$('.dex_showlist_unspents_tbl tbody').empty();
		$.each(data, function(index, val) {
			//console.log(index);
			//console.log(val);
			var show_list_unspents_tbl_tr = '';
			show_list_unspents_tbl_tr += '
';
				show_list_unspents_tbl_tr += 'Index	';
				show_list_unspents_tbl_tr += 'coin	';
				show_list_unspents_tbl_tr += 'height	';
				show_list_unspents_tbl_tr += 'TX Possition	';
				show_list_unspents_tbl_tr += 'Value	';
				show_list_unspents_tbl_tr += 'TX Hash	';
			show_list_unspents_tbl_tr += '
';
			show_list_unspents_tbl_tr += '
';
				show_list_unspents_tbl_tr += '' + index + '	';
				show_list_unspents_tbl_tr += '' + coin_data.coin + '	';
				show_list_unspents_tbl_tr += '' + val.height + '	';
				show_list_unspents_tbl_tr += '' + val.tx_pos + '	';
				show_list_unspents_tbl_tr += '' + (parseFloat(val.value)/100000000).toFixed(8) + ' ' + coin_data.coin + '	';
				show_list_unspents_tbl_tr += '' + val.tx_hash + '	';
			show_list_unspents_tbl_tr += '
';

			$('.dex_showlist_unspents_tbl tbody').append(show_list_unspents_tbl_tr);
		})

	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

$("#inventory_slider_input1").keyup(function(){
	var utxo_input = $("#inventory_slider_input1").val();
	var slider1_value = $("#inventory-slider1").val();
	$("#inventory-slider1Total").text((slider1_value*utxo_input).toFixed(8));

	var slider1_total = parseFloat($('#inventory-slider1Total').text());
	var slider2_total = parseFloat($('#inventory-slider2Total').text());
	var slider3_total = parseFloat($('#inventory-slider3Total').text());
	var slider_total = slider1_total + slider2_total + slider3_total;
	$('.inventory-sliderTotal').text(slider_total.toFixed(8));

	//var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin_balance = $('.inventory-title').data('balance');
	console.log(coin_balance);

	if(slider_total >= coin_balance) {
		$('.inventory-sliderTotal').css('color', 'red');
		$('.inventory-sliderTotalCoin').css('color', 'red');
		$('.btn-makeinventory').attr("disabled", "disabled");
	} else if (slider_total < coin_balance) {
		$('.inventory-sliderTotal').css('color', '');
		$('.inventory-sliderTotalCoin').css('color', '');
		$('.btn-makeinventory').removeAttr("disabled");
	}
});

$("#inventory_slider_input2").keyup(function(){
	utxo_input = $("#inventory_slider_input2").val();
	var slider2_value = $("#inventory-slider2").val();
	$("#inventory-slider2Total").text((slider2_value*utxo_input).toFixed(8));

	var slider1_total = parseFloat($('#inventory-slider1Total').text());
	var slider2_total = parseFloat($('#inventory-slider2Total').text());
	var slider3_total = parseFloat($('#inventory-slider3Total').text());
	var slider_total = slider1_total + slider2_total + slider3_total;
	$('.inventory-sliderTotal').text(slider_total.toFixed(8));

	//var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin_balance = $('.inventory-title').data('balance');
	console.log(coin_balance);

	if(slider_total >= coin_balance) {
		$('.inventory-sliderTotal').css('color', 'red');
		$('.inventory-sliderTotalCoin').css('color', 'red');
		$('.btn-makeinventory').attr("disabled", "disabled");
	} else if (slider_total < coin_balance) {
		$('.inventory-sliderTotal').css('color', '');
		$('.inventory-sliderTotalCoin').css('color', '');
		$('.btn-makeinventory').removeAttr("disabled");
	}
});

$("#inventory_slider_input3").keyup(function(){
	utxo_input = $("#inventory_slider_input3").val();
	var slider3_value = $("#inventory-slider3").val();
	$("#inventory-slider3Total").text((slider3_value*utxo_input).toFixed(8));

	var slider1_total = parseFloat($('#inventory-slider1Total').text());
	var slider2_total = parseFloat($('#inventory-slider2Total').text());
	var slider3_total = parseFloat($('#inventory-slider3Total').text());
	var slider_total = slider1_total + slider2_total + slider3_total;
	$('.inventory-sliderTotal').text(slider_total.toFixed(8));

	//var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin_balance = $('.inventory-title').data('balance');
	console.log(coin_balance);

	if(slider_total >= coin_balance) {
		$('.inventory-sliderTotal').css('color', 'red');
		$('.inventory-sliderTotalCoin').css('color', 'red');
		$('.btn-makeinventory').attr("disabled", "disabled");
	} else if (slider_total < coin_balance) {
		$('.inventory-sliderTotal').css('color', '');
		$('.inventory-sliderTotalCoin').css('color', '');
		$('.btn-makeinventory').removeAttr("disabled");
	}
});

$("#inventory-slider1").slider();
$("#inventory-slider1").on("slide", function(slideEvt) {
	$("#inventory-slider1Val").text(slideEvt.value);

	utxo_input = $("#inventory_slider_input1").val();
	$("#inventory-slider1Total").text((slideEvt.value*utxo_input).toFixed(8));

	var slider1_total = parseFloat($('#inventory-slider1Total').text());
	var slider2_total = parseFloat($('#inventory-slider2Total').text());
	var slider3_total = parseFloat($('#inventory-slider3Total').text());
	var slider_total = slider1_total + slider2_total + slider3_total;
	$('.inventory-sliderTotal').text(slider_total.toFixed(8));

	//var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin_balance = $('.inventory-title').data('balance');
	console.log(coin_balance);

	if(slider_total >= coin_balance) {
		$('.inventory-sliderTotal').css('color', 'red');
		$('.inventory-sliderTotalCoin').css('color', 'red');
		$('.btn-makeinventory').attr("disabled", "disabled");
	} else if (slider_total < coin_balance) {
		$('.inventory-sliderTotal').css('color', '');
		$('.inventory-sliderTotalCoin').css('color', '');
		$('.btn-makeinventory').removeAttr("disabled");
	}
});

$("#inventory-slider2").slider();
$("#inventory-slider2").on("slide", function(slideEvt) {
	$("#inventory-slider2Val").text(slideEvt.value);

	utxo_input = $("#inventory_slider_input2").val();
	$("#inventory-slider2Total").text((slideEvt.value*utxo_input).toFixed(8));

	var slider1_total = parseFloat($('#inventory-slider1Total').text());
	var slider2_total = parseFloat($('#inventory-slider2Total').text());
	var slider3_total = parseFloat($('#inventory-slider3Total').text());
	var slider_total = slider1_total + slider2_total + slider3_total;
	$('.inventory-sliderTotal').text(slider_total.toFixed(8));

	//var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin_balance = $('.inventory-title').data('balance');
	console.log(coin_balance);

	if(slider_total >= coin_balance) {
		$('.inventory-sliderTotal').css('color', 'red');
		$('.inventory-sliderTotalCoin').css('color', 'red');
		$('.btn-makeinventory').attr("disabled", "disabled");
	} else if (slider_total < coin_balance) {
		$('.inventory-sliderTotal').css('color', '');
		$('.inventory-sliderTotalCoin').css('color', '');
		$('.btn-makeinventory').removeAttr("disabled");
	}
});

$("#inventory-slider3").slider();
$("#inventory-slider3").on("slide", function(slideEvt) {
	$("#inventory-slider3Val").text(slideEvt.value);

	utxo_input = $("#inventory_slider_input3").val();
	$("#inventory-slider3Total").text((slideEvt.value*utxo_input).toFixed(8));

	var slider1_total = parseFloat($('#inventory-slider1Total').text());
	var slider2_total = parseFloat($('#inventory-slider2Total').text());
	var slider3_total = parseFloat($('#inventory-slider3Total').text());
	var slider_total = slider1_total + slider2_total + slider3_total;
	$('.inventory-sliderTotal').text(slider_total.toFixed(8));

	//var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin_balance = $('.inventory-title').data('balance');
	console.log(coin_balance);

	if(slider_total >= coin_balance) {
		$('.inventory-sliderTotal').css('color', 'red');
		$('.inventory-sliderTotalCoin').css('color', 'red');
		$('.btn-makeinventory').attr("disabled", "disabled");
	} else if (slider_total < coin_balance) {
		$('.inventory-sliderTotal').css('color', '');
		$('.inventory-sliderTotalCoin').css('color', '');
		$('.btn-makeinventory').removeAttr("disabled");
	}
});

function clac_coin_inventory(data) {
	console.log(data);

	utxo_input1 = (parseFloat(data.balance)*0.12).toFixed(8);
	utxo_input2 = (parseFloat(data.balance)*0.01).toFixed(8);
	utxo_input3 = (parseFloat(data.balance)*0.1).toFixed(8);
	///console.log(utxo_input1);
	//console.log(utxo_input2);
	//console.log(utxo_input3);
	$("#inventory_slider_input1").val(utxo_input1);
	$("#inventory_slider_input2").val(utxo_input2);
	$("#inventory_slider_input3").val(utxo_input3);

	var slider_input1 = $('#inventory-slider1').val();
	var slider_input2 = $('#inventory-slider2').val();
	var slider_input3 = $('#inventory-slider3').val();
	$("#inventory-slider1Total").text(parseFloat(slider_input1*utxo_input1).toFixed(8));
	$("#inventory-slider2Total").text(parseFloat(slider_input2*utxo_input2).toFixed(8));
	$("#inventory-slider3Total").text(parseFloat(slider_input3*utxo_input3).toFixed(8));

	var slider_total = parseFloat(slider_input1*utxo_input1) + parseFloat(slider_input2*utxo_input2) + parseFloat(slider_input3*utxo_input3);
	console.log(slider_total);

	$('.inventory-sliderTotal').text(slider_total.toFixed(8));
}

function make_inventory_withdraw(data) {
	//console.log(data);
	coin = data.coin;

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"withdraw","coin": data.coin, "outputs": data.outputs};
	var url = "http://127.0.0.1:7783";

	console.log(ajax_data);

	var a1 = $.ajax({
			async: true,
			data: JSON.stringify(ajax_data),
			dataType: 'json',
			type: 'POST',
			url: url
		}),
		a2 = a1.then(function(data) {
			// .then() returns a new promise
			console.log(data);
			if (data.complete == false) {
				toastr.error('Uncessful Transaction. Please try again.','Tansaction info');
			}
			if (data.complete == true) {
				bootbox.confirm({
					message: 'Please confirm if you are ready to make inventory.',
					buttons: {
						confirm: {
							label: 'Confirm',
							className: 'btn-primary'
						},
						cancel: {
							label: 'Cancel',
							className: 'btn-default'
						}
					},
					callback: function (result) {
						console.log('This was logged in the callback: ' + result);

						if (result == true) {
							var ajax_data2 = {"userpass":<PASSWORD>,"method":"sendrawtransaction","coin": coin, "signedtx": data.hex};
							console.log(ajax_data2);

							toastr.info('Transaction Executed', 'Transaction Status');

							return $.ajax({
									async: true,
									data: JSON.stringify(ajax_data2),
									dataType: 'json',
									type: 'POST',
									url: url
								})
						} else {
							console.log('Sending Transaction operation canceled.');
							return {'output': 'canceled'};
						}
					}
				});
			}
	});

	a2.done(function(data) {
		console.log(data);
	});
}

function addcoin_enable_disable_coin(data) {
	//console.log(data.coin);
	//console.log(data.status);
	var electrum_option = $('.toggle_checkbox[data-coin="' + data.coin + '"]').prop('checked'); //If 'false', electrum option selected
	var userpass = sessionStorage.getItem('mm_userpass');

	if (data.coin !== ' ' ) {
		console.log('coin value is not empty');
	} else {
		console.log('coin value is empty');
	}
	if (data.coin !== ' ' && data.status == 'enable') {
		if (electrum_option == false) {
		console.log(electrum_option);
		console.log("electrum selected for " + data.coin);
		var ajax_data = {"userpass":<PASSWORD>pass,"method":"electrum","coin":data.coin,"ipaddr":"192.168.3.11","port":50001};
		} else {
			console.log(electrum_option);
			console.log("native selected for " + data.coin);
			var ajax_data = {"userpass":<PASSWORD>pass,"method":data.status,"coin":data.coin};
		}
	} else if (data.coin !== ' ' && data.status == 'disable') {
		var ajax_data = {"userpass":userpass,"method":data.status,"coin":data.coin};
	} else if (data.coin == ' ') {
		var ajax_data = {"userpass":<PASSWORD>pass,"method":"getcoins"};
	}
	var url = "http://127.0.0.1:7783";

	console.log(ajax_data);

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		//console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
			if (ajax_data.status === 'enable') {
				toastr.success(ajax_data.coin+' Enabled','Coin Status');
			}
			if (ajax_data.status === 'disable') {
				toastr.success(ajax_data.coin+' Disabled','Coin Status');
			}
			get_coins_list(data.coins);
		} else {
			$('.initcoinswap-output').html(JSON.stringify(data, null, 2));
			//get_coins_list(data);
			if (electrum_option == false) {
				//get_coins_list('');
				$('.refresh_dex_balances').trigger('click');
			} else {
				get_coins_list(data);
			}
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function get_coins_list() {

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');

	var ajax_data = {"userpass":userpass,"method":"getcoins"};
	console.log(ajax_data)
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		console.log(data);

		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
			get_coins_list();
			return
		} else {
			$('.addcoins_tbl tbody').empty();

			$.each(data, function(index, val) {
				console.log(index);
				console.log(val);

				var coin_name = return_coin_name(val.coin)

				var addcoins_tbl_tr = '';

				addcoins_tbl_tr += '
';
					addcoins_tbl_tr += ' '+ coin_name + ' (' + val.coin + ')	';
					addcoins_tbl_tr += '' + val.balance + '	';
					addcoins_tbl_tr += '' + val.smartaddress + '	';
					addcoins_tbl_tr += '' + val.status + '	';
					addcoins_tbl_tr += '' + (parseFloat(val.txfee)/100000000).toFixed(8) + '	';
					addcoins_tbl_tr += '<input class="toggle_checkbox" type="checkbox" checked data-toggle="toggle" data-on="Native" data-off="Electrum" data-onstyle="grey" data-offstyle="info" data-width="100px" data-coin="' + val.coin + '" disabled>	';
					addcoins_tbl_tr += '
' + (( val.status == 'active' ) ? '<button class="btn btn-xs btn-warning addcoins_tbl_disable_btn" data-coin="' + val.coin + '">Disable</button>' : '<button class="btn btn-xs btn-success addcoins_tbl_enable_btn" data-coin="' + val.coin + '">Enable</button>') + '
	';
				addcoins_tbl_tr += '
';

				$('.addcoins_tbl tbody').append(addcoins_tbl_tr);

				/*if (val.status == 'active') {
					$('.selectpicker option').filter(function () { return $(this).html() == val.coin; }).removeAttr('disabled');
				}else {
					$('.selectpicker option').filter(function () { return $(this).html() == val.coin; }).attr("disabled","disabled");
				}

				$('.selectpicker').selectpicker('refresh');*/
				$('.toggle_checkbox[data-coin="BTC"]').removeAttr('disabled');
				$('.toggle_checkbox').bootstrapToggle();

				if (!val.electrum === false) {
					console.log(val);
					$('.toggle_checkbox[data-coin="' + val.coin + '"]').prop('checked', false).change()
				}
			})
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
		// If fail
		console.log(textStatus + ': ' + errorThrown);
	});
};

function addcoins_dialog(){

	var bot_update_bootbox = bootbox.dialog({
		message: `

Add Coin

							<select class="selectpicker addcoin_enable_disable_selection" data-live-search="true" data-hide-disabled="true" data-width="100%"></select>

							<input class="toggle_checkbox toggle_font_lg" id="addcoin_toggle_native_electrum" type="checkbox" checked data-toggle="toggle" data-on="Native Mode" data-off="Electrum Mode" data-size="large" data-onstyle="primary" data-offstyle="info" data-width="100%" data-height="64px">

`,
		closeButton: false,
		size: 'medium',

		buttons: {
			cancel: {
				label: "Cancel",
				className: 'btn-default',
				callback: function(){

				}
			},
			ok: {
				label: "Enable",
				className: 'btn-success btn-addcoins_enable',
				callback: function(){
					var addcoin_data = {}
					addcoin_data.coin = $('.addcoin_enable_disable_selection').selectpicker('val');
					addcoin_data.electrum = $('#addcoin_toggle_native_electrum').prop('checked');
					addcoin_data.method = 'enable';
					console.log(addcoin_data);

					enable_disable_coin(addcoin_data);
					CheckPortfolioFn();

				}
			}
		}
	});
	bot_update_bootbox.init(function(){
		$('.addcoin_enable_disable_selection').html(coin_select_options);
		$('.addcoin_enable_disable_selection').selectpicker('render');

		$('.toggle_checkbox').bootstrapToggle();

		//console.log('bot_update_settings dialog opened.')
		//$('.btn-bot_settings_update').attr("disabled", "disabled");
		//$('.trading_pair_coin_newprice').inputNumber();
		//$('.trading_pair_coin_newvolume').inputNumber();

	});
}

/* Portfolio section functions START */

function CheckPortfolioFn(sig) {
	if (sig == false) {
		clearInterval(CheckPortfolio_Interval);
		return 'Check portfolio calls stopped.';
	} else {
		console.log('checking portfolio');
	}

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');

	var ajax_data = {"userpass":userpass,"method":"portfolio"};
	console.log(ajax_data)
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);

		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			CheckPortfolioFn();
			get_coin_info('MNZ');
			return
		}

		PortfolioTblDataFn(data);
		PortfolioChartUpdate(data.portfolio);
	   //$('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function PortfolioTblDataFn(data) {
	//console.log(data);

	$('.portfolio_kmd_equiv').html(data.kmd_equiv);
	$('.portfolio_buycoin').html(data.buycoin);
	$('.portfolio_buyforce').html(data.buyforce);
	$('.portfolio_sellcoin').html(data.sellcoin);
	$('.portfolio_sellforce').html(data.sellforce);
	$('.portfolio_base').html(data.base);
	$('.portfolio_rel').html(data.rel);
	$('.portfolio_relvolume').html(data.relvolume);

	$('.dex_portfolio_coins_tbl tbody').empty();

	$('.porfolio_coins_list tbody').empty();
	$.each(data.portfolio, function(index, val) {
		//console.log(index);
		console.log(val);

		var coin_name = return_coin_name(val.coin)

		var dex_portfolio_coins_tbl_tr = '';

		dex_portfolio_coins_tbl_tr += '
';
			dex_portfolio_coins_tbl_tr += ' '+ coin_name +' ('+val.coin + ')	';
			//dex_portfolio_coins_tbl_tr += '' + val.address + '	';
			dex_portfolio_coins_tbl_tr += '' + val.amount + '	';
            dex_portfolio_coins_tbl_tr += '' + val.price + '	';
            dex_portfolio_coins_tbl_tr += '' + val.kmd_equiv + '	';
            dex_portfolio_coins_tbl_tr += '<button class="btn btn-sm btn-default btn-portfoliogo" data-coin="' + val.coin + '" data-coinname="' + coin_name + '" data-addr="' + val.address + '" data-balance="' + val.amount + '"></button>	'
            /*dex_portfolio_coins_tbl_tr += '' + val.perc + '	';
            dex_portfolio_coins_tbl_tr += '' + val.goal + '	';
            dex_portfolio_coins_tbl_tr += '' + val.goalperc + '	';
            dex_portfolio_coins_tbl_tr += '' + val.relvolume + '	';
            dex_portfolio_coins_tbl_tr += '' + val.force + '	';
            dex_portfolio_coins_tbl_tr += '' + val.balanceA + '	';
            dex_portfolio_coins_tbl_tr += '' + val.valuesumA + '	';
            dex_portfolio_coins_tbl_tr += '' + val.aliceutil + '	';
            dex_portfolio_coins_tbl_tr += '' + val.balanceB + '	';
            dex_portfolio_coins_tbl_tr += '' + val.valuesumB + '	';
            dex_portfolio_coins_tbl_tr += '' + val.balance + '	';
            dex_portfolio_coins_tbl_tr += '' + val.bobutil + '	';*/
		dex_portfolio_coins_tbl_tr += '
';

		$('.porfolio_coins_list tbody').append(dex_portfolio_coins_tbl_tr);
	})
};

function PortfolioChartUpdate(chart_data) {
	console.log(chart_data)
	var chart = AmCharts.makeChart( "portfolio_chart_current", {
	  "type": "pie",
	  "theme": "light",
	  "dataProvider": chart_data,
	  "valueField": "perc",
	  "titleField": "coin",
	  "startDuration": 0,
	  "innerRadius": 50,
	  "pullOutRadius": 20,
	  "marginTop": 30,
	  "marginBottom": 15,
	  "marginLeft": 0,
	  "marginRight": 0,
	  "pullOutRadius": 0,
	  /*"titles": [
	    {
	      "text": "Current Portfolio Goal"
	    }
	  ],*/
	  "allLabels": [
	    {
	      "y": "46%",
	      "align": "center",
	      "size": 25,
	      "bold": true,
	      "text": "Now",
	      "color": "#555"
	    },
	    {
	      "y": "40%",
	      "align": "center",
	      "size": 15,
	      "text": "Goal",
	      "color": "#555"
	    }
	  ],
	  "export": {
	    "enabled": false
	  }
	});

	var chart2 = AmCharts.makeChart( "portfolio_chart_target", {
	  "type": "pie",
	  "theme": "light",
	  "dataProvider": chart_data,
	  "valueField": "goalperc",
	  "titleField": "coin",
	  "startDuration": 0,
	  "innerRadius": 50,
	  "pullOutRadius": 20,
	  "marginTop": 30,
	  "marginBottom": 15,
	  "marginLeft": 0,
	  "marginRight": 0,
	  "pullOutRadius": 0,
	  /*"titles": [
	    {
	      "text": "Target Portfolio Goal"
	    }
	  ],*/
	  "allLabels": [
	    {
	      "y": "46%",
	      "align": "center",
	      "size": 25,
	      "bold": true,
	      "text": "Target",
	      "color": "#555"
	    },
	    {
	      "y": "40%",
	      "align": "center",
	      "size": 15,
	      "text": "Goal",
	      "color": "#555"
	    }
	  ],
	  "export": {
	    "enabled": false
	  }
	});
}

$('.btn-refreshportfolio').click(function() {
	console.log('clicked refresh button at dex portfolio charts');
	CheckPortfolioFn();
});

$('.refresh_dex_potfolio').click(function() {
	console.log('clicked refresh button at dex portfolio charts');
	CheckPortfolioFn();
});

$('.refresh_dex_potfolio_coins').click(function() {
	console.log('clicked refresh button at dex portfolio charts');
	CheckPortfolioFn();
});

$('.portfolio_set_price_btn').click(function() {
	var price = $('#portfolio_set_price').val();
	var base_coin = $('.buy_coin_p').selectpicker('val');
	var rel_coin = $('.sell_coin_p').selectpicker('val');

	console.log('price ' + price);
	console.log('base '+ base_coin);
	console.log('rel ' + rel_coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"setprice","base":base_coin,"rel":rel_coin,"price":price};
	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
	    // If successful
	   console.log(data);
	   toastr.success('Price for Base: ' + base_coin + ' Rel: ' + rel_coin + ' set to: ' + price + ' ' + rel_coin, 'Portfolio Info')
	   $('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

})

$('.portfolio_set_autoprice_btn').click(function() {
	var margin = $('#portfolio_set_autoprice').val();
	var base_coin = $('.buy_coin_p').selectpicker('val');
	var rel_coin = $('.sell_coin_p').selectpicker('val');

	console.log('margin ' + margin);
	console.log('base '+ base_coin);
	console.log('rel ' + rel_coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"autoprice","base":base_coin,"rel":rel_coin,"margin":margin};
	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
	    // If successful
	   console.log(data);
	   toastr.success('Margin Price for Base: ' + base_coin + ' Rel: ' + rel_coin + ' set to: ' + margin + '% ' + rel_coin, 'Portfolio Info')
	   $('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

})

$('.portfolio_set_goal_btn').click(function() {
	var percent = $('#portfolio_set_goal').val();
	var coin = $('.sell_coin_p').selectpicker('val');

	console.log('percent ' + percent);
	console.log('coin '+ coin);
	//console.log('rel ' + rel_coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"goal","coin":coin,"val":percent};
	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
	    // If successful
	   console.log(data);
	   toastr.success('Goal for ' + coin + ' set to: ' + percent, 'Portfolio Info')
	   $('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

	CheckPortfolioFn();
})

$( ".sell_coin_p" ).change(function() {
	$('.set_goal_label_portfolio').html($('.sell_coin_p').selectpicker('val'));
})

$('.portfolio_set_autogoals_btn').click(function() {
	//var percent = $('#portfolio_set_goal').val();
	//var coin = $('.sell_coin_p').selectpicker('val');

	//console.log('percent ' + percent);
	//console.log('coin '+ coin);
	//console.log('rel ' + rel_coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"goal"};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
	    // If successful
	   console.log(data);
	   toastr.success('Auto goal setup executed!', 'Portfolio Info')
	   $('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

	CheckPortfolioFn();
})

/* Portfolio section functions END */

/* Auto Trading Bot */

function CheckOrderBookFn(sig) {
	if (sig == false) {
		clearInterval(CheckOrderbook_Interval);
		return
	} else {
		console.log('checking orderbook');
	}

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	console.log(coin);

	buying_or_selling = $('input[name=trading_pair_options]:checked').val();

	if(buying_or_selling == 'buying') {
		var base_coin = coin;
		var rel_coin = $('.trading_pair_coin').selectpicker('val');
	}
	if(buying_or_selling == 'selling') {
		var base_coin = $('.trading_pair_coin').selectpicker('val');
		var rel_coin = coin;
	}

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');

	$('.orderbook_rel_coin').html(rel_coin);
	$('.orderbook_base_coin').html(base_coin);

	var ajax_data = {"userpass":userpass,"method":"orderbook","base":base_coin,"rel":rel_coin};
	//console.log(ajax_data)
	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
			//CheckOrderBookFn();
		} else {
			//console.log(data.asks);

			$('.orderbook_numasks').html(data.numasks);
			$('.orderbook_numbids').html(data.numbids);

			$('.orderbook_bids tbody').empty();
			$.each(data.bids, function(index, val) {
				//console.log(index);
				//console.log(val);
				var mytrade_true = '';
				if (val.pubkey === mypubkey) {
					var mytrade_true = 'class="warning"';
				}
				var orderbook_bids_tr = '';
				orderbook_bids_tr += '
';
				orderbook_bids_tr += '' + val.price + '	';
				orderbook_bids_tr += '' + val.minvolume + '	';
				orderbook_bids_tr += '' + val.maxvolume + '	';
				orderbook_bids_tr += '' + val.age + '	';
				orderbook_bids_tr += '' + val.numutxos + '	';
				orderbook_bids_tr += '
';
				$('.orderbook_bids tbody').append(orderbook_bids_tr);
			})

			$('.orderbook_asks tbody').empty();
			$.each(data.asks, function(index, val) {
				//console.log(index);
				//console.log(val);
				var mytrade_true = '';
				if (val.pubkey === mypubkey) {
					var mytrade_true = 'class="warning"';
				}
				var orderbook_asks_tr = '';
				orderbook_asks_tr += '
';
				orderbook_asks_tr += '' + val.price + '	';
				orderbook_asks_tr += '' + val.minvolume + '	';
				orderbook_asks_tr += '' + val.maxvolume + '	';
				orderbook_asks_tr += '' + val.age + '	';
				orderbook_asks_tr += '' + val.numutxos + '	';
				orderbook_asks_tr += '
';
				$('.orderbook_asks tbody').append(orderbook_asks_tr);
			})
		}

	   //$('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

	return 'Check orderbook calls stopped.';
}

function check_my_prices(sig){
	if (sig == false) {
		clearInterval(check_my_prices_Internal);
		return
	} else {
		console.log('checking my prices');
	}

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	console.log(coin);

	buying_or_selling = $('input[name=trading_pair_options]:checked').val();

	if(buying_or_selling == 'buying') {
		var base_coin = coin;
		var rel_coin = $('.trading_pair_coin').selectpicker('val');
	}
	if(buying_or_selling == 'selling') {
		var base_coin = $('.trading_pair_coin').selectpicker('val');
		var rel_coin = coin;
	}

	var userpass = sessionStorage.getItem('mm_userpass');
	//var ajax_data = {"userpass":userpass,"method":"myprice","base":base_coin,"rel":rel_coin};
	var ajax_data = {"userpass":userpass,"method":"myprices"};
	console.log(ajax_data)
	var url = "http://1192.168.3.11:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		} else {
			//console.log(data);
			$('.exchange_my_orders_tbl tbody').empty();
			if (!data.error === false) {
				var exchange_my_orders_tr = '';
				exchange_my_orders_tr += '
';
				exchange_my_orders_tr += '
' + data.error + ' for pair ' + base_coin + '/' + rel_coin + '
	';
				exchange_my_orders_tr += '
';
				$('.exchange_my_orders_tbl tbody').append(exchange_my_orders_tr);
			} else {
				$.each(data, function(index, val) {
					console.log(index);
					console.log(val);

					var base_coin_name = return_coin_name(val.base)
					var rel_coin_name = return_coin_name(val.rel)

					var exchange_my_orders_tr = '';
					exchange_my_orders_tr += '
';
						exchange_my_orders_tr += ''+ val.base + ' (' + base_coin_name + ')	';
						exchange_my_orders_tr += ''+ val.rel + ' (' + rel_coin_name + ')	';
						exchange_my_orders_tr += '' + val.bid + '	';
						exchange_my_orders_tr += '' + val.ask + '	';
					exchange_my_orders_tr += '
';
					$('.exchange_my_orders_tbl tbody').append(exchange_my_orders_tr);
				});

				/*var base_coin_name = return_coin_name(data.base)
				var rel_coin_name = return_coin_name(data.rel)

				var exchange_my_orders_tr = '';
				exchange_my_orders_tr += '
';
					exchange_my_orders_tr += ''+ data.base + ' (' + base_coin_name + ')	';
					exchange_my_orders_tr += ''+ data.rel + ' (' + rel_coin_name + ')	';
					exchange_my_orders_tr += '' + data.bid + '	';
					exchange_my_orders_tr += '' + data.ask + '	';
				exchange_my_orders_tr += '
';
				$('.exchange_my_orders_tbl tbody').append(exchange_my_orders_tr);*/
			}
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

}

$('.trading_pair_coin').on('change', function (e) {
	var optionSelected = $("option:selected", this);
	var valueSelected = this.value;
	console.log(valueSelected);

	//update_min_max_price_input();

});

$('.btn-refreshtrading_pair').click(function(e){
	e.preventDefault();
	console.log('btn-refreshtrading_pair clicked');
	console.log($(this).data());

	//update_min_max_price_input();
})

$('input[name=trading_pair_options]').change(function() {
	console.log('trading_pair_options changed');

	buying_or_selling = $('input[name=trading_pair_options]:checked').val();
	//console.log(buying_or_selling);

	if(buying_or_selling == 'buying') {
		$('#trading_pair_coin_price_max_min').html('Max');
		$('.trading_pair_lable_text_one').html('Max');
		$('.trading_pair_lable_text_two').html('Buy');
		$('.btn-bot_action').html('BUY');
		$('.btn-bot_action').attr('data-action', 'buy');
	}
	if(buying_or_selling == 'selling') {
		$('#trading_pair_coin_price_max_min').html('Min');
		$('.trading_pair_lable_text_one').html('Min');
		$('.trading_pair_lable_text_two').html('Sell');
		$('.btn-bot_action').html('SELL');
		$('.btn-bot_action').attr('data-action', 'sell');
	}
});

$('.trading_pair_coin').on('changed.bs.select', function (e) {
	$('.trading_pair_coin').selectpicker('val');
	$('.relvol_basevol_coin').html($('.trading_pair_coin').selectpicker('val'));
	bot_screen_sellcoin_balance();
	bot_screen_coin_balance();
});

$('.your_coins_balance_info').on('click', '.coin_balance_enable_native', function() {
	console.log('coin_balance_enable_native clicked');
	console.log($(this).data());

	enable_disable_coin($(this).data());
	bot_screen_sellcoin_balance();
	bot_screen_coin_balance();
});

$('.your_coins_balance_info').on('click', '.coin_balance_enable_electrum', function() {
	console.log('coin_balance_enable_electrum clicked');
	console.log($(this).data());

	enable_disable_coin($(this).data());
	bot_screen_sellcoin_balance();
	bot_screen_coin_balance();
});

$('.your_coins_balance_info').on('click', '.coin_balance_disable', function() {
	console.log('coin_balance_disable clicked');
	console.log($(this).data());

	enable_disable_coin($(this).data());
	bot_screen_sellcoin_balance();
	bot_screen_coin_balance();
});

$('.your_coins_balance_info').on('click', '.coin_balance_receive', function() {
	console.log('coin_balance_receive clicked');
	console.log($(this).data());
	coin = $(this).data('coin');

	var coin_name = return_coin_name(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"getcoin","coin": coin};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		}

		bootbox.dialog({
		    //title: 'A custom dialog with init',
			message: '

'+data.coin.smartaddress+'

'
		});

		var qrcode = new QRCode("receive_addr_qrcode");
		qrcode.makeCode(data.coin.smartaddress); // make another code.
		$('#receive_addr_qrcode > img').removeAttr('style');
		$('#receive_addr_qrcode > img').css('display', 'initial');
		$('#receive_addr_qrcode > img').css('border', '9px solid #f1f1f1','border-radius','5px','margin', '5px');
		$('#receive_addr_qrcode > img').css('border-radius','5px');
		$('#receive_addr_qrcode > img').css('margin', '5px');

	}).fail(function(jqXHR, textStatus, errorThrown) {
		// If fail
		console.log(textStatus + ': ' + errorThrown);
	});
})

$('.your_coins_balance_info').on('click', '.coin_balance_send', function() {
	console.log('coin_balance_send clicked');
	console.log($(this).data());

	var tx_coin = $(this).data('coin');

	var coin_balance_send_bootbox = bootbox.dialog({
		message: `

Send Transaction

							<form class="form-horizontal">

									To

										<input type="text" class="form-control" id="bot_send_toaddr" placeholder="Address">

									Amount

										<input type="text" class="form-control" id="bot_send_amount" placeholder="e.g. 0.01">

							</form>

`,
		closeButton: false,
		size: 'large',
		className: 'custom_class_for_bootbox',

		buttons: {
			cancel: {
				label: "Cancel",
				className: 'btn-default',
				callback: function(){

				}
			},
			ok: {
				label: "Send Transaction",
				className: 'btn-primary',
				callback: function(){
					var to_addr = $('#bot_send_toaddr').val();
					var send_amount = $('#bot_send_amount').val();
					console.log(to_addr);
					console.log(send_amount);

					var output_data = {};
					output_data[to_addr] = send_amount;
					console.log(output_data);

					console.log(tx_coin);
					create_sendtx(tx_coin, output_data);
				}
			}
		}
	});
	coin_balance_send_bootbox.init(function(){
		console.log('coin_balance_send_bootbox dialog opened.')

	});

});

$('.your_coins_balance_info').on('click', '.coin_balance_inventory', function() {
	console.log('coin_balance_inventory clicked');
	console.log($(this).data());
	coin = $(this).data('coin');
	addr = $(this).data('addr');
	balance = $(this).data('balance');

	$('.screen-exchange').hide()
	$('.screen-inventory').show();
	CheckOrderBookFn(false);
	check_swap_status(false);
	check_bot_list(false);
	check_my_prices(false);
	bot_screen_coin_balance(false);
	bot_screen_sellcoin_balance(false);

	$('.inventory-title').html('Manage Inventory ('+balance+' '+coin+')');
	$('.inventory-title').data('coin', coin);
	$('.inventory-title').data('balance', balance);
	$('.coininventory[data-coin]').attr('data-coin', coin);
	//$('.coininventory[data-coin]').attr('data-pair', $(this).data('pair'));
	$('.coininventory[data-coin]').attr('data-addr', addr);
	$('.inventory-sliderTotalCoin').html(' '+coin);

	$('.dex_showinv_alice_tbl tbody').html('
Loading...
	');
	$('.dex_showlist_unspents_tbl tbody').html('
Loading...
	');

	check_coin_inventory(coin);
	check_coin_listunspent($(this).data());

	calc_data = {"coin": coin, "balance": balance};
	clac_coin_inventory(calc_data);

});

function create_sendtx(coin,tx_data){
	console.log(tx_data);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"withdraw","coin": coin, "outputs": [tx_data]};
	var url = "http://127.0.0.1:7783";

	console.log(ajax_data);

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
		} else {
			if (data.complete == true) {
				console.log(data.hex);
				bot_sendrawtx(data);
			} else {
				toastr.error('Transaction did not complete. Please try again.', 'Transaction Info');
			}
		}

	}).fail(function(jqXHR, textStatus, errorThrown) {
		// If fail
		console.log(textStatus + ': ' + errorThrown);
	});
}

function update_min_max_price_input(){
	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	console.log(coin);

	buying_or_selling = $('input[name=trading_pair_options]:checked').val();

	if(buying_or_selling == 'buying') {
		var base_coin = coin;
		var rel_coin = $('.trading_pair_coin').selectpicker('val');
	}
	if(buying_or_selling == 'selling') {
		var base_coin = $('.trading_pair_coin').selectpicker('val');
		var rel_coin = coin;
	}

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');

	$('.orderbook_rel_coin').html(rel_coin);
	$('.orderbook_base_coin').html(base_coin);

	var ajax_data = {"userpass":userpass,"method":"orderbook","base":base_coin,"rel":rel_coin};
	//console.log(ajax_data)
	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
			//get_coins_list(data.coins);
		} else {
			//console.log(data.asks);
			if(buying_or_selling == 'buying') {
				$('.trading_pair_coin_price').val(data.asks[0].price);
			}
			if(buying_or_selling == 'selling') {
				$('.trading_pair_coin_price').val(data.bids[0].price);
			}
		}

	   //$('.initcoinswap-output').html(JSON.stringify(data, null, 2));
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function check_bot_list(sig) {
	if (sig == false) {
		clearInterval(check_bot_list_Internal);
		return
	} else {
		console.log('checking bot list');
	}

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	//console.log(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":userpass,"method":"bot_statuslist"};
	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);

		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		} else {
			$('.exchange_bot_list_tbl tbody').empty();
			$.each(data, function(index, val) {
				console.log(index);
				console.log(val);
				if(!val.error === false) {
					var exchange_bot_list_tr = '';
					exchange_bot_list_tr += '
';
					exchange_bot_list_tr += '
error
	';
					exchange_bot_list_tr += '-	';
					exchange_bot_list_tr += '
';
					$('.exchange_bot_list_tbl tbody').append(exchange_bot_list_tr);
				} else {

					if (!val.paused === false) {
						var disable_resume_btn = ' ';
						var disable_pause_btn = 'disabled="disabled"';
					} else {
						var disable_resume_btn = 'disabled="disabled"';
						var disable_pause_btn = ' ';
					}
					if (!val.stopped === false) {
						var disable_stop_btn = 'disabled="disabled"';
					} else {
						var disable_stop_btn = ' ';
					}

					if (!val.minprice === false){
						var max_min_val = val.minprice;
					}
					if (!val.maxprice === false){
						var max_min_val = val.maxprice;
					}

					var exchange_bot_list_tr = '';
					exchange_bot_list_tr += '
';
					//exchange_bot_list_tr += ''+val.botid+'	';
					exchange_bot_list_tr += ''+val.name+'	';
					//exchange_bot_list_tr += ''+val.action+'	';
					exchange_bot_list_tr += ''+max_min_val+'	';
					exchange_bot_list_tr += ''+val.totalrelvolume+'	';
					exchange_bot_list_tr += ''+val.trades.length+'	';
					exchange_bot_list_tr += '
<button class="btn btn-info btn_bot_status" data-botid="' + val.botid + '" data-action="status"></button><button class="btn btn-success btn_bot_resume" data-botid="' + val.botid + '" data-action="resume" ' + disable_resume_btn + '></button><button class="btn btn-warning btn_bot_pause" data-botid="' + val.botid + '" data-action="pause" ' + disable_pause_btn + '></button><button class="btn btn-danger btn_bot_stop" data-botid="' + val.botid + '" data-action="stop" ' + disable_stop_btn + '></button>
	';
					exchange_bot_list_tr += '
';
					$('.exchange_bot_list_tbl tbody').append(exchange_bot_list_tr);
				}
			})
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function bot_buy_sell(bot_data) {
	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	//console.log(coin);

	buying_or_selling = $('input[name=trading_pair_options]:checked').val();

	/*if(buying_or_selling == 'buying') {
		var base_coin = coin;
		var rel_coin = $('.trading_pair_coin').selectpicker('val');
	}
	if(buying_or_selling == 'selling') {
		var base_coin = $('.trading_pair_coin').selectpicker('val');
		var rel_coin = coin;
	}*/

	var base_coin = coin;
	var rel_coin = $('.trading_pair_coin').selectpicker('val');

	console.log('BUYING or SELLING??: ' + buying_or_selling);
	console.log('BASE: ' + base_coin);
	console.log('REL: '+ rel_coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');

	if (bot_data.action == 'buy') {
		var ajax_data = {"userpass":<PASSWORD>pass,"method":"bot_buy","base":base_coin,"rel":rel_coin,"maxprice":bot_data.price,"relvolume":bot_data.volume};
	}
	if (bot_data.action == 'sell') {
		var ajax_data = {"userpass":userpass,"method":"bot_sell","base":base_coin,"rel":rel_coin,"minprice":bot_data.price,"basevolume":bot_data.volume};
	}

	console.log(ajax_data);

	console.log(JSON.stringify(ajax_data));

	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);

		if (!data.error === false) {
			if (data.error == 'not enough funds') {
				//toastr.info(data.error + '
Balance: ' + data.balance + ' ' + data.coin, 'Bot Info');
				bootbox.alert(`Looks like you don't have enough UTXOs in your balance.

					Not a problem. I have executed the recommended command to make required UTXOs for you.

					If you see some outgoing transactions from your barterDEX smartaddress that's sent to the same smartaddress of yours to create some inventory transactions for barterDEX to make required trades.

					Please try in a moment with same or different volume and you should be all good to go.`);
				console.log(JSON.stringify(data))

				if (data.withdraw.complete === true) {
					bot_sendrawtx(data.withdraw);
				} else {
					toastr.error('No withdraw info found. Please try again.', 'Bot Info');
				}
			}
		} else if (data.result == 'success') {
			toastr.success(data.name + ' started
 Bot ID: ' + data.botid, 'Bot Info');
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

	check_bot_list();
}

function bot_sendrawtx(bot_data) {
	console.log(bot_data);
	console.log(bot_data.hex)
	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	console.log(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":<PASSWORD>,"method":"sendrawtransaction","coin": coin, "signedtx": bot_data.hex};
	var url = "http://127.0.0.1:7783";

	console.log(ajax_data);
	console.log(JSON.stringify(ajax_data));

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		console.log(JSON.stringify(data));

		if (!data.error === false) {
			toastr.error(data.error.message, 'Transaction Info');
		} else if (data.result == 'success') {
			toastr.info('Low no. of UTXOs
Please try again in 1 Minute.', 'Transaction Status');
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function bot_stop_pause_resume(bot_data) {
	console.log(bot_data);
	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');

	if (bot_data.action == 'pause') {
		var ajax_data = {"userpass":<PASSWORD>,"method":"bot_pause","botid":bot_data.botid};
		var action_result = 'paused';
	}
	if (bot_data.action == 'resume') {
		var ajax_data = {"userpass":<PASSWORD>,"method":"bot_resume","botid":bot_data.botid};
		var action_result = 'resumed';
	}
	if (bot_data.action == 'stop') {
		var ajax_data = {"userpass":<PASSWORD>pass,"method":"bot_stop","botid":bot_data.botid};
		var action_result = 'stopped';
	}

	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);

		if (!data.error === false) {
			toastr.error(data.error, 'Bot Info');
		} else if (data.result == 'success') {
			toastr.success('Bot ID: ' + bot_data.botid + ' ' + action_result + 'ed', 'Bot Info');
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

	check_bot_list();
}

function bot_settings(bot_data) {
	console.log(bot_data);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":<PASSWORD>,"method":"bot_settings","botid":bot_data.botid,"newprice":bot_data.newprice,"newvolume":bot_data.newvolume};

	console.log(ajax_data);

	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);

		if (!data.error === false) {
			toastr.error(data.error, 'Bot Info');
		} else if (data.result == 'success') {
			toastr.success('Bot ID: ' + bot_data.botid + ' Updateded', 'Bot Info');
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

	check_bot_list();
}

function bot_status(bot_data) {
	console.log(bot_data);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":userpass,"method":"bot_status","botid":bot_data.botid};
	var url = "http://127.0.0.1:7783";

	$.ajax({
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		console.log(data);

		if (!data.error === false) {
			toastr.error(data.error, 'Bot Info');
		} else if (data.result == 'success') {

			var max_min = null;
			var max_min_val = null;
			if (!data.minprice === false){
				max_min = 'Minimum';
				max_min_val = data.minprice;
			}
			if (!data.maxprice === false){
				max_min = 'Maximum';
				max_min_val = data.maxprice;
			}

			result_answer = (data.result == 'success') ? '
 Success
' : '
 ' + data.result + '
';
			rel_answer = ' '+ return_coin_name(data.rel) + ' ('+data.rel+')';
			base_answer = ' '+ return_coin_name(data.base) + ' ('+data.base+')';

			rel_form = ' '+ data.rel;
			base_form = ' '+ data.base;

			buy_sell_text = (data.action == 'buy') ? 'Buy' : 'Sell';
			max_min_text = (data.action == 'buy') ? 'Max' : 'Min';

			var bot_update_bootbox = bootbox.dialog({
				message: `

							Auto Trader ID
							` + data.botid + `

							Auto Trade Name
							` + data.name + `

							Trade Action
							` + data.action + `

							Selling Currency
							` + rel_answer + `

							Buying Currency
							` + base_answer + `

							` + max_min + ` Price
							` + max_min_val + ` ` + data.rel + `

							Total Selling Volume
							` + data.totalrelvolume + ` ` + data.rel + `

							Total Buying Volume
							` + data.totalbasevolume + ` ` + data.base + `

							Result
							` + result_answer + `

							Trades Attempts
							` + JSON.stringify(data.trades, null, 2) + `

Change This Auto Trade's Settings

										New ` + max_min_text + ` Price to ` + buy_sell_text + `

										` + rel_form + `
										<input type="number" class="form-control trading_pair_coin_newprice" placeholder="Price e.g. 0.01" style="height: 64px; font-size: 20px;">
										` + max_min_text + `

										New Max Amount to ` + buy_sell_text + `

										` + base_form + `
										<input type="number" class="form-control trading_pair_coin_newvolume" placeholder="Amount e.g. 12.5" style="height: 64px; font-size: 20px;">

										It'll cost you
										0 ` + data.rel.toUpperCase() + `

`,
				closeButton: true,
				size: 'large',

				buttons: {
					cancel: {
						label: "Close",
						className: 'btn-default',
						callback: function(){

						}
					},
					ok: {
						label: "Update",
						className: 'btn-primary btn-bot_settings_update',
						callback: function(){
							//console.log($('.trading_pair_coin_newprice').val())
							//console.log($('.trading_pair_coin_newvolume').val())
							//console.log(data.rel);
							//console.log(data.base);

							var newmaxprice = $('.trading_pair_coin_newprice').val();
							var newbasevol = $('.trading_pair_coin_newvolume').val();
							var newrelvolume = newmaxprice * newbasevol;

							bot_update_data = {}
							bot_update_data.rel = data.rel;
							bot_update_data.base = data.base;
							bot_update_data.botid = data.botid;
							bot_update_data.newprice = newmaxprice;
							bot_update_data.newvolume = newrelvolume;

							//console.log(bot_update_data);

							bot_settings(bot_update_data);

						}
					}
				}
			});
			bot_update_bootbox.init(function(){
				console.log('bot_update_settings dialog opened.')
				$('.btn-bot_settings_update').attr("disabled", "disabled");
				$('.trading_pair_coin_newprice').inputNumber();
				$('.trading_pair_coin_newvolume').inputNumber();

				$('.trading_pair_coin_newprice').keyup(function() {

					var newmaxprice = $('.trading_pair_coin_newprice').val();
					var newbasevol = $('.trading_pair_coin_newvolume').val();
					var newrelvolume = newmaxprice * newbasevol;

					$('.new_relvol_basevol').html(newrelvolume.toFixed(8));

					var max_min_newprice = $('.trading_pair_coin_newprice')
					var max_newvolume = $('.trading_pair_coin_newvolume')

					var empty = false;
					if (max_min_newprice.val().length == 0 ) {
						console.log('new price is empty');
						empty = true;
					} else if (max_min_newprice.val().length !== 0 ) {
						console.log('NEW PRICE IS :' + max_min_newprice.val());
						empty = false;
					}
					console.log(empty);

					if (empty){
						$('.btn-bot_settings_update').attr("disabled", "disabled");
					} else {
						$('.btn-bot_settings_update').removeAttr("disabled");
					}

				});

				$('.trading_pair_coin_newvolume').keyup(function() {

					var newmaxprice = $('.trading_pair_coin_newprice').val();
					var newbasevol = $('.trading_pair_coin_newvolume').val();
					var newrelvolume = newmaxprice * newbasevol;

					$('.new_relvol_basevol').html(newrelvolume.toFixed(8));

					var max_min_newprice = $('.trading_pair_coin_newprice')
					var max_newvolume = $('.trading_pair_coin_newvolume')

					var empty = false;
					if (max_newvolume.val().length == 0 ) {
						console.log('new price is empty');
						empty = true;
					} else if (max_newvolume.val().length !== 0 ) {
						console.log('NEW PRICE IS :' + max_newvolume.val());
						empty = false;
					}
					console.log(empty);

					if (empty){
						$('.btn-bot_settings_update').attr("disabled", "disabled");
					} else {
						$('.btn-bot_settings_update').removeAttr("disabled");
					}

				});

			});

			//toastr.success('Bot ID: ' + bot_data.botid + ' ' + bot_data.action + ' presented.', 'Bot Info');
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});

	check_bot_list();
}

function bot_screen_sellcoin_balance(sig) {
	if (sig == false) {
		clearInterval(bot_screen_sellcoin_balance_Internal);
		return
	} else {
		console.log('checking bot screen coin balance');
	}

	coin = $('.trading_pair_coin').selectpicker('val');
	console.log(coin);

	var coin_name = return_coin_name(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"getcoin","coin": coin};
	var url = "http://1192.168.3.11:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
			get_coin_info('MNZ');
			bot_screen_sellcoin_balance();
		} else {
			if (!data.error === false && data.error === 'coin is disabled') {
				var button_controls = `

					<button class="btn btn-primary btn-xs coin_balance_enable_native" style="margin-top: 6px; margin-right: 3px;" data-electrum=true data-method="enable" data-coin="` + coin + `">Enable Native</button>
					<button class="btn btn-warning btn-xs coin_balance_enable_electrum" style="margin-top: 6px;" data-electrum=false data-method="enable" data-coin="` + coin + `">Enable Electrum</button>
				`;
				$('.trading_sellcoin_ticker_name').html(' '+ return_coin_name(coin) + ' ('+coin+')'+button_controls);
				$('.trading_sellcoin_balance').html('Coin is disabled');
			} else {
				var button_controls = `

					<button class="btn btn-danger btn-xs coin_balance_disable" style="margin-top: 6px;" data-electrum=true data-method="disable" data-coin="` + coin + `">Disable</button>
					<button class="btn btn-warning btn-xs coin_balance_receive" style="margin-top: 6px;" data-coin="` + coin + `">Receive</button>
					<button class="btn btn-success btn-xs coin_balance_send" style="margin-top: 6px;" data-coin="` + coin + `">Send</button>
					<button class="btn btn-info btn-xs coin_balance_inventory" style="margin-top: 6px;" data-coin="` + coin + `" data-addr="` + data.coin.smartaddress + `" data-balance="` + data.coin.balance + `">Inventory</button>
				`;
				$('.trading_sellcoin_ticker_name').html(' '+ return_coin_name(coin) + ' ('+coin+')'+button_controls);
				$('.trading_sellcoin_balance').html(data.coin.balance + ' ' + coin + '
' + data.coin.smartaddress + '');
			}
		}

	}).fail(function(jqXHR, textStatus, errorThrown) {
		// If fail
		console.log(textStatus + ': ' + errorThrown);
	});
}

function bot_screen_coin_balance(sig) {
	if (sig == false) {
		clearInterval(bot_screen_coin_balance_Internal);
		return
	} else {
		console.log('checking bot screen coin balance');
	}

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	console.log(coin);

	var coin_name = return_coin_name(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var ajax_data = {"userpass":userpass,"method":"getcoin","coin": coin};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
		data: JSON.stringify(ajax_data),
		dataType: 'json',
		type: 'POST',
		url: url
	}).done(function(data) {
		// If successful
		console.log(data);
		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
			bot_screen_coin_balance();
		} else {
			if (!data.error === false && data.error === 'coin is disabled') {
				var button_controls = `

					<button class="btn btn-primary btn-xs coin_balance_enable_native" style="margin-top: 6px; margin-right: 3px;" data-electrum=true data-method="enable" data-coin="` + coin + `">Enable Native</button>
					<button class="btn btn-warning btn-xs coin_balance_enable_electrum" style="margin-top: 6px;" data-electrum=false data-method="enable" data-coin="` + coin + `">Enable Electrum</button>
				`;
				$('.trading_coin_ticker_name').html(' '+ return_coin_name(coin) + ' ('+coin+')'+button_controls);
				$('.trading_coin_balance').html('Coin is disabled');
			} else {
				var button_controls = `

					<button class="btn btn-danger btn-xs coin_balance_disable" style="margin-top: 6px;" data-electrum=true data-method="disable" data-coin="` + coin + `">Disable</button>
					<button class="btn btn-warning btn-xs coin_balance_receive" style="margin-top: 6px;" data-coin="` + coin + `">Receive</button>
					<button class="btn btn-success btn-xs coin_balance_send" style="margin-top: 6px;" data-coin="` + coin + `">Send</button>
					<button class="btn btn-info btn-xs coin_balance_inventory" style="margin-top: 6px;" data-coin="` + coin + `" data-addr="` + data.coin.smartaddress + `" data-balance="` + data.coin.balance + `">Inventory</button>
				`;
				$('.trading_coin_ticker_name').html(' '+ return_coin_name(coin) + ' ('+coin+')'+button_controls);
				$('.trading_coin_balance').html(data.coin.balance + ' ' + coin + '
' + data.coin.smartaddress + '');
			}

			//$('.trading_coin_ticker_name').html(' '+ return_coin_name(coin) + ' ('+coin+')');
			//$('.trading_coin_balance').html(data.coin.balance + ' ' + coin + '
' + data.coin.smartaddress + '');
		}

	}).fail(function(jqXHR, textStatus, errorThrown) {
		// If fail
		console.log(textStatus + ': ' + errorThrown);
	});
}

/* Auto Trading Bot END */

/* Swap Status */

$('.btn-swapstatusrefresh').click(function() {
	check_swap_status();
})

$('.exchange_swap_status_tbl tbody').on('click', '.swapstatus_details', function() {
	console.log('swapstatus details button clicked')
	console.log($(this).data());

	check_swap_status_details($(this).data());
});

function check_swap_status_details(swap_data) {
	console.log(swap_data);

	var requestid = swap_data.requestid;
	var quoteid = swap_data.quoteid;
	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":userpass,"method":"swapstatus","requestid":requestid,"quoteid":quoteid};
	var url = "http://127.0.0.1:7783/";

	$.ajax({
		async: true,
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		//console.log(data);

		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		} else {
			result_answer = (data.result == 'success') ? '
 Success
' : '
 ' + data.result + '
';
			alice_answer = ' '+ return_coin_name(data.alice) + ' ('+data.alice+')';
			bob_answer = ' '+ return_coin_name(data.bob) + ' ('+data.bob+')';
			iambob_answer = (data.iambob == 0) ? 'Buyer' : 'Seller';

			bootbox.dialog({
				message: `

							Trade info
							Quote ID
							` + data.quoteid + `

							Request ID
							` + data.requestid + `

							Trade id
							` + data.tradeid + `

							Source Amount
							` + data.srcamount + `

							Result
							` + result_answer + `

							Buyer Info
							Buyer Coin
							` + alice_answer + `

							Buyer ID
							` + data.aliceid + `

							Buyer Payment
							` + data.alicepayment + `

							Buyer Tx Fee
							` + data.alicetxfee + `

							Seller Info
							Seller Coin
							` + bob_answer + `

							Seller Deposit
							` + data.bobdeposit + `

							Seller Payment
							` + data.bobpayment + `

							Seller Tx Fee
							` + data.bobtxfee + `

							Other Info
							You are
							` + iambob_answer + `

							Sent Flags
							` + JSON.stringify(data.sentflags, null, 2) + `

							Values
							` + JSON.stringify(data.values, null, 2) + `

							depositspent
							` + data.depositspent + `

							Apayment Spent
							` + data.Apaymentspent + `

`,
				closeButton: true,
				size: 'large'
			});
		}

	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

function check_swap_status(sig) {
	if (sig == false) {
		clearInterval(check_swap_status_Internal);
		return
	} else {
		console.log('checking swap status');
	}

	var selected_coin = JSON.parse(sessionStorage.getItem('mm_selectedcoin'));
	var coin = selected_coin.coin;
	//console.log(coin);

	var userpass = sessionStorage.getItem('mm_userpass');
	var mypubkey = sessionStorage.getItem('mm_mypubkey');
	var ajax_data = {"userpass":userpass,"method":"swapstatus"};
	var url = "http://127.0.0.1:7783";

	$.ajax({
		async: true,
	    data: JSON.stringify(ajax_data),
	    dataType: 'json',
	    type: 'POST',
	    url: url
	}).done(function(data) {
		// If successful
		//console.log(data);

		if (!data.userpass === false) {
			console.log('first marketmaker api call execution after marketmaker started.')
			sessionStorage.setItem('mm_usercoins', JSON.stringify(data.coins));
			sessionStorage.setItem('mm_userpass', data.userpass);
			sessionStorage.setItem('mm_mypubkey', data.mypubkey);
			get_coin_info('MNZ');
		} else {
			var reversed_swap_list = data.swaps.reverse();

			$('.exchange_swap_status_tbl tbody').empty();
			$.each(reversed_swap_list, function(index, val) {
				//console.log(index);
				//console.log(val);
				if(!val.error === false) {
					var exchange_swap_status_tr = '';
					exchange_swap_status_tr += '
';
					exchange_swap_status_tr += '
error
	';
					exchange_swap_status_tr += '-	';
					exchange_swap_status_tr += '-	';
					exchange_swap_status_tr += '-	';
					exchange_swap_status_tr += '
';
					$('.exchange_swap_status_tbl tbody').append(exchange_swap_status_tr);
				} else {
					var exchange_swap_status_tr = '';
					exchange_swap_status_tr += '
';
					exchange_swap_status_tr += '' + val.status + '	';
					exchange_swap_status_tr += '' + val.quoteid + '	';
					exchange_swap_status_tr += '' + val.requestid + '	';
					exchange_swap_status_tr += '<button class="btn btn-default swapstatus_details" data-quoteid="' + val.quoteid + '" data-requestid="' + val.requestid + '">Details</button>	';
					exchange_swap_status_tr += '
';
					$('.exchange_swap_status_tbl tbody').append(exchange_swap_status_tr);
				}
			})
		}
	}).fail(function(jqXHR, textStatus, errorThrown) {
	    // If fail
	    console.log(textStatus + ': ' + errorThrown);
	});
}

/* Swap Status END */<file_sep>/ReadMe.md
# dICO App

Before starting make sure you have `marketmaker` daemon compiled and running on your machine.

You can find instructions to install `marketmaker` here:

https://github.com/SuperNETorg/komodo/wiki/Setting-up-Liquidity-Provider-(LP)-Node#installing-liquidity-provider-lp-node-on-ubuntudebian-system

### Setup
Once running, follow these steps:
```shell
git clone https://github.com/SuperNETorg/dICOApp.git
cd dICOApp
npm install
npm start
```

It will download "dICOApp". Open "dICOApp", and from there open "index.html" file in your web browser.

### Update
To update, follow these steps:
```shell
cd dICOApp
git pull
```

#### For end users

To build the production ready app, install `electron-packager` and `electron-prebuilt` packages from npm
```shell
sudo npm install electron-packager -g
sudo npm install electron-prebuilt -g
```

#### **Build the App**
Refer to the original [electron-packager](https://github.com/electron-userland/electron-packager) repository for more detailed information.

##### Linux
Change directory to dICOApp and execute the following command to build the Linux app
```shell
cd dICOApp
electron-packager . --platform=linux --arch=x64 --out=build/ --buildVersion=VERSION_NUMBER_HERE --ignore=assets/bin/win64 --ignore=assets/bin/osx --overwrite
```
change architecture build parameter to ```--arch=x32``` for 32 bit build

##### OSX
Change directory to dICOApp and execute the following command to build the OSX app
```shell
cd dICOApp
electron-packager . --platform=darwin --arch=x64 --out=build/ --buildVersion=VERSION_NUMBER_HERE --ignore=assets/bin/win64 --ignore=assets/bin/linux64 --overwrite
```

##### Windows
Change directory to iguana and execute the following command to build the Windows app
```shell
dir iguana
electron-packager . --platform=win32 --arch=x64 --icon=assets/icons/agama_icons/agama_app_icon.ico --out=build/ --buildVersion=VERSION_NUMBER_HERE --ignore=assets/bin/osx --ignore=assets/bin/linux64 --overwrite

# If generating 32bit desktop package
electron-packager . --platform=win32 --arch=ia32 --icon=assets/icons/agama_icons/agama_app_icon.ico --out=build/ --buildVersion=VERSION_NUMBER_HERE --ignore=assets/bin/osx --ignore=assets/bin/linux64 --overwrite

# To build both x64 and x86 desktop package
electron-packager . --platform=win32 --arch=all --icon=assets/icons/agama_icons/agama_app_icon.ico --out=build/ --buildVersion=VERSION_NUMBER_HERE --ignore=assets/bin/osx --ignore=assets/bin/linux64 --overwrite
```
change architecture build parameter to ```--arch=x64``` for 64 bit build

languages: Markdown JavaScript