Similar to the orderbook, we need to set an event stream for the successful trades in the network.
To do so, we use the following setTrades method:
setTrades = () => {
let app = this;
var tradeHandler = function (traderesponse) {
var tradesList = app.state.tradesList;
tradesList.push(traderesponse);
app.setState
({
tradesList
});
};
var es = this.server.trades()
.cursor('now')
.stream({
onmessage: tradeHandler
})
};
The internal tradeHandler method is called any time a new message is published to the trades event stream. The tradeHandler function updates the list of trades stored in the state variable, tradesList.
The tradesList array is mapped and rendered by the Trades.js component and displayed to the user in real time.