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 +++++++++-- routes/transactions.js | 2 +- src/routes/transactions.coffee | 2 +- views/transactions/notification.html | 4 ++-- 5 files changed, 18 insertions(+), 7 deletions(-) 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; diff --git a/routes/transactions.js b/routes/transactions.js index 63e416e6..c6a86271 100644 --- a/routes/transactions.js +++ b/routes/transactions.js @@ -81,7 +81,7 @@ helper = require('sendgrid').mail; from_email = new helper.Email('info@coinos.io'); to_email = new helper.Email(user.email); - subject = 'Transaction Sent'; + subject = 'Payment Received'; content = new helper.Content('text/html', html); mail = new helper.Mail(from_email, subject, to_email, content); sg = require('sendgrid')(config.sendgrid_token); diff --git a/src/routes/transactions.coffee b/src/routes/transactions.coffee index 70447901..2eca7766 100644 --- a/src/routes/transactions.coffee +++ b/src/routes/transactions.coffee @@ -59,7 +59,7 @@ module.exports = helper = require('sendgrid').mail from_email = new helper.Email('info@coinos.io') to_email = new helper.Email(user.email) - subject = 'Transaction Sent' + subject = 'Payment Received' content = new helper.Content('text/html', html) mail = new helper.Mail(from_email, subject, to_email, content) diff --git a/views/transactions/notification.html b/views/transactions/notification.html index 5f066cf8..3e6946a4 100644 --- a/views/transactions/notification.html +++ b/views/transactions/notification.html @@ -1,3 +1,3 @@ -

Transaction Received

+

Payment Received

-You received {{amount}} from {{address}}. Visit https://blockchain.info/tx/{{txid}} for more details. +You received {{amount}} from {{address}}. Click here for more details. -- cgit v1.2.3