Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
feat(sdk): fix using infuraurl for fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
joeandrews committed Jul 8, 2020
1 parent 72f6fbc commit 76791ce
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class SyncManager {
constructor() {
this.config = {
syncInterval: 5000, // ms
blocksPerRequest: 50, // ~ per 3 months (~6000 per day)
precisionDelta: 10, //
maxNumberOfAttempts: 5,
};
this.syncConfig = undefined;
this.networks = new Map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const infuraLimitError = {
message: 'query returned more than 10000 results',
};

const isInfuraLimitError = error => error && error.code === infuraLimitError.code;

const uriTooLong = {
code: -32603,
};

const isInfuraLimitError = error => error && error.code === infuraLimitError.code || error.code === uriTooLong.code;

const SYNCING_STATUS = {
ACTIVE: 'ACTIVE',
Expand All @@ -30,7 +35,7 @@ const SYNCING_STATUS = {
class SyncManager {
constructor() {
this.config = {
blocksPerRequest: 540000, // ~ per 3 months (~6000 per day)
blocksPerRequest: 6000 * 30, // ~ per 3 months (~6000 per day)
precisionDelta: 10, //
maxNumberOfAttempts: 5,
networkId: null,
Expand Down Expand Up @@ -134,7 +139,7 @@ class SyncManager {
lastSyncedBlock,
assets,
progressCallbacks,
retriedNumber = 0,
retriedNumber = 5,
} = options;

const syncAddress = this.addresses.get(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ class Watcher {

return subscription;
}

handleFetchError = (error) => {
errorLog('Failed to sync CreateNote / UpdateMetadata / DestroyNote with web3.', error);
if (process.env.NODE_ENV === 'development') {
this.paused = true;
}
};
}

export default Watcher;
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Web3 from 'web3';
import Web3Service from '~/helpers/Web3Service';
import {
ZkAsset,
} from '~/config/contracts';
import decodeNoteLogs from './helpers/decodeNoteLogs';
import { getProviderUrl } from '~/utils/network';

export default async function fetchNotes({
owner,
Expand All @@ -16,7 +18,9 @@ export default async function fetchNotes({
ZkAsset.events.updateNoteMetaData,
],
} = {}) {
const { abi, getPastLogs } = Web3Service.eth;
// TODO require network selection
const provider = new Web3.providers.HttpProvider(getProviderUrl(Web3Service.networkId));
const { abi, getPastLogs } = new Web3(provider).eth;

const eventsTopics = events
.map(e => ZkAsset.config.abi.find(({ name, type }) => name === e && type === 'event'))
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/config/provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const infuraProjectId = '09c4eed231c840d5ace14ba5389a1a7c';

export const infuraProviderUrlPattern = 'wss://{networkName}.infura.io/ws/v3/{projectId}';
export const infuraProviderUrlPattern = 'https://{networkName}.infura.io/v3/{projectId}';

export const defaultProviderUrl = 'ws://localhost:8545';

0 comments on commit 76791ce

Please sign in to comment.