aboutsummaryrefslogtreecommitdiffstats
path: root/public/js/calculator.coffee
diff options
context:
space:
mode:
authorAlex Millar <[email protected]>2015-11-13 14:10:56 -0800
committerAlex Millar <[email protected]>2015-11-13 14:10:56 -0800
commitb08cf52fffff2ca5d6af2a24aabfc15a106a9bae (patch)
tree34cee48f5ac001b51cc1098c9f649899634d97e6 /public/js/calculator.coffee
parent8e87409f6deb2dddfa071976448e602527558757 (diff)
parentdd304a2cc7675b09d1db93f2835c4603474c8581 (diff)
downloadcoinos-server-b08cf52fffff2ca5d6af2a24aabfc15a106a9bae.tar.gz
coinos-server-b08cf52fffff2ca5d6af2a24aabfc15a106a9bae.zip
Merge remote-tracking branch 'asoltys/master'
Diffstat (limited to 'public/js/calculator.coffee')
-rw-r--r--public/js/calculator.coffee38
1 files changed, 23 insertions, 15 deletions
diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee
index cc2dcece..f709465f 100644
--- a/public/js/calculator.coffee
+++ b/public/js/calculator.coffee
@@ -11,8 +11,8 @@
#= require js/modsqrt.js
#= require js/rfc1751.js
-EXCHANGE_FAIL = "Error fetching exchange rate"
-SOCKET_FAIL = "Error connecting to payment server"
+EXCHANGE_FAIL = "Problem fetching exchange rate"
+SOCKET_FAIL = "Problem connecting to payment server, notifications may not appear"
ADDRESS_FAIL = "Invalid address"
g = exports ? this
@@ -59,7 +59,9 @@ setup = ->
$('#title').html("<a href='/#{g.user.username}/edit'>#{g.user.title}</a>").show()
if g.user.logo
- $('#logo').attr('src', g.user.logo).show()
+ ext = g.user.logo.substr(g.user.logo.length - 3)
+ src = "/assets/img/logos/#{g.user.username}.#{ext}"
+ $('#logo').attr('src', src).show()
getAddress()
@@ -108,25 +110,29 @@ updateTotal = ->
new QRCode('qr', text: "bitcoin:#{g.user.address}?amount=#{g.amount_requested.toString()}", width: 280, height: 280)
listen = ->
- setTimeout(listen, 10000)
-
- unless g.blockchain and g.blockchain.readyState is 1
+ g.attempts++
+ if g.blockchain and g.blockchain.readyState is 1
+ setTimeout(listen, 12000)
+ else
+ fail(SOCKET_FAIL) if g.attempts > 3
g.blockchain = new WebSocket("wss://ws.blockchain.info/inv")
g.blockchain.onopen = ->
- $('#connection').fadeIn().removeClass('glyphicon-exclamation-sign').addClass('glyphicon-signal')
- clear(SOCKET_FAIL)
- g.blockchain.send('{"op":"addr_sub", "addr":"' + g.user.address + '"}')
+ if g.blockchain.readyState is 1
+ g.attempts = 0
+ clear(SOCKET_FAIL)
+ g.blockchain.send('{"op":"addr_sub", "addr":"' + g.user.address + '"}')
+ else
+ setTimeout(g.blockchain.onopen, 12000)
g.blockchain.onerror = ->
- $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal')
- g.blockchain = null
fail(SOCKET_FAIL)
+ g.blockchain.close()
+ delete g.blockchain
+ listen()
g.blockchain.onclose = ->
- $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal')
- g.blockchain = null
- fail(SOCKET_FAIL)
+ delete g.blockchain
listen()
g.blockchain.onmessage = (e) ->
@@ -149,7 +155,7 @@ logTransaction = (txid, amount) ->
$('#amount').blur()
$('#payment').hide()
$('#received').fadeIn('slow')
- $('#chaching')[0].play()
+ $('#success')[0].play()
g.user.index++
$.post("/#{g.user.username}/transactions",
@@ -171,6 +177,8 @@ getAddress = ->
master = bitcoin.HDNode.fromBase58(g.user.pubkey)
child = master.derive(0).derive(g.user.index)
g.user.address = child.pubKey.getAddress().toString()
+ g.blockchain.close() if g.blockchain
+ listen()
catch
fail(ADDRESS_FAIL)