From 4d4c0bcc6edeec9f5c5b1e25176bede268969184 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Wed, 29 Mar 2017 12:43:42 -0700 Subject: [PATCH] fixed CheckIfConnected async false --- assets/scripts/dashboard.js | 2 +- assets/scripts/kmd_wallet/KMDInit.js | 273 +++++++++++++------------ assets/scripts/kmd_wallet_dashboard.js | 11 +- 3 files changed, 147 insertions(+), 139 deletions(-) diff --git a/assets/scripts/dashboard.js b/assets/scripts/dashboard.js index 2fe2eff..7d69e9f 100644 --- a/assets/scripts/dashboard.js +++ b/assets/scripts/dashboard.js @@ -1085,7 +1085,7 @@ var Dashboard = function() { }); } - }, 1000); + }, 10000); var FetchBasiliskData = setInterval(function() { var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'), diff --git a/assets/scripts/kmd_wallet/KMDInit.js b/assets/scripts/kmd_wallet/KMDInit.js index 890d484..dad995d 100644 --- a/assets/scripts/kmd_wallet/KMDInit.js +++ b/assets/scripts/kmd_wallet/KMDInit.js @@ -15,155 +15,158 @@ function RunKMDInitFunctions() { }); NProgress.start(); - var check1 = CheckIfConnected(); - console.log(check1[0]); - if ( check1[0] == 'not active' ) { - console.log('Could not connect to external wallet. Is external wallet running?'); - toastr.error(_lang[defaultLang].TOASTR.KMD_NATIVE_CON_ERROR, _lang[defaultLang].TOASTR.WALLET_NOTIFICATION); - $('#extcoin-wallet').hide(); - $('#extcoin-wallet-connection-alert').show(); - } - if ( check1[0] == 'null return' ) { - console.log('Could not connect to external wallet. Is iguana connected to external wallet?'); - toastr.error(_lang[defaultLang].TOASTR.KMD_IGUANA_CON_ERROR, _lang[defaultLang].TOASTR.WALLET_NOTIFICATION); - $('#extcoin-wallet').hide(); - $('#extcoin-wallet-connection-alert').show(); - } - if ( check1[0] == 'activating' ) { - $('#extcoin-wallet-activating-alert').show(); - $('#extcoin-wallet').show(); - $('#extcoin-wallet-connection-alert').hide(); - - function _getKMDInfo() { - var passthru_agent = getPassthruAgent(), - tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), - ajax_data = { - 'userpass': tmpIguanaRPCAuth, - 'agent': passthru_agent, - 'method': 'passthru', - 'function': 'getinfo', - 'hex': '' - }; - - console.log(ajax_data); - $.ajax({ - type: 'POST', - data: JSON.stringify(ajax_data), - url: 'http://127.0.0.1:' + config.iguanaPort, - success: function(data, textStatus, jqXHR) { - var AjaxOutputData = JSON.parse(data); - - if (AjaxOutputData && !AjaxOutputData.blocks) { - startBestBlockInterval(); - } else { - clearInterval(currentBestBlockInterval); - } - }, - 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 _RunKMDInitFunctions(check1) { + console.log(check1[0]); + if ( check1[0] == 'not active' ) { + console.log('Could not connect to external wallet. Is external wallet running?'); + toastr.error(_lang[defaultLang].TOASTR.KMD_NATIVE_CON_ERROR, _lang[defaultLang].TOASTR.WALLET_NOTIFICATION); + $('#extcoin-wallet').hide(); + $('#extcoin-wallet-connection-alert').show(); + } + if ( check1[0] == 'null return' ) { + console.log('Could not connect to external wallet. Is iguana connected to external wallet?'); + toastr.error(_lang[defaultLang].TOASTR.KMD_IGUANA_CON_ERROR, _lang[defaultLang].TOASTR.WALLET_NOTIFICATION); + $('#extcoin-wallet').hide(); + $('#extcoin-wallet-connection-alert').show(); } + if ( check1[0] == 'activating' ) { + $('#extcoin-wallet-activating-alert').show(); + $('#extcoin-wallet').show(); + $('#extcoin-wallet-connection-alert').hide(); + + function _getKMDInfo() { + var passthru_agent = getPassthruAgent(), + tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + ajax_data = { + 'userpass': tmpIguanaRPCAuth, + 'agent': passthru_agent, + 'method': 'passthru', + 'function': 'getinfo', + 'hex': '' + }; + + console.log(ajax_data); + $.ajax({ + type: 'POST', + data: JSON.stringify(ajax_data), + url: 'http://127.0.0.1:' + config.iguanaPort, + success: function(data, textStatus, jqXHR) { + var AjaxOutputData = JSON.parse(data); + + if (AjaxOutputData && !AjaxOutputData.blocks) { + startBestBlockInterval(); + } else { + clearInterval(currentBestBlockInterval); + } + }, + 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 getRemoteCurrentHeight() { - var extcoin = $('[data-extcoin]').attr('data-extcoin'); + function getRemoteCurrentHeight() { + var extcoin = $('[data-extcoin]').attr('data-extcoin'); - $.ajax({ - type: 'GET', - url: 'http://localhost:' + config.iguanaPort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + extcoin, - success: function(data, textStatus, jqXHR) { - data = JSON.parse(data); + $.ajax({ + type: 'GET', + url: 'http://localhost:' + config.iguanaPort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + extcoin, + success: function(data, textStatus, jqXHR) { + data = JSON.parse(data); - if (data && data.blocks) { - totalBlocksInExplorer = data.blocks; + if (data && data.blocks) { + totalBlocksInExplorer = data.blocks; + } + }, + error: function(xhr, textStatus, error) { + console.log('failed getinfo from dex api'); + console.log(xhr.statusText); + console.log(textStatus); + console.log(error); } - }, - error: function(xhr, textStatus, error) { - console.log('failed getinfo from dex api'); - console.log(xhr.statusText); - console.log(textStatus); - console.log(error); - } - }); - } - - var currentBestBlockInterval; - function startBestBlockInterval() { - currentBestBlockInterval = setInterval(function() { - if (!chainActivationLastUpdate || checkTimestamp(chainActivationLastUpdate) > chainActivationLastUpdateTimeout) { - $.ajax({ - type: 'POST', - data: { - 'herdname': 'komodo', - 'lastLines': 1 - }, - url: 'http://127.0.0.1:17777/shepherd/debuglog', - success: function(data, textStatus, jqXHR) { - if (data.indexOf('UpdateTip') > -1) { - var temp = data.split(' '); - - for (var i = 0; i < temp.length; i++) { - if (temp[i].indexOf('height=') > -1) { - var currentBestChain = temp[i].replace('height=', ''); - $('#activating-komodod-tridot').hide(); - $('#activating-komodod-progress').html(': ' + Math.floor(currentBestChain * 100 / totalBlocksInExplorer) + '% (blocks ' + currentBestChain + ' / ' + totalBlocksInExplorer + ')'); - chainActivationLastUpdate = Date.now(); - if (currentBestChain === totalBlocksInExplorer) { - clearInterval(currentBestBlockInterval); + }); + } + + var currentBestBlockInterval; + function startBestBlockInterval() { + currentBestBlockInterval = setInterval(function() { + if (!chainActivationLastUpdate || checkTimestamp(chainActivationLastUpdate) > chainActivationLastUpdateTimeout) { + $.ajax({ + type: 'POST', + data: { + 'herdname': 'komodo', + 'lastLines': 1 + }, + url: 'http://127.0.0.1:17777/shepherd/debuglog', + success: function(data, textStatus, jqXHR) { + if (data.indexOf('UpdateTip') > -1) { + var temp = data.split(' '); + + for (var i = 0; i < temp.length; i++) { + if (temp[i].indexOf('height=') > -1) { + var currentBestChain = temp[i].replace('height=', ''); + $('#activating-komodod-tridot').hide(); + $('#activating-komodod-progress').html(': ' + Math.floor(currentBestChain * 100 / totalBlocksInExplorer) + '% (blocks ' + currentBestChain + ' / ' + totalBlocksInExplorer + ')'); + chainActivationLastUpdate = Date.now(); + if (currentBestChain === totalBlocksInExplorer) { + clearInterval(currentBestBlockInterval); + } } } } + }, + error: function(xhr, textStatus, error) { + console.log('failed getting debug.log'); + console.log(xhr.statusText); + console.log(textStatus); + console.log(error); } - }, - error: function(xhr, textStatus, error) { - console.log('failed getting debug.log'); - console.log(xhr.statusText); - console.log(textStatus); - console.log(error); - } - }); - } - }, 2000); - } - - if (sessionStorage.getItem('edexTmpMode') === 'Native') { - getRemoteCurrentHeight(); + }); + } + }, 2000); + } - var totalBlocksInExplorer = 0, - totalBlocksInExplorerInterval = setInterval(function() { + if (sessionStorage.getItem('edexTmpMode') === 'Native') { getRemoteCurrentHeight(); - _getKMDInfo(); - }, 60000); - } else { - clearInterval(totalBlocksInExplorerInterval); - clearInterval(currentBestBlockInterval); + + var totalBlocksInExplorer = 0, + totalBlocksInExplorerInterval = setInterval(function() { + getRemoteCurrentHeight(); + _getKMDInfo(); + }, 60000); + } else { + clearInterval(totalBlocksInExplorerInterval); + clearInterval(currentBestBlockInterval); + } + + $('#kmd_wallet_dashoard_section').show(); + $('#kmd_wallet_dashboardinfo').show(); + $('#kmd_wallet_send').hide(); + $('#kmd_wallet_recieve_section').hide(); + $('#kmd_wallet_settings').hide(); + } + if ( check1[0] == 'connected') { + getTotalKMDBalance(); + KMDfillTxHistoryT(); + $('#extcoin-wallet').show(); + $('#extcoin-wallet-connection-alert').hide(); + + $('#kmd_wallet_dashoard_section').show(); + $('#kmd_wallet_dashboardinfo').show(); + $('#kmd_wallet_send').hide(); + $('#kmd_wallet_recieve_section').hide(); + $('#kmd_wallet_settings').hide(); } - $('#kmd_wallet_dashoard_section').show(); - $('#kmd_wallet_dashboardinfo').show(); - $('#kmd_wallet_send').hide(); - $('#kmd_wallet_recieve_section').hide(); - $('#kmd_wallet_settings').hide(); - } - if ( check1[0] == 'connected') { - getTotalKMDBalance(); - KMDfillTxHistoryT(); - $('#extcoin-wallet').show(); - $('#extcoin-wallet-connection-alert').hide(); - - $('#kmd_wallet_dashoard_section').show(); - $('#kmd_wallet_dashboardinfo').show(); - $('#kmd_wallet_send').hide(); $('#kmd_wallet_recieve_section').hide(); - $('#kmd_wallet_settings').hide(); + NProgress.done(); } + CheckIfConnected(_RunKMDInitFunctions); - $('#kmd_wallet_recieve_section').hide(); - NProgress.done(); } \ No newline at end of file diff --git a/assets/scripts/kmd_wallet_dashboard.js b/assets/scripts/kmd_wallet_dashboard.js index 9056ec2..a47af8f 100644 --- a/assets/scripts/kmd_wallet_dashboard.js +++ b/assets/scripts/kmd_wallet_dashboard.js @@ -55,7 +55,7 @@ function getPassthruAgent() { return passthru_agent; } -function CheckIfConnected() { +function CheckIfConnected(cb) { var result = [], extcoin = $('[data-extcoin]').attr('data-extcoin'), passthru_agent = getPassthruAgent(), @@ -82,7 +82,7 @@ function CheckIfConnected() { console.log(ajax_data); $.ajax({ - async: false, + //async: false, type: 'POST', data: JSON.stringify(ajax_data), url: 'http://127.0.0.1:' + config.iguanaPort, @@ -98,6 +98,8 @@ function CheckIfConnected() { } else { result.push(AjaxOutputData.errors); } + + cb.call(this, result); }, error: function(xhr, textStatus, error) { console.log('failed getting Coin History.'); @@ -107,12 +109,15 @@ function CheckIfConnected() { } console.log(textStatus); console.log(error); + + cb.call(this, result); } }); return result; } +// TODO: this func is not used anywhere function CheckIfWalletEncrypted() { var result = [], passthru_agent = getPassthruAgent(), @@ -195,7 +200,6 @@ function KMD_getInfo_rtrn(cb) { } $.ajax({ - //async: true, type: 'POST', data: JSON.stringify(ajax_data), url: 'http://127.0.0.1:' + config.iguanaPort, @@ -222,6 +226,7 @@ function KMD_getInfo_rtrn(cb) { } console.log(textStatus); console.log(error); + cb.call(this, result); } });