aboutsummaryrefslogtreecommitdiffstats
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
parent722825386a47c85190013b1aa47050bdaae61077 (diff)
downloadcoinos-server-1e24fe8d3d87104a7d70b4be286dc82003e48912.tar.gz
coinos-server-1e24fe8d3d87104a7d70b4be286dc82003e48912.zip
Use blockchain socket too for redundancy
-rw-r--r--Gruntfile.coffee6
-rw-r--r--app.js5
-rw-r--r--public/css/calculator.less4
-rw-r--r--public/js/calculator.coffee43
-rw-r--r--src/app.coffee3
5 files changed, 52 insertions, 9 deletions
diff --git a/Gruntfile.coffee b/Gruntfile.coffee
index cf72ee20..977b25e5 100644
--- a/Gruntfile.coffee
+++ b/Gruntfile.coffee
@@ -9,15 +9,11 @@ module.exports = (grunt) ->
dest: '.'
ext: '.js'
watch:
- less:
- files: ['public/css/**/*.less']
- tasks: ['less']
coffee:
files: ['**/*.coffee']
tasks: ['coffee']
)
grunt.loadNpmTasks('grunt-contrib-coffee')
- grunt.loadNpmTasks('grunt-contrib-less')
grunt.loadNpmTasks('grunt-contrib-watch')
- grunt.registerTask('default', ['less', 'coffee']);
+ grunt.registerTask('default', ['coffee']);
diff --git a/app.js b/app.js
index 59bb3c54..c739c325 100644
--- a/app.js
+++ b/app.js
@@ -92,9 +92,12 @@
var r, stream;
stream = fs.createWriteStream(file);
r = request("https://api.bitcoinaverage.com/exchanges/all");
- return r.on('data', function(chunk) {
+ r.on('data', function(chunk) {
return stream.write(chunk);
});
+ return r.on('error', function(error) {
+ return console.log(error);
+ });
});
return setTimeout(fetchRates, 120000);
};
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')
diff --git a/src/app.coffee b/src/app.coffee
index ffb8ec46..361a9a56 100644
--- a/src/app.coffee
+++ b/src/app.coffee
@@ -49,6 +49,9 @@ fetchRates = ->
r.on('data', (chunk) ->
stream.write(chunk)
)
+ r.on('error', (error) ->
+ console.log(error)
+ )
)
setTimeout(fetchRates, 120000)