Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
reverse caching: use subscribeToEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Jan 9, 2017
1 parent 67c2981 commit f12937a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion js/src/contracts/verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const awaitPuzzle = (api, contract, account) => {
return blockNumber(api)
.then((block) => {
return new Promise((resolve, reject) => {
const subscription = subscribeToEvents(contract, 'Puzzled', {
const subscription = subscribeToEvents(contract, ['Puzzled'], {
from: block.toNumber(),
filter: (log) => log.params.who.value === account
});
Expand Down
18 changes: 6 additions & 12 deletions js/src/redux/providers/registry/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import Contracts from '~/contracts';
import subscribeToEvent from '~/util/subscribe-to-event';
import subscribeToEvents from '~/util/subscribe-to-events';

import registryABI from '~/contracts/abi/registry.json';

import { setReverse, startCachingReverses } from './actions';

export default (api) => (store) => {
let contract, confirmedEvents, removedEvents, timeout, interval;
let contract, subscription, timeout, interval;

let addressesToCheck = {};

Expand Down Expand Up @@ -68,11 +68,8 @@ export default (api) => (store) => {
.then((_contract) => {
contract = _contract;

confirmedEvents = subscribeToEvent(_contract, 'ReverseConfirmed');
confirmedEvents.on('log', onLog);

removedEvents = subscribeToEvent(_contract, 'ReverseRemoved');
removedEvents.on('log', onLog);
subscription = subscribeToEvents(_contract, ['ReverseConfirmed', 'ReverseRemoved']);
subscription.on('log', onLog);

timeout = setTimeout(checkReverses, 5000);
interval = setInterval(checkReverses, 20000);
Expand All @@ -84,11 +81,8 @@ export default (api) => (store) => {

break;
case 'stopCachingReverses':
if (confirmedEvents) {
confirmedEvents.unsubscribe();
}
if (removedEvents) {
removedEvents.unsubscribe();
if (subscription) {
subscription.unsubscribe();
}
if (interval) {
clearInterval(interval);
Expand Down

0 comments on commit f12937a

Please sign in to comment.