From 6eff3caac21057fee81228d4e58a6d51580d49ea Mon Sep 17 00:00:00 2001 From: Satinder Grewal Date: Tue, 6 Sep 2016 12:13:36 +1200 Subject: [PATCH] error checks and notifications update --- assets/scripts/dashboard.js | 19 ++++- assets/scripts/iguana_api.js | 22 +++++- assets/scripts/login.js | 146 +++++++++++++++-------------------- 3 files changed, 100 insertions(+), 87 deletions(-) diff --git a/assets/scripts/dashboard.js b/assets/scripts/dashboard.js index 06169ca..183a469 100644 --- a/assets/scripts/dashboard.js +++ b/assets/scripts/dashboard.js @@ -191,6 +191,9 @@ var Dashboard = function() { 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); } @@ -215,6 +218,9 @@ var Dashboard = function() { 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"); @@ -349,8 +355,8 @@ function ShowCoinHistory(getData) { console.log('failed getting Coin History.'); console.log(xhr.statusText); if ( xhr.readyState == 0 ) { - console.log('Network Error with history api'); - //ClearOnLogout(true, true); + Iguana_ServiceUnavailable(); + ClearOnLogout(true, true); } console.log(textStatus); console.log(error); @@ -420,6 +426,9 @@ function SwitchBasicliskFull(switch_data) { 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"); @@ -495,6 +504,9 @@ function TotalFiatValue() { 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); } @@ -570,6 +582,9 @@ function ShowCoinProgressBar(coin) { error: function(xhr, textStatus, error) { console.log('failed getting Coin History.'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); } diff --git a/assets/scripts/iguana_api.js b/assets/scripts/iguana_api.js index 11a4ff0..9991f90 100644 --- a/assets/scripts/iguana_api.js +++ b/assets/scripts/iguana_api.js @@ -67,6 +67,9 @@ function Iguana_rmd160conv(rmd160conv_data) { 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); } @@ -94,6 +97,9 @@ function Iguana_activehandle() { error: function(xhr, textStatus, error) { console.log('failed getting Coin History.'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); return false; @@ -149,6 +155,9 @@ function Iguana_addcoinLogin(addcoin_data) { 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); } @@ -250,7 +259,9 @@ function Iguana_addcoin(addcoin_data) { if (addcoinData.result === 'coin added') { console.log('coin added'); toastr.success(logincoinfullname+" started in "+ logincoinmodeinfo +" Mode", "Coin Notification"); - location.reload(); + if ( typeof addcoin_data.reload == 'undefined' || addcoin_data.reload != false ) { + location.reload(); + } } else if (addcoinData.result === 'coin already there') { console.log('coin already there'); toastr.info("Looks like "+ logincoinfullname +" already running.", "Coin Notification"); @@ -262,8 +273,17 @@ function Iguana_addcoin(addcoin_data) { 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 Iguana_ServiceUnavailable() { + console.log('Network Error with history api'); + toastr.error("Unable to connect with iguana service. 127.0.0.1:7778", "Service Notification") + toastr.info("Are you sure Iguana is running?", "Account Notification") } \ No newline at end of file diff --git a/assets/scripts/login.js b/assets/scripts/login.js index 52e2bd1..df4bf67 100644 --- a/assets/scripts/login.js +++ b/assets/scripts/login.js @@ -90,42 +90,6 @@ var Login = function() { //swal("Oops...", "Something went wrong!", "error"); if (LoginOutput.error === 'bitcoinrpc needs coin') { toastr.info("Seems like there's no coin running. Activating BTC.", "Coin Notification"); - //var AddBTCDBasiliskData = {"prefetchlag":5,"poll":1,"active":1,"agent":"iguana","method":"addcoin","newcoin":"BTC","startpend":64,"endpend":2,"services":128,"maxpeers":512,"RELAY":1,"VALIDATE":1,"portp2p":8333} - //Start Bitcoin in Full/Basilisk mode - /*$.ajax({ - type: 'GET', - data: AddBTCDBasiliskData, - url: 'http://127.0.0.1:7778/api/iguana/addcoin', - dataType: 'text', - success: function(data, textStatus, jqXHR) { - var BTCDBasiliskDataOutput = JSON.parse(data); - //console.log('== Data OutPut =='); - //console.log(BTCDBasiliskDataOutput); - - if (BTCDBasiliskDataOutput.result === 'coin added') { - console.log('coin added'); - toastr.success("Bitcoin started in Full Mode", "Coin Notification"); - $( ".login-form" ).submit(); - } else if (BTCDBasiliskDataOutput.result === 'coin already there') { - console.log('coin already there'); - toastr.info("Looks like Bitcoin already running.", "Coin Notification"); - } else if (BTCDBasiliskDataOutput.result === null) { - console.log('coin already there'); - toastr.info("Looks like Bitcoin already running.", "Coin Notification"); - } - }, - error: function(xhr, textStatus, error) { - console.log('failed starting Bitcoin.'); - console.log(xhr.statusText); - console.log(textStatus); - console.log(error); - //swal("Oops...", "Something went wrong!", "error"); - toastr.warning("Opps... Something went wrong!", "Coin Notification") - } - });*/ - - - var logincoinnames = []; $('#logincoinslist input[type=checkbox]:checked').each(function() { logincoinnames.push(this.value); }); console.log(logincoinnames); $.each(logincoinnames, function( index, value ) { if ( value == 'BTC' ) { @@ -138,51 +102,6 @@ var Login = function() { var logincoin_data = {"coin": value, "mode": logincoinmodeval}; Iguana_addcoinLogin(logincoin_data); } - /*var AddCoinData = { - "poll": 100, - "active": 1, - "newcoin": value, - "startpend": 1, - "endpend": 1, - "services": 128, - "maxpeers": 16, - "RELAY": 0, - "VALIDATE": 0, - "portp2p": 14631 - }*/ - //Start BitcoinDark in Basilisk mode - /*$.ajax({ - type: 'POST', - data: AddCoinData, - url: 'http://127.0.0.1:7778', - //dataType: 'text', - success: function(data, textStatus, jqXHR) { - var LoginCoinDataOutput = JSON.parse(data); - console.log('== Data OutPut for'+ logincoinfullname +' =='); - console.log(LoginCoinDataOutput); - - if (LoginCoinDataOutput.result === 'coin added') { - console.log('coin added'); - toastr.success(logincoinfullname + " started in "+ logincoinmodeinfo +" Mode", "Coin Notification"); - } else if (LoginCoinDataOutput.result === 'coin already there') { - console.log('coin already there'); - //toastr.info("Looks like" + value + "already running.", "Coin Notification"); - } else if (LoginCoinDataOutput.result === null) { - console.log('coin already there'); - //toastr.info("Looks like" + value + "already running.", "Coin Notification"); - } - }, - error: function(xhr, textStatus, error) { - console.log('failed starting BitcoinDark.'); - console.log(xhr.statusText); - 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") - } - } - });*/ }); } else { toastr.warning("Opps... Something went wrong!", "Account Notification"); @@ -195,10 +114,13 @@ var Login = function() { error: function(xhr, textStatus, error) { console.log('failure'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); //swal("Oops...", "Something went wrong!", "error"); - toastr.warning("Opps... Something went wrong!", "Account Notification") + //toastr.warning("Opps... Something went wrong!", "Account Notification") } }); @@ -322,8 +244,8 @@ var Login = function() { success: function(data, textStatus, jqXHR) { var CreateWalletOutput = JSON.parse(data); //console.log(sessionStorage); - console.log('== Data OutPut =='); - console.log(CreateWalletOutput); + //console.log('== Data OutPut =='); + //console.log(CreateWalletOutput); if (CreateWalletOutput.result === 'success') { console.log('Success'); @@ -337,7 +259,39 @@ var Login = function() { // If something goes wrong, alert the error message that our service returned //swal("Oops...", "Something went wrong!", "error"); toastr.warning("Opps... Something went wrong!", "Account Notification") + console.log(CreateWalletOutput) + if (CreateWalletOutput.error === 'bitcoinrpc needs coin') { + toastr.info("Seems like there's no coin running. Activating BTC.", "Coin Notification"); + var logincoinnames = []; $('#logincoinslist input[type=checkbox]:checked').each(function() { logincoinnames.push(this.value); }); console.log(logincoinnames); + $.each(logincoinnames, function( index, value ) { + if ( value == 'BTC' ) { + var logincoinmodeval = $("input[name='logincoinbtcmode']:checked").val(); + var logincoin_data = {"coin": value, "mode": logincoinmodeval, "reload": false}; + Iguana_addcoin(logincoin_data); + if (index == '0' ) { + console.log(value+' '+index); + $('.register-form').submit(); + toastr.success("Wallet created successfully", "Account Notification") + } + } + if ( value == 'BTCD' ) { + var logincoinmodeval = $("input[name='logincoinbtcdmode']:checked").val(); + var logincoin_data = {"coin": value, "mode": logincoinmodeval, "reload": false}; + Iguana_addcoin(logincoin_data); + if (index == '0' ) { + console.log(value+' '+index); + $('.register-form').submit(); + toastr.success("Wallet created successfully", "Account Notification") + } + } + }); + } else { + toastr.warning("Opps... Something went wrong!", "Account Notification"); + } console.log(data.statusText); + if ( data.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(jqXHR); @@ -346,6 +300,9 @@ var Login = function() { error: function(xhr, textStatus, error) { console.log('failure'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); //swal("Oops...", "Something went wrong!", "error"); @@ -432,6 +389,9 @@ var Login = function() { //swal("Oops...", "Something went wrong!", "error"); toastr.warning("Opps... Something went wrong!", "Account Notification") console.log(data.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(jqXHR); @@ -440,6 +400,9 @@ var Login = function() { error: function(xhr, textStatus, error) { console.log('failure'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); //swal("Oops...", "Something went wrong!", "error"); @@ -493,6 +456,9 @@ var Login = function() { //swal("Oops...", "Something went wrong!", "error"); toastr.warning("Opps... Something went wrong!", "Account Notification") console.log(data.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(jqXHR); @@ -501,6 +467,9 @@ var Login = function() { error: function(xhr, textStatus, error) { console.log('failure'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); //swal("Oops...", "Something went wrong!", "error"); @@ -516,6 +485,9 @@ var Login = function() { error: function(xhr, textStatus, error) { console.log('failure'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); //swal("Oops...", "Something went wrong!", "error"); @@ -678,6 +650,9 @@ var Login = function() { //swal("Oops...", "Something went wrong!", "error"); toastr.warning("Opps... Something went wrong!", "Account Notification") console.log(data.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(jqXHR); } @@ -685,6 +660,9 @@ var Login = function() { error: function(xhr, textStatus, error) { console.log('failure'); console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + Iguana_ServiceUnavailable(); + } console.log(textStatus); console.log(error); //swal("Oops...", "Something went wrong!", "error");