From b4037fd1a0d115dee40b7d20eec31c3875e4fa39 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 17 Aug 2014 23:25:02 -0700 Subject: Let users configure BTC units --- public/js/calculator.coffee | 50 +++++++++++++++++++++++++-------------------- public/js/report.coffee | 4 ++-- public/js/setup.coffee | 7 ++++++- src/app.coffee | 1 - views/users/edit.html | 11 +++++----- 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} ") $('#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) -> #{moment(this.date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma')} #{exchange.toFixed(2)} - #{received.toFixed(5)} + #{received.toFixed(8)} #{amount.toFixed(2)} """) @@ -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("") + ) + $('#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 @@ -12,11 +12,6 @@ -
- - -
-
@@ -33,6 +28,12 @@
+ +
+ + +
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 @@
-

Please send 0.0 BTC to

+

Please send 0.0 to

-- cgit v1.2.3