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) return blockNumber(api)
.then((block) => { .then((block) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const subscription = subscribeToEvents(contract, 'Puzzled', { const subscription = subscribeToEvents(contract, ['Puzzled'], {
from: block.toNumber(), from: block.toNumber(),
filter: (log) => log.params.who.value === account filter: (log) => log.params.who.value === account
}); });

View File

@ -15,14 +15,14 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import Contracts from '~/contracts'; 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 registryABI from '~/contracts/abi/registry.json';
import { setReverse, startCachingReverses } from './actions'; import { setReverse, startCachingReverses } from './actions';
export default (api) => (store) => { export default (api) => (store) => {
let contract, confirmedEvents, removedEvents, timeout, interval; let contract, subscription, timeout, interval;
let addressesToCheck = {}; let addressesToCheck = {};
@ -68,11 +68,8 @@ export default (api) => (store) => {
.then((_contract) => { .then((_contract) => {
contract = _contract; contract = _contract;
confirmedEvents = subscribeToEvent(_contract, 'ReverseConfirmed'); subscription = subscribeToEvents(_contract, ['ReverseConfirmed', 'ReverseRemoved']);
confirmedEvents.on('log', onLog); subscription.on('log', onLog);
removedEvents = subscribeToEvent(_contract, 'ReverseRemoved');
removedEvents.on('log', onLog);
timeout = setTimeout(checkReverses, 5000); timeout = setTimeout(checkReverses, 5000);
interval = setInterval(checkReverses, 20000); interval = setInterval(checkReverses, 20000);
@ -84,11 +81,8 @@ export default (api) => (store) => {
break; break;
case 'stopCachingReverses': case 'stopCachingReverses':
if (confirmedEvents) { if (subscription) {
confirmedEvents.unsubscribe(); subscription.unsubscribe();
}
if (removedEvents) {
removedEvents.unsubscribe();
} }
if (interval) { if (interval) {
clearInterval(interval); clearInterval(interval);