From 9e43e34929668366341b77bd3d946e9049d63ac4 Mon Sep 17 00:00:00 2001 From: Roman Storm Date: Wed, 6 Dec 2017 23:11:01 -0800 Subject: [PATCH] check if no metamask --- src/App.js | 7 ++++--- src/keysManager.js | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/App.js b/src/App.js index 8e74a63..cc8de18 100644 --- a/src/App.js +++ b/src/App.js @@ -25,7 +25,8 @@ class App extends Component { this.onClick = this.onClick.bind(this); this.state = { web3Config: {}, - mining: null + mining: null, + isDisabledBtn: false } this.keysManager = null; getWeb3().then((web3Config) => { @@ -35,6 +36,7 @@ class App extends Component { }); }).catch((error) => { if(error.msg){ + this.setState({isDisabledBtn: true}); swal({ icon: 'warning', title: 'Warning', @@ -49,7 +51,6 @@ class App extends Component { const isValid = await this.keysManager.isInitialKeyValid(initialKey); console.log(isValid); if(Number(isValid) !== 1){ - this.setState({loading: false}) swal("Warning!", "The key is not valid initial Key! Please make sure you have loaded correct initial key in metamask", "warning"); return; } @@ -100,7 +101,7 @@ class App extends Component { Please proceed with care, don't lose your keys and follow instructions.
- +
) diff --git a/src/keysManager.js b/src/keysManager.js index 9cfd87d..5fd8758 100644 --- a/src/keysManager.js +++ b/src/keysManager.js @@ -2,10 +2,12 @@ import KeysManagerAbi from './keysManagerAbi.json' import Web3 from 'web3'; import addressGenerator from './addressGenerator'; -let web3_10 = new Web3(window.web3.currentProvider); export default class KeysManager { - constructor({web3}){ - this.keysInstance = new web3_10.eth.Contract(KeysManagerAbi, '0x758492834ed6454f41d6d3d6b73d6e46d4555429'); + constructor(){ + if(window.web3.currentProvider){ + let web3_10 = new Web3(window.web3.currentProvider); + this.keysInstance = new web3_10.eth.Contract(KeysManagerAbi, '0x758492834ed6454f41d6d3d6b73d6e46d4555429'); + } } async isInitialKeyValid(initialKey) { return await this.keysInstance.methods.initialKeys(initialKey).call();