From 083f14611eba89b47f681454509b0185e7deaa99 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 4 Feb 2016 22:06:28 -0800 Subject: Prevent duplicate transaction logging --- public/js/calculator.coffee | 17 ++++++++++------- public/js/calculator.js | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee index 9583a018..407a80f5 100644 --- a/public/js/calculator.coffee +++ b/public/js/calculator.coffee @@ -8,6 +8,7 @@ g = exports ? this g.errors = [] g.amount_requested = 0 g.tip = 1 +g.transactions = [] $(-> $.ajax( @@ -147,13 +148,15 @@ logTransaction = (txid, amount) -> $('#success')[0].play() g.user.index++ - $.post("/#{g.user.username}/transactions", - txid: txid, - address: g.user.address, - date: moment().format("YYYY-MM-DD HH:mm:ss"), - received: amount, - exchange: g.exchange - ) + if g.transactions.indexOf(txid) is -1 + g.transactions.push(txid) + $.post("/#{g.user.username}/transactions", + txid: txid, + address: g.user.address, + date: moment().format("YYYY-MM-DD HH:mm:ss"), + received: amount, + exchange: g.exchange + ) getAddress() diff --git a/public/js/calculator.js b/public/js/calculator.js index 4d0491cf..2808ad64 100644 --- a/public/js/calculator.js +++ b/public/js/calculator.js @@ -18,6 +18,8 @@ g.tip = 1; + g.transactions = []; + $(function() { $.ajax({ url: $('#user').val() + '.json', @@ -169,13 +171,16 @@ $('#received').fadeIn('slow'); $('#success')[0].play(); g.user.index++; - $.post("/" + g.user.username + "/transactions", { - txid: txid, - address: g.user.address, - date: moment().format("YYYY-MM-DD HH:mm:ss"), - received: amount, - exchange: g.exchange - }); + if (g.transactions.indexOf(txid) === -1) { + g.transactions.push(txid); + $.post("/" + g.user.username + "/transactions", { + txid: txid, + address: g.user.address, + date: moment().format("YYYY-MM-DD HH:mm:ss"), + received: amount, + exchange: g.exchange + }); + } return getAddress(); } }; -- cgit v1.2.3