reverse caching: use subscribeToEvents

This commit is contained in:
Jannis R 2017-01-09 19:03:19 +01:00
parent 67c2981975
commit f12937a21e
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
2 changed files with 7 additions and 13 deletions

View File

@ -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
});

View File

@ -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 = {};
@ -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);
@ -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);