aboutsummaryrefslogtreecommitdiffstats
path: root/public
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2014-08-19 09:26:25 -0700
committerAdam Soltys <[email protected]>2014-08-19 09:26:25 -0700
commit1e24fe8d3d87104a7d70b4be286dc82003e48912 (patch)
treee6a92ee4d7110c3342fe3015d3f2186beef13664 /public
parent722825386a47c85190013b1aa47050bdaae61077 (diff)
downloadcoinos-server-1e24fe8d3d87104a7d70b4be286dc82003e48912.tar.gz
coinos-server-1e24fe8d3d87104a7d70b4be286dc82003e48912.zip
Use blockchain socket too for redundancy
Diffstat (limited to 'public')
-rw-r--r--public/css/calculator.less4
-rw-r--r--public/js/calculator.coffee43
2 files changed, 44 insertions, 3 deletions
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')