From 69fe9bc5e29415e66e5463adb37d9524d7ac185a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 22 Nov 2016 17:04:29 -0800 Subject: Listen for testnet payments --- public/js/calculator.coffee | 6 +++++- public/js/calculator.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'public') diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index 7d185f24..7dfb6186 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -1,6 +1,8 @@ EXCHANGE_FAIL = "Problem fetching exchange rate" SOCKET_FAIL = "Problem connecting to payment server, notifications may not appear" ADDRESS_FAIL = "Invalid address" +API_URL = "wss://socket.blockcypher.com/v1/btc/main" +TEST_URL = "wss://socket.blockcypher.com/v1/btc/test3" g = exports ? this g.errors = [] @@ -90,6 +92,8 @@ setup = -> $('#logo').attr('src', src).show() getAddress() + if g.user.address[0] is 'm' + API_URL = TEST_URL $('.symbol').html(g.user.currency) $('.currency').html(g.user.currency) @@ -169,7 +173,7 @@ listen = -> setTimeout(listen, 12000) else fail(SOCKET_FAIL) if g.attempts > 3 - g.blockchain = new WebSocket("wss://socket.blockcypher.com/v1/btc/main") + g.blockchain = new WebSocket(API_URL) g.blockchain.onopen = -> if g.blockchain.readyState is 1 diff --git a/public/js/calculator.js b/public/js/calculator.js index 3a564034..c85c9bb3 100644 --- a/public/js/calculator.js +++ b/public/js/calculator.js @@ -1,5 +1,5 @@ (function() { - var ADDRESS_FAIL, EXCHANGE_FAIL, SOCKET_FAIL, clear, fail, fetchExchangeRate, g, getAddress, listen, logTransaction, multiplier, setup, updateTotal; + var ADDRESS_FAIL, API_URL, EXCHANGE_FAIL, SOCKET_FAIL, TEST_URL, clear, fail, fetchExchangeRate, g, getAddress, listen, logTransaction, multiplier, setup, updateTotal; EXCHANGE_FAIL = "Problem fetching exchange rate"; @@ -7,6 +7,10 @@ ADDRESS_FAIL = "Invalid address"; + API_URL = "wss://socket.blockcypher.com/v1/btc/main"; + + TEST_URL = "wss://socket.blockcypher.com/v1/btc/test3"; + g = typeof exports !== "undefined" && exports !== null ? exports : this; g.errors = []; @@ -96,6 +100,9 @@ $('#logo').attr('src', src).show(); } getAddress(); + if (g.user.address[0] === 'm') { + API_URL = TEST_URL; + } $('.symbol').html(g.user.currency); $('.currency').html(g.user.currency); $('.unit').html(g.user.unit); @@ -173,7 +180,7 @@ if (g.attempts > 3) { fail(SOCKET_FAIL); } - g.blockchain = new WebSocket("wss://socket.blockcypher.com/v1/btc/main"); + g.blockchain = new WebSocket(API_URL); g.blockchain.onopen = function() { if (g.blockchain.readyState === 1) { g.attempts = 0; -- cgit v1.2.3