From 1e24fe8d3d87104a7d70b4be286dc82003e48912 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 19 Aug 2014 09:26:25 -0700 Subject: Use blockchain socket too for redundancy --- public/css/calculator.less | 4 ++-- public/js/calculator.coffee | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) (limited to 'public') diff --git a/public/css/calculator.less b/public/css/calculator.less index 45ce7e58..2a36be4f 100644 --- a/public/css/calculator.less +++ b/public/css/calculator.less @@ -13,9 +13,9 @@ div.container-fluid { padding-bottom: 50px; } -.navbar-toggle { background-color: #428bca; width: 100%; position: absolute; top: 0px; height: 30px; margin: 0; float: none; z-index: 1; } +.navbar-toggle { background-color: #428bca; width: 100%; position: absolute; top: 0px; height: 30px; margin: 0; float: none; z-index: 1; margin-bottom: -30px; } .navbar-toggle .glyphicon { margin-top: -5px; padding-left: 10px; } -.navbar { margin: 0; } +.navbar { margin: 0; margin-bottom: 15px; } .navbar-collapse.in { overflow-y: visible; } .nav { margin-top: 30px; } .nav li a { padding: 10px 0 10px 10px; } diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index 4acb0f50..700e9903 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -103,6 +103,47 @@ finalize = -> setupSocket = -> setTimeout(setupSocket, 10000) + unless g.blockchain and g.blockchain.readyState is 1 + g.blockchain = new WebSocket("wss://ws.blockchain.info/inv") + + g.blockchain.onopen = -> + $('#connection').fadeIn().removeClass('glyphicon-exclamation-sign').addClass('glyphicon-signal') + g.blockchain.send('{"op":"addr_sub", "addr":"' + g.address + '"}') + + g.blockchain.onerror = -> + $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal') + g.blockchain = null + fail(SOCKET_FAIL) + + g.blockchain.onclose = -> + $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal') + g.blockchain = null + fail(SOCKET_FAIL) + + g.blockchain.onmessage = (e) -> + results = eval('(' + e.data + ')') + from_address = '' + received = 0 + + $.each(results.x.out, (i, v) -> + if (v.addr == g.address) + received += v.value / 100000000 + ) + + if $('#received').is(":hidden") and g.amount_requested <= received + $('#amount').blur() + $('#payment').hide() + $('#received').fadeIn('slow') + $('#chaching')[0].play() + + if g.user + $.post("/#{g.user}/transactions", + address: from_address, + date: moment().format("YYYY-MM-DD HH:mm:ss"), + received: received, + exchange: g.exchange + ) + unless g.btcd and g.btcd.readyState is 1 g.btcd = new WebSocket("wss://coinos.io/ws") @@ -137,7 +178,7 @@ setupSocket = -> exchange: g.exchange ) - if amount_received >= g.amount_requested + if $('#received').is(":hidden") and amount_received >= g.amount_requested $('#amount').blur() $('#payment').hide() $('#received').fadeIn('slow') -- cgit v1.2.3