OSDN Git Service

netinfo fetch after network init.
authorZhiting Lin <zlin035@uottawa.ca>
Thu, 18 Jul 2019 08:22:14 +0000 (16:22 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Thu, 18 Jul 2019 08:22:14 +0000 (16:22 +0800)
src/features/app/components/Container.jsx

index 49b024d..111b502 100644 (file)
@@ -64,6 +64,37 @@ class Container extends React.Component {
             })
             this.props.showRoot()
           })
+          this.props.fetchAccountItem().then(resp => {
+            const promise = new Promise((resolve, reject) => {
+              if (resp.data.length == 0) {
+                this.props.switchAccount('')
+                resolve()
+              }else{
+                const aliasArray = resp.data.map(account => account.alias)
+                if(!aliasArray.includes(this.props.currentAccount) ){
+                  this.props.setDefaultAccount().then(()=>{
+                    resolve()
+                  })
+                }else{
+                  resolve()
+                }
+              }
+            })
+
+            return promise.then(()=>{
+              return this.props.fetchKeyItem().then(resp => {
+                if (resp.data.length == 0) {
+                  this.props.updateAccountInit(false)
+                }else{
+                  this.props.updateAccountInit(true)
+                }
+                return this.props.fetchInfo().then(() => {
+                  this.redirectRoot(this.props)
+                })
+              })
+            })
+          })
+          
           setInterval(() => this.props.fetchInfo(), CORE_POLLING_TIME)
         }
         if(arg === 'init'){
@@ -75,6 +106,7 @@ class Container extends React.Component {
         this.props.updateMiningState(isMining)
       })
     }
+
     if(this.props.lng === 'zh'){
       moment.locale('zh-cn')
     }else{
@@ -82,41 +114,6 @@ class Container extends React.Component {
     }
   }
 
-  componentWillMount() {
-    this.props.fetchAccountItem().then(resp => {
-      const promise = new Promise((resolve, reject) => {
-        if (resp.data.length == 0) {
-          this.props.switchAccount('')
-          resolve()
-        }else{
-          const aliasArray = resp.data.map(account => account.alias)
-          if(!aliasArray.includes(this.props.currentAccount) ){
-            this.props.setDefaultAccount().then(()=>{
-              resolve()
-            })
-          }else{
-            resolve()
-          }
-        }
-      })
-
-      return promise.then(()=>{
-        return this.props.fetchKeyItem().then(resp => {
-          if (resp.data.length == 0) {
-            this.props.updateAccountInit(false)
-          }else{
-            this.props.updateAccountInit(true)
-          }
-          return this.props.fetchInfo().then(() => {
-            this.redirectRoot(this.props)
-          })
-        })
-      })
-    })
-
-    setInterval(() => this.props.fetchInfo(), CORE_POLLING_TIME)
-  }
-
   componentWillReceiveProps(nextProps) {
     if (nextProps.accountInit != this.props.accountInit ||
         nextProps.configured != this.props.configured ||