diff --git a/content/_code-samples/monitor-payments-websocket/read-amount-received.js b/content/_code-samples/monitor-payments-websocket/read-amount-received.js index 0a61c2cf80..925a39a0ed 100644 --- a/content/_code-samples/monitor-payments-websocket/read-amount-received.js +++ b/content/_code-samples/monitor-payments-websocket/read-amount-received.js @@ -3,6 +3,9 @@ function CountXRPDifference(affected_nodes, address) { // its balance changed, if at all. Fortunately, each account appears at most // once in the AffectedNodes array, so we can return as soon as we find it. + // Note: this reports the net balance change. If the address is the sender, + // the transaction cost is deducted and combined with XRP sent/received + for (let i=0; i { socket.addEventListener('open', (event) => { // This callback runs when the connection is open writeToConsole("#monitor-console-connect", "Connected!") + $("#connection-status").text("Connected") const command = { "id": "on_open_ping_1", "command": "ping" @@ -84,8 +85,13 @@ $("#connect-button").click((event) => { socket.send(JSON.stringify(command)) complete_step("Connect") + $("#connect-button").prop("disabled", "disabled") $("#enable_dispatcher").prop("disabled",false) }) + socket.addEventListener('close', (event) => { + $("#connection-status").text("Disconnected") + $("#connect-button").prop("disabled", false) + }) socket.addEventListener('message', (event) => { writeToConsole("#monitor-console-connect", "Got message from server: "+JSON.stringify(event.data)) }) @@ -298,6 +304,7 @@ async function do_subscribe() { $("#tx_subscribe").click((event) => { do_subscribe() complete_step("Subscribe") + $("#tx_read").prop("disabled", false) }) const log_tx = function(tx) { @@ -312,7 +319,7 @@ WS_HANDLERS["transaction"] = log_tx -## {{n.next()}}. Identify Incoming Payments +## {{n.next()}}. Read Incoming Payments When you subscribe to an account, you get messages for _all transactions to or from the account_, as well as _transactions that affect the account indirectly_, such as trading its [issued currencies](issued-currencies.html). If your goal is to recognize when the account has received incoming payments, you must filter the transactions stream and process the payments based on the amount they actually delivered. Look for the following information: @@ -342,7 +349,105 @@ The following sample code looks at transaction metadata of all the above transac {% include '_code-samples/monitor-payments-websocket/read-amount-received.js' %} ``` -***TODO: interactive part for identifying incoming payments*** +{{ start_step("Read Payments") }} + +
Transactions
+
(Log is empty)
+{{ end_step() }} + + ## {{n.next()}}. Look Out for Gaps