Skip to content

Commit

Permalink
Fix some transactions not triggering websockets
Browse files Browse the repository at this point in the history
This is an attempted, untested fix
  • Loading branch information
Lemmmy committed Feb 12, 2020
1 parent 9bdab5d commit db4c9ff
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/transactions.js
Expand Up @@ -92,6 +92,20 @@ Transactions.createTransaction = function (to, from, value, name, op) {
}).then(function(transaction) {
webhooks.callTransactionWebhooks(transaction);

websockets.broadcastEvent({
type: 'event',
event: 'transaction',
transaction: Transactions.transactionToJSON(transaction)
}, function(ws) {
return new Promise(function(resolve, reject) {
if ((!ws.isGuest && (ws.auth === to || ws.auth === from) && ws.subscriptionLevel.indexOf("ownTransactions") >= 0) || ws.subscriptionLevel.indexOf("transactions") >= 0) {
return resolve();
}

reject();
});
});

resolve(transaction);
}).catch(reject);
});
Expand Down Expand Up @@ -120,20 +134,6 @@ Transactions.pushTransaction = function(sender, recipientAddress, amount, metada
}

Promise.all(promises).then(function(results) {
websockets.broadcastEvent({
type: 'event',
event: 'transaction',
transaction: Transactions.transactionToJSON(results[2])
}, function(ws) {
return new Promise(function(resolve, reject) {
if ((!ws.isGuest && (ws.auth === recipientAddress || ws.auth === sender.address) && ws.subscriptionLevel.indexOf("ownTransactions") >= 0) || ws.subscriptionLevel.indexOf("transactions") >= 0) {
return resolve();
}

reject();
});
});

resolve(results[2]);
}).catch(reject);
}).catch(reject);
Expand All @@ -152,4 +152,4 @@ Transactions.transactionToJSON = function(transaction) {
};
};

module.exports = Transactions;
module.exports = Transactions;

0 comments on commit db4c9ff

Please sign in to comment.