Skip to content

Commit

Permalink
[FIX] Resolve web3 (#57)
Browse files Browse the repository at this point in the history
* fallback node

* missed

* step

* package

* package

* downgrade web3

* restore web3

* lint
  • Loading branch information
adibas03 authored Sep 7, 2019
1 parent e848389 commit d1ddaf0
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 1,421 deletions.
1,878 changes: 467 additions & 1,411 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"autoprefixer": "^9.6.1",
"babel-eslint": "^10.0.2",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"copy-webpack-plugin": "^5.0.4",
"cross-env": "^5.2.0",
"cross-env": "^5.2.1",
"css-loader": "^3.2.0",
"eslint": "^6.1.0",
"eslint": "^6.3.0",
"eslint-plugin-react": "^7.14.3",
"file-loader": "^4.2.0",
"html-webpack-plugin": "^3.2.0",
"postcss-loader": "^3.0.0",
"react-hot-loader": "^4.12.10",
"react-hot-loader": "^4.12.12",
"style-loader": "^1.0.0",
"url-loader": "^2.1.0",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7",
"webpack-dev-server": "^3.8.0",
"webpack-merge": "^4.2.1"
"webpack-merge": "^4.2.2"
},
"dependencies": {
"bignumber.js": "^9.0.0",
Expand All @@ -72,7 +72,7 @@
"react-router": "^5.0.1",
"react-router-dom": "^5.0.1",
"react-toastify": "^5.3.2",
"semantic-ui-react": "^0.87.3",
"semantic-ui-react": "^0.88.0",
"web3": "^1.2.1"
},
"pre-commit": [
Expand Down
3 changes: 3 additions & 0 deletions src/components/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default class Content extends HasAlert {
web3Service.emitter.on('error', (e) =>
this.notify({ msg: e.message|| e, type: 'error' })
);
web3Service.emitter.on('info', (e) =>
this.notify({ msg: e.message|| e, type: 'info' })
);
}

state = {
Expand Down
2 changes: 2 additions & 0 deletions src/config/backupNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const infura = 'https://mainnet.infura.io/v3/33621b0ea64d4069b9e5a6d29fdac33a';
export default infura;
1 change: 1 addition & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export { default as call2Action } from './call2Action';
export { default as explorers } from './explorers';
export { default as networks } from './networks';
export { default as features } from './features';
export { default as backupNode } from './backupNode';
export { default as ethereumNode } from './ethereumNode';
export { default as fnSignatures } from './fnSignatures';
25 changes: 24 additions & 1 deletion src/services/web3Service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Web3 from 'web3';
import EventEmitter from 'events';
import { ethereumNode, explorers, fnSignatures, networks } from '../config';
import { backupNode, ethereumNode, explorers, fnSignatures, networks } from '../config';
import ERC20 from '../abi/ForeignToken';

class web3Service {
Expand Down Expand Up @@ -29,6 +29,29 @@ class web3Service {
this._web3 = new Web3(
Web3.givenProvider || window.web3.currentProvider
);
} else {
this.emitter.emit('info', 'Using backup(infura) Mainnet node');
if (backupNode.includes('http')) {
const slashIndex = backupNode.indexOf('//')+2;
const queryIndex = backupNode.indexOf('/', slashIndex) || backupNode.indexOf('?', slashIndex);
const domain = queryIndex >= 0 ? backupNode.substring(0, queryIndex) : backupNode;

this._web3 = new Web3(
new Web3.providers.HttpProvider(
backupNode,
{
headers: [{
name: 'Access-Control-Allow-Origin',
value: domain
}]
}
)
);
} else {
this._web3 = new Web3(
backupNode
);
}
}
this.isMetamask = this._web3.currentProvider.isMetaMask;
this.netId = await this._web3.eth.net.getId().valueOf();
Expand Down
2 changes: 1 addition & 1 deletion src/www/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<title>Token Transfer Dapp - Easy and optimized erc20 token transfer dapp</title>
<meta name="description" content="A decentralized dapp, to make quick ERC20, enabled tokens transfers">
<meta name="keywords" content="ethereum,ethereum-dapp,erc20,erc20-tokens,transfer,decentralized,dapp,token,tokens,online,metamask">
<link rel="icon" href="../images/icons/favicon.ico" />
<link rel="icon" href="./images/icons/favicon.ico" />
<link rel="canonical" href="https://ttd.icobusses.io/" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"></link>
<link href="https://fonts.googleapis.com/css?family=Roboto:500,700,900&display=swap" rel="stylesheet">
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const settings = merge(baseConfig, {
contentBase: path.resolve('src/'),
publicPath: 'http://localhost:8080/', // full URL is necessary for Hot Module Replacement if additional path will be added.
quiet: false,
https: true,
hot: true,
historyApiFallback: true,
inline: true
Expand Down

0 comments on commit d1ddaf0

Please sign in to comment.