Browse Source

Fix for events firing multiple times

develop
Ezerous 4 years ago
parent
commit
09ee4f277f
  1. 2
      package.json
  2. 17
      src/contracts/contractsSaga.js

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@ezerous/drizzle", "name": "@ezerous/drizzle",
"version": "0.4.1", "version": "0.4.2",
"description": "A reactive data-store for web3 and smart contracts.", "description": "A reactive data-store for web3 and smart contracts.",
"license": "MIT", "license": "MIT",
"author": "Ezerous <ezerous@gmail.com>", "author": "Ezerous <ezerous@gmail.com>",

17
src/contracts/contractsSaga.js

@ -6,6 +6,18 @@ import * as TransactionsActions from '../transactions/transactionsActions'
/* /*
* Events * Events
*/ */
// Patch for EVENT_FIRED being called multiple times for the same event
let eventSet = new Set();
function isEventUnique(event){
const size = eventSet.size;
eventSet.add(event.event + '-' + event.transactionHash);
if(eventSet.size>size)
return true;
return false;
}
export function createContractEventChannel ({ export function createContractEventChannel ({
contract, contract,
eventName, eventName,
@ -14,9 +26,10 @@ export function createContractEventChannel ({
const name = contract.contractName const name = contract.contractName
return eventChannel(emit => { return eventChannel(emit => {
const eventListener = contract.events[eventName](eventOptions) const eventListener = contract.events[eventName]()
.on('data', event => { .on('data', event => {
emit({ type: ContractActions.CONTRACT_EVENT_FIRED, name, event }) if(isEventUnique(event))
emit({ type: ContractActions.CONTRACT_EVENT_FIRED, name, event })
}) })
.on('changed', event => { .on('changed', event => {
emit({ type: ContractActions.CONTRACT_EVENT_CHANGED, name, event }) emit({ type: ContractActions.CONTRACT_EVENT_CHANGED, name, event })

Loading…
Cancel
Save