diff options
| author | Adam Soltys <[email protected]> | 2012-11-07 17:46:49 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2012-11-07 17:52:50 -0800 |
| commit | 3e900e0bba211c2bbf2bb10c85a82dd9ce6943f0 (patch) | |
| tree | bb3ce237413df5fb0896a1696f7bd6f41ac248f3 /public/js/bitcoin_pos.js | |
| parent | 5a4e3ff9bf1db2db4fc5ae8d3bd7dcefc8c58e25 (diff) | |
| download | coinos-server-3e900e0bba211c2bbf2bb10c85a82dd9ce6943f0.tar.gz coinos-server-3e900e0bba211c2bbf2bb10c85a82dd9ce6943f0.zip | |
Use coffeescript
Diffstat (limited to 'public/js/bitcoin_pos.js')
| -rw-r--r-- | public/js/bitcoin_pos.js | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/public/js/bitcoin_pos.js b/public/js/bitcoin_pos.js deleted file mode 100644 index 869e72e2..00000000 --- a/public/js/bitcoin_pos.js +++ /dev/null @@ -1,159 +0,0 @@ -$(function() { - var websocket = null; - var client = $('#client').val(); - var title = get('title'); - var address = get('address'); - var commission = get('commission'); - var logo = get('logo'); - var exchange = 0; - - setupPage(); - setupQR(); - setupSocket(); - - if (client != "") { - $.getJSON('client/' + client, function(data) { - var user = data[0]; - title = user.title; - address = user.address; - commission = user.commission; - logo = user.logo; - setupPage(); - }); - } - - $('#amount').keyup(updateTotal); - $('#amount').focus(); - $('#amount').focus(function() { - $('#received').hide(); - $('#payment').fadeIn('slow'); - $(this).val(''); - updateTotal(); - }); - - $('#error').click(function() { - location.reload(); - }); - - function updateTotal() { - var amount = parseFloat($('#amount').val()); - var total = amount / exchange; - total = Math.ceil(total * 10000) / 10000; - - if (!$.isNumeric(total)) { - total = ''; - } - - $('#total').html(total.toString()); - displayQR('bitcoin:' + address + '?amount=' + total.toString()); - } - - function exchangeFail() { - $('#error').show().html("Error fetching exchange rate"); - $('#calculator').hide(); - } - - function fetchExchangeRate() { - $.getJSON('ticker') - .success(function (data) { - if (data == null) { - exchangeFail(); - return; - } - - exchange = 1000 / data.out; - exchange = exchange - exchange * commission * 0.01; - exchange = Math.ceil(exchange * 100) / 100; - $('#exchange').val(exchange.toFixed(2)); - updateTotal(); - - $('#error').hide(); - $('#calculator').fadeIn('slow'); - } - ).error(exchangeFail); - - setTimeout(fetchExchangeRate, 900000); - } - - function setupPage() { - if (address == "") - address = '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' - - if (commission == "") - commission = 3; - - if (logo != "") - $('#logo').attr('src', logo).show(); - else - $('#title').html(title); - - $('#address').html(address); - $('#received').hide(); - - fetchExchangeRate(); - } - - function setupSocket() { - setTimeout(setupSocket, 10000); - - if (!websocket || websocket.readyState != 1) { - websocket = new WebSocket("ws://api.blockchain.info:8335/inv"); - - websocket.onopen = function() { - websocket.send('{"op":"addr_sub", "addr":"' + address + '"}'); - } - - websocket.onerror = websocket.onclose = function() { - $('#calculator').hide(); - $('#error').show().html("Error connecting to payment server"); - }; - - websocket.onmessage = function(e) { - var results = eval('(' + e.data + ')'); - var from_address = ''; - var total = 0; - var received = 0; - - $.each(results.x.out, function(i, v) { - if (v.addr == address) { - received += v.value / 100000000; - } - }); - - $.each(results.x.inputs, function(i, v) { - from_address = v.prev_out.addr - if (v.prev_out.addr == address) { - input -= v.prev_out.value / 100000000; - } - }); - - if (total <= received) { - $('#amount').blur(); - $('#payment').hide(); - $('#received').fadeIn('slow'); - } - - $.get('record_transaction.php', - { - address: from_address, - date: moment().format("YYYY-MM-DD HH:mm:ss"), - received: received, - exchange: exchange - } - ); - } - } - } -}); - -function get(name) { - name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); - var regexS = "[\\?&]" + name + "=([^&#]*)"; - var regex = new RegExp(regexS); - var results = regex.exec(window.location.search); - - if(results == null) - return ""; - else - return decodeURIComponent(results[1].replace(/\+/g, " ")); -} |
