OSDN Git Service

fixed the account referesh error.
authorZhiting Lin <zlin035@uottawa.ca>
Mon, 22 Jul 2019 05:57:36 +0000 (13:57 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Mon, 22 Jul 2019 05:57:36 +0000 (13:57 +0800)
src/components/App.js
src/components/layout/account/index.jsx

index 83fff5e..da45f08 100644 (file)
@@ -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 () {
index d6bffc6..b1e53a9 100644 (file)
@@ -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)
       }
     }