(Fix) SearchBar, Set Metadata bugfix, and refactoring (#114)
* Fix SearchBar and refactoring * Improve message texts
This commit is contained in:
parent
a1c023202d
commit
67fc237996
|
@ -1,144 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'production';
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs-extra');
|
||||
const webpack = require('webpack');
|
||||
const config = require('../config/webpack.config.prod');
|
||||
const paths = require('../config/paths');
|
||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
||||
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||
|
||||
const measureFileSizesBeforeBuild =
|
||||
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||
|
||||
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||
|
||||
// Warn and crash if required files are missing
|
||||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// First, read the current file sizes in build directory.
|
||||
// This lets us display how much they changed later.
|
||||
measureFileSizesBeforeBuild(paths.appBuild)
|
||||
.then(previousFileSizes => {
|
||||
// Remove all content but keep the directory so that
|
||||
// if you're in it, you don't end up in Trash
|
||||
fs.emptyDirSync(paths.appBuild);
|
||||
// Merge with the public folder
|
||||
copyPublicFolder();
|
||||
// Start the webpack build
|
||||
return build(previousFileSizes);
|
||||
})
|
||||
.then(
|
||||
({ stats, previousFileSizes, warnings }) => {
|
||||
if (warnings.length) {
|
||||
console.log(chalk.yellow('Compiled with warnings.\n'));
|
||||
console.log(warnings.join('\n\n'));
|
||||
console.log(
|
||||
'\nSearch for the ' +
|
||||
chalk.underline(chalk.yellow('keywords')) +
|
||||
' to learn more about each warning.'
|
||||
);
|
||||
console.log(
|
||||
'To ignore, add ' +
|
||||
chalk.cyan('// eslint-disable-next-line') +
|
||||
' to the line before.\n'
|
||||
);
|
||||
} else {
|
||||
console.log(chalk.green('Compiled successfully.\n'));
|
||||
}
|
||||
|
||||
console.log('File sizes after gzip:\n');
|
||||
printFileSizesAfterBuild(
|
||||
stats,
|
||||
previousFileSizes,
|
||||
paths.appBuild,
|
||||
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
||||
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||
);
|
||||
console.log();
|
||||
|
||||
const appPackage = require(paths.appPackageJson);
|
||||
const publicUrl = paths.publicUrl;
|
||||
const publicPath = config.output.publicPath;
|
||||
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
||||
printHostingInstructions(
|
||||
appPackage,
|
||||
publicUrl,
|
||||
publicPath,
|
||||
buildFolder,
|
||||
useYarn
|
||||
);
|
||||
},
|
||||
err => {
|
||||
console.log(chalk.red('Failed to compile.\n'));
|
||||
console.log((err.message || err) + '\n');
|
||||
process.exit(1);
|
||||
}
|
||||
);
|
||||
|
||||
// Create the production build and print the deployment instructions.
|
||||
function build(previousFileSizes) {
|
||||
console.log('Creating an optimized production build...');
|
||||
|
||||
let compiler = webpack(config);
|
||||
return new Promise((resolve, reject) => {
|
||||
compiler.run((err, stats) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
const messages = formatWebpackMessages(stats.toJson({}, true));
|
||||
if (messages.errors.length) {
|
||||
return reject(new Error(messages.errors.join('\n\n')));
|
||||
}
|
||||
if (
|
||||
process.env.CI &&
|
||||
(typeof process.env.CI !== 'string' ||
|
||||
process.env.CI.toLowerCase() !== 'false') &&
|
||||
messages.warnings.length
|
||||
) {
|
||||
console.log(
|
||||
chalk.yellow(
|
||||
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
||||
'Most CI servers set it automatically.\n'
|
||||
)
|
||||
);
|
||||
return reject(new Error(messages.warnings.join('\n\n')));
|
||||
}
|
||||
return resolve({
|
||||
stats,
|
||||
previousFileSizes,
|
||||
warnings: messages.warnings,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function copyPublicFolder() {
|
||||
fs.copySync(paths.appPublic, paths.appBuild, {
|
||||
dereference: true,
|
||||
filter: file => file !== paths.appHtml,
|
||||
});
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'development';
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const webpack = require('webpack');
|
||||
const WebpackDevServer = require('webpack-dev-server');
|
||||
const clearConsole = require('react-dev-utils/clearConsole');
|
||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||
const {
|
||||
choosePort,
|
||||
createCompiler,
|
||||
prepareProxy,
|
||||
prepareUrls,
|
||||
} = require('react-dev-utils/WebpackDevServerUtils');
|
||||
const openBrowser = require('react-dev-utils/openBrowser');
|
||||
const paths = require('../config/paths');
|
||||
const config = require('../config/webpack.config.dev');
|
||||
const createDevServerConfig = require('../config/webpackDevServer.config');
|
||||
|
||||
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||
const isInteractive = process.stdout.isTTY;
|
||||
|
||||
// Warn and crash if required files are missing
|
||||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Tools like Cloud9 rely on this.
|
||||
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
||||
const HOST = process.env.HOST || '0.0.0.0';
|
||||
|
||||
// We attempt to use the default port but if it is busy, we offer the user to
|
||||
// run on a different port. `detect()` Promise resolves to the next free port.
|
||||
choosePort(HOST, DEFAULT_PORT)
|
||||
.then(port => {
|
||||
if (port == null) {
|
||||
// We have not found a port.
|
||||
return;
|
||||
}
|
||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||
const appName = require(paths.appPackageJson).name;
|
||||
const urls = prepareUrls(protocol, HOST, port);
|
||||
// Create a webpack compiler that is configured with custom messages.
|
||||
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
|
||||
// Load proxy config
|
||||
const proxySetting = require(paths.appPackageJson).proxy;
|
||||
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
||||
// Serve webpack assets generated by the compiler over a web sever.
|
||||
const serverConfig = createDevServerConfig(
|
||||
proxyConfig,
|
||||
urls.lanUrlForConfig
|
||||
);
|
||||
const devServer = new WebpackDevServer(compiler, serverConfig);
|
||||
// Launch WebpackDevServer.
|
||||
devServer.listen(port, HOST, err => {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
if (isInteractive) {
|
||||
clearConsole();
|
||||
}
|
||||
console.log(chalk.cyan('Starting the development server...\n'));
|
||||
openBrowser(urls.localUrlForBrowser);
|
||||
});
|
||||
|
||||
['SIGINT', 'SIGTERM'].forEach(function(sig) {
|
||||
process.on(sig, function() {
|
||||
devServer.close();
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
if (err && err.message) {
|
||||
console.log(err.message);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
|
@ -1,27 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'test';
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.PUBLIC_URL = '';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const jest = require('jest');
|
||||
const argv = process.argv.slice(2);
|
||||
|
||||
// Watch unless on CI or in coverage mode
|
||||
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
|
||||
argv.push('--watch');
|
||||
}
|
||||
|
||||
|
||||
jest.run(argv);
|
|
@ -12780,6 +12780,47 @@
|
|||
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-5.1.2.tgz",
|
||||
"integrity": "sha512-7kEBKwU9R8fKnZJBRa5RSIfay4KJwnYvKB6gODGicUmDSAhQJ7Tdnll5S0RLtYrzRfMVXlqYw61rzrSpP4ThLQ=="
|
||||
},
|
||||
"react-html-parser": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/react-html-parser/-/react-html-parser-2.0.2.tgz",
|
||||
"integrity": "sha512-XeerLwCVjTs3njZcgCOeDUqLgNIt/t+6Jgi5/qPsO/krUWl76kWKXMeVs2LhY2gwM6X378DkhLjur0zUQdpz0g==",
|
||||
"requires": {
|
||||
"htmlparser2": "^3.9.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"domhandler": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz",
|
||||
"integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==",
|
||||
"requires": {
|
||||
"domelementtype": "1"
|
||||
}
|
||||
},
|
||||
"htmlparser2": {
|
||||
"version": "3.10.1",
|
||||
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz",
|
||||
"integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==",
|
||||
"requires": {
|
||||
"domelementtype": "^1.3.1",
|
||||
"domhandler": "^2.3.0",
|
||||
"domutils": "^1.5.1",
|
||||
"entities": "^1.1.1",
|
||||
"inherits": "^2.0.1",
|
||||
"readable-stream": "^3.1.1"
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz",
|
||||
"integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==",
|
||||
"requires": {
|
||||
"inherits": "^2.0.3",
|
||||
"string_decoder": "^1.1.1",
|
||||
"util-deprecate": "^1.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"react-input-autosize": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/react-input-autosize/-/react-input-autosize-2.2.1.tgz",
|
||||
|
@ -16079,6 +16120,14 @@
|
|||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
||||
},
|
||||
"typedarray-to-buffer": {
|
||||
"version": "3.1.5",
|
||||
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
|
||||
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
|
||||
"requires": {
|
||||
"is-typedarray": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.4.9",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz",
|
||||
|
@ -16933,30 +16982,8 @@
|
|||
"integrity": "sha1-fecPG4Py3jZHZ3IVa+z+9uNRbrM=",
|
||||
"requires": {
|
||||
"underscore": "1.8.3",
|
||||
"web3-core-helpers": "1.0.0-beta.34"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"websocket": {
|
||||
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
|
||||
"from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
|
||||
"requires": {
|
||||
"debug": "^2.2.0",
|
||||
"nan": "^2.3.3"
|
||||
}
|
||||
}
|
||||
"web3-core-helpers": "1.0.0-beta.34",
|
||||
"websocket": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible"
|
||||
}
|
||||
},
|
||||
"web3-shh": {
|
||||
|
@ -17576,6 +17603,31 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"websocket": {
|
||||
"version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2",
|
||||
"from": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible",
|
||||
"requires": {
|
||||
"debug": "^2.2.0",
|
||||
"nan": "^2.3.3",
|
||||
"typedarray-to-buffer": "^3.1.2",
|
||||
"yaeti": "^0.0.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
}
|
||||
}
|
||||
},
|
||||
"websocket-driver": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.0.tgz",
|
||||
|
@ -17952,6 +18004,11 @@
|
|||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
|
||||
"integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE="
|
||||
},
|
||||
"yaeti": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
|
||||
"integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc="
|
||||
},
|
||||
"yallist": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
"react-app-polyfill": "0.1.3",
|
||||
"react-dev-utils": "6.1.1",
|
||||
"react-dom": "16.6.3",
|
||||
"react-html-parser": "^2.0.2",
|
||||
"react-places-autocomplete": "5.4.3",
|
||||
"react-router": "4.3.1",
|
||||
"react-router-dom": "4.3.1",
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<link rel="manifest" href="%PUBLIC_URL%/favicons/manifest.json">
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicons/favicon.ico">
|
||||
<link href="https://fonts.googleapis.com/css?family=Nunito:300,400,700" rel="stylesheet">
|
||||
<title>POA Validators dApp</title>
|
||||
<title>POA Validators DApp</title>
|
||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD97qDOBYZ2fH86Wq1vzhDOiSUsZGVqbVQ&libraries=places"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"short_name": "POA Validators dApp",
|
||||
"name": "POA Validators dApp",
|
||||
"short_name": "POA Validators DApp",
|
||||
"name": "POA Validators DApp",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
|
|
|
@ -12,6 +12,7 @@ import { Loading } from './components/Loading'
|
|||
import { MainTitle } from './components/MainTitle'
|
||||
import { constants } from './utils/constants'
|
||||
import { geocodeByAddress } from 'react-places-autocomplete'
|
||||
import ReactHtmlParser from 'react-html-parser'
|
||||
import messages from './utils/messages'
|
||||
|
||||
import './assets/stylesheets/index.css'
|
||||
|
@ -264,7 +265,7 @@ class App extends Component {
|
|||
const netId = Number(this.props.web3Config.netId)
|
||||
const { isCompany } = this.state.form
|
||||
const { networkBranch } = this.props
|
||||
const hideNote = netId !== helpers.netIdByName(constants.branches.CORE)
|
||||
const hideNote = netId !== helpers.netIdByBranch(constants.branches.CORE)
|
||||
const isCompanyAllowed = helpers.isCompanyAllowed(netId)
|
||||
const inputProps = {
|
||||
id: 'address',
|
||||
|
@ -298,7 +299,7 @@ class App extends Component {
|
|||
<div className="vld-App">
|
||||
<MainTitle text={constants.navigationData[1].title} />
|
||||
{error ? (
|
||||
<p>{error}</p>
|
||||
<p>{ReactHtmlParser(error)}</p>
|
||||
) : (
|
||||
<div>
|
||||
{isCompanyAllowed ? (
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
display: none;
|
||||
}
|
||||
}
|
||||
a {
|
||||
button {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
|
@ -85,6 +85,9 @@
|
|||
color: #fff;
|
||||
transition: .15s ease-in;
|
||||
height: 50px;
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
@media (min-width: $breakpoint-md) {
|
||||
padding: 8px 18px;
|
||||
height: auto;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,5 @@
|
|||
import React, { Component } from 'react'
|
||||
import { constants } from '../../utils/constants'
|
||||
import helpers from '../../utils/helpers'
|
||||
|
||||
export default class NetworkSelect extends Component {
|
||||
changeNetworkRPC(e) {
|
||||
|
@ -9,7 +8,7 @@ export default class NetworkSelect extends Component {
|
|||
let getCurrentClickedLinkId = ''
|
||||
for (const _netId in constants.NETWORKS) {
|
||||
if (constants.NETWORKS[_netId].FULLNAME === getCurrentClickedLink) {
|
||||
getCurrentClickedLinkId = helpers.netIdByName(constants.NETWORKS[_netId].NAME)
|
||||
getCurrentClickedLinkId = _netId
|
||||
}
|
||||
}
|
||||
this.props.onChange({ value: getCurrentClickedLinkId })
|
||||
|
@ -45,9 +44,7 @@ export default class NetworkSelect extends Component {
|
|||
}
|
||||
return (
|
||||
<li key={name.toString()} className={className}>
|
||||
<a href="#" onClick={e => this.changeNetworkRPC(e)}>
|
||||
{name}
|
||||
</a>
|
||||
<button onClick={e => this.changeNetworkRPC(e)}>{name}</button>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React from 'react'
|
||||
|
||||
export const SearchBar = ({ extraClassName = '', networkBranch = false, onSearch }) => {
|
||||
export const SearchBar = ({ extraClassName = '', networkBranch = false, searchTerm = '', onSearch }) => {
|
||||
return (
|
||||
<div className={`sw-SearchBar sw-SearchBar-${networkBranch} ${extraClassName}`}>
|
||||
<div className="sw-SearchBar_Content">
|
||||
|
@ -9,6 +9,7 @@ export const SearchBar = ({ extraClassName = '', networkBranch = false, onSearch
|
|||
onChange={onSearch}
|
||||
placeholder="Search..."
|
||||
type="search"
|
||||
value={searchTerm}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
21
src/index.js
21
src/index.js
|
@ -75,9 +75,8 @@ class AppMainRouter extends Component {
|
|||
netId: web3Config.netId,
|
||||
addresses
|
||||
})
|
||||
await this.onAccountChange(web3Config.defaultAccount)
|
||||
this.setState({
|
||||
votingKey: web3Config.defaultAccount,
|
||||
miningKey: await this.state.keysManager.miningKeyByVoting(web3Config.defaultAccount),
|
||||
injectedWeb3: web3Config.injectedWeb3,
|
||||
networkMatch: web3Config.networkMatch
|
||||
})
|
||||
|
@ -124,13 +123,13 @@ class AppMainRouter extends Component {
|
|||
this.setState(newState)
|
||||
}
|
||||
|
||||
onAccountChange(account) {
|
||||
this.state.keysManager.miningKeyByVoting(account).then(miningKey => {
|
||||
this.setState({
|
||||
votingKey: account,
|
||||
miningKey: miningKey
|
||||
})
|
||||
async onAccountChange(votingKey) {
|
||||
const miningKey = await this.state.keysManager.miningKeyByVoting(votingKey)
|
||||
this.setState({
|
||||
votingKey,
|
||||
miningKey
|
||||
})
|
||||
console.log(`Accounts set:\nvotingKey = ${votingKey}\nminingKey = ${miningKey}`)
|
||||
}
|
||||
|
||||
onRouteChange() {
|
||||
|
@ -252,7 +251,7 @@ class AppMainRouter extends Component {
|
|||
}
|
||||
|
||||
onNetworkChange(e) {
|
||||
this.setState({ loading: true, loadingNetworkBranch: getNetworkBranch(e.value) })
|
||||
this.setState({ loading: true, loadingNetworkBranch: getNetworkBranch(e.value), searchTerm: '' })
|
||||
window.localStorage.netId = e.value
|
||||
this.initChain()
|
||||
}
|
||||
|
@ -278,7 +277,9 @@ class AppMainRouter extends Component {
|
|||
onMenuToggle={this.toggleMobileMenu}
|
||||
showMobileMenu={this.state.showMobileMenu}
|
||||
/>
|
||||
{this.state.showSearch ? <SearchBar networkBranch={networkBranch} onSearch={this.onSearch} /> : null}
|
||||
{this.state.showSearch ? (
|
||||
<SearchBar networkBranch={networkBranch} onSearch={this.onSearch} searchTerm={this.state.searchTerm} />
|
||||
) : null}
|
||||
{this.state.loading
|
||||
? ReactDOM.createPortal(
|
||||
<Loading networkBranch={networkBranch} />,
|
||||
|
|
|
@ -41,7 +41,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'Kovan Testnet',
|
||||
RPC: 'https://kovan.infura.io/v3/1125fe73d87c4e5396678f4e3089b3dd',
|
||||
BRANCH: constants.branches.KOVAN,
|
||||
TESTNET: true,
|
||||
SORTORDER: 3
|
||||
},
|
||||
'77': {
|
||||
|
@ -49,7 +48,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'Sokol Testnet',
|
||||
RPC: 'https://sokol.poa.network',
|
||||
BRANCH: constants.branches.SOKOL,
|
||||
TESTNET: true,
|
||||
SORTORDER: 4
|
||||
},
|
||||
'99': {
|
||||
|
@ -57,7 +55,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'POA Core',
|
||||
RPC: 'https://core.poa.network',
|
||||
BRANCH: constants.branches.CORE,
|
||||
TESTNET: false,
|
||||
SORTORDER: 1
|
||||
},
|
||||
'100': {
|
||||
|
@ -65,7 +62,6 @@ constants.NETWORKS = {
|
|||
FULLNAME: 'xDai Stable Chain',
|
||||
RPC: 'https://dai.poa.network',
|
||||
BRANCH: constants.branches.DAI,
|
||||
TESTNET: false,
|
||||
SORTORDER: 2
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import Web3 from 'web3'
|
|||
import helpers from './helpers'
|
||||
import { constants } from './constants'
|
||||
|
||||
const defaultNetId = helpers.netIdByName(constants.branches.CORE)
|
||||
const defaultNetId = helpers.netIdByBranch(constants.branches.CORE)
|
||||
|
||||
export default async function getWeb3(netId = defaultNetId, onAccountChange) {
|
||||
let web3 = null
|
||||
|
@ -17,6 +17,7 @@ export default async function getWeb3(netId = defaultNetId, onAccountChange) {
|
|||
} catch (e) {
|
||||
throw Error('You have denied access to your accounts')
|
||||
}
|
||||
window.ethereum.autoRefreshOnNetworkChange = true
|
||||
} else if (window.web3) {
|
||||
web3 = new Web3(window.web3.currentProvider)
|
||||
console.log('Injected web3 detected.')
|
||||
|
@ -37,11 +38,11 @@ export default async function getWeb3(netId = defaultNetId, onAccountChange) {
|
|||
}
|
||||
|
||||
let currentAccount = defaultAccount ? defaultAccount.toLowerCase() : ''
|
||||
web3.currentProvider.publicConfigStore.on('update', function(obj) {
|
||||
web3.currentProvider.publicConfigStore.on('update', async function(obj) {
|
||||
const account = obj.selectedAddress
|
||||
if (account && account !== currentAccount) {
|
||||
currentAccount = account
|
||||
onAccountChange(account)
|
||||
await onAccountChange(account)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -13,18 +13,17 @@ function generateAlert(icon, title, msg) {
|
|||
|
||||
function isCompanyAllowed(netId) {
|
||||
switch (netId) {
|
||||
case netIdByName(constants.branches.DAI):
|
||||
case netIdByName(constants.branches.KOVAN):
|
||||
case netIdByBranch(constants.branches.DAI):
|
||||
case netIdByBranch(constants.branches.KOVAN):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function netIdByName(netName) {
|
||||
const netNameLowerCase = netName.toLowerCase()
|
||||
for (let netId in constants.NETWORKS) {
|
||||
if (constants.NETWORKS[netId].NAME.toLowerCase() === netNameLowerCase) {
|
||||
function netIdByBranch(branch) {
|
||||
for (const netId in constants.NETWORKS) {
|
||||
if (constants.NETWORKS[netId].BRANCH === branch) {
|
||||
return Number(netId)
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +33,7 @@ function netIdByName(netName) {
|
|||
const helpers = {
|
||||
generateAlert,
|
||||
isCompanyAllowed,
|
||||
netIdByName
|
||||
netIdByBranch
|
||||
}
|
||||
|
||||
export default helpers
|
||||
|
|
|
@ -5,13 +5,13 @@ messages.wrongRepo = function(repo) {
|
|||
return `There is no such file in configured repo ${repo}`
|
||||
}
|
||||
messages.invalidaVotingKey =
|
||||
'The current key is not a valid Voting Key! Please make sure you have loaded the correct Voting Key in Metamask / Nifty Wallet.'
|
||||
messages.noMetamaskAccount = 'Your MetaMask is locked.'
|
||||
messages.noMetamaskFound = 'Metamask is not found.'
|
||||
'The current key is not a valid Voting Key! Please make sure you have loaded the correct Voting Key in MetaMask / Nifty Wallet.'
|
||||
messages.noMetamaskAccount = 'Your MetaMask / Nifty Wallet is locked.'
|
||||
messages.noMetamaskFound = 'MetaMask / Nifty Wallet is not found.'
|
||||
|
||||
messages.networkMatchError = function(netId) {
|
||||
const networkName = getNetworkFullName(Number(netId))
|
||||
return `Networks in DApp and MetaMask do not match. Switch MetaMask to ${networkName} or change the network in DApp.`
|
||||
return `Networks in DApp and MetaMask (Nifty Wallet) do not match. Switch MetaMask / Nifty Wallet to <b>${networkName}</b> or change the network in DApp.`
|
||||
}
|
||||
|
||||
export default messages
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
import { constants } from './constants'
|
||||
|
||||
export const isTestnet = netId => {
|
||||
return netId in constants.NETWORKS && constants.NETWORKS[netId].TESTNET
|
||||
}
|
||||
|
||||
export const isValidNetwork = netId => {
|
||||
return netId in constants.NETWORKS
|
||||
}
|
||||
|
||||
export const getNetworkBranch = netId => {
|
||||
return constants.NETWORKS[netId].BRANCH
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue