diff options
| author | Adam Soltys <[email protected]> | 2014-08-17 23:25:02 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2014-08-17 23:25:02 -0700 |
| commit | b4037fd1a0d115dee40b7d20eec31c3875e4fa39 (patch) | |
| tree | 0a4fd4451989513a2c52c51b8f3c944f03aef5b4 | |
| parent | 64edb5636736a9c897958e7b743374addba96bcb (diff) | |
| download | coinos-server-b4037fd1a0d115dee40b7d20eec31c3875e4fa39.tar.gz coinos-server-b4037fd1a0d115dee40b7d20eec31c3875e4fa39.zip | |
Let users configure BTC units
| -rw-r--r-- | public/js/calculator.coffee | 50 | ||||
| -rw-r--r-- | public/js/report.coffee | 4 | ||||
| -rw-r--r-- | public/js/setup.coffee | 7 | ||||
| -rw-r--r-- | src/app.coffee | 1 | ||||
| -rw-r--r-- | views/users/edit.html | 11 | ||||
| -rw-r--r-- | views/users/show.html | 2 |
6 files changed, 43 insertions, 32 deletions
diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index c22d05ee..fde28652 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -17,23 +17,22 @@ $(-> g.errors = [] g.amount_requested = 0 g.tip = 1 + g.unit = 'BTC' - if g.user - $.ajax( - url: g.user + '.json', - dataType: 'json', - success: (data) -> - if data? - g.title = data.title - g.address = data.address - g.currency = data.currency - g.symbol = data.symbol - g.commission = data.commission - g.logo = data.logo - setup() - ) - else - setup() + $.ajax( + url: g.user + '.json', + dataType: 'json', + success: (data) -> + if data? + g.title = data.title + g.address = data.address + g.currency = data.currency + g.symbol = data.symbol + g.commission = data.commission + g.logo = data.logo + g.unit = data.unit + setup() + ) $('#tip button').click(-> value = $(this).html().slice(0, -1) @@ -54,8 +53,6 @@ $(-> ) ) -activateTip = (p) -> - setup = -> g.address or= '' g.commission or= 0 @@ -73,6 +70,7 @@ setup = -> $('#address').html("#{address} <a href='http://blockchain.info/address/#{address}' target='_blank'><img src='/assets/img/blockchain.png' /></a>") $('#symbol').html(g.symbol + " bid") $('#currency').html(g.currency) + $('#unit').html(g.unit) $('#received').hide() setupSocket() @@ -144,16 +142,16 @@ setupSocket = -> $('#payment').hide() $('#received').fadeIn('slow') $('#chaching')[0].play() - if data.method and data.method is 'recvtx' and data.params.length is 1 msg = JSON.stringify { jsonrpc: "1.0", id: "coinos", method: 'decoderawtransaction', params: [data.params[0]] } g.btcd.send(msg) updateTotal = -> + precision = 9 - multiplier().toString().length amount = parseFloat($('#amount').val() * g.tip) - total = (amount / g.exchange).toFixed(8) - g.amount_requested = (amount / g.exchange).toFixed(8) + total = (amount * multiplier() / g.exchange).toFixed(precision) + g.amount_requested = total unless $.isNumeric(total) total = '' @@ -162,7 +160,6 @@ updateTotal = -> $('#qr').html('') new QRCode('qr', "bitcoin:#{g.address}?amount=#{g.amount_requested.toString()}") - fail = (msg) -> g.errors.push(msg) g.errors = g.errors.uniq() @@ -182,3 +179,12 @@ Array::uniq = -> output = {} output[@[key]] = @[key] for key in [0...@length] value for key, value of output + +multiplier = -> + switch g.unit + when 'BTC' then 1 + when 'mBTC' then 1000 + when 'µBTC' then 1000000 + when 'satoshis' then 100000000 + + diff --git a/public/js/report.coffee b/public/js/report.coffee index 90b7c0aa..99a0df25 100644 --- a/public/js/report.coffee +++ b/public/js/report.coffee @@ -64,7 +64,7 @@ display = (transactions) -> <tr> <td>#{moment(this.date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma')}</td> <td>#{exchange.toFixed(2)}</td> - <td>#{received.toFixed(5)}</td> + <td>#{received.toFixed(8)}</td> <td>#{amount.toFixed(2)}</td> </tr> """) @@ -74,7 +74,7 @@ display = (transactions) -> $('table.report tbody td:nth-child(3)').each(-> btc += parseFloat($(this).html()) ) - $('#btc').html(btc.toFixed(5)) + $('#btc').html(btc.toFixed(8)) cad = 0 $('table.report tbody td:nth-child(4)').each(-> diff --git a/public/js/setup.coffee b/public/js/setup.coffee index 53660449..ce6b3963 100644 --- a/public/js/setup.coffee +++ b/public/js/setup.coffee @@ -40,6 +40,11 @@ $(-> ).change() + units = ['BTC', 'mBTC', 'µBTC', 'satoshis'] + $.each(units, (i, v) -> + $('#unit').append("<option value='#{v}'>#{v}</option>") + ) + $('#title').blur(-> if $(this).val() == '' $(this).parent().addClass('has-error') @@ -74,10 +79,10 @@ $(-> $('#setup').attr('action', "/#{user}").attr('method', 'post') $.getJSON("/#{user}.json", (data) -> $('#title').val(data.title) - $('#logo').val(data.logo) $('#address').val(data.address) $("#symbol option[value='#{data.symbol}']").attr('selected', 'selected') $('#commission').val(data.commission) + $('#unit').val(data.unit) $('#setup').fadeIn() ) ) diff --git a/src/app.coffee b/src/app.coffee index dec4205a..75b83560 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -16,7 +16,6 @@ session = require('express-session') RedisStore = require('connect-redis')(session) sessionStore = new RedisStore(require('./redis').host, ttl: 172800) - app = express() app.enable('trust proxy') app.engine('html', require('hogan-express')) diff --git a/views/users/edit.html b/views/users/edit.html index 9037d83d..703ef9c0 100644 --- a/views/users/edit.html +++ b/views/users/edit.html @@ -13,11 +13,6 @@ </div> <div class="form-group"> - <label for="logo">Logo <small>(optional URL)</small>:</label> - <input type="text" id="logo" name="logo" class="form-control" /> - </div> - - <div class="form-group"> <label for="address">Bitcoin Address:</label> <input type="text" id="address" name="address" class="form-control" /> </div> @@ -33,6 +28,12 @@ <select id="symbol" name="symbol" class="form-control"> </select> </div> + + <div class="form-group"> + <label for="unit">Bitcoin Display Units:</label> + <select id="unit" name="unit" class="form-control"> + </select> + </div> <div class="form-group"> <label for="commission">Commission/Discount <small>(optional %)</small>:</label> diff --git a/views/users/show.html b/views/users/show.html index 8ecce37a..bbf214b4 100644 --- a/views/users/show.html +++ b/views/users/show.html @@ -36,7 +36,7 @@ <br /> <div id="payment"> - <p>Please send <strong id="total">0.0</strong> BTC to</p> + <p>Please send <strong id="total">0.0</strong> <span id="unit"></span> to</p> <div id="qr"></div> <p id="address"></p> </div> |
