From: Zhiting Lin Date: Mon, 22 Jul 2019 05:57:36 +0000 (+0800) Subject: fixed the account referesh error. X-Git-Url: http://git.osdn.net/view?p=bytom%2FBytom-Dapp-Demo.git;a=commitdiff_plain;h=4f7638eef514506b9ef927078700c163c051f775 fixed the account referesh error. --- diff --git a/src/components/App.js b/src/components/App.js index 83fff5e..da45f08 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -15,13 +15,13 @@ import GetContractArgs from "./constants"; import Bytom from 'bytom-js-sdk' class App extends Component { - componentDidMount(){ + componentWillMount(){ const { bytom, setBytom } = this.props; if(!bytom){ document.addEventListener('chromeBytomLoaded', bytomExtension => { const bytom = window.bytom; - setBytom(bytom); this.bytomLoaded(bytom); + setBytom(bytom); }); }else { this.bytomLoaded(bytom); @@ -38,13 +38,14 @@ class App extends Component { try { const BYTOM_ACCOUNT = await bytom.enable() - this.props.updateConnection(true) const bytomAPI = new Bytom(networks, '') bytomAPI.setNetType(bytom.net) global.bytomAPI = bytomAPI + this.props.updateConnection(true) + // Check to see if the user has signed in/out of their // bytom wallet or switched accounts let accountInterval = setInterval(function () { diff --git a/src/components/layout/account/index.jsx b/src/components/layout/account/index.jsx index d6bffc6..b1e53a9 100644 --- a/src/components/layout/account/index.jsx +++ b/src/components/layout/account/index.jsx @@ -27,7 +27,9 @@ class Account extends Component { const account = bytom.default_account this.setState({ account }) if(account){ - this.props.updateBalances(account.accountId) + if(global.bytomAPI){ + this.props.updateBalances(account.accountId) + } this.listBalance(account, GetContractArgs().assetDeposited) } }