diff --git a/assets/scripts/dashboard.js b/assets/scripts/dashboard.js index 7fbfbff..05f1a9b 100644 --- a/assets/scripts/dashboard.js +++ b/assets/scripts/dashboard.js @@ -30,7 +30,131 @@ var Dashboard = function() { var handle_edex_send = function() { $('#btn_edexcoin_wallet_send').click(function() { + var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin"); + //console.log(active_edexcoin); + + + $('#edexcoin_dashboardinfo').hide(); $('#edexcoin_send').show(); + $('#edexcoin_recieve_section').hide(); + $('#edexcoin_settings').hide(); + + //Disabled dropdown list address in EasyDEX's main send option, as it's using sendtoaddress at the moment. + //This option can be enabled later for other section where user can select particular address to send funds from. + /*var edexcoin_addr_list_with_balance = EDEXlistunspent(active_edexcoin); + console.log(edexcoin_addr_list_with_balance); + var tmpoptions = ''; + tmpoptions += ''; + $.each(edexcoin_addr_list_with_balance, function(index) { + tmpoptions += ''; + $('#edexcoin_send_from').html(tmpoptions); + }); + + $('.showedexcoinaddrs').selectpicker({ style: 'btn-info' }); + $('.showedexcoinaddrs').selectpicker('refresh');*/ + clearEdexSendFieldData(); + + }); + + $('.showedexcoinaddrs').on('change', function(){ + var selected = $(this).find("option:selected").val(); + //console.log(selected); + //console.log($(this).find("option:selected").data('total')); + }); + + $('#edexcoin_amount').keyup(function() { + var sum_val1 = parseFloat($('#edexcoin_amount').val()) + var sum_val2 = parseFloat($('#edexcoin_fee').val()) + var total_minus_currency_fee = sum_val1 - sum_val2; + var mdl_send_btn = $('#edexcoin_send_coins_btn'); + + //console.log($('#edexcoin_amount').val()); + $('#edexcoin_total_value').text(total_minus_currency_fee.toFixed(8)); + + if ($('#edexcoin_send_from').val() != '- Select Transparent or Private KMD Address -' && $('#edexcoin_amount').val() != '' && $('#edexcoin_sendto') != '' && $('#edexcoin_fee') != '' ) { + mdl_send_btn.removeClass('disabled'); + //mdl_send_btn.attr('data-dismiss','modal'); + //mdl_send_btn.attr('data-target','#SendCoinModelStep2'); + } else { + mdl_send_btn.addClass('disabled'); + mdl_send_btn.removeAttr('data-dismiss'); + mdl_send_btn.removeAttr('data-target'); + } + }); + + $('#edexcoin_fee').keyup(function() { + var sum_val1 = parseFloat($('#edexcoin_amount').val()) + var sum_val2 = parseFloat($('#edexcoin_fee').val()) + var total_minus_currency_fee = sum_val1 - sum_val2; + var mdl_send_btn = $('#edexcoin_send_coins_btn'); + + //console.log($('#edexcoin_amount').val()); + $('#edexcoin_total_value').text(total_minus_currency_fee.toFixed(8)); + + if ($('#edexcoin_send_from').val() != '- Select Transparent or Private KMD Address -' && $('#edexcoin_amount').val() != '' && $('#edexcoin_sendto') != '' && $('#edexcoin_fee') != '' ) { + mdl_send_btn.removeClass('disabled'); + //mdl_send_btn.attr('data-dismiss','modal'); + //mdl_send_btn.attr('data-target','#SendCoinModelStep2'); + } else { + mdl_send_btn.addClass('disabled'); + mdl_send_btn.removeAttr('data-dismiss'); + mdl_send_btn.removeAttr('data-target'); + } + }); + + $('.edexcoin-send-form').validate({ + //errorElement: 'span', //default input error message container + //errorClass: 'help-block', // default input error message class + //focusInvalid: false, // do not focus the last invalid input + rules: { + edexcoin_send_from: { + required: true + }, + edexcoin_sendto: { + required: true + }, + edexcoin_amount: { + required: true + }, + edexcoin_fee: { + required: true + }, + edexcoin_total_value: { + required: true + } + }, + + messages: { + edexcoin_send_from: { + required: "From Address is required." + }, + edexcoin_sendto: { + required: "To Address is required." + }, + edexcoin_amount: { + required: "Please enter amount to send." + }, + edexcoin_fee: { + required: "Make sure you have fee entered. Default value is 0.0001." + }, + edexcoin_total_value: { + required: "Make sure you have both amount and fee entered to calculate final total." + } + }, + + submitHandler: function(form) { + console.log('Sent control here after clicked in form...'); + + var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin"); + var tmp_send_from_addr = $('#edexcoin_send_from').val(); + var tmp_send_to_addr = $('#edexcoin_sendto').val(); + var tmp_send_total_amount = $('#edexcoin_total_value').text(); + var tmp_json_data = {'coin':active_edexcoin,'sendtoaddr':tmp_send_to_addr,'amount':tmp_send_total_amount}; + //console.log(tmp_json_data); + var tmp_sendtoaddr_output = EDEXSendToAddr(tmp_json_data); + console.log(tmp_sendtoaddr_output); + //clearSendManyFieldData(); + } }); } @@ -290,7 +414,7 @@ var Dashboard = function() { var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin"); ShowCoinProgressBar(active_edexcoin); if ( sessionStorage.getItem('Activate'+active_edexcoin+'History') === 'Yes' ) { - console.log('Show coin history'); + //console.log('Show coin history'); var historyvalues = {"timeout":20000,"immediate":100,"agent":"basilisk","method":"history","vals":{"coin":"" + active_edexcoin + ""}}; //ShowCoinHistory(historyvalues); //} @@ -328,8 +452,8 @@ var Dashboard = function() { RunTotalFiatValue = setInterval(function() { if ( sessionStorage.getItem('IguanaActiveAccount') === null ) { - console.log('=> No wallet logged in. No need to get Rates.'); - StopTotalFiatValue(); + //console.log('=> No wallet logged in. No need to get Rates.'); + //StopTotalFiatValue(); } else { //TotalFiatValue(); //console.log('Get Rates (every 60 seconds)'); @@ -359,10 +483,21 @@ function resizeDashboardWindow() { function edexCoinBtnAction() { $('.edexcoin-logo').click(function() { console.log($(this).data('edexcoincode')); + + //get selected coin's code and populate in easydex wallet widget's html elements var coincode = $(this).data('edexcoincode'); $.each($('[data-edexcoin]'), function(index, value) {$('[data-edexcoin]').attr("data-edexcoin",coincode); $('[data-edexcoin="'+coincode+'"]')}); $.each($('[data-edexcoinmenu]'), function(index, value) {$('[data-edexcoinmenu]').attr("data-edexcoinmenu",coincode); $('[data-edexcoinmenu="'+coincode+'"]')}); + $('#edexcoin-active').text(coincode); + //populate selected coin's address + var coinmainaddr = EDEXMainAddr(coincode); + $('#edexcoin_active_addr').text(coinmainaddr[0]); + + //populate selected coin's balance + var coinwalletbalance = EDEXgetBalance(coincode); + $('#edex_total_balance').text(coinwalletbalance[0]); + }); } @@ -526,6 +661,7 @@ function getCoinBalance(coin) { var ajax_data = {"agent":"bitcoinrpc","method":"getbalance","coin": coin}; //console.log(ajax_data); $.ajax({ + async: false, type: 'POST', data: JSON.stringify(ajax_data), url: 'http://127.0.0.1:7778', diff --git a/assets/scripts/iguana_api.js b/assets/scripts/iguana_api.js index 902732d..6c36546 100644 --- a/assets/scripts/iguana_api.js +++ b/assets/scripts/iguana_api.js @@ -412,4 +412,173 @@ function Iguana_HashHex(data) { } }); return result; +} + + +function EDEXlistunspent(coin) { + NProgress.done(true); + NProgress.configure({ + template: '
' + }); + NProgress.start(); + var result = []; + + var ajax_data = {"coin":coin,"method":"listunspent","params":[]} + //console.log(ajax_data); + $.ajax({ + async: false, + type: 'POST', + data: JSON.stringify(ajax_data), + url: 'http://127.0.0.1:7778', + //dataType: 'text', + success: function(data, textStatus, jqXHR) { + var AjaxOutputData = JSON.parse(data); //Ajax output gets the whole list of unspent coin with addresses + //console.log('== Data OutPut =='); + //console.log(AjaxOutputData); + var unique_addresses = _.keys(_.countBy(AjaxOutputData, function(data) { return data.address; })); //This code using undscore.js takes only the address into an array which are unique in that list + + // This function calls each unique address and calculates the total amount of coins in it. + $.each(unique_addresses, function(index) { + console.log(unique_addresses[index]); + var unique_addr_tmp_array = _.where(AjaxOutputData, {address: unique_addresses[index]}); + //console.log(unique_addr_tmp_array); + + var tmpcalcnum = 0; + $.each(unique_addr_tmp_array, function(index, value) { + //console.log(value.amount); + tmpcalcnum = tmpcalcnum + value.amount; + }); + //console.log(tmpcalcnum); + var tmp_addr_total_balance_output = {"addr": unique_addr_tmp_array[0].address, "total": tmpcalcnum}; + //console.log(tmp_addr_total_balance_output); + result.push(tmp_addr_total_balance_output); + + }); + }, + error: function(xhr, textStatus, error) { + console.log('failed getting Coin History.'); + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } + console.log(textStatus); + console.log(error); + } + }); + //console.log(result); + NProgress.done(); + return result; +} + +function clearEdexSendFieldData() { + $('.showedexcoinaddrs').selectpicker('refresh'); + $('#edexcoin_sendto').val(''); + $('#edexcoin_total_value').text(''); + $('#edexcoin_amount').val(''); +} + +function EDEXMainAddr(coin) { + NProgress.done(true); + NProgress.configure({ + template: '
' + }); + NProgress.start(); + var result = []; + + var ajax_data = {"agent":"SuperNET","method":"activehandle"} + //console.log(ajax_data); + $.ajax({ + async: false, + type: 'POST', + data: JSON.stringify(ajax_data), + url: 'http://127.0.0.1:7778', + //dataType: 'text', + success: function(data, textStatus, jqXHR) { + var AjaxOutputData = JSON.parse(data); //Ajax output gets the whole list of unspent coin with addresses + //console.log('== Data OutPut =='); + //console.log(AjaxOutputData[coin]); + result.push(AjaxOutputData[coin]); + }, + error: function(xhr, textStatus, error) { + console.log('failed getting Coin History.'); + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } + console.log(textStatus); + console.log(error); + } + }); + //console.log(result); + NProgress.done(); + return result; +} + + +function EDEXgetBalance(coin) { + var result = []; + //console.log(rmd160conv_data); + //return rmd160conv_data; + + //comment + var ajax_data = {"agent":"bitcoinrpc","method":"getbalance","coin": coin}; + //console.log(ajax_data); + $.ajax({ + async: false, + type: 'POST', + data: JSON.stringify(ajax_data), + url: 'http://127.0.0.1:7778', + //dataType: 'text', + success: function(data, textStatus, jqXHR) { + var AjaxOutputData = JSON.parse(data); + //console.log('== Data OutPut getbalance =='); + //console.log(AjaxOutputData.result); + result.push(AjaxOutputData['result']); + }, + error: function(xhr, textStatus, error) { + console.log('failed getting Coin History.'); + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } + console.log(textStatus); + console.log(error); + } + }); + return result; +} + + +function EDEXSendToAddr(data) { + var result = []; + var confirm_coinname_to_send = data.coin; + var confirm_send_amount = data.amount; + var confirm_sendto_address = data.sendtoaddr; + + //Get parameters values from confirm dialog and send currency + var sendtoaddrvalues = {"coin": confirm_coinname_to_send,"method":"sendtoaddress","params":[confirm_sendto_address,confirm_send_amount,"EasyDEX","EasyDEXTransaction"]}; + console.log(sendtoaddrvalues); + $.ajax({ + async: false, + type: 'POST', + data: JSON.stringify(sendtoaddrvalues), + url: 'http://127.0.0.1:7778', + //dataType: 'text', + success: function(data, textStatus, jqXHR) { + var SendToAddrData = JSON.parse(data); + console.log('== Data OutPut =='); + //console.log(SendToAddrData); + result.push(SendToAddrData); + }, + error: function(xhr, textStatus, error) { + console.log('failed getting Coin History.'); + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } + console.log(textStatus); + console.log(error); + } + }); + return result; } \ No newline at end of file diff --git a/index.html b/index.html index 27e72a7..5cfd5fe 100755 --- a/index.html +++ b/index.html @@ -465,9 +465,7 @@