Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions apis/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as TokenSale from '../components/constants/contracts/TokenSale';
import * as MyBitToken from '../components/constants/contracts/MyBitToken';
import { NODESMITH_WEBSOCKET_PROVIDER } from '../components/constants';
import dayjs from 'dayjs';
import Web3 from 'web3';
const abiDecoder = require('abi-decoder');
Expand Down Expand Up @@ -279,9 +280,7 @@ export const getAllContributionsPerDay = async (userAddress, currentDay, timesta
new Promise(async (resolve, reject) => {
try {
debug("fetching all contributions with web3")
// If we try to fetch the logs using Infura (MetaMask's default) it won't work.
// See https://community.infura.io/t/getlogs-error-query-returned-more-than-1000-results/358
const web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.WEBSOCKET_PROVIDER_MAINNET));
const web3 = new Web3(new Web3.providers.WebsocketProvider(NODESMITH_WEBSOCKET_PROVIDER));
const tokenSaleContract = new web3.eth.Contract(
TokenSale.ABI,
TokenSale.ADDRESS,
Expand Down Expand Up @@ -491,7 +490,7 @@ const resetSocket = async () => {
let errorCounter = 0;

const subscribeToEvents = async () => {
const provider = new Web3.providers.WebsocketProvider(process.env.WEBSOCKET_PROVIDER_MAINNET);
const provider = new Web3.providers.WebsocketProvider(NODESMITH_WEBSOCKET_PROVIDER);
provider.on('error', e => {
debug("socket connection error ")
debug(e)
Expand Down
2 changes: 2 additions & 0 deletions components/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const tokenSaleEvents = {

export const correctNetwork = 'main';

export const NODESMITH_WEBSOCKET_PROVIDER = `wss://ethereum.api.nodesmith.io/v1/mainnet/jsonrpc/ws?apiKey=${process.env.NODESMITH_API_KEY}`;

export const BLOCK_NUMBER_CONTRACT_CREATION = 6910971;

export const getSecondsUntilNextPeriod = (timestampStartTokenSale) => {
Expand Down
3 changes: 2 additions & 1 deletion components/context/AppInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
tokensPerDay,
correctNetwork,
MyBitTokenSaleAPIEndpoint,
NODESMITH_WEBSOCKET_PROVIDER,
} from '../constants/';
import * as Core from '../../apis/core';
import * as TokenSale from '../constants/contracts/TokenSale';
Expand Down Expand Up @@ -93,7 +94,7 @@ class AppInfo extends React.Component {
//case where user has metamask but is connected to the wrong network, we
//still need to load the data properly from the correct network
else if(this.props.isMetamaskInstalled && (this.props.network !== correctNetwork)){
window.web3js = new Web3(new Web3.providers.WebsocketProvider(process.env.WEBSOCKET_PROVIDER_MAINNET))
window.web3js = new Web3(new Web3.providers.WebsocketProvider(NODESMITH_WEBSOCKET_PROVIDER))
this.loadInfo();
}
this.subscribeToEvents();
Expand Down
3 changes: 1 addition & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
config.plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.WEBSOCKET_PROVIDER_ROPSTEN': JSON.stringify(process.env.WEBSOCKET_PROVIDER_ROPSTEN),
'process.env.WEBSOCKET_PROVIDER_MAINNET': JSON.stringify(process.env.WEBSOCKET_PROVIDER_MAINNET),
'process.env.NODESMITH_API_KEY': JSON.stringify(process.env.NODESMITH_API_KEY),
}),
new CompressionPlugin({
asset: "[path].gz[query]",
Expand Down
3 changes: 1 addition & 2 deletions now.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "mybit.io",
"version": 1,
"env": {
"WEBSOCKET_PROVIDER_ROPSTEN": "@websocket_provider_ropsten",
"WEBSOCKET_PROVIDER_MAINNET": "@websocket_provider_mainnet"
"NODESMITH_API_KEY": "@nodesmith_api_key"
}
}