Browse Source

fixed CheckIfConnected async false

master
Petr Balashov 8 years ago
parent
commit
4d4c0bcc6e
  1. 2
      assets/scripts/dashboard.js
  2. 273
      assets/scripts/kmd_wallet/KMDInit.js
  3. 11
      assets/scripts/kmd_wallet_dashboard.js

2
assets/scripts/dashboard.js

@ -1085,7 +1085,7 @@ var Dashboard = function() {
}); });
} }
}, 1000); }, 10000);
var FetchBasiliskData = setInterval(function() { var FetchBasiliskData = setInterval(function() {
var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'), var active_edexcoin = $('[data-edexcoin]').attr('data-edexcoin'),

273
assets/scripts/kmd_wallet/KMDInit.js

@ -15,155 +15,158 @@ function RunKMDInitFunctions() {
}); });
NProgress.start(); NProgress.start();
var check1 = CheckIfConnected(); function _RunKMDInitFunctions(check1) {
console.log(check1[0]); console.log(check1[0]);
if ( check1[0] == 'not active' ) { if ( check1[0] == 'not active' ) {
console.log('Could not connect to external wallet. Is external wallet running?'); 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); toastr.error(_lang[defaultLang].TOASTR.KMD_NATIVE_CON_ERROR, _lang[defaultLang].TOASTR.WALLET_NOTIFICATION);
$('#extcoin-wallet').hide(); $('#extcoin-wallet').hide();
$('#extcoin-wallet-connection-alert').show(); $('#extcoin-wallet-connection-alert').show();
} }
if ( check1[0] == 'null return' ) { if ( check1[0] == 'null return' ) {
console.log('Could not connect to external wallet. Is iguana connected to external wallet?'); 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); toastr.error(_lang[defaultLang].TOASTR.KMD_IGUANA_CON_ERROR, _lang[defaultLang].TOASTR.WALLET_NOTIFICATION);
$('#extcoin-wallet').hide(); $('#extcoin-wallet').hide();
$('#extcoin-wallet-connection-alert').show(); $('#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);
}
});
} }
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() { function getRemoteCurrentHeight() {
var extcoin = $('[data-extcoin]').attr('data-extcoin'); var extcoin = $('[data-extcoin]').attr('data-extcoin');
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: 'http://localhost:' + config.iguanaPort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + extcoin, url: 'http://localhost:' + config.iguanaPort + '/api/dex/getinfo?userpass=tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth') + '&symbol=' + extcoin,
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
data = JSON.parse(data); data = JSON.parse(data);
if (data && data.blocks) { if (data && data.blocks) {
totalBlocksInExplorer = 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); var currentBestBlockInterval;
console.log(textStatus); function startBestBlockInterval() {
console.log(error); currentBestBlockInterval = setInterval(function() {
} if (!chainActivationLastUpdate || checkTimestamp(chainActivationLastUpdate) > chainActivationLastUpdateTimeout) {
}); $.ajax({
} type: 'POST',
data: {
var currentBestBlockInterval; 'herdname': 'komodo',
function startBestBlockInterval() { 'lastLines': 1
currentBestBlockInterval = setInterval(function() { },
if (!chainActivationLastUpdate || checkTimestamp(chainActivationLastUpdate) > chainActivationLastUpdateTimeout) { url: 'http://127.0.0.1:17777/shepherd/debuglog',
$.ajax({ success: function(data, textStatus, jqXHR) {
type: 'POST', if (data.indexOf('UpdateTip') > -1) {
data: { var temp = data.split(' ');
'herdname': 'komodo',
'lastLines': 1 for (var i = 0; i < temp.length; i++) {
}, if (temp[i].indexOf('height=') > -1) {
url: 'http://127.0.0.1:17777/shepherd/debuglog', var currentBestChain = temp[i].replace('height=', '');
success: function(data, textStatus, jqXHR) { $('#activating-komodod-tridot').hide();
if (data.indexOf('UpdateTip') > -1) { $('#activating-komodod-progress').html(': ' + Math.floor(currentBestChain * 100 / totalBlocksInExplorer) + '% (blocks ' + currentBestChain + ' / ' + totalBlocksInExplorer + ')');
var temp = data.split(' '); chainActivationLastUpdate = Date.now();
if (currentBestChain === totalBlocksInExplorer) {
for (var i = 0; i < temp.length; i++) { clearInterval(currentBestBlockInterval);
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'); }, 2000);
console.log(xhr.statusText); }
console.log(textStatus);
console.log(error);
}
});
}
}, 2000);
}
if (sessionStorage.getItem('edexTmpMode') === 'Native') {
getRemoteCurrentHeight();
var totalBlocksInExplorer = 0, if (sessionStorage.getItem('edexTmpMode') === 'Native') {
totalBlocksInExplorerInterval = setInterval(function() {
getRemoteCurrentHeight(); getRemoteCurrentHeight();
_getKMDInfo();
}, 60000); var totalBlocksInExplorer = 0,
} else { totalBlocksInExplorerInterval = setInterval(function() {
clearInterval(totalBlocksInExplorerInterval); getRemoteCurrentHeight();
clearInterval(currentBestBlockInterval); _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_recieve_section').hide();
$('#kmd_wallet_settings').hide(); NProgress.done();
} }
CheckIfConnected(_RunKMDInitFunctions);
$('#kmd_wallet_recieve_section').hide();
NProgress.done();
} }

11
assets/scripts/kmd_wallet_dashboard.js

@ -55,7 +55,7 @@ function getPassthruAgent() {
return passthru_agent; return passthru_agent;
} }
function CheckIfConnected() { function CheckIfConnected(cb) {
var result = [], var result = [],
extcoin = $('[data-extcoin]').attr('data-extcoin'), extcoin = $('[data-extcoin]').attr('data-extcoin'),
passthru_agent = getPassthruAgent(), passthru_agent = getPassthruAgent(),
@ -82,7 +82,7 @@ function CheckIfConnected() {
console.log(ajax_data); console.log(ajax_data);
$.ajax({ $.ajax({
async: false, //async: false,
type: 'POST', type: 'POST',
data: JSON.stringify(ajax_data), data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:' + config.iguanaPort, url: 'http://127.0.0.1:' + config.iguanaPort,
@ -98,6 +98,8 @@ function CheckIfConnected() {
} else { } else {
result.push(AjaxOutputData.errors); result.push(AjaxOutputData.errors);
} }
cb.call(this, result);
}, },
error: function(xhr, textStatus, error) { error: function(xhr, textStatus, error) {
console.log('failed getting Coin History.'); console.log('failed getting Coin History.');
@ -107,12 +109,15 @@ function CheckIfConnected() {
} }
console.log(textStatus); console.log(textStatus);
console.log(error); console.log(error);
cb.call(this, result);
} }
}); });
return result; return result;
} }
// TODO: this func is not used anywhere
function CheckIfWalletEncrypted() { function CheckIfWalletEncrypted() {
var result = [], var result = [],
passthru_agent = getPassthruAgent(), passthru_agent = getPassthruAgent(),
@ -195,7 +200,6 @@ function KMD_getInfo_rtrn(cb) {
} }
$.ajax({ $.ajax({
//async: true,
type: 'POST', type: 'POST',
data: JSON.stringify(ajax_data), data: JSON.stringify(ajax_data),
url: 'http://127.0.0.1:' + config.iguanaPort, url: 'http://127.0.0.1:' + config.iguanaPort,
@ -222,6 +226,7 @@ function KMD_getInfo_rtrn(cb) {
} }
console.log(textStatus); console.log(textStatus);
console.log(error); console.log(error);
cb.call(this, result);
} }
}); });

Loading…
Cancel
Save