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 /public | |
| parent | 64edb5636736a9c897958e7b743374addba96bcb (diff) | |
| download | coinos-server-b4037fd1a0d115dee40b7d20eec31c3875e4fa39.tar.gz coinos-server-b4037fd1a0d115dee40b7d20eec31c3875e4fa39.zip | |
Let users configure BTC units
Diffstat (limited to 'public')
| -rw-r--r-- | public/js/calculator.coffee | 50 | ||||
| -rw-r--r-- | public/js/report.coffee | 4 | ||||
| -rw-r--r-- | public/js/setup.coffee | 7 |
3 files changed, 36 insertions, 25 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() ) ) |
