diff --git a/src/getWeb3.js b/src/getWeb3.js
index d490bcb..d8d429d 100644
--- a/src/getWeb3.js
+++ b/src/getWeb3.js
@@ -1,9 +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 wiki for more info.`;
-
let getWeb3 = () => {
return new Promise(function (resolve, reject) {
// Wait for loading completion to avoid race conditions with web3 injection timing.
@@ -40,9 +36,6 @@ let getWeb3 = () => {
if(errorMsg !== null){
reject({message: errorMsg})
}
- if(defaultAccount === null){
- reject({message: errorMsgNoMetamaskAccount})
- }
results = {
web3Instance: web3,
netIdName,
diff --git a/src/index.js b/src/index.js
index b7b6d04..2f88f46 100644
--- a/src/index.js
+++ b/src/index.js
@@ -17,6 +17,10 @@ import createBrowserHistory from 'history/createBrowserHistory'
import Loading from './Loading'
import AllValidators from './AllValidators'
+let errorMsgNoMetamaskAccount = `Your MetaMask is locked.
+Please, choose your voting key in MetaMask and reload the page.
+Check POA Network wiki for more info.`;
+
const history = createBrowserHistory()
function generateElement(msg){
@@ -90,30 +94,46 @@ class AppMainRouter extends Component {
this.setState({showSearch: true})
}
}
+ checkForVotingKey(cb){
+ if(this.state.votingKey){
+ return cb();
+ } else {
+ swal({
+ icon: 'warning',
+ title: 'Warning',
+ content: generateElement(errorMsgNoMetamaskAccount)
+ });
+ return ''
+ }
+ }
onSetRender() {
- return this.state.votingKey ? : '';
+ return this.checkForVotingKey(() => {
+ return
+ })
}
async _onBtnClick({event, methodToCall, successMsg}){
event.preventDefault();
- this.setState({loading: true})
- const miningKey = event.currentTarget.getAttribute('miningkey');
- try{
- let result = await this.state.metadataContract[methodToCall]({
- miningKeyToConfirm: miningKey,
- senderVotingKey: this.state.votingKey
- });
- console.log(result);
- this.setState({loading: false})
- swal("Congratulations!", successMsg, "success");
- } catch(error) {
- this.setState({loading: false})
- console.error(error.message);
- swal({
- icon: 'error',
- title: 'Error',
- content: generateElement(error.message)
- });
- }
+ this.checkForVotingKey(async () => {
+ this.setState({loading: true})
+ const miningKey = event.currentTarget.getAttribute('miningkey');
+ try{
+ let result = await this.state.metadataContract[methodToCall]({
+ miningKeyToConfirm: miningKey,
+ senderVotingKey: this.state.votingKey
+ });
+ console.log(result);
+ this.setState({loading: false})
+ swal("Congratulations!", successMsg, "success");
+ } catch(error) {
+ this.setState({loading: false})
+ console.error(error.message);
+ swal({
+ icon: 'error',
+ title: 'Error',
+ content: generateElement(error.message)
+ });
+ }
+ })
}
async onConfirmPendingChange(event) {
await this._onBtnClick({
@@ -145,7 +165,7 @@ class AppMainRouter extends Component {
this.setState({searchTerm: term.target.value.toLowerCase()})
}
render(){
- console.log('v2.05')
+ console.log('v2.06')
const search = this.state.showSearch ? : ''
const loading = this.state.loading ? : ''
return (