diff options
| author | Adam Soltys <[email protected]> | 2012-11-13 19:27:09 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2012-11-13 19:27:09 -0800 |
| commit | 16062edf148ea44bc8a5f40732c0dc1d363d588c (patch) | |
| tree | 1c29230affc47ce26fee30d9f971c1f75e79a43a | |
| parent | 54c28a395db853c601d3592c967f322c7f09e1d4 (diff) | |
| download | coinos-server-16062edf148ea44bc8a5f40732c0dc1d363d588c.tar.gz coinos-server-16062edf148ea44bc8a5f40732c0dc1d363d588c.zip | |
Allow market selection
| -rw-r--r-- | app.coffee | 32 | ||||
| -rw-r--r-- | public/js/calculator.coffee | 21 | ||||
| -rw-r--r-- | public/js/index.coffee | 9 | ||||
| -rw-r--r-- | views/calculator.html | 6 | ||||
| -rw-r--r-- | views/index.html | 5 |
5 files changed, 51 insertions, 22 deletions
@@ -1,3 +1,4 @@ + express = require('express') http = require('http') path = require('path') @@ -54,13 +55,10 @@ app.get('/:user/transactions', (req, res) -> app.get('/ticker', (req, res) -> - symbol = req.params.symbol - symbol or= 'virtexCAD' - options = host: 'bitcoincharts.com', - path: '/t/depthcalc.json?symbol=' + symbol + '&type=bid&amount=1000¤cy=true' - + path: '/t/depthcalc.json?symbol=' + req.query.symbol + '&type=bid&amount=1000¤cy=true' + require('http').get(options, (r) -> r.setEncoding('utf-8') r.on('data', (chunk) -> @@ -70,11 +68,17 @@ app.get('/ticker', (req, res) -> ) app.post('/users', (req, res) -> - db = require("redis").createClient() - db.hmset(req.body.login, req.body, -> - res.writeHead(302, 'Location': '/' + req.body.login) - res.end() - ) + if req.body.login + db = require("redis").createClient() + db.hmset(req.body.login, req.body, -> + res.redirect(req.body.login) + ) + else + params = [] + for k,v of req.body + params.push(encodeURIComponent(k), '=', encodeURIComponent(v), '&') + params.pop() if (params.length) + res.redirect('calculator?' + params.join('')) ) app.post('/:user/transactions', (req, res) -> @@ -90,6 +94,13 @@ app.post('/:user/transactions', (req, res) -> ) ) +app.get('/calculator', (req, res) -> + res.render('calculator', + js: (-> global.js), + css: (-> global.css) + ) +) + app.get('/:user', (req, res) -> res.render('calculator', user: req.params.user, @@ -102,4 +113,5 @@ app.use((err, req, res, next) -> console.log(err) ) + app.listen(3000) diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index 01523d9a..3d1d61b4 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -8,8 +8,9 @@ g = exports ? this $(-> g.websocket = null g.user = $('#user').val() - g.title = get('title') + g.name = get('name') g.address = get('address') + g.symbol = get('symbol') g.commission = get('commission') g.logo = get('logo') g.exchange = 0 @@ -20,7 +21,7 @@ $(-> if user? and user $.getJSON(user + '.json', (data) -> - g.title = data.name + g.name = data.name g.address = data.address g.commission = data.commission g.logo = data.logo @@ -53,7 +54,7 @@ exchangeFail = -> $('#calculator').hide() fetchExchangeRate = -> - $.getJSON('ticker') + $.getJSON('ticker?symbol=' + g.symbol) .success((data) -> unless data? exchangeFail() @@ -71,18 +72,20 @@ fetchExchangeRate = -> setTimeout(fetchExchangeRate, 900000) setupPage = -> - unless g.address - g.address = '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' - - unless g.commission - g.commission = 3 + g.address or= '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' + g.commission or= 3 + g.symbol or= 'virtexCAD' if g.logo $('#logo').attr('src', g.logo).show() + else if not g.name + $('#logo').attr('src', 'img/bitcoin.png').show() else - $('#title').html(title).show() + $('#name').html(g.name).show() $('#address').html(g.address) + $('#symbol').html(g.symbol + " - " + commission.toFixed(0) + "%") + $('#currency').html(g.symbol.slice(-3)) $('#received').hide() fetchExchangeRate() diff --git a/public/js/index.coffee b/public/js/index.coffee new file mode 100644 index 00000000..d832c4ed --- /dev/null +++ b/public/js/index.coffee @@ -0,0 +1,9 @@ +#= require jquery-1.8.2.min.js + +$(-> + symbols = ['mtgoxUSD', 'btceUSD', 'bitstampUSD', 'virwoxSLL', 'btcdeEUR', 'mtgoxEUR', 'btc24EUR', 'mtgoxAUD', 'cryptoxAUD', 'mtgoxGBP', 'btcnCNY', 'intrsngEUR', 'virtexCAD', 'mtgoxPLN', 'cbxUSD', 'bitcurexPLN', 'bitmarketEUR', 'bitfloorUSD', 'mrcdBRL', 'bcEUR'] + + $.each(symbols, (i, v) -> + $('#symbol').append("<option>#{v}</option>") + ) +) diff --git a/views/calculator.html b/views/calculator.html index 87042825..8acc0276 100644 --- a/views/calculator.html +++ b/views/calculator.html @@ -13,16 +13,16 @@ <div id="calculator" style="display: none"> <input id="user" type="hidden" value="{{user}}" /> - <h1 id="title"></h1> + <h1 id="name"></h1> <img id="logo" src="img/logo.jpg" alt="Logo" /> <label for="exchange">Exchange Rate:</label> <input type="text" id="exchange" value="0" disabled="disabled" /> - <small>CAD / BTC</small> + <small id="symbol"></small> <label for="amount">Amount:</label> <input type="text" id="amount" /> - <small>CAD</small> + <small id="currency"></small> <br /><br /> diff --git a/views/index.html b/views/index.html index c9f2cee8..0625dd6f 100644 --- a/views/index.html +++ b/views/index.html @@ -6,6 +6,7 @@ <title>Bitcoin Payment Calculator</title> <link href="img/favicon.ico" rel="shortcut icon" /> {{#css}}common{{/css}} + {{#js}}index{{/js}} </head> <body> <div class="container-fluid"> @@ -23,6 +24,10 @@ <label for="address">Bitcoin Address:</label> <input type="text" id="address" name="address" /> + + <label for="symbol">Market Symbol:</label> + <select id="symbol" name="symbol"> + </select> <label for="commission">Commission (%):</label> <input type="text" id="commission" name="commission" /> |
