#21 - if no web3 found, load hardcoded rpc
#19 - hardcode MoC Data
#22 - fix title
This commit is contained in:
Roman Storm 2017-12-29 22:27:13 -08:00
parent 3084f19d85
commit 654d77a42f
6 changed files with 67 additions and 23 deletions

View File

@ -20,7 +20,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>POA Validators dApp</title>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD97qDOBYZ2fH86Wq1vzhDOiSUsZGVqbVQ&libraries=places"></script>
</head>

View File

@ -5,11 +5,9 @@ import {KEYS_MANAGER_ADDRESS} from './addresses';
console.log('Keys Manager', KEYS_MANAGER_ADDRESS);
export default class KeysManager {
constructor(){
if(window.web3.currentProvider){
let web3_10 = new Web3(window.web3.currentProvider);
this.keysInstance = new web3_10.eth.Contract(KeysManagerAbi, KEYS_MANAGER_ADDRESS);
}
constructor({web3}){
let web3_10 = new Web3(web3.currentProvider);
this.keysInstance = new web3_10.eth.Contract(KeysManagerAbi, KEYS_MANAGER_ADDRESS);
}
async isVotingActive(votingKey) {
return await this.keysInstance.methods.isVotingActive(votingKey).call();

View File

@ -19,12 +19,12 @@ var toAscii = function(hex) {
};
console.log('Metadata contract:', METADATA_ADDRESS)
const SOKOL_MOC = '0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca';
const CORE_MOC = '0xCf260eA317555637C55F70e55dbA8D5ad8414Cb0';
export default class Metadata {
constructor(){
if(window.web3.currentProvider){
this.web3_10 = new Web3(window.web3.currentProvider);
this.metadataInstance = new this.web3_10.eth.Contract(MetadataAbi, METADATA_ADDRESS);
}
constructor({web3}){
this.web3_10 = new Web3(web3.currentProvider);
this.metadataInstance = new this.web3_10.eth.Contract(MetadataAbi, METADATA_ADDRESS);
}
async createMetadata({
firstName,
@ -49,6 +49,21 @@ export default class Metadata {
).send({from: votingKey});
}
getMocData() {
// Barinov, Igor 755 Bounty Dr 202 Foster City CA 94404 41 2206724 07/23/2021
return {
firstName: 'Igor',
lastName: 'Barinov',
fullAddress: '755 Bounty Dr 202',
createdDate: '2017-12-18',
updatedDate: '',
expirationDate: '2021-07-23',
licenseId: '2206724',
us_state: 'CA',
postal_code: 94404,
}
}
async getValidatorData({votingKey, miningKey}){
miningKey = miningKey || await this.getMiningByVoting(votingKey);
let validatorData = await this.metadataInstance.methods.validators(miningKey).call();
@ -75,11 +90,15 @@ export default class Metadata {
async getAllValidatorsData(){
let all = [];
return new Promise(async(resolve, reject) => {
const poaInstance = new PoaConsensus({web3: this.web3_10})
const keys = await poaInstance.getValidators()
for (let key of keys) {
let data = await this.getValidatorData({miningKey: key})
if(key === SOKOL_MOC || key === CORE_MOC) {
data = this.getMocData()
}
data.address = key
all.push(data)
}

View File

@ -4,11 +4,9 @@ import {POA_ADDRESS} from './addresses';
console.log('POA Address ' , POA_ADDRESS)
export default class POAConsensus {
constructor(){
if(window.web3.currentProvider){
let web3_10 = new Web3(window.web3.currentProvider);
this.poaInstance = new web3_10.eth.Contract(poaConsensusAbi, POA_ADDRESS);
}
constructor({web3}){
let web3_10 = new Web3(web3.currentProvider);
this.poaInstance = new web3_10.eth.Contract(poaConsensusAbi, POA_ADDRESS);
}
async getValidators(){
return await this.poaInstance.methods.getValidators().call();

View File

@ -1,3 +1,5 @@
import Web3 from 'web3'
let errorMsgNoMetamaskAccount = `You haven't chosen any account in MetaMask.
Please, choose your initial key in MetaMask and reload the page.
Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>wiki</a> for more info.`;
@ -29,10 +31,11 @@ let getWeb3 = () => {
default:
netIdName = 'ERROR'
errorMsg = `You aren't connected to POA Network.
Please, switch on POA plugin and refresh the page.
Please, switch to POA network and refresh the page.
Check POA Network <a href='https://github.com/poanetwork/wiki' target='blank'>wiki</a> for more info.`
console.log('This is an unknown network.', netId)
}
document.title = `${netIdName} - POA validators dApp`
var defaultAccount = web3.eth.defaultAccount || null;
if(defaultAccount === null){
reject({message: errorMsgNoMetamaskAccount})
@ -53,7 +56,24 @@ let getWeb3 = () => {
console.log('Injected web3 detected.');
} else {
reject({message: errorMsgNoMetamaskAccount})
// Fallback to localhost if no web3 injection.
const POA_CORE = { RPC_URL: 'https://core.poa.network', netIdName: 'CORE', netId: '99' }
const POA_SOKOL = { RPC_URL: 'https://sokol.poa.network', netIdName: 'SOKOL', netId: '77' }
const network = window.location.host.indexOf('sokol') !== -1 ? POA_SOKOL : POA_CORE
document.title = `${network.netIdName} - POA validators dApp`
const provider = new Web3.providers.HttpProvider(network.RPC_URL)
let web3 = new Web3(provider)
results = {
web3Instance: web3,
netIdName: network.netIdName,
netId: network.netIdName,
injectedWeb3: false,
defaultAccount: null
}
resolve(results)
console.log('No web3 instance injected, using Local web3.');
console.error('Metamask not found');
}
})

View File

@ -46,7 +46,8 @@ class AppMainRouter extends Component {
poaConsensus: null,
votingKey :null,
loading: true,
searchTerm: ''
searchTerm: '',
injectedWeb3: null
}
getWeb3().then(async (web3Config) => {
const keysManager = new KeysManager({
@ -60,6 +61,7 @@ class AppMainRouter extends Component {
keysManager,
metadataContract,
loading: false,
injectedWeb3: web3Config.injectedWeb3
})
}).catch((error) => {
console.error(error.message);
@ -75,6 +77,13 @@ class AppMainRouter extends Component {
const setMetadata = this.rootPath + "/set";
if(history.location.pathname === setMetadata){
this.setState({showSearch: false})
if(this.state.injectedWeb3 === false){
swal({
icon: 'warning',
title: 'Warning',
content: generateElement('Metamask was not found')
});
}
} else {
this.setState({showSearch: true})
}
@ -119,16 +128,16 @@ class AppMainRouter extends Component {
});
}
onPendingChangesRender() {
return this.state.votingKey ? <AllValidators
return this.state.loading ? '' : <AllValidators
methodToCall="getAllPendingChanges"
searchTerm={this.state.searchTerm}
web3Config={this.state}>
<button onClick={this.onFinalize} className="create-keys-button finalize">Finalize</button>
<button onClick={this.onConfirmPendingChange} className="create-keys-button">Confirm</button>
</AllValidators> : '';
</AllValidators>;
}
onAllValidatorsRender() {
return this.state.votingKey ? <AllValidators searchTerm={this.state.searchTerm} methodToCall="getAllValidatorsData" web3Config={this.state} /> : '';
return this.state.loading ? '' : <AllValidators searchTerm={this.state.searchTerm} methodToCall="getAllValidatorsData" web3Config={this.state} />
}
onSearch(term){
this.setState({searchTerm: term.target.value.toLowerCase()})