From eb75029273e477a6ed4486d204a19ee762af07bf Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 22 Jul 2014 14:42:18 -0700 Subject: Display connection status icon --- public/js/calculator.coffee | 8 ++++++-- public/js/calculator.js | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'public/js') diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index f035855e..48e14764 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -92,7 +92,7 @@ setup = -> $('#currency').html(g.currency) $('#received').hide() - # setupSocket() + setupSocket() fetchExchangeRate() fetchExchangeRate = -> @@ -126,14 +126,18 @@ setupSocket = -> g.websocket = new WebSocket("wss://ws.blockchain.info/inv") g.websocket.onopen = -> + $('#connection').fadeIn().removeClass('glyphicon-exclamation-sign').addClass('glyphicon-signal') g.websocket.send('{"op":"addr_sub", "addr":"' + g.address + '"}') g.websocket.onerror = -> + $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal') g.websocket = null fail(SOCKET_FAIL) g.websocket.onclose = -> - setupSocket() + $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal') + g.websocket = null + fail(SOCKET_FAIL) g.websocket.onmessage = (e) -> results = eval('(' + e.data + ')') diff --git a/public/js/calculator.js b/public/js/calculator.js index d552b895..ba6f6511 100644 --- a/public/js/calculator.js +++ b/public/js/calculator.js @@ -88,6 +88,7 @@ $('#symbol').html(g.symbol + " bid"); $('#currency').html(g.currency); $('#received').hide(); + setupSocket(); return fetchExchangeRate(); }; @@ -125,14 +126,18 @@ if (!(g.websocket && g.websocket.readyState === 1)) { g.websocket = new WebSocket("wss://ws.blockchain.info/inv"); g.websocket.onopen = function() { + $('#connection').fadeIn().removeClass('glyphicon-exclamation-sign').addClass('glyphicon-signal'); return g.websocket.send('{"op":"addr_sub", "addr":"' + g.address + '"}'); }; g.websocket.onerror = function() { + $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal'); g.websocket = null; return fail(SOCKET_FAIL); }; g.websocket.onclose = function() { - return setupSocket(); + $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal'); + g.websocket = null; + return fail(SOCKET_FAIL); }; return g.websocket.onmessage = function(e) { var from_address, received, results; -- cgit v1.2.3