diff --git a/assets/scripts/dashboard.js b/assets/scripts/dashboard.js index 82ea2f7..007d42e 100644 --- a/assets/scripts/dashboard.js +++ b/assets/scripts/dashboard.js @@ -36,7 +36,6 @@ var Dashboard = function() { $('#btn_edexcoin_dashboard').hide(); $('#btn_edexcoin_send').show(); $('#btn_edexcoin_recieve').show(); - var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'); if ( sessionStorage.getItem('edexTmpMode') === 'Full') { sessionStorage.setItem('edexTmpRefresh', 'start'); @@ -53,7 +52,7 @@ var Dashboard = function() { var selected_coinmode = sessionStorage.getItem('edexTmpMode'); if ( selected_coinmode == 'Basilisk' ) { - getDEXGetBalance(active_edexcoin).then(function(result){ + getDEXGetBalance_cache(active_edexcoin).then(function(result) { console.log(result) if ( result.interest !== undefined ) { $('#edexcoin_getbalance_interest').show(); @@ -77,36 +76,36 @@ var Dashboard = function() { $('#edex_total_balance_coincode').text(active_edexcoin); }); } else { - EDEXlistunspent(active_edexcoin).then(function(result){ + EDEXlistunspent(active_edexcoin).then(function(result) { //console.log(result) if (result[0] != undefined) { //console.log(result[0]) if ( result[0].interest !== undefined ) { - $('#edexcoin_getbalance_interest').show() - $('#edexcoin_getbalance_total_interest').show() + $('#edexcoin_getbalance_interest').show(); + $('#edexcoin_getbalance_total_interest').show(); $('#edexcoin_getbalance_t').removeClass( 'col-lg-12' ).addClass( 'col-lg-4' ); - $('#edex_interest_balance').text(result[0].interest) - $('#edex_total_balance_interest').text(result[0].totalbalance) + $('#edex_interest_balance').text(result[0].interest); + $('#edex_total_balance_interest').text(result[0].totalbalance); $('#edex_total_interest_coincode').text(active_edexcoin); $('#edex_total_balance_interest_coincode').text(active_edexcoin); } if ( result[0].interest === undefined ) { - $('#edexcoin_getbalance_interest').hide() - $('#edexcoin_getbalance_total_interest').hide() + $('#edexcoin_getbalance_interest').hide(); + $('#edexcoin_getbalance_total_interest').hide(); $('#edexcoin_getbalance_t').removeClass( 'col-lg-4' ).addClass( 'col-lg-12' ); - $('#edex_interest_balance').text('-') - $('#edex_total_balance_interest').text('-') + $('#edex_interest_balance').text('-'); + $('#edex_total_balance_interest').text('-'); } $('#edex_total_balance').text(result[0].total); $('#edex_total_balance_coincode').text(active_edexcoin); - } else { $('#edex_total_balance').text('0'); } }); } + EdexfillTxHistory(active_edexcoin); $('.edexcoin-send-form')[0].reset(); }); @@ -118,8 +117,6 @@ var Dashboard = function() { $('#btn_edexcoin_send').hide(); $('#btn_edexcoin_recieve').show(); sessionStorage.setItem('edexTmpRefresh', 'stop'); - - $('#edexcoin_dashboardinfo').hide(); $('#edexcoin_send').show(); $('#edexcoin_recieve').hide(); @@ -141,16 +138,16 @@ var Dashboard = function() { $('.showedexcoinaddrs').selectpicker('refresh');*/ //clearEdexSendFieldData(); $('.edexcoin-send-form')[0].reset(); - var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'), - selected_coinmode = sessionStorage.getItem('edexTmpMode'); + var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'); + var selected_coinmode = sessionStorage.getItem('edexTmpMode') if ( selected_coinmode == 'Full' ) { - EDEXgetinfo(active_edexcoin).then(function(result){ + EDEXgetinfo(active_edexcoin).then(function(result) { $('#edexcoin_fee').val(result.kbfee); }); } }); - $('.showedexcoinaddrs').on('change', function(){ + $('.showedexcoinaddrs').on('change', function() { var selected = $(this).find('option:selected').val(); }); @@ -162,11 +159,13 @@ var Dashboard = function() { $('#edexcoin_total_value').text(total_minus_currency_fee.toFixed(8)); - if ( $('#edexcoin_send_from').val() != '- Select Transparent or Private KMD Address -' && + 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'); @@ -180,6 +179,7 @@ var Dashboard = function() { total_minus_currency_fee = sum_val1 - sum_val2, 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 -' && @@ -187,6 +187,8 @@ var Dashboard = function() { $('#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'); @@ -237,15 +239,15 @@ var Dashboard = function() { submitHandler: function(form) { NProgress.done(true); NProgress.configure({ - template: '
' + - '
' + - '
' + - '
' + template: '
' + + '
' + + '
' + + '
' }); NProgress.start(); console.log('Sent control here after clicked in form...'); - EDEXMainAddr($('[data-edexcoin]').attr('data-edexcoin')).then(function(result){ + EDEXMainAddr($('[data-edexcoin]').attr("data-edexcoin")).then(function(result) { $('#mdl_confirm_currency_sendfrom_addr').text(result); }); $('#mdl_confirm_currency_sendto_addr').text($('#edexcoin_sendto').val()); @@ -264,7 +266,6 @@ var Dashboard = function() { var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'), tmp_send_to_addr = $('#edexcoin_sendto').val(), tmp_send_total_amount = $('#edexcoin_total_value').text(); - $('#edexcoin-send-screen').hide(); $('#edexcoin-send-confirm-screen').show(); $('#edexcoin_send_step_1').removeClass( 'current' ).addClass( '' ); @@ -281,9 +282,9 @@ var Dashboard = function() { var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'), tmp_send_to_addr = $('#edexcoin_sendto').val(), tmp_send_total_amount = $('#edexcoin_total_value').text(); - console.log(active_edexcoin) - console.log(tmp_send_to_addr) - console.log(tmp_send_total_amount) + console.log(active_edexcoin); + console.log(tmp_send_to_addr); + console.log(tmp_send_total_amount); var edexcoin_sendto_result_tbl = ''; edexcoin_sendto_result_tbl += '' + @@ -314,14 +315,15 @@ var Dashboard = function() { $('#edexcoin-send-confirm-screen').hide(); $('#edexcoin-send-txdetails-screen').hide(); $('#edexcoin-send-screen').show(); - var active_edexcoin = '', - tmp_send_to_addr = '', - tmp_send_total_amount = ''; + var active_edexcoin = ''; + var tmp_send_to_addr = ''; + var tmp_send_total_amount = ''; edexcoin_send_form_validator.resetForm(); $('#edexcoin_send_step_1').removeClass( '' ).addClass( 'current' ); $('#edexcoin_send_step_2').removeClass( 'current' ).addClass( '' ); $('#edexcoin_send_step_3').removeClass( 'current' ).addClass( '' ); }); + $('#edexcoin_send_coins_anothertx_btn').click(function() { $( '#edexcoin_send_coins_back_btn' ).trigger( 'click' ); var active_edexcoin = '', @@ -331,7 +333,7 @@ var Dashboard = function() { edexcoin_send_form_validator.resetForm(); }); - $('.edexcoin_sendto_result').on('click', '.edexcoin_sendto_output_result', function(e){ + $('.edexcoin_sendto_result').on('click', '.edexcoin_sendto_output_result', function(e) { var selected_coin = $(this).data('edexcoin'), selected_coin_mode = sessionStorage.getItem('edexTmpMode'); $( '#nav-iguana-atomic-explorer' ).trigger( 'click' ); @@ -342,7 +344,7 @@ var Dashboard = function() { if ( selected_coin_mode == 'Basilisk') { $('#atomic_explorer_select_command_options option[value=dex_gettransaction]').attr('selected', 'selected'); } - $('#atomic_explorer_input_data').val($(this).data('sendtotxresult')) + $('#atomic_explorer_input_data').val($(this).data('sendtotxresult')); $( '#atomic_explorer_getcoinpeers_btn' ).trigger( 'click' ); }); } @@ -375,6 +377,7 @@ var Dashboard = function() { var handleWalletWidgets = function() { var walletDivContent = '', AddColumnDiv = 0; + $.each([ 'native', 'basilisk', @@ -393,7 +396,6 @@ var Dashboard = function() { url: 'http://127.0.0.1:7778', success: function(data, textStatus, jqXHR) { var AllcoinsDataOutput = JSON.parse(data); - $.each(AllcoinsDataOutput[value], function(index) { var coinlogo = '', coinname = '', @@ -401,120 +403,120 @@ var Dashboard = function() { modetip = '', modecolor = ''; - switch (value) { - case 'native': - modecode = 'Native'; - modetip = 'Native'; - modecolor = 'primary'; - break; - case 'basilisk': - modecode = 'Basilisk'; - modetip = 'Basilisk'; - modecolor = 'info'; - break; - case 'full': - modecode = 'Full'; - modetip = 'Full'; - modecolor = 'success'; - break; - case 'virtual': - modecode = 'Virtual'; - modetip = 'Virtual'; - modecolor = 'danger'; - break; - case 'notarychains': - modecode = 'Notarychains'; - modetip = 'Notarychains'; - modecolor = 'dark'; - break; - } - - switch (AllcoinsDataOutput[value][index]) { - case 'BTC': - coinlogo = 'bitcoin'; - coinname = 'Bitcoin'; - break; - case 'BTCD': - coinlogo = 'bitcoindark'; - coinname = 'BitcoinDark'; - break; - case 'LTC': - coinlogo = 'litecoin'; - coinname = 'Litecoin'; - break; - case 'VPN': - coinlogo = 'vpncoin'; - coinname = 'VPNcoin'; - break; - case 'SYS': - coinlogo = 'syscoin'; - coinname = 'Syscoin'; - break; - case 'ZEC': - coinlogo = 'zcash'; - coinname = 'Zcash'; - break; - case 'NMC': - coinlogo = 'namecoin'; - coinname = 'Namecoin'; - break; - case 'DEX': - coinlogo = 'dex'; - coinname = 'DEX'; - break; - case 'DOGE': - coinlogo = 'dogecoin'; - coinname = 'Dogecoin'; - break; - case 'DGB': - coinlogo = 'digibyte'; - coinname = 'Digibyte'; - break; - case 'MZC': - coinlogo = 'mazacoin'; - coinname = 'Mazacoin'; - break; - case 'UNO': - coinlogo = 'unobtanium'; - coinname = 'Unobtanium'; - break; - case 'ZET': - coinlogo = 'zetacoin'; - coinname = 'Zetacoin'; - break; - case 'KMD': - coinlogo = 'komodo'; - coinname = 'Komodo'; - break; - case 'BTM': - coinlogo = 'bitmark'; - coinname = 'Bitmark'; - break; - case 'CARB': - coinlogo = 'carboncoin'; - coinname = 'Carboncoin'; - break; - case 'ANC': - coinlogo = 'anoncoin'; - coinname = 'AnonCoin'; - break; - case 'FRK': - coinlogo = 'franko'; - coinname = 'Franko'; - break; - case 'SUPERNET': - coinlogo = 'SUPERNET'; - coinname = 'SUPERNET'; - break; - case 'REVS': - coinlogo = 'REVS'; - coinname = 'REVS'; - break; - case 'USD': - coinlogo = 'USD'; - coinname = 'USD'; - break; - } + switch (value) { + case 'native': + modecode = 'Native'; + modetip = 'Native'; + modecolor = 'primary'; + break; + case 'basilisk': + modecode = 'Basilisk'; + modetip = 'Basilisk'; + modecolor = 'info'; + break; + case 'full': + modecode = 'Full'; + modetip = 'Full'; + modecolor = 'success'; + break; + case 'virtual': + modecode = 'Virtual'; + modetip = 'Virtual'; + modecolor = 'danger'; + break; + case 'notarychains': + modecode = 'Notarychains'; + modetip = 'Notarychains'; + modecolor = 'dark'; + break; + } + + switch (AllcoinsDataOutput[value][index]) { + case 'BTC': + coinlogo = 'bitcoin'; + coinname = 'Bitcoin'; + break; + case 'BTCD': + coinlogo = 'bitcoindark'; + coinname = 'BitcoinDark'; + break; + case 'LTC': + coinlogo = 'litecoin'; + coinname = 'Litecoin'; + break; + case 'VPN': + coinlogo = 'vpncoin'; + coinname = 'VPNcoin'; + break; + case 'SYS': + coinlogo = 'syscoin'; + coinname = 'Syscoin'; + break; + case 'ZEC': + coinlogo = 'zcash'; + coinname = 'Zcash'; + break; + case 'NMC': + coinlogo = 'namecoin'; + coinname = 'Namecoin'; + break; + case 'DEX': + coinlogo = 'dex'; + coinname = 'DEX'; + break; + case 'DOGE': + coinlogo = 'dogecoin'; + coinname = 'Dogecoin'; + break; + case 'DGB': + coinlogo = 'digibyte'; + coinname = 'Digibyte'; + break; + case 'MZC': + coinlogo = 'mazacoin'; + coinname = 'Mazacoin'; + break; + case 'UNO': + coinlogo = 'unobtanium'; + coinname = 'Unobtanium'; + break; + case 'ZET': + coinlogo = 'zetacoin'; + coinname = 'Zetacoin'; + break; + case 'KMD': + coinlogo = 'komodo'; + coinname = 'Komodo'; + break; + case 'BTM': + coinlogo = 'bitmark'; + coinname = 'Bitmark'; + break; + case 'CARB': + coinlogo = 'carboncoin'; + coinname = 'Carboncoin'; + break; + case 'ANC': + coinlogo = 'anoncoin'; + coinname = 'AnonCoin'; + break; + case 'FRK': + coinlogo = 'franko'; + coinname = 'Franko'; + break; + case 'SUPERNET': + coinlogo = 'SUPERNET'; + coinname = 'SUPERNET'; + break; + case 'REVS': + coinlogo = 'REVS'; + coinname = 'REVS'; + break; + case 'USD': + coinlogo = 'USD'; + coinname = 'USD'; + break; + } walletDivContent += ''; walletDivContent += '
'; @@ -545,263 +547,244 @@ var Dashboard = function() { console.log(textStatus); console.log(error); if (xhr.readyState == '0' ) { - toastr.error('Unable to connect to Iguana', "Account Notification") + toastr.error('Unable to connect to Iguana', 'Account Notification'); } } }); }); } - var handleWalletWidgetBtns = function() { - $('#addcoin_mdl_native_mode').prop('disabled', true); - $('#addcoin_mdl_basilisk_mode').prop('disabled', true); - $('#addcoin_mdl_full_mode').prop('disabled', true); - $('#addcoin_mdl_full_mode').prop("checked", false); + var handleWalletWidgetBtns = function() { + $('#addcoin_mdl_native_mode').prop('disabled', true); + $('#addcoin_mdl_basilisk_mode').prop('disabled', true); + $('#addcoin_mdl_full_mode').prop('disabled', true); + $('#addcoin_mdl_full_mode').prop('checked', false); - $('.mdl_addcoin_done_btn').click(function(){ - ExecuteAddCoinFn(); - }); + $('.mdl_addcoin_done_btn').click(function(){ + ExecuteAddCoinFn(); + }); - $( "#addcoin_select_coin_mdl_options" ).change(function() { - var tmp_coin_val = $('#addcoin_select_coin_mdl_options').val() + $( "#addcoin_select_coin_mdl_options" ).change(function() { + var tmp_coin_val = $('#addcoin_select_coin_mdl_options').val(); - if (tmp_coin_val !== 'KMD' || tmp_coin_val !== 'KMD' ) { - $('#addcoin_mdl_native_mode').prop('disabled', true); - $('#addcoin_mdl_basilisk_mode').prop('disabled', true); - $('#addcoin_mdl_full_mode').prop('disabled', false); - $('#addcoin_mdl_full_mode').prop("checked", true); - } - if (tmp_coin_val == 'KMD') { - $('#addcoin_mdl_native_mode').prop('disabled', false); - $('#addcoin_mdl_basilisk_mode').prop('disabled', false); - $('#addcoin_mdl_full_mode').prop('disabled', false); - $('#addcoin_mdl_basilisk_mode').prop("checked", true); - } - if (tmp_coin_val == 'SUPERNET' - || tmp_coin_val == 'REVS' - || tmp_coin_val == 'USD') { - $('#addcoin_mdl_native_mode').prop('disabled', true); - $('#addcoin_mdl_basilisk_mode').prop('disabled', false); - $('#addcoin_mdl_full_mode').prop('disabled', true); - $('#addcoin_mdl_basilisk_mode').prop("checked", true); - } - if (tmp_coin_val == 'BTC') { - $('#addcoin_mdl_basilisk_mode').prop('disabled', false); - $('#addcoin_mdl_native_mode').prop('disabled', true); - $('#addcoin_mdl_full_mode').prop('disabled', false); - $('#addcoin_mdl_basilisk_mode').prop("checked", true); - } - }); - } + if (tmp_coin_val !== 'KMD' || tmp_coin_val !== 'KMD' ) { + $('#addcoin_mdl_native_mode').prop('disabled', true); + $('#addcoin_mdl_basilisk_mode').prop('disabled', true); + $('#addcoin_mdl_full_mode').prop('disabled', false); + $('#addcoin_mdl_full_mode').prop('checked', true); + } + if (tmp_coin_val == 'KMD') { + $('#addcoin_mdl_native_mode').prop('disabled', false); + $('#addcoin_mdl_basilisk_mode').prop('disabled', false); + $('#addcoin_mdl_full_mode').prop('disabled', false); + $('#addcoin_mdl_basilisk_mode').prop('checked', true); + } + if (tmp_coin_val == 'SUPERNET' || + tmp_coin_val == 'REVS' || + tmp_coin_val == 'USD') { + $('#addcoin_mdl_native_mode').prop('disabled', true); + $('#addcoin_mdl_basilisk_mode').prop('disabled', false); + $('#addcoin_mdl_full_mode').prop('disabled', true); + $('#addcoin_mdl_basilisk_mode').prop('checked', true); + } + if (tmp_coin_val == 'BTC') { + $('#addcoin_mdl_basilisk_mode').prop('disabled', false); + $('#addcoin_mdl_native_mode').prop('disabled', true); + $('#addcoin_mdl_full_mode').prop('disabled', false); + $('#addcoin_mdl_basilisk_mode').prop('checked', true); + } + }); + } - var handleBasiliskWalletActions = function() { - $(".btn_edexcoin_dashboard_getnotaries").click(function() { - var selected_coin = $(this).data('edexcoin') - $( "#nav-iguana-atomic-explorer" ).trigger( "click" ); - $('#atomic_explorer_select_coin_options option[value=' + selected_coin + ']').attr('selected','selected'); - $('#atomic_explorer_select_command_options option[value=dex_getnotaries]').attr('selected','selected'); - $( "#atomic_explorer_getcoinpeers_btn" ).trigger( "click" ); - }) + var handleBasiliskWalletActions = function() { + $('.btn_edexcoin_dashboard_getnotaries').click(function() { + var selected_coin = $(this).data('edexcoin'); + $( '#nav-iguana-atomic-explorer' ).trigger( 'click' ); + $('#atomic_explorer_select_coin_options option[value=' + selected_coin + ']').attr('selected', 'selected'); + $('#atomic_explorer_select_command_options option[value=dex_getnotaries]').attr('selected', 'selected'); + $( '#atomic_explorer_getcoinpeers_btn' ).trigger( 'click' ); + }); - $(".btn_edexcoin_dashboard_register").click(function() { - var selected_coin = $(this).data('edexcoin') - EDEXMainAddr(selected_coin).then(function(result){ - //console.log(result) - Iguana_DEXImportAllWalletAddr(selected_coin); - //Iguana_DEXImportAddr(selected_coin,result); - }) - }) + $('.btn_edexcoin_dashboard_register').click(function() { + var selected_coin = $(this).data('edexcoin'); + EDEXMainAddr(selected_coin).then(function(result){ + Iguana_DEXImportAllWalletAddr(selected_coin); + }); + }); - $(".btn_edexcoin_dashboard_refresh_basilisk_conn").click(function() { - var show_mdl = setTimeout(function() { - var selected_coin = $(this).data('edexcoin') - $('#RefreshBasiliskConnectionsMdl').modal('show') - }, 0) - var start_refresh = setTimeout(function() { - EDEX_DEXgetinfoAll() - }, 3000) - - Promise.all([show_mdl, start_refresh]).then(function() { - console.log('all promises executed!!!'); - }); - }) + $('.btn_edexcoin_dashboard_refresh_basilisk_conn').click(function() { + var show_mdl = setTimeout(function() { + var selected_coin = $(this).data('edexcoin'); + $('#RefreshBasiliskConnectionsMdl').modal('show'); + }, 0) + var start_refresh = setTimeout(function() { + EDEX_DEXgetinfoAll(); + }, 3000) + + Promise.all([show_mdl, start_refresh]).then(function() { + console.log('all promises executed!!!'); + }); + }); - $(".btn_edexcoin_dashboard_validate").click(function() { - var selected_coin = $(this).data('edexcoin') - EDEXMainAddr(selected_coin).then(function(result){ - //console.log(result) - Iguana_DEXValidateAddr(selected_coin,result); - }) - }) - } + $(".btn_edexcoin_dashboard_validate").click(function() { + var selected_coin = $(this).data('edexcoin'); + EDEXMainAddr(selected_coin).then(function(result) { + Iguana_DEXValidateAddr(selected_coin,result); + }); + }); + } + + var handleWalletToAtomicExplorer = function() { + $('#edex-tx-history-tbl').on('click', '.kmd-txid-details-btn', function(e) { + var selected_coin = $(this).data('edexcoin'), + selected_coin_mode = sessionStorage.getItem('edexTmpMode'), + selected_txid = $(this).data('txid'); + $( '#nav-iguana-atomic-explorer' ).trigger( 'click' ); + $('#atomic_explorer_select_coin_options option[value=' + selected_coin + ']').attr('selected', 'selected'); + if ( selected_coin_mode == 'Full') { + $('#atomic_explorer_select_command_options option[value=gettransaction]').attr('selected', 'selected'); + } + if ( selected_coin_mode == 'Basilisk') { + $('#atomic_explorer_select_command_options option[value=dex_gettransaction]').attr('selected', 'selected'); + } + $('#atomic_explorer_input_data').val(selected_txid); + $( '#atomic_explorer_getcoinpeers_btn' ).trigger( 'click' ); + }) + } - var handleWalletToAtomicExplorer = function() { - $('#edex-tx-history-tbl').on('click', '.kmd-txid-details-btn', function(e){ - var selected_coin = $(this).data('edexcoin') - var selected_coin_mode = sessionStorage.getItem('edexTmpMode'); - var selected_txid = $(this).data('txid') - $( "#nav-iguana-atomic-explorer" ).trigger( "click" ); - $('#atomic_explorer_select_coin_options option[value=' + selected_coin + ']').attr('selected','selected'); - if ( selected_coin_mode == 'Full') { - $('#atomic_explorer_select_command_options option[value=gettransaction]').attr('selected','selected'); + var handleEdexWalletInfo = function() { + // Get coin history and pupulate balance and other info to wallet widget + var ExecuteShowCoinHistory = setInterval(function() { + if ( sessionStorage.getItem('IguanaActiveAccount') === null || + sessionStorage.getItem('DashboardActions') === null || + sessionStorage.getItem('DashboardActions') === 'stop' ) { + clearInterval(ExecuteShowCoinHistory); + console.log('=> No wallet logged in, or Dashboard not ative. No need to Run History.'); + } else if ( sessionStorage.getItem('DashboardActions') === null || sessionStorage.getItem('DashboardActions') === 'start') { + var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'), + active_edexcoinmodecode = sessionStorage.getItem('edexTmpMode'); + + // TODO: refactor + if ( active_edexcoinmodecode == 'Basilisk' || active_edexcoinmodecode == 'Native' ) { + //console.log(active_edexcoinmodecode) + //console.log('No need to show Progress bar for Native or Basilisk mode.') + } else { + ShowCoinProgressBar(active_edexcoin); } - if ( selected_coin_mode == 'Basilisk') { - $('#atomic_explorer_select_command_options option[value=dex_gettransaction]').attr('selected','selected'); + } + }, 1000); + + var CheckIfIguanaRunning = setInterval(function() { + // TODO: refactor + if ( sessionStorage.getItem('IguanaActiveAccount') === null ) { + //clearInterval(CheckIfIguanaRunning); + //console.log('=> No wallet logged in, or Dashboard not ative. No need to Run History.'); + } else { + Iguana_activehandle().then(function(result){ + //console.log(result) + //console.log("Iguana is running"); + }); + } + }, 1000); + + var RefreshEdexWalletDashboard = setInterval(function() { + if ( sessionStorage.getItem('IguanaActiveAccount') === null || + sessionStorage.getItem('DashboardActions') === null || + sessionStorage.getItem('DashboardActions') === 'stop' ) { + clearInterval(RefreshEdexWalletDashboard); + } else if ( sessionStorage.getItem('DashboardActions') === null || sessionStorage.getItem('DashboardActions') === 'start') { + if ( $('[data-edexcoin]').attr('data-edexcoin') !== 'COIN' ) { + if ( sessionStorage.getItem('edexTmpMode') !== null || sessionStorage.getItem('edexTmpMode') === 'Full') { + if ( sessionStorage.getItem('edexTmpRefresh') === null || sessionStorage.getItem('edexTmpRefresh') === 'start') { + $( '#btn_edexcoin_dashboard' ).trigger( 'click' ); + } + } } - $('#atomic_explorer_input_data').val(selected_txid) - $( "#atomic_explorer_getcoinpeers_btn" ).trigger( "click" ); - }) - } + } + }, 30000); + } + return { + // main function to initiate the module + init: function() { + resizeDashboardWindow(); + handle_edex_wallet(); + handle_edex_dashboard(); + handle_edex_send(); + handle_edex_recieve(); + + window.onresize = function(event) { + resizeDashboardWindow(); + }; - var handleEdexWalletInfo = function() { - //Get coin history and pupulate balance and other info to wallet widget - var ExecuteShowCoinHistory = setInterval(function() { - if ( sessionStorage.getItem('IguanaActiveAccount') === null || sessionStorage.getItem('DashboardActions') === null || sessionStorage.getItem('DashboardActions') === "stop" ) { - clearInterval(ExecuteShowCoinHistory); - console.log('=> No wallet logged in, or Dashboard not ative. No need to Run History.'); - } else if ( sessionStorage.getItem('DashboardActions') === null || sessionStorage.getItem('DashboardActions') === "start") { - //if ( value == "basilisk") { - //console.log("ShowCoinHistory and ShowCoinProgressBar not executing for basilisk..."); - //} else { - //console.log('wallet widget refereshed (every 1 seconds)'); - //Show Coin Progress Bars - var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin"); - var active_edexcoinmodecode = sessionStorage.getItem('edexTmpMode'); - - if ( active_edexcoinmodecode == 'Basilisk' || active_edexcoinmodecode == 'Native' ) { - //console.log(active_edexcoinmodecode) - //console.log('No need to show Progress bar for Native or Basilisk mode.') - } else { - ShowCoinProgressBar(active_edexcoin); - } - if ( sessionStorage.getItem('Activate'+active_edexcoin+'History') === 'Yes' ) { - //console.log('Show coin history'); - //var historyvalues = {"timeout":20000,"immediate":100,"agent":"basilisk","method":"history","vals":{"coin":"" + active_edexcoin + ""}}; - //ShowCoinHistory(historyvalues); - //} - } - } - }, 1000); + if ( sessionStorage.getItem('IguanaActiveAccount') === null ) { + console.log('=> No wallet logged in. No need to run Dashboard JS.'); + } else { + handleWalletWidgets(); + handleWalletWidgetBtns(); + handleEdexWalletInfo(); + handleBasiliskWalletActions(); + handleWalletToAtomicExplorer(); + //TotalFiatValue(); + } - var CheckIfIguanaRunning = setInterval(function() { + /*setInterval(function() { + handleWalletWidgets(); + console.log('wallet widget refereshed (every 15 seconds)'); + }, 15000);*/ + + /*RunTotalFiatValue = setInterval(function() { if ( sessionStorage.getItem('IguanaActiveAccount') === null ) { - //clearInterval(CheckIfIguanaRunning); - //console.log('=> No wallet logged in, or Dashboard not ative. No need to Run History.'); + //console.log('=> No wallet logged in. No need to get Rates.'); + //StopTotalFiatValue(); } else { - Iguana_activehandle().then(function(result){ - //console.log(result) - //console.log("Iguana is running"); - }) + //TotalFiatValue(); + //console.log('Get Rates (every 60 seconds)'); } - }, 1000); - - var RefreshEdexWalletDashboard = setInterval(function() { - if ( sessionStorage.getItem('IguanaActiveAccount') === null || sessionStorage.getItem('DashboardActions') === null || sessionStorage.getItem('DashboardActions') === "stop" ) { - clearInterval(RefreshEdexWalletDashboard); - //console.log('=> No wallet logged in, or Dashboard not ative. No need to Run History.'); - } else if ( sessionStorage.getItem('DashboardActions') === null || sessionStorage.getItem('DashboardActions') === "start") { - if ( $('[data-edexcoin]').attr("data-edexcoin") !== "COIN" ) { - if ( sessionStorage.getItem('edexTmpMode') !== null || sessionStorage.getItem('edexTmpMode') === "Full") { - if ( sessionStorage.getItem('edexTmpRefresh') === null || sessionStorage.getItem('edexTmpRefresh') === "start") { - //console.log('it is not COIN. '+'It is: ' + $('[data-edexcoin]').attr("data-edexcoin")); - $( "#btn_edexcoin_dashboard" ).trigger( "click" ); - } - } - } - } - }, 30000); + }, 60000);*/ } - - - return { - //main function to initiate the module - init: function() { - - resizeDashboardWindow(); - handle_edex_wallet(); - handle_edex_dashboard(); - handle_edex_send(); - handle_edex_recieve(); - - - - window.onresize = function(event) { resizeDashboardWindow(); }; - - if ( sessionStorage.getItem('IguanaActiveAccount') === null ) { - console.log('=> No wallet logged in. No need to run Dashboard JS.'); - } else { - handleWalletWidgets(); - handleWalletWidgetBtns(); - handleEdexWalletInfo(); - handleBasiliskWalletActions(); - handleWalletToAtomicExplorer(); - //TotalFiatValue(); - } - - /*setInterval(function() { - handleWalletWidgets(); - console.log('wallet widget refereshed (every 15 seconds)'); - }, 15000);*/ - - /*RunTotalFiatValue = setInterval(function() { - if ( sessionStorage.getItem('IguanaActiveAccount') === null ) { - //console.log('=> No wallet logged in. No need to get Rates.'); - //StopTotalFiatValue(); - } else { - //TotalFiatValue(); - //console.log('Get Rates (every 60 seconds)'); - } - }, 60000);*/ - - } - - }; - + }; }(); jQuery(document).ready(function() { - Dashboard.init(); - + Dashboard.init(); }); function resizeDashboardWindow() { /* set default map height */ - var navbarH = $(".site-navbar").outerHeight(); - //var footerH = $(".site-footer").outerHeight(); - var edexDashH = $(".edexcoin_dashoard_section_main_div").outerHeight(); - - var mapH = $(window).height() - navbarH; + var navbarH = $('.site-navbar').outerHeight(), + edexDashH = $('.edexcoin_dashoard_section_main_div').outerHeight(), + mapH = $(window).height() - navbarH; - $(".page-main").outerHeight(mapH); - $(".scrollable-container").outerHeight(mapH); + $('.page-main').outerHeight(mapH); + $('.scrollable-container').outerHeight(mapH); } function edexCoinBtnAction() { $('.edexcoin-logo').click(function() { - $( "#edexcoin_send_coins_back_btn" ).trigger( "click" ); + $( '#edexcoin_send_coins_back_btn' ).trigger( 'click' ); $('#btn_edexcoin_dashboard').hide(); $('#btn_edexcoin_send').show(); $('#btn_edexcoin_recieve').show(); - //console.log($(this).data('edexcoincode')); - //console.log($(this).data('edexcoinmodecode')) - var selected_coin = $(this).data('edexcoincode') - var selected_coinmode = $(this).data('edexcoinmodecode') - var selected_coinname = $(this).data('edexcoinname') + + var selected_coin = $(this).data('edexcoincode'), + selected_coinmode = $(this).data('edexcoinmodecode'), + selected_coinname = $(this).data('edexcoinname'); + sessionStorage.setItem('edexTmpMode', selected_coinmode); - resizeDashboardWindow() + resizeDashboardWindow(); + if ( selected_coinmode == 'Basilisk' ) { $('#edex-footer').hide(); $('#btn_edexcoin_basilisk').show(); - $('#edexcoin-wallet-waitingrt-alert').hide() - StopShowCoinHistory(); - sessionStorage.setItem('edexTmpRefresh', "stop"); + $('#edexcoin-wallet-waitingrt-alert').hide(); + sessionStorage.setItem('edexTmpRefresh', 'start'); } if ( selected_coinmode == 'Full' ) { $('#edex-footer').show(); $('#btn_edexcoin_basilisk').hide(); - sessionStorage.setItem('edexTmpRefresh', "start"); + sessionStorage.setItem('edexTmpRefresh', 'start'); } if ( selected_coinmode !== 'Native' ) { $('#edexcoin_dashoard_section').show(); @@ -814,365 +797,490 @@ function edexCoinBtnAction() { $('#edexcoin_settings').hide(); $('#currency-progressbars').show(); - //get selected coin's code and populate in easydex wallet widget's html elements + // 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+'"]')}); + $.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(selected_coinname); $('#edex_total_balance_coincode').text(coincode); //populate selected coin's address - EDEXMainAddr(selected_coin).then(function(result){ - //console.log(result) + EDEXMainAddr(selected_coin).then(function(result) { $('#edexcoin_active_addr').text(result); - $('#edexcoin_active_addr_clipboard').attr("data-clipboard-text",result) + $('#edexcoin_active_addr_clipboard').attr('data-clipboard-text', result); }) - $('#edexcoin_active_addr_clipboard').click(function(){alertify.success("Address Copied.");}) + $('#edexcoin_active_addr_clipboard').click(function() { + alertify.success('Address Copied.'); + }); var clipboard = new Clipboard('.clipboard-edexaddr'); clipboard.destroy(); var clipboard = null; - if( clipboard != null ) { + if ( clipboard != null ) { clipboard.destroy(); } var clipboard = new Clipboard('.clipboard-edexaddr'); clipboard.on('success', function(e) { - console.info('Action:', e.action); - console.info('Text:', e.text); - console.info('Trigger:', e.trigger); + console.info('Action: ', e.action); + console.info('Text: ', e.text); + console.info('Trigger: ', e.trigger); e.clearSelection(); }); clipboard.on('error', function(e) { - console.error('Action:', e.action); - console.error('Trigger:', e.trigger); + console.error('Action: ', e.action); + console.error('Trigger: ', e.trigger); }); - //populate selected coin's balance - - if ( selected_coinmode == 'Basilisk' - && selected_coin !== 'BTC' - && selected_coin !== 'BTCD' - && selected_coin !== 'LTC' - && selected_coin !== 'DOGE' - && selected_coin !== 'DGB' - && selected_coin !== 'SYS' - && selected_coin !== 'MZC' - && selected_coin !== 'UNO' - && selected_coin !== 'ZET' - && selected_coin !== 'BTM' - && selected_coin !== 'CARB' - && selected_coin !== 'ANC' - && selected_coin !== 'FRK') { - getDEXGetBalance(selected_coin).then(function(result){ - //console.log(result) + + // populate selected coin's balance + if ( selected_coinmode == 'Basilisk' && + selected_coin !== 'BTC' && + selected_coin !== 'BTCD' && + selected_coin !== 'LTC' && + selected_coin !== 'DOGE' && + selected_coin !== 'DGB' && + selected_coin !== 'SYS' && + selected_coin !== 'MZC' && + selected_coin !== 'UNO' && + selected_coin !== 'ZET' && + selected_coin !== 'BTM' && + selected_coin !== 'CARB' && + selected_coin !== 'ANC' && + selected_coin !== 'FRK') { + getDEXGetBalance_cache(selected_coin).then(function(result) { if ( result.interest !== undefined ) { - $('#edexcoin_getbalance_interest').show() - $('#edexcoin_getbalance_total_interest').show() - $('#edexcoin_getbalance_t').removeClass( "col-lg-12 " ).addClass( " col-lg-4" ); - $('#edex_interest_balance').text(result.interest) - $('#edex_total_balance_interest').text(result.totalbalance) + $('#edexcoin_getbalance_interest').show(); + $('#edexcoin_getbalance_total_interest').show(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-12' ).addClass( 'col-lg-4' ); + $('#edex_interest_balance').text(result.interest); + $('#edex_total_balance_interest').text(result.totalbalance); $('#edex_total_interest_coincode').text(selected_coin); $('#edex_total_balance_interest_coincode').text(selected_coin); } if ( result.interest === undefined || selected_coin !== 'KMD') { - $('#edexcoin_getbalance_interest').hide() - $('#edexcoin_getbalance_total_interest').hide() - $('#edexcoin_getbalance_t').removeClass( " col-lg-4" ).addClass( " col-lg-12" ); - $('#edex_interest_balance').text('-') - $('#edex_total_balance_interest').text('-') + $('#edexcoin_getbalance_interest').hide(); + $('#edexcoin_getbalance_total_interest').hide(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-4' ).addClass( 'col-lg-12' ); + $('#edex_interest_balance').text('-'); + $('#edex_total_balance_interest').text('-'); } - //console.log(result.total) $('#edex_total_balance').text(result.total); $('#edex_total_balance_coincode').text(selected_coin); }); } else if (selected_coinmode == 'Basilisk') { - getDEXGetBalance2(selected_coin).then(function(result){ - //console.log(result) + getDEXGetBalance2(selected_coin).then(function(result) { if ( result.interest !== undefined ) { - $('#edexcoin_getbalance_interest').show() - $('#edexcoin_getbalance_total_interest').show() - $('#edexcoin_getbalance_t').removeClass( "col-lg-12 " ).addClass( " col-lg-4" ); - $('#edex_interest_balance').text(result.interest) - $('#edex_total_balance_interest').text(result.totalbalance) + $('#edexcoin_getbalance_interest').show(); + $('#edexcoin_getbalance_total_interest').show(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-12' ).addClass( 'col-lg-4' ); + $('#edex_interest_balance').text(result.interest); + $('#edex_total_balance_interest').text(result.totalbalance); $('#edex_total_interest_coincode').text(selected_coin); $('#edex_total_balance_interest_coincode').text(selected_coin); } if ( result.interest === undefined || selected_coin !== 'KMD') { - $('#edexcoin_getbalance_interest').hide() - $('#edexcoin_getbalance_total_interest').hide() - $('#edexcoin_getbalance_t').removeClass( " col-lg-4" ).addClass( " col-lg-12" ); - $('#edex_interest_balance').text('-') - $('#edex_total_balance_interest').text('-') + $('#edexcoin_getbalance_interest').hide(); + $('#edexcoin_getbalance_total_interest').hide(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-4' ).addClass( 'col-lg-12' ); + $('#edex_interest_balance').text('-'); + $('#edex_total_balance_interest').text('-'); } - //console.log(result.total) $('#edex_total_balance').text(result.total); $('#edex_total_balance_coincode').text(selected_coin); }); } else { - EDEXlistunspent(selected_coin).then(function(result){ - //console.log(result) + EDEXlistunspent(selected_coin).then(function(result) { if (result[0] != undefined) { - //console.log(result[0]) if ( result[0].interest !== undefined ) { - $('#edexcoin_getbalance_interest').show() - $('#edexcoin_getbalance_total_interest').show() - $('#edexcoin_getbalance_t').removeClass( "col-lg-12 " ).addClass( " col-lg-4" ); - $('#edex_interest_balance').text(result[0].interest) - $('#edex_total_balance_interest').text(result[0].totalbalance) + $('#edexcoin_getbalance_interest').show(); + $('#edexcoin_getbalance_total_interest').show(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-12' ).addClass( 'col-lg-4' ); + $('#edex_interest_balance').text(result[0].interest); + $('#edex_total_balance_interest').text(result[0].totalbalance); $('#edex_total_interest_coincode').text(selected_coin); $('#edex_total_balance_interest_coincode').text(selected_coin); } if ( result[0].interest === undefined ) { - $('#edexcoin_getbalance_interest').hide() - $('#edexcoin_getbalance_total_interest').hide() - $('#edexcoin_getbalance_t').removeClass( " col-lg-4" ).addClass( " col-lg-12" ); - $('#edex_interest_balance').text('-') - $('#edex_total_balance_interest').text('-') + $('#edexcoin_getbalance_interest').hide(); + $('#edexcoin_getbalance_total_interest').hide(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-4' ).addClass( 'col-lg-12' ); + $('#edex_interest_balance').text('-'); + $('#edex_total_balance_interest').text('-'); } $('#edex_total_balance').text(result[0].total); $('#edex_total_balance_coincode').text(selected_coin); - - //$('#edex_total_balance').text(result[0].total.toFixed(8)); - //console.log(result[0].total) } else { $('#edex_total_balance').text('0'); } }); } - //getCoinBalance(active_edexcoin); EdexfillTxHistory(coincode); } else { $('#currency-progressbars').hide(); if ( selected_coin == 'KMD' ) { sessionStorage.setItem('edexTmpMode', selected_coinmode); - sessionStorage.setItem('edexTmpRefresh', "start"); - $( "#nav-komodo-wallet" ).trigger( "click" ); + sessionStorage.setItem('edexTmpRefresh', 'start'); + $( '#nav-komodo-wallet' ).trigger( 'click' ); } if ( selected_coin == 'ZEC' ) { sessionStorage.setItem('edexTmpMode', selected_coinmode); - sessionStorage.setItem('edexTmpRefresh', "start"); - $( "#nav-zcash-wallet" ).trigger( "click" ); + sessionStorage.setItem('edexTmpRefresh', 'start'); + $( '#nav-zcash-wallet' ).trigger( 'click' ); } } - - }); } function getActiveEdexcoin() { - var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin"); - return active_edexcoin; + var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'); + return active_edexcoin; } -function hideExtCoinsinEdexDashboard(coin) { - //var tmp_getinfo = EDEXgetinfo(coin) - //console.log(tmp_getinfo); -} +/*function hideExtCoinsinEdexDashboard(coin) { + var tmp_getinfo = EDEXgetinfo(coin); + console.log(tmp_getinfo); +}*/ function EdexfillTxHistory(coin) { NProgress.done(true); NProgress.configure({ - template: '
' + template: '
' + + '
' + + '
' + + '
' }); NProgress.start(); - EdexGetTxList(coin).then(function(result){ - //console.log(result) + var active_edexcoinmodecode = sessionStorage.getItem('edexTmpMode'); + + if ( active_edexcoinmodecode === 'Basilisk' ) { + EdexGetTxList_cache(coin).then(function(result) { var edex_txhistory_table = ''; - edex_txhistory_table = $('#edex-tx-history-tbl').DataTable( { data: result, - "order": [[ 3, "desc" ]], - select: true, - retrieve: true + edex_txhistory_table = $('#edex-tx-history-tbl').DataTable({ + data: result, + 'order': [ + [ 3, 'desc' ] + ], + select: true, + retrieve: true }); edex_txhistory_table.destroy(); - edex_txhistory_table = $('#edex-tx-history-tbl').DataTable( { data: result, - "order": [[ 3, "desc" ]], - select: true, - retrieve: true + edex_txhistory_table = $('#edex-tx-history-tbl').DataTable({ + data: result, + 'order': [ + [ 3, 'desc' ] + ], + select: true, + retrieve: true }); }); + } + + if ( active_edexcoinmodecode === 'Full' ) { + EdexGetTxList(coin).then(function(result){ + var edex_txhistory_table = ''; + edex_txhistory_table = $('#edex-tx-history-tbl').DataTable({ + data: result, + 'order': [ + [ 3, 'desc' ] + ], + select: true, + retrieve: true + }); + + edex_txhistory_table.destroy(); + edex_txhistory_table = $('#edex-tx-history-tbl').DataTable({ + data: result, + 'order': [ + [ 3, 'desc' ] + ], + select: true, + retrieve: true + }); + }); + } } function getDEXCoinBalance(coin) { - getDEXGetBalance(coin).then(function(result){ - console.log(result) + getDEXGetBalance_cache(coin).then(function(result) { + console.log(result) }); } - function getDEXGetBalance(coin) { NProgress.done(true); NProgress.configure({ - template: '
' + template: '
' + + '
' + + '
' + + '
' }); NProgress.start(); - return new Promise((resolve) =>{ + return new Promise((resolve) => { + + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + ajax_data_2 = { + 'userpass': tmpIguanaRPCAuth, + 'coin': coin, + 'agent': 'bitcoinrpc', + 'method': 'getaddressesbyaccount', + 'account': '*' + }; - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var ajax_data_2 = {'userpass':tmpIguanaRPCAuth,"coin":coin,"agent":"bitcoinrpc","method":"getaddressesbyaccount","account":"*"} $.ajax({ - data: JSON.stringify(ajax_data_2), - url: 'http://127.0.0.1:7778', - type: 'POST', - dataType: 'json', + data: JSON.stringify(ajax_data_2), + url: 'http://127.0.0.1:7778', + type: 'POST', + dataType: 'json' }).then(data => { - var total_balance = 0 - var total_interest = 0 - Promise.all(data.result.map((coinaddr_value,coinaddr_index) => { - let params = {'userpass':tmpIguanaRPCAuth,"agent":"dex","method":"getbalance","address":coinaddr_value,"symbol":coin}; - return new Promise((resolve, reject) => { - $.ajax({ - data: JSON.stringify(params), - url: 'http://127.0.0.1:7778', - type: 'POST', - dataType: 'json', - }).then(data => { - total_balance = total_balance + data.balance - if (data.interest !== undefined) { - total_interest = total_interest + data.interest - pass_data = {"total":total_balance.toFixed(8),"interest":total_interest.toFixed(8)} - } - if (data.interest == undefined) { - pass_data = {"total":total_balance} - } - console.log(pass_data) - - resolve(pass_data) - }) - }) - - })).then(result => { - //console.log(result[result.length-1]) - resolve(result[result.length-1]) - NProgress.done(); - }) - }) - }) + var total_balance = 0, + total_interest = 0; + + Promise.all(data.result.map((coinaddr_value,coinaddr_index) => { + let params = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getbalance', + 'address': coinaddr_value, + 'symbol': coin + }; + + console.log(params); + + return new Promise((resolve, reject) => { + $.ajax({ + data: JSON.stringify(params), + url: 'http://127.0.0.1:7778', + type: 'POST', + dataType: 'json' + }).then(data => { + console.log(data); + total_balance = total_balance + data.balance; + + if (data.interest !== undefined) { + total_interest = total_interest + data.interest; + pass_data = { + 'total': total_balance.toFixed(8), + 'interest': total_interest.toFixed(8) + } + } + + if (data.interest == undefined) { + pass_data = { 'total': total_balance }; + } + + console.log(pass_data); + resolve(pass_data); + }); + }); + })).then(result => { + resolve(result[result.length-1]); + NProgress.done(); + }); + }); + }); } -function getDEXGetBalance2(coin) { +function getDEXGetBalance_cache(coin) { NProgress.done(true); NProgress.configure({ - template: '
' + template: '
' + + '
' + + '
' + + '
' }); NProgress.start(); - return new Promise((resolve) =>{ - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var ajax_data_1 = {'userpass':tmpIguanaRPCAuth,"agent":"SuperNET","method":"activehandle"} - var tmp_coin_addr = null - - var ajax_call_1 = $.ajax({ - data: JSON.stringify(ajax_data_1), - url: 'http://127.0.0.1:7778', - type: 'POST', - dataType: 'json', - }), - ajax_call_2 = ajax_call_1.then(function(data) { - // .then() returns a new promise - tmp_coin_addr = data[coin] - //console.log(tmp_coin_addr); - var ajax_data_2 = {'userpass':tmpIguanaRPCAuth,"agent":"dex","method":"listunspent","address":data[coin],"symbol":coin} - return $.ajax({ - data: JSON.stringify(ajax_data_2), - url: 'http://127.0.0.1:7778', - type: 'POST', - dataType: 'json', - }); - }); - ajax_call_2.done(function(data) { - //console.log(tmp_coin_addr); - //console.log(data); - if (data.error === 'less than required responses') { - toastr.error("Less than required responses. Please try again.", "Basilisk Notification") + return new Promise((resolve) => { + Shepherd_GetBasiliskCache().then(function(result) { + var _data = JSON.parse(result), + query = _data.result.basilisk, + total_balance = 0, + total_interest = 0; + + Promise.all(query[coin].addresses.map((coinaddr_value,coinaddr_index) => { + return new Promise((resolve, reject) => { + if ( query[coin][coinaddr_value].getbalance !== undefined ) { + var data = query[coin][coinaddr_value].getbalance; + total_balance = parseFloat(total_balance) + parseFloat(data.balance); + + if (data.interest !== undefined) { + total_interest = parseFloat(total_interest) + parseFloat(data.interest); + total_final = parseFloat(total_balance) + parseFloat(total_interest); + pass_data = { + 'total': total_balance.toFixed(8), + 'interest': total_interest.toFixed(8), + 'totalbalance': total_final.toFixed(8) + } } - var tmpcalcnum = 0; - var tmpcalcinterest = 0; - var interest_enable = false - var tmptotalbalance = 0; - $.each(data, function(index) { - if ( data[index].interest !== undefined ) { - //console.log('interest is available for this currency. Adding to total balance.'); - tmpcalcnum = tmpcalcnum + data[index].amount - tmpcalcinterest = tmpcalcinterest + data[index].interest - interest_enable = true - } - if ( data[index].interest === undefined ) { - tmpcalcnum = tmpcalcnum + data[index].amount; + if (data.interest == undefined) { + pass_data = { 'total': total_balance.toFixed(8) }; } - }); - - if ( coin == 'KMD' ) { - tmptotalbalance = parseFloat(tmpcalcnum) + parseFloat(tmpcalcinterest) - var tmp_addr_total_balance_output = {"addr": tmp_coin_addr, "total": tmpcalcnum.toFixed(8), "interest": tmpcalcinterest.toFixed(8), "totalbalance": tmptotalbalance.toFixed(8)}; - } - if ( coin !== 'KMD' ) { - var tmp_addr_total_balance_output = {"addr": tmp_coin_addr, "total": tmpcalcnum.toFixed(8)}; + } else { + pass_data = { 'total': 0.00000000 }; } - console.log(tmp_addr_total_balance_output); - if (data == '' ) { - tmp_addr_total_balance_output = {"addr": tmp_coin_addr, "total":0}; - } + resolve(pass_data); + }); + })).then(result => { + resolve(result[result.length-1]); + NProgress.done(); + }); + }); + }); +} - //console.log(tmp_addr_total_balance_output) - resolve(tmp_addr_total_balance_output) - NProgress.done(); - }).fail(function(xhr, textStatus, error) { - // handle request failures - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - Iguana_ServiceUnavailable(); - } - console.log(textStatus); - console.log(error); +function getDEXGetBalance2(coin) { + NProgress.done(true); + NProgress.configure({ + template: '
' + + '
' + + '
' + + '
' + }); + NProgress.start(); + + return new Promise((resolve) => { + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + ajax_data_1 = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'SuperNET', + 'method': 'activehandle' + }, + tmp_coin_addr = null + ajax_call_1 = $.ajax({ + data: JSON.stringify(ajax_data_1), + url: 'http://127.0.0.1:7778', + type: 'POST', + dataType: 'json' + }), + ajax_call_2 = ajax_call_1.then(function(data) { + // .then() returns a new promise + tmp_coin_addr = data[coin]; + + var ajax_data_2 = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listunspent', + 'address': data[coin], + 'symbol': coin + }; + + return $.ajax({ + data: JSON.stringify(ajax_data_2), + url: 'http://127.0.0.1:7778', + type: 'POST', + dataType: 'json' + }); }); - }) + + ajax_call_2.done(function(data) { + console.log(data); + if (data.error === 'less than required responses') { + toastr.error('Less than required responses. Please try again.', 'Basilisk Notification'); + } + + var tmpcalcnum = 0, + tmpcalcinterest = 0, + interest_enable = false, + tmptotalbalance = 0; + + $.each(data, function(index) { + if ( data[index].interest !== undefined ) { + tmpcalcnum = tmpcalcnum + data[index].amount; + tmpcalcinterest = tmpcalcinterest + data[index].interest; + interest_enable = true; + } + + if ( data[index].interest === undefined ) { + tmpcalcnum = tmpcalcnum + data[index].amount; + } + }); + + if ( coin == 'KMD' ) { + tmptotalbalance = parseFloat(tmpcalcnum) + parseFloat(tmpcalcinterest); + var tmp_addr_total_balance_output = { + 'addr': tmp_coin_addr, + 'total': tmpcalcnum.toFixed(8), + 'interest': tmpcalcinterest.toFixed(8), + 'totalbalance': tmptotalbalance.toFixed(8) + }; + } + if ( coin !== 'KMD' ) { + var tmp_addr_total_balance_output = { + 'addr': tmp_coin_addr, + 'total': tmpcalcnum.toFixed(8) + }; + } + console.log(tmp_addr_total_balance_output); + + if (data == '' ) { + tmp_addr_total_balance_output = { + 'addr': tmp_coin_addr, + 'total': 0 + }; + } + + resolve(tmp_addr_total_balance_output) + NProgress.done(); + }).fail(function(xhr, textStatus, error) { + // handle request failures + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } + console.log(textStatus); + console.log(error); + }); + }); } function getCoinBalance(coin) { - var active_edexcoin = $('[data-edexcoin]').attr("data-edexcoin"); - EDEXlistunspent(active_edexcoin).then(function(result){ + var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'); + + EDEXlistunspent(active_edexcoin).then(function(result) { console.log(result) if (result[0] != undefined) { - //console.log(result[0]) if ( result[0].interest !== undefined ) { - $('#edexcoin_getbalance_interest').show() - $('#edexcoin_getbalance_total_interest').show() - $('#edexcoin_getbalance_t').removeClass( "col-lg-12 " ).addClass( " col-lg-4" ); - $('#edex_interest_balance').text(result[0].interest) - $('#edex_total_balance_interest').text(result[0].totalbalance) + $('#edexcoin_getbalance_interest').show(); + $('#edexcoin_getbalance_total_interest').show(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-12' ).addClass( 'col-lg-4' ); + $('#edex_interest_balance').text(result[0].interest); + $('#edex_total_balance_interest').text(result[0].totalbalance); $('#edex_total_interest_coincode').text(active_edexcoin); $('#edex_total_balance_interest_coincode').text(active_edexcoin); } if ( result[0].interest === undefined ) { - $('#edexcoin_getbalance_interest').hide() - $('#edexcoin_getbalance_total_interest').hide() - $('#edexcoin_getbalance_t').removeClass( " col-lg-4" ).addClass( " col-lg-12" ); - $('#edex_interest_balance').text('-') - $('#edex_total_balance_interest').text('-') + $('#edexcoin_getbalance_interest').hide(); + $('#edexcoin_getbalance_total_interest').hide(); + $('#edexcoin_getbalance_t').removeClass( 'col-lg-4' ).addClass( 'col-lg-12' ); + $('#edex_interest_balance').text('-'); + $('#edex_total_balance_interest').text('-'); } $('#edex_total_balance').text(result[0].total); $('#edex_total_balance_coincode').text(active_edexcoin); - - //$('span[data-edexcoincode="' + coin + '"][id="edexcoin-balance"]').text(result[0].total); - //console.log(result[0].total) } else { $('span[data-edexcoincode="' + coin + '"][id="edexcoin-balance"]').text('0'); } @@ -1182,7 +1290,7 @@ function getCoinBalance(coin) { function getBasiliskCoinBalance(coin) { EDEXMainAddr(coin).then(function(result){ console.log(result) - EDEX_DEXlistunspent(coin, result).then(function(result_listunspent){ + EDEX_DEXlistunspent(coin, result).then(function(result_listunspent) { console.log(result_listunspent[0].amount); $('span[data-edexcoincode="' + coin + '"][id="edexcoin-balance"]').text(result_listunspent[0].amount); }); @@ -1190,530 +1298,738 @@ function getBasiliskCoinBalance(coin) { } function StopShowCoinHistory() { - clearInterval(ExecuteShowCoinHistory); - console.log('Stopped executing History and ProgressBar API.'); + clearInterval(ExecuteShowCoinHistory); + console.log('Stopped executing History and ProgressBar API.'); } - function refreshEDEXCoinWalletList() { - var walletDivContent = ''; - var AddColumnDiv = 0 - $.each([ 'native', 'basilisk', 'full' ], function( index, value ) { - - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var ajax_data = {'userpass':tmpIguanaRPCAuth,"agent":"InstantDEX","method":"allcoins"}; - //console.log(ajax_data); - $.ajax({ - type: 'POST', - data: JSON.stringify(ajax_data), - url: 'http://127.0.0.1:7778', - //dataType: 'JSON', - success: function(data, textStatus, jqXHR) { - var AllcoinsDataOutput = JSON.parse(data); - //console.log('== AllCoins Data OutPut =='); - //console.log(value); - //console.log(AllcoinsDataOutput[value]); - - $.each(AllcoinsDataOutput[value], function(index) { - - var coinlogo = ''; - var coinname = ''; - var modecode = ''; - var modetip = ''; - var modecolor = ''; - - if ( value == 'native' ) { modecode = 'Native'; modetip = 'Native'; modecolor = 'primary'; } - if ( value == 'basilisk' ) { modecode = 'Basilisk'; modetip = 'Basilisk'; modecolor = 'info'; } - if ( value == 'full' ) { modecode = 'Full'; modetip = 'Full'; modecolor = 'success'; } - if ( value == 'virtual' ) { modecode = 'Virtual'; modetip = 'Virtual'; modecolor = 'danger'; } - if ( value == 'notarychains' ) { modecode = 'Notarychains'; modetip = 'Notarychains'; modecolor = 'dark'; } - - if ( AllcoinsDataOutput[value][index] == 'BTC' ) { coinlogo = 'bitcoin'; coinname = 'Bitcoin'; } - if ( AllcoinsDataOutput[value][index] == 'BTCD' ) { coinlogo = 'bitcoindark'; coinname = 'BitcoinDark'; } - if ( AllcoinsDataOutput[value][index] == 'LTC' ) { coinlogo = 'litecoin'; coinname = 'Litecoin'; } - if ( AllcoinsDataOutput[value][index] == 'VPN' ) { coinlogo = 'vpncoin'; coinname = 'VPNcoin'; } - if ( AllcoinsDataOutput[value][index] == 'SYS' ) { coinlogo = 'syscoin'; coinname = 'Syscoin'; } - if ( AllcoinsDataOutput[value][index] == 'ZEC' ) { coinlogo = 'zcash'; coinname = 'Zcash'; } - if ( AllcoinsDataOutput[value][index] == 'NMC' ) { coinlogo = 'namecoin'; coinname = 'Namecoin'; } - if ( AllcoinsDataOutput[value][index] == 'DEX' ) { coinlogo = 'dex'; coinname = 'DEX'; } - if ( AllcoinsDataOutput[value][index] == 'DOGE' ) { coinlogo = 'dogecoin'; coinname = 'Dogecoin'; } - if ( AllcoinsDataOutput[value][index] == 'DGB' ) { coinlogo = 'digibyte'; coinname = 'Digibyte'; } - if ( AllcoinsDataOutput[value][index] == 'MZC' ) { coinlogo = 'mazacoin'; coinname = 'Mazacoin'; } - if ( AllcoinsDataOutput[value][index] == 'UNO' ) { coinlogo = 'unobtanium'; coinname = 'Unobtanium'; } - if ( AllcoinsDataOutput[value][index] == 'ZET' ) { coinlogo = 'zetacoin'; coinname = 'Zetacoin'; } - if ( AllcoinsDataOutput[value][index] == 'KMD' ) { coinlogo = 'komodo'; coinname = 'Komodo'; } - if ( AllcoinsDataOutput[value][index] == 'BTM' ) { coinlogo = 'bitmark'; coinname = 'Bitmark'; } - if ( AllcoinsDataOutput[value][index] == 'CARB' ) { coinlogo = 'carboncoin'; coinname = 'Carboncoin'; } - if ( AllcoinsDataOutput[value][index] == 'ANC' ) { coinlogo = 'anoncoin'; coinname = 'AnonCoin'; } - if ( AllcoinsDataOutput[value][index] == 'FRK' ) { coinlogo = 'franko'; coinname = 'Franko'; } - if ( AllcoinsDataOutput[value][index] == 'SUPERNET' ) { coinlogo = 'SUPERNET'; coinname = 'SUPERNET'; } - if ( AllcoinsDataOutput[value][index] == 'REVS' ) { coinlogo = 'REVS'; coinname = 'REVS'; } - if ( AllcoinsDataOutput[value][index] == 'USD' ) { coinlogo = 'USD'; coinname = 'USD'; } - - //console.log(AllcoinsDataOutput[value][index]); - - walletDivContent += ''; - walletDivContent += '
'; - walletDivContent += '
'; - walletDivContent += '
'; - //walletDivContent += ''; - walletDivContent += ''; - walletDivContent += '
'+coinname+'
'; - //walletDivContent += '
- '+AllcoinsDataOutput[value][index]+'
'; - walletDivContent += '
'; - walletDivContent += '
'; - walletDivContent += '
'; - walletDivContent += ''; - - $('.wallet-widgets-row').html(walletDivContent); - //getCoinBalance(AllcoinsDataOutput[value][index]); - //getCoinBalance_altfn('KMD'); - //getCoinBalance('KMD'); - /*if ( modecode == 'Basilisk' ) { - $('span[data-edexcoincode="' + AllcoinsDataOutput[value][index] + '"][id="edexcoin-balance"]').parent().hide(); - //getBasiliskCoinBalance(AllcoinsDataOutput[value][index]) - }*/ - - $('.scrollbar-dynamic').scrollbar(); //Make sure widget-body has scrollbar for transactions history - $('[data-toggle="tooltip"]').tooltip(); //Make sure tooltips are working for wallet widgets and anywhere else in wallet. - //console.log(walletDivContent); - edexCoinBtnAction(); - }); - }, - error: function(xhr, textStatus, error) { - console.log('failed starting BitcoinDark.'); - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - Iguana_ServiceUnavailable(); - } - console.log(textStatus); - console.log(error); - //swal("Oops...", "Something went wrong!", "error"); - if (xhr.readyState == '0' ) { - toastr.error("Unable to connect to Iguana", "Account Notification") - } - } - }); - }); -} - - -function SwitchBasicliskFull(switch_data) { - //console.log(switch_data.currency); - //console.log(switch_data.modecode); - var relay_value = ''; - var validate_value = ''; - var mode_value = ''; - - if ( switch_data.modecode == 'B' ) { relay_value = 1; validate_value = 1; mode_value = 'Basilisk'; } - if ( switch_data.modecode == 'F' ) { relay_value = 0; validate_value = 0; mode_value = 'Full'; } - - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var SwitchCoinModeData = { - 'userpass':tmpIguanaRPCAuth, - "poll": 100, - "immediate":100, - "active": 1, - "newcoin": switch_data.currency, - "startpend": 1, - "endpend": 1, - "services": 128, - "maxpeers": 16, - "RELAY": relay_value, - "VALIDATE": validate_value, - "portp2p": 14631 - } - //console.log(SwitchCoinModeData); - //Switch selected coins' mode - $.ajax({ - type: 'GET', - data: SwitchCoinModeData, - url: 'http://127.0.0.1:7778/api/iguana/addcoin', - dataType: 'text', - success: function(data, textStatus, jqXHR) { - var SwitchCoinDataOutput = JSON.parse(data); - //console.log('== Data OutPut =='); - //console.log(SwitchCoinDataOutput); - - if (SwitchCoinDataOutput.result === 'coin added') { - console.log('coin added'); - toastr.success(switch_data.currency + " switched to " + mode_value + " Mode", "Coin Notification"); - } else if (SwitchCoinDataOutput.result === 'coin already there') { - console.log('coin already there'); - //toastr.info("Looks like" + switch_data.currency + "already running.", "Coin Notification"); - } else if (SwitchCoinDataOutput.result === null) { - console.log('coin already there'); - //toastr.info("Looks like" + switch_data.currency + "already running.", "Coin Notification"); - } - }, - error: function(xhr, textStatus, error) { + var walletDivContent = '', + AddColumnDiv = 0; + + $.each([ + 'native', + 'basilisk', + 'full' + ], function( index, value ) { + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + ajax_data = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'InstantDEX', + 'method': 'allcoins' + }; + + $.ajax({ + type: 'POST', + data: JSON.stringify(ajax_data), + url: 'http://127.0.0.1:7778', + success: function(data, textStatus, jqXHR) { + var AllcoinsDataOutput = JSON.parse(data); + + $.each(AllcoinsDataOutput[value], function(index) { + var coinlogo = '', + coinname = '', + modecode = '', + modetip = '', + modecolor = ''; + + switch (value) { + case 'native': + modecode = 'Native'; + modetip = 'Native'; + modecolor = 'primary'; + break; + case 'basilisk': + modecode = 'Basilisk'; + modetip = 'Basilisk'; + modecolor = 'info'; + break; + case 'full': + modecode = 'Full'; + modetip = 'Full'; + modecolor = 'success'; + break; + case 'virtual': + modecode = 'Virtual'; + modetip = 'Virtual'; + modecolor = 'danger'; + break; + case 'notarychains': + modecode = 'Notarychains'; + modetip = 'Notarychains'; + modecolor = 'dark'; + break; + } + + switch (AllcoinsDataOutput[value][index]) { + case 'BTC': + coinlogo = 'bitcoin'; + coinname = 'Bitcoin'; + break; + case 'BTCD': + coinlogo = 'bitcoindark'; + coinname = 'BitcoinDark'; + break; + case 'LTC': + coinlogo = 'litecoin'; + coinname = 'Litecoin'; + break; + case 'VPN': + coinlogo = 'vpncoin'; + coinname = 'VPNcoin'; + break; + case 'SYS': + coinlogo = 'syscoin'; + coinname = 'Syscoin'; + break; + case 'ZEC': + coinlogo = 'zcash'; + coinname = 'Zcash'; + break; + case 'NMC': + coinlogo = 'namecoin'; + coinname = 'Namecoin'; + break; + case 'DEX': + coinlogo = 'dex'; + coinname = 'DEX'; + break; + case 'DOGE': + coinlogo = 'dogecoin'; + coinname = 'Dogecoin'; + break; + case 'DGB': + coinlogo = 'digibyte'; + coinname = 'Digibyte'; + break; + case 'MZC': + coinlogo = 'mazacoin'; + coinname = 'Mazacoin'; + break; + case 'UNO': + coinlogo = 'unobtanium'; + coinname = 'Unobtanium'; + break; + case 'ZET': + coinlogo = 'zetacoin'; + coinname = 'Zetacoin'; + break; + case 'KMD': + coinlogo = 'komodo'; + coinname = 'Komodo'; + break; + case 'BTM': + coinlogo = 'bitmark'; + coinname = 'Bitmark'; + break; + case 'CARB': + coinlogo = 'carboncoin'; + coinname = 'Carboncoin'; + break; + case 'ANC': + coinlogo = 'anoncoin'; + coinname = 'AnonCoin'; + break; + case 'FRK': + coinlogo = 'franko'; + coinname = 'Franko'; + break; + case 'SUPERNET': + coinlogo = 'SUPERNET'; + coinname = 'SUPERNET'; + break; + case 'REVS': + coinlogo = 'REVS'; + coinname = 'REVS'; + break; + case 'USD': + coinlogo = 'USD'; + coinname = 'USD'; + break; + } + + walletDivContent += ''; + walletDivContent += '
'; + walletDivContent += '
'; + walletDivContent += '
'; + walletDivContent += ''; + walletDivContent += '
' + coinname + '
'; + walletDivContent += '
'; + walletDivContent += '
'; + walletDivContent += '
'; + walletDivContent += ''; + + $('.wallet-widgets-row').html(walletDivContent); + //getCoinBalance(AllcoinsDataOutput[value][index]); + //getCoinBalance_altfn('KMD'); + //getCoinBalance('KMD'); + /*if ( modecode == 'Basilisk' ) { + $('span[data-edexcoincode="' + AllcoinsDataOutput[value][index] + '"][id="edexcoin-balance"]').parent().hide(); + //getBasiliskCoinBalance(AllcoinsDataOutput[value][index]) + }*/ + + $('.scrollbar-dynamic').scrollbar(); //Make sure widget-body has scrollbar for transactions history + $('[data-toggle="tooltip"]').tooltip(); //Make sure tooltips are working for wallet widgets and anywhere else in wallet. + edexCoinBtnAction(); + }); + }, + error: function(xhr, textStatus, error) { console.log('failed starting BitcoinDark.'); console.log(xhr.statusText); if ( xhr.readyState == 0 ) { - Iguana_ServiceUnavailable(); + Iguana_ServiceUnavailable(); } console.log(textStatus); console.log(error); - //swal("Oops...", "Something went wrong!", "error"); + if (xhr.readyState == '0' ) { - toastr.error("Unable to connect to Iguana", "Account Notification") + toastr.error('Unable to connect to Iguana', 'Account Notification'); } + } + }); + }); +} + +function SwitchBasicliskFull(switch_data) { + var relay_value = '', + validate_value = '', + mode_value = ''; + + if ( switch_data.modecode == 'B' ) { + relay_value = 1; + validate_value = 1; + mode_value = 'Basilisk'; + } + if ( switch_data.modecode == 'F' ) { + relay_value = 0; + validate_value = 0; + mode_value = 'Full'; + } + + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + SwitchCoinModeData = { + 'userpass': tmpIguanaRPCAuth, + 'poll': 100, + 'immediate':100, + 'active': 1, + 'newcoin': switch_data.currency, + 'startpend': 1, + 'endpend': 1, + 'services': 128, + 'maxpeers': 16, + 'RELAY': relay_value, + 'VALIDATE': validate_value, + 'portp2p': 14631 + }; + + // Switch selected coins' mode + $.ajax({ + type: 'GET', + data: SwitchCoinModeData, + url: 'http://127.0.0.1:7778/api/iguana/addcoin', + dataType: 'text', + success: function(data, textStatus, jqXHR) { + var SwitchCoinDataOutput = JSON.parse(data); + + if (SwitchCoinDataOutput.result === 'coin added') { + console.log('coin added'); + toastr.success(switch_data.currency + ' switched to ' + mode_value + ' Mode', 'Coin Notification'); + } else if (SwitchCoinDataOutput.result === 'coin already there') { + console.log('coin already there'); + //toastr.info("Looks like" + switch_data.currency + "already running.", "Coin Notification"); + } else if (SwitchCoinDataOutput.result === null) { + console.log('coin already there'); + //toastr.info("Looks like" + switch_data.currency + "already running.", "Coin Notification"); } + }, + error: function(xhr, textStatus, error) { + console.log('failed starting BitcoinDark.'); + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } + console.log(textStatus); + console.log(error); + if (xhr.readyState == '0' ) { + toastr.error('Unable to connect to Iguana', 'Account Notification'); + } + } }); } function TotalFiatValue() { - var BTC_balance = $('span[data-currency="BTC"][id="currency-balance"]').text(); - var BTCD_balance = $('span[data-currency="BTCD"][id="currency-balance"]').text(); - var Fiat_Currency = localStorage.getItem('EasyDEX_FiatCurrency'); - var BTC_Fiat_pair_value = ''; - var Conversion_Fiat_Pair = ''; - var BTCD_Fiat_pair_value = ''; + var BTC_balance = $('span[data-currency="BTC"][id="currency-balance"]').text(), + BTCD_balance = $('span[data-currency="BTCD"][id="currency-balance"]').text(), + Fiat_Currency = localStorage.getItem('EasyDEX_FiatCurrency'), + BTC_Fiat_pair_value = '', + Conversion_Fiat_Pair = '', + BTCD_Fiat_pair_value = ''; $('span[data-currency="BTC"][id="header_coinname_balance"]').text(BTC_balance + ' BTC'); - $('span[data-currency="BTCD"][id="header_coinname_balance"]').text(BTCD_balance + ' BTCD' ); + $('span[data-currency="BTCD"][id="header_coinname_balance"]').text(BTCD_balance + ' BTCD'); if ( Fiat_Currency == 'USD' ) { - BTC_Fiat_pair_value = 'BTC/'+Fiat_Currency; + BTC_Fiat_pair_value = 'BTC/' + Fiat_Currency; Conversion_Fiat_Pair = 'EUR/USD'; } else { BTC_Fiat_pair_value = 'BTC/USD'; - Conversion_Fiat_Pair = Fiat_Currency+'/USD'; + Conversion_Fiat_Pair = Fiat_Currency + '/USD'; } - //console.log(BTC_balance); console.log(BTCD_balance); - - var TotalFiatValueData = {"agent":"iguana","method":"rates","quotes":["BTCD/BTC", BTC_Fiat_pair_value, Conversion_Fiat_Pair],"immediate":100,"timeout":5000}; - //console.log(TotalFiatValueData); + var TotalFiatValueData = { + 'agent': 'iguana', + 'method': 'rates', + 'quotes': [ + 'BTCD/BTC', + BTC_Fiat_pair_value, + Conversion_Fiat_Pair + ], + 'immediate': 100, + 'timeout': 5000 + }; if ( sessionStorage.getItem('IguanaActiveAccount') === null ) { console.log('=> No wallet logged in. No need to get Rates.'); } else { - //Get Rates + // Get Rates $.ajax({ type: 'POST', data: JSON.stringify(TotalFiatValueData), url: 'http://127.0.0.1:7778', - //dataType: 'text', success: function(data, textStatus, jqXHR) { - var RatesData = JSON.parse(data); - var label_color = ''; - var label_icon = ''; - var wallettblContent = ''; - //console.log('== Rates Data OutPut =='); - //console.log(RatesData.rates[2]); - localStorage.setItem('EasyDEX_BTCD_BTC_pair_value', RatesData.rates[0]['BTCD/BTC']); //e.g BTCD/BTC - localStorage.setItem('EasyDEX_BTC_Fiat_pair_value', RatesData.rates[1][BTC_Fiat_pair_value]); //e.g BTC/USD - localStorage.setItem('EasyDEX_Conversion_Fiat_Pair', Conversion_Fiat_Pair); //e.g EUR/USD - localStorage.setItem('EasyDEX_Conversion_Fiat_Pair_value', RatesData.rates[2][Conversion_Fiat_Pair]); //e.g EUR/USD: 1.11830926 - - var tmp_btcd_btc = RatesData.rates[0]; - var tmp_btc_fiat = RatesData.rates[1]; - //console.log(tmp_btcd_btc['BTCD/BTC']); console.log(tmp_btc_fiat[BTC_Fiat_pair_value]); - - BTCD_Fiat_pair_value = parseFloat(tmp_btcd_btc['BTCD/BTC']) * parseFloat(tmp_btc_fiat[BTC_Fiat_pair_value]); - //console.log(BTCD_Fiat_pair_value); - localStorage.setItem('EasyDEX_BTCD_Fiat_pair_value', BTCD_Fiat_pair_value); //e.g BTCD/USD: 2.0873619962 - - var tmp_btcd_fiat_toal = parseFloat(BTCD_balance) * parseFloat(BTCD_Fiat_pair_value); - var tmp_btc_fiat_toal = parseFloat(BTC_balance) * parseFloat(tmp_btc_fiat[BTC_Fiat_pair_value]); - //console.log('total btc btcd usd value') - //console.log(tmp_btcd_fiat_toal); console.log(tmp_btc_fiat_toal); - - $('span[data-currency="BTC"][id="header_coinfiatbalance"]').text(tmp_btc_fiat_toal.toFixed(2) + ' ' + Fiat_Currency); - $('span[data-currency="BTCD"][id="header_coinfiatbalance"]').text(tmp_btcd_fiat_toal.toFixed(2) + ' ' + Fiat_Currency); + var RatesData = JSON.parse(data), + label_color = '', + label_icon = '', + wallettblContent = ''; + + localStorage.setItem('EasyDEX_BTCD_BTC_pair_value', RatesData.rates[0]['BTCD/BTC']); // e.g BTCD/BTC + localStorage.setItem('EasyDEX_BTC_Fiat_pair_value', RatesData.rates[1][BTC_Fiat_pair_value]); // e.g BTC/USD + localStorage.setItem('EasyDEX_Conversion_Fiat_Pair', Conversion_Fiat_Pair); // e.g EUR/USD + localStorage.setItem('EasyDEX_Conversion_Fiat_Pair_value', RatesData.rates[2][Conversion_Fiat_Pair]); // e.g EUR/USD: 1.11830926 + + var tmp_btcd_btc = RatesData.rates[0], + tmp_btc_fiat = RatesData.rates[1]; + BTCD_Fiat_pair_value = parseFloat(tmp_btcd_btc['BTCD/BTC']) * parseFloat(tmp_btc_fiat[BTC_Fiat_pair_value]); + localStorage.setItem('EasyDEX_BTCD_Fiat_pair_value', BTCD_Fiat_pair_value); // e.g BTCD/USD: 2.0873619962 + + var tmp_btcd_fiat_toal = parseFloat(BTCD_balance) * parseFloat(BTCD_Fiat_pair_value), + tmp_btc_fiat_toal = parseFloat(BTC_balance) * parseFloat(tmp_btc_fiat[BTC_Fiat_pair_value]); + + $('span[data-currency="BTC"][id="header_coinfiatbalance"]').text(tmp_btc_fiat_toal.toFixed(2) + ' ' + Fiat_Currency); + $('span[data-currency="BTCD"][id="header_coinfiatbalance"]').text(tmp_btcd_fiat_toal.toFixed(2) + ' ' + Fiat_Currency); }, 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('failed getting Coin History.'); + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } + console.log(textStatus); + console.log(error); } }); } } function StopTotalFiatValue() { - clearInterval(RunTotalFiatValue); - console.log('Stopped executing Total Fiat Value API with Rates'); + clearInterval(RunTotalFiatValue); + console.log('Stopped executing Total Fiat Value API with Rates'); } function ShowCoinProgressBar(coin) { - //console.log('Showing Prgoress bar of '+coin); - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var getinfoValues = {'userpass':tmpIguanaRPCAuth,"coin":coin,"agent":"bitcoinrpc","method":"getinfo","immediate":100,"timeout":4000}; + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'); + getinfoValues = { + 'userpass': tmpIguanaRPCAuth, + 'coin': coin, + 'agent': 'bitcoinrpc', + 'method': 'getinfo', + 'immediate': 100, + 'timeout': 4000 + }; + $.ajax({ - type: 'POST', - data: JSON.stringify(getinfoValues), + type: 'POST', + data: JSON.stringify(getinfoValues), + url: 'http://127.0.0.1:7778', + success: function(data, textStatus, jqXHR) { + var CoinInfoData = JSON.parse(data); + + // TODO: refactor + if (typeof CoinInfoData.bundles == 'undefined') { + //console.log(coin+' is undefined'); + } else { + if ( parseInt(CoinInfoData.RTheight) != 0 ) { + var coin_blocks = parseInt(CoinInfoData.blocks), + coin_blocks_plus1 = coin_blocks + 1; + + sessionStorage.setItem('Activate' + coin + 'History', 'Yes'); + $('div[data-edexcoin="'+coin+'"][id="currency-progressbars"]').show(); + $('div[data-edexcoin="'+coin+'"][id="currency-bundles"]').width(parseFloat(CoinInfoData.bundles).toFixed(2) + '%'); + $('span[data-edexcoin="'+coin+'"][id="currency-bundles-percent"]').text('(' + coin + ') ' + parseFloat(CoinInfoData.bundles).toFixed(2) + '% - ( ' + coin_blocks_plus1 + ' / '+ CoinInfoData.longestchain + ' ) ==>> RT' + CoinInfoData.RTheight); + $('div[data-edexcoin="'+coin+'"][id="additional-progress-bars"]').hide(); + $('div[data-edexcoin="'+coin+'"][id="currency-bundles"]').removeClass( 'progress-bar-info' ).addClass( 'progress-bar-indicating progress-bar-success' ); + $('#edex-footer').css('height', '11px'); + resizeDashboardWindow(); + $('#edexcoin-wallet-waitingrt-alert').hide() + } + if ( parseInt(CoinInfoData.RTheight) == 0 ) { + var coin_blocks = parseInt(CoinInfoData.blocks), + coin_blocks_plus1 = coin_blocks + 1; + + sessionStorage.setItem('Activate' + coin + 'History', 'No'); + console.log(coin + ': ' + CoinInfoData.bundles); + $('div[data-edexcoin="' + coin + '"][id="additional-progress-bars"]').show(); + $('div[data-edexcoin="' + coin + '"][id="currency-progressbars"]').show(); + $('div[data-edexcoin="' + coin + '"][id="currency-bundles"]').removeClass( 'progress-bar-indicating progress-bar-success' ).addClass( 'progress-bar-info' ); + $('div[data-edexcoin="' + coin + '"][id="currency-bundles"]').width(parseFloat(CoinInfoData.bundles).toFixed(2) + '%'); + $('span[data-edexcoin="' + coin + '"][id="currency-bundles-percent"]').text('(' + coin + ') ' + parseFloat(CoinInfoData.bundles).toFixed(2) + '% - ( ' + coin_blocks_plus1 + ' / ' + CoinInfoData.longestchain + ' )'); + $('div[data-edexcoin="' + coin + '"][id="currency-utxo"]').width(parseFloat(CoinInfoData.utxo).toFixed(2) + '%'); + $('span[data-edexcoin="' + coin + '"][id="currency-utxo-percent"]').text('(' + coin + ') ' + parseFloat(CoinInfoData.utxo).toFixed(2) + '%'); + $('div[data-edexcoin="' + coin + '"][id="currency-balances"]').width(parseFloat(CoinInfoData.balances).toFixed(2) + '%'); + $('span[data-edexcoin="' + coin + '"][id="currency-balances-percent"]').text('(' + coin + ') '+parseFloat(CoinInfoData.balances).toFixed(2) + '%'); + $('div[data-edexcoin="' + coin + '"][id="currency-validated"]').width(parseFloat(CoinInfoData.validated).toFixed(2) + '%'); + $('span[data-edexcoin="' + coin + '"][id="currency-validated-percent"]').text('(' + coin + ') '+parseFloat(CoinInfoData.validated).toFixed(2) + '%'); + $('#edex-footer').css('height', '44px'); + resizeDashboardWindow(); + $('#edexcoin-wallet-waitingrt-alert').show(); + } + } + }, + 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); + } + }); +} + +function EdexGetTxList(coin) { + NProgress.done(true); + NProgress.configure({ + template: '
' + + '
' + + '
' + + '
' + }); + NProgress.start(); + + return new Promise((resolve) => { + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + ajax_data_2 = { + 'userpass': tmpIguanaRPCAuth, + 'coin': coin, + 'agent': 'bitcoinrpc', + 'method': 'getaddressesbyaccount', + 'account': '*' + }, + active_edexcoinmodecode = sessionStorage.getItem('edexTmpMode'); + + $.ajax({ + data: JSON.stringify(ajax_data_2), url: 'http://127.0.0.1:7778', - //dataType: 'text', - success: function(data, textStatus, jqXHR) { - var CoinInfoData = JSON.parse(data); - //console.log('== Coin Info Data OutPut =='); + type: 'POST', + dataType: 'json' + }).then(data => { + var total_utxos = []; + let params = ''; + + Promise.all(data.result.map((coinaddr_value,coinaddr_index) => { + if ( active_edexcoinmodecode == 'Basilisk' ) { + if ( coin == 'BTC' || + coin == 'BTCD' || + coin == 'LTC' || + coin == 'DOGE' || + coin == 'DGB' || + coin == 'SYS' || + coin == 'MZC' || + coin == 'UNO' || + coin == 'ZET' || + coin == 'BTM' || + coin == 'CARB' || + coin == 'ANC' || + coin == 'FRK') { + params = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listtransactions', + 'address': coinaddr_value, + 'count': 100, + 'skip': 0, + 'symbol': coin + }; + } else { + params = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'listtransactions2', + 'address': coinaddr_value, + 'count': 100, + 'skip': 0, + 'symbol': coin + }; + } + } else { + params = { + 'userpass': tmpIguanaRPCAuth, + "coin": coin, + "method": "listtransactions", + "params": [ + 0, + 9999999, + [] + ] + }; + } - if (typeof CoinInfoData.bundles == 'undefined') { - //console.log(coin+' is undefined'); - } else { - if ( parseInt(CoinInfoData.RTheight) != 0 ) { - sessionStorage.setItem('Activate'+coin+'History', 'Yes'); - var coin_blocks = parseInt(CoinInfoData.blocks); - var coin_blocks_plus1 = coin_blocks + 1; - //console.log(coin+' is less than 99.98% complete.'); - $('div[data-edexcoin="'+coin+'"][id="currency-progressbars"]').show(); - $('div[data-edexcoin="'+coin+'"][id="currency-bundles"]').width(parseFloat(CoinInfoData.bundles).toFixed(2)+'%'); - $('span[data-edexcoin="'+coin+'"][id="currency-bundles-percent"]').text('('+coin+') '+parseFloat(CoinInfoData.bundles).toFixed(2)+'% - ( '+coin_blocks_plus1+' / '+CoinInfoData.longestchain+' ) ==>> RT'+CoinInfoData.RTheight); - $('div[data-edexcoin="'+coin+'"][id="additional-progress-bars"]').hide(); - $('div[data-edexcoin="'+coin+'"][id="currency-bundles"]').removeClass( "progress-bar-info" ).addClass( "progress-bar-indicating progress-bar-success" ); - $('#edex-footer').css("height", "11px"); - resizeDashboardWindow(); - $('#edexcoin-wallet-waitingrt-alert').hide() - //getCoinBalance(coin); - //EdexfillTxHistory(coin); + return new Promise((resolve, reject) => { + $.ajax({ + data: JSON.stringify(params), + url: 'http://127.0.0.1:7778', + type: 'POST', + dataType: 'json' + }).then(data => { + if ( active_edexcoinmodecode == 'Full' ) { + data = data.result; + } + //console.log(data) + total_utxos = $.merge(total_utxos, data); + resolve(total_utxos); + }); + }); + })).then(result => { + let result_data = result[result.length - 1]; + let compiled_result = []; + + $.each(result_data, function(index, value) { + if ( active_edexcoinmodecode == 'Full' || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'BTC') || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'BTCD' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'LTC' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'DOGE' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'DGB' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'SYS' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'MZC' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'UNO' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'ZET' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'BTM' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'CARB' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'ANC' ) || + ( active_edexcoinmodecode == 'Basilisk' && coin == 'FRK' ) ) { + var tmp_category = '', + tmp_amount = result_data[index].amount; + if (!('amount' in result_data[index])) { + tmp_amount = 'Unknown'; + } + + var tmp_addr = result_data[index].address; + if (!('address' in result_data[index])) { + tmp_addr = ' Z Address not listed by wallet!'; + } + + var tmp_secondsToString = secondsToString(result_data[index].blocktime); + + if ( result_data[index].category == 'send' ) { + tmp_category = ' OUT'; } - if ( parseInt(CoinInfoData.RTheight) == 0 ) { - sessionStorage.setItem('Activate'+coin+'History', 'No'); - console.log(coin+': '+CoinInfoData.bundles); - var coin_blocks = parseInt(CoinInfoData.blocks); - var coin_blocks_plus1 = coin_blocks + 1; - $('div[data-edexcoin="'+coin+'"][id="additional-progress-bars"]').show(); - $('div[data-edexcoin="'+coin+'"][id="currency-progressbars"]').show(); - $('div[data-edexcoin="'+coin+'"][id="currency-bundles"]').removeClass( "progress-bar-indicating progress-bar-success" ).addClass( "progress-bar-info" ); - $('div[data-edexcoin="'+coin+'"][id="currency-bundles"]').width(parseFloat(CoinInfoData.bundles).toFixed(2)+'%'); - $('span[data-edexcoin="'+coin+'"][id="currency-bundles-percent"]').text('('+coin+') '+parseFloat(CoinInfoData.bundles).toFixed(2)+'% - ( '+coin_blocks_plus1+' / '+CoinInfoData.longestchain+' )'); - $('div[data-edexcoin="'+coin+'"][id="currency-utxo"]').width(parseFloat(CoinInfoData.utxo).toFixed(2)+'%'); - $('span[data-edexcoin="'+coin+'"][id="currency-utxo-percent"]').text('('+coin+') '+parseFloat(CoinInfoData.utxo).toFixed(2)+'%'); - $('div[data-edexcoin="'+coin+'"][id="currency-balances"]').width(parseFloat(CoinInfoData.balances).toFixed(2)+'%'); - $('span[data-edexcoin="'+coin+'"][id="currency-balances-percent"]').text('('+coin+') '+parseFloat(CoinInfoData.balances).toFixed(2)+'%'); - $('div[data-edexcoin="'+coin+'"][id="currency-validated"]').width(parseFloat(CoinInfoData.validated).toFixed(2)+'%'); - $('span[data-edexcoin="'+coin+'"][id="currency-validated-percent"]').text('('+coin+') '+parseFloat(CoinInfoData.validated).toFixed(2)+'%'); - $('#edex-footer').css("height", "44px"); - resizeDashboardWindow(); - $('#edexcoin-wallet-waitingrt-alert').show() + if ( result_data[index].category == 'receive' ) { + tmp_category = ' IN'; } + if ( result_data[index].category == 'generate' ) { + tmp_category = ' Mined'; + }if ( result_data[index].category == 'immature' ) { + tmp_category = ' Immature'; + } + if ( result_data[index].category == 'unknown' ) { + tmp_category = ' Unknown'; + } + + tmplisttransactions = [ + tmp_category, + result_data[index].confirmations, + tmp_amount, + tmp_secondsToString, + tmp_addr, + '' + ]; + compiled_result.push(tmplisttransactions); } - }, - error: function(xhr, textStatus, error) { - console.log('failed getting Coin History.'); - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - Iguana_ServiceUnavailable(); + + if ( active_edexcoinmodecode == 'Basilisk' && + coin !== 'BTC' && + coin !== 'BTCD' && + coin !== 'LTC' && + coin !== 'DOGE' && + coin !== 'DGB' && + coin !== 'SYS' && + coin !== 'MZC' && + coin !== 'UNO' && + coin !== 'ZET' && + coin !== 'BTM' && + coin !== 'CARB' && + coin !== 'ANC' && + coin !== 'FRK' ) { + var tmp_category = '', + tmp_amount = result_data[index].amount; + + if (!('amount' in result_data[index])) { + tmp_amount = 'Unknown'; + } + + var tmp_addr = null + if (!('paid' in result_data[index])) { + tmp_addr = ' Z Address not listed by wallet!'; + } + if (('paid' in result_data[index])) { + var first_addr = Object.keys(result_data[index].paid['vouts'][0]), + tmp_addr = first_addr[0]; + } + + var tmp_secondsToString = secondsToString(result_data[index].timestamp); + + if ( result_data[index].type == 'sent' ) { + tmp_category = ' OUT'; + } + if ( result_data[index].type == 'received' ) { + tmp_category = ' IN'; + } + if ( result_data[index].type == 'generate' ) { + tmp_category = ' Mined'; + } + if ( result_data[index].type == 'immature' ) { + tmp_category = ' Immature'; + } + if ( result_data[index].type == 'unknown' ) { + tmp_category = ' Unknown'; + } + + if (!('confirmations' in result_data[index])) { + tmp_confirms = ' Unknown'; + } + if (('confirmations' in result_data[index])) { + tmp_confirms = result_data[index].confirmations; + } + + tmplisttransactions = [ + tmp_category, + tmp_confirms, + tmp_amount, + tmp_secondsToString, + tmp_addr, + '' + ]; + compiled_result.push(tmplisttransactions); } - console.log(textStatus); - console.log(error); - } + }); + + resolve(compiled_result); + NProgress.done(); + }); + }); }); } - -function EdexGetTxList(coin) { +function EdexGetTxList_cache(coin) { NProgress.done(true); NProgress.configure({ - template: '
' + template: '
' + + '
' + + '
' + + '
' }); NProgress.start(); - return new Promise((resolve) =>{ - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var ajax_data_2 = {'userpass':tmpIguanaRPCAuth,"coin":coin,"agent":"bitcoinrpc","method":"getaddressesbyaccount","account":"*"} - var active_edexcoinmodecode = sessionStorage.getItem('edexTmpMode'); - $.ajax({ - data: JSON.stringify(ajax_data_2), - url: 'http://127.0.0.1:7778', - type: 'POST', - dataType: 'json', - }).then(data => { - //console.log(data) - var total_utxos = [] - let params = '' - Promise.all(data.result.map((coinaddr_value,coinaddr_index) => { - if ( active_edexcoinmodecode == 'Basilisk' ) { - if ( coin == 'BTC' - || coin == 'BTCD' - || coin == 'LTC' - || coin == 'DOGE' - || coin == 'DGB' - || coin == 'SYS' - || coin == 'MZC' - || coin == 'UNO' - || coin == 'ZET' - || coin == 'BTM' - || coin == 'CARB' - || coin == 'ANC' - || coin == 'FRK') { - params = {'userpass':tmpIguanaRPCAuth,"agent":"dex","method":"listtransactions","address":coinaddr_value,"count":100,"skip":0,"symbol":coin} - } else { - params = {'userpass':tmpIguanaRPCAuth,"agent":"dex","method":"listtransactions2","address":coinaddr_value,"count":100,"skip":0,"symbol":coin} - } - } else { - params = {'userpass':tmpIguanaRPCAuth,"coin":coin,"method":"listtransactions","params":[0, 9999999, []]} + + return new Promise((resolve) => { + Shepherd_GetBasiliskCache().then(function(result) { + var _data = JSON.parse(result) + query = _data.result.basilisk; + + var active_edexcoinmodecode = sessionStorage.getItem('edexTmpMode'), + total_utxos = []; + + Promise.all(query[coin].addresses.map((coinaddr_value, coinaddr_index) => { + return new Promise((resolve, reject) => { + var data = query[coin][coinaddr_value].listtransactions; + + total_utxos = $.merge(total_utxos, data); + resolve(total_utxos); + }); + })).then(result => { + let result_data = result[result.length - 1]; + let compiled_result = []; + + $.each(result_data, function(index, value) { + if ( active_edexcoinmodecode == 'Basilisk' && coin !== 'BTC' && coin !== 'SYS') { + var tmp_category = '', + tmp_amount = result_data[index].amount; + + if (!('amount' in result_data[index])) { + tmp_amount = 'Unknown'; + } + + var tmp_addr = null + if (!('paid' in result_data[index])) { + tmp_addr = ' Z Address not listed by wallet!'; + } + if (('paid' in result_data[index])) { + var first_addr = Object.keys(result_data[index].paid['vouts'][0]), + tmp_addr = first_addr[0]; + } + + var tmp_secondsToString = secondsToString(result_data[index].timestamp); + + if ( result_data[index].type == 'sent' ) { + tmp_category = ' OUT'; + } + if ( result_data[index].type == 'received' ) { + tmp_category = ' IN'; + } + if ( result_data[index].type == 'generate' ) { + tmp_category = ' Mined'; + } + if ( result_data[index].type == 'immature' ) { + tmp_category = ' Immature'; + } + if ( result_data[index].type == 'unknown' ) { + tmp_category = ' Unknown'; } - //console.log(params) - return new Promise((resolve, reject) => { - $.ajax({ - data: JSON.stringify(params), - url: 'http://127.0.0.1:7778', - type: 'POST', - dataType: 'json', - }).then(data => { - if ( active_edexcoinmodecode == 'Full' ) { - data = data.result; - } - //console.log(data) - total_utxos = $.merge(total_utxos, data) - resolve(total_utxos) - }) - }) - - })).then(result => { - let result_data = result[result.length-1] - //console.log(result_data) - - let compiled_result = [] - $.each(result_data, function(index, value) { - //console.log(value) - if ( active_edexcoinmodecode == 'Full' - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'BTC') - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'BTCD' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'LTC' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'DOGE' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'DGB' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'SYS' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'MZC' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'UNO' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'ZET' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'BTM' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'CARB' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'ANC' ) - || ( active_edexcoinmodecode == 'Basilisk' && coin == 'FRK' ) ) { - var tmp_category = ''; - var tmp_amount = result_data[index].amount; - if(!("amount" in result_data[index])) { - tmp_amount = 'Unknown' - } - var tmp_addr = result_data[index].address; - if(!("address" in result_data[index])) { - tmp_addr = ' Z Address not listed by wallet!' - } - - //tmp_secondsToString = ' Unknown' - //if(("blocktime" in result_data[index])) { - //console.log('blocktime FOUND'); - //var tmp_secondsToString = secondsToString(result_data[index].blocktime) - //} - - var tmp_secondsToString = secondsToString(result_data[index].blocktime) - - if (isNaN(tmp_secondsToString)) { - //tmp_secondsToString = 'Unknown'; - } - if ( result_data[index].category == 'send' ) { - tmp_category = ' OUT'; - } - if ( result_data[index].category == 'receive' ) { - tmp_category = ' IN'; - } - if ( result_data[index].category == 'generate' ) { - tmp_category = ' Mined'; - }if ( result_data[index].category == 'immature' ) { - tmp_category = ' Immature'; - } - if ( result_data[index].category == 'unknown' ) { - tmp_category = ' Unknown'; - } - //console.log(tmp_addr); - //tmplisttransactions = {"category": result_data[index].category,"confirmations": result_data[index].confirmations,"amount": result_data[index].amount,"time": result_data[index].time,"address": result_data[index].address,"txid": result_data[index].txid} - tmplisttransactions = [tmp_category,result_data[index].confirmations,tmp_amount,tmp_secondsToString,tmp_addr,''] - //console.log(tmplisttransactions); - compiled_result.push(tmplisttransactions); - } - - if ( active_edexcoinmodecode == 'Basilisk' - && coin !== 'BTC' - && coin !== 'BTCD' - && coin !== 'LTC' - && coin !== 'DOGE' - && coin !== 'DGB' - && coin !== 'SYS' - && coin !== 'MZC' - && coin !== 'UNO' - && coin !== 'ZET' - && coin !== 'BTM' - && coin !== 'CARB' - && coin !== 'ANC' - && coin !== 'FRK' ) { - var tmp_category = ''; - var tmp_amount = result_data[index].amount; - if(!("amount" in result_data[index])) { - tmp_amount = 'Unknown' - } - var tmp_addr = null - if(!("paid" in result_data[index])) { - tmp_addr = ' Z Address not listed by wallet!' - } - if(("paid" in result_data[index])) { - var first_addr = Object.keys(result_data[index].paid['vouts'][0]); - var tmp_addr = first_addr[0]; - //console.log(result_data[index].paid['vouts'][0]) - - } - - //tmp_secondsToString = ' Unknown' - //if(("blocktime" in result_data[index])) { - //console.log('blocktime FOUND'); - //var tmp_secondsToString = secondsToString(result_data[index].blocktime) - //} - - var tmp_secondsToString = secondsToString(result_data[index].timestamp) - - if (isNaN(tmp_secondsToString)) { - //tmp_secondsToString = 'Unknown'; - } - - //console.log(result_data[index].type) - if ( result_data[index].type == 'sent' ) { - tmp_category = ' OUT'; - } - if ( result_data[index].type == 'received' ) { - tmp_category = ' IN'; - } - if ( result_data[index].type == 'generate' ) { - tmp_category = ' Mined'; - }if ( result_data[index].type == 'immature' ) { - tmp_category = ' Immature'; - } - if ( result_data[index].type == 'unknown' ) { - tmp_category = ' Unknown'; - } - - - if(!("confirmations" in result_data[index])) { - tmp_confirms = ' Unknown'; - } - if(("confirmations" in result_data[index])) { - tmp_confirms = result_data[index].confirmations - } - - //console.log(tmp_addr); - //tmplisttransactions = {"category": result_data[index].category,"confirmations": result_data[index].confirmations,"amount": result_data[index].amount,"time": result_data[index].time,"address": result_data[index].address,"txid": result_data[index].txid} - tmplisttransactions = [tmp_category,tmp_confirms,tmp_amount,tmp_secondsToString,tmp_addr,''] - //console.log(tmplisttransactions); - compiled_result.push(tmplisttransactions); - } - }) - - //console.log(compiled_result) - resolve(compiled_result); - NProgress.done(); + if (!('confirmations' in result_data[index])) { + tmp_confirms = ' Unknown'; + } + if (('confirmations' in result_data[index])) { + tmp_confirms = result_data[index].confirmations; + } + + tmplisttransactions = [ + tmp_category, + tmp_confirms, + tmp_amount, + tmp_secondsToString, + tmp_addr, + '' + ]; + compiled_result.push(tmplisttransactions); + } }) - }) - }) + + resolve(compiled_result); + NProgress.done(); + }); + }); + }); } /*function EdexGetTxList(coin) { @@ -1919,51 +2235,58 @@ function EdexGetTxList(coin) { }*/ function clearEdexSendFieldData() { - //$('.showedexcoinaddrs').selectpicker('refresh'); - //$('#edexcoin_sendto').val(''); - //$('#edexcoin_total_value').text(''); - //$('#edexcoin_amount').val(''); + //$('.showedexcoinaddrs').selectpicker('refresh'); + //$('#edexcoin_sendto').val(''); + //$('#edexcoin_total_value').text(''); + //$('#edexcoin_amount').val(''); } function EdexListAllAddr(coin) { - NProgress.done(true); - NProgress.configure({ - template: '
' + NProgress.done(true); + NProgress.configure({ + template: '
' + + '
' + + '
' + + '
' + }); + NProgress.start(); + + EDEXgetaddrbyaccount(coin).then(function(result) { + console.log(result) + var only_reciving_addr_data = []; + + $.each(result, function(index, value) { + if(value.interest == undefined || coin !== 'KMD') { + console.log('interest is undefined') + tmp_interest = 'NA' + } else { + tmp_interest = value.interest + } + only_reciving_addr_data.push([ + value.label, + value.addr, + value.total, + tmp_interest + ]); }); - NProgress.start(); - - EDEXgetaddrbyaccount(coin).then(function(result){ - console.log(result) - var only_reciving_addr_data = []; - - $.each(result, function(index, value) { - //console.log(index) - //console.log(value) - //tmp_addr_label = ' public'; - //var tmp_addr_action_button = ''; - if(value.interest == undefined || coin !== 'KMD') { - console.log('interest is undefined') - tmp_interest = 'NA' - } else { - tmp_interest = value.interest - } - only_reciving_addr_data.push([value.label, value.addr, value.total,tmp_interest]); - }); - console.log(only_reciving_addr_data); + console.log(only_reciving_addr_data); - var edexcoin_recieve_table = ''; + var edexcoin_recieve_table = ''; - edexcoin_recieve_table = $('#edexcoin-recieve-addr-tbl').DataTable( { data: only_reciving_addr_data, - select: false, - retrieve: true - }); + edexcoin_recieve_table = $('#edexcoin-recieve-addr-tbl').DataTable({ + data: only_reciving_addr_data, + select: false, + retrieve: true + }); - edexcoin_recieve_table.destroy(); + edexcoin_recieve_table.destroy(); - edexcoin_recieve_table = $('#edexcoin-recieve-addr-tbl').DataTable( { data: only_reciving_addr_data, - select: false, - retrieve: true - }); - NProgress.done(); - }) -} + edexcoin_recieve_table = $('#edexcoin-recieve-addr-tbl').DataTable({ + data: only_reciving_addr_data, + select: false, + retrieve: true + }); + + NProgress.done(); + }); +} \ No newline at end of file diff --git a/assets/scripts/iguana_api.js b/assets/scripts/iguana_api.js index f743a0b..e216200 100644 --- a/assets/scripts/iguana_api.js +++ b/assets/scripts/iguana_api.js @@ -646,6 +646,9 @@ function Iguana_addcoin(addcoin_data) { console.log('command NOT executed from login. RELOADING WALLET WIDGETS...'); refreshEDEXCoinWalletList() //Iguana_DEXImportAll(); + Shepherd_FetchBasiliskData().then(function(result){ + console.log(result) + }) //EDEXMainAddr(addcoin_data.coin).then(function(result){ //console.log(result) //Iguana_DEXImportAddr(addcoin_data.coin,result); @@ -1831,3 +1834,49 @@ function Shepherd_herdlist(data) { }) } + + +function Shepherd_FetchBasiliskData() { + return new Promise((resolve) =>{ + var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); + parse_session_data = sessionStorage.getItem('IguanaActiveAccount') + parse_session_data = JSON.parse(JSON.parse(parse_session_data)) + session_pubkey = parse_session_data.pubkey + + var ajax_data = {'userpass':tmpIguanaRPCAuth,'pubkey':session_pubkey} + + $.ajax({ + type: 'GET', + data: ajax_data, + url: 'http://127.0.0.1:17777/shepherd/allcoins', + contentType: 'application/json', // send as JSON + }).done(function(data) { + //console.log(data) + resolve(data) + }) + }) +} + + + +function Shepherd_GetBasiliskCache() { + return new Promise((resolve) =>{ + var parse_session_data = sessionStorage.getItem('IguanaActiveAccount') + parse_session_data = JSON.parse(JSON.parse(parse_session_data)) + session_pubkey = parse_session_data.pubkey + + var ajax_data = {'pubkey':session_pubkey} + + $.ajax({ + type: 'GET', + data: ajax_data, + url: 'http://127.0.0.1:17777/shepherd/cache', + contentType: 'application/json', // send as JSON + }).done(function(data) { + //console.log(data) + resolve(data) + }) + }) +} + + diff --git a/assets/scripts/login.js b/assets/scripts/login.js index 4009c05..cb66be4 100644 --- a/assets/scripts/login.js +++ b/assets/scripts/login.js @@ -99,7 +99,10 @@ var Login = function() { $('body').removeClass( "page-login layout-full page-dark" ).addClass( "" ); $('link[id=loginStyle]')[0].disabled=true; //refreshEDEXCoinWalletList() - location.reload(); + Shepherd_FetchBasiliskData().then(function(result){ + console.log(result) + location.reload(); + }) } else { // If something goes wrong, alert the error message that our service returned @@ -821,7 +824,7 @@ var Login = function() { handleCheckLogin(); handleLoginAnotherWallet(); handleAddCoinLoginBtn(); - handleAddCoinOSOptions(); + //handleAddCoinOSOptions(); }