Reuse intervalutils in website
This commit is contained in:
parent
9ad9e1204c
commit
ce242b10e2
@ -23,7 +23,7 @@ import {
|
||||
LedgerWalletSubprovider,
|
||||
RedundantRPCSubprovider,
|
||||
} from '@0xproject/subproviders';
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {intervalUtils, promisify} from '@0xproject/utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import compareVersions = require('compare-versions');
|
||||
import ethUtil = require('ethereumjs-util');
|
||||
@ -75,7 +75,7 @@ export class Blockchain {
|
||||
private userAddress: string;
|
||||
private cachedProvider: Web3.Provider;
|
||||
private ledgerSubprovider: LedgerWalletSubprovider;
|
||||
private zrxPollIntervalId: number;
|
||||
private zrxPollIntervalId: NodeJS.Timer;
|
||||
private static async onPageLoadAsync() {
|
||||
if (document.readyState === 'complete') {
|
||||
return; // Already loaded
|
||||
@ -359,7 +359,7 @@ export class Blockchain {
|
||||
|
||||
const [currBalance] = await this.getTokenBalanceAndAllowanceAsync(this.userAddress, token.address);
|
||||
|
||||
this.zrxPollIntervalId = window.setInterval(async () => {
|
||||
this.zrxPollIntervalId = intervalUtils.setAsyncExcludingInterval(async () => {
|
||||
const [balance] = await this.getTokenBalanceAndAllowanceAsync(this.userAddress, token.address);
|
||||
if (!balance.eq(currBalance)) {
|
||||
this.dispatcher.replaceTokenBalanceByAddress(token.address, balance);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {promisify} from '@0xproject/utils';
|
||||
import {intervalUtils, promisify} from '@0xproject/utils';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import * as _ from 'lodash';
|
||||
import {Dispatcher} from 'ts/redux/dispatcher';
|
||||
@ -9,7 +9,7 @@ export class Web3Wrapper {
|
||||
private web3: Web3;
|
||||
private prevNetworkId: number;
|
||||
private shouldPollUserAddress: boolean;
|
||||
private watchNetworkAndBalanceIntervalId: number;
|
||||
private watchNetworkAndBalanceIntervalId: NodeJS.Timer;
|
||||
private prevUserEtherBalanceInEth: BigNumber;
|
||||
private prevUserAddress: string;
|
||||
constructor(dispatcher: Dispatcher, provider: Web3.Provider, networkIdIfExists: number,
|
||||
@ -98,7 +98,7 @@ export class Web3Wrapper {
|
||||
let prevNodeVersion: string;
|
||||
this.prevUserEtherBalanceInEth = new BigNumber(0);
|
||||
this.dispatcher.updateNetworkId(this.prevNetworkId);
|
||||
this.watchNetworkAndBalanceIntervalId = window.setInterval(async () => {
|
||||
this.watchNetworkAndBalanceIntervalId = intervalUtils.setAsyncExcludingInterval(async () => {
|
||||
// Check for network state changes
|
||||
const currentNetworkId = await this.getNetworkIdIfExists();
|
||||
if (currentNetworkId !== this.prevNetworkId) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user