const switchAccount = (accountAlias) => {
return (dispatch) => {
- return action.transaction.getAddresses({accountAlias}).then(address => {
- return chainClient().accounts.setMiningAddress({'miningAddress':address}).then(resp =>{
- if (resp.status === 'fail') {
- throw resp
- }
+ dispatch({type: 'SET_CURRENT_ACCOUNT', account: accountAlias})
+ }
+}
- dispatch({type: 'SET_CURRENT_ACCOUNT', account: accountAlias})
- })
+const setMiningAddress = (accountAlias) =>{
+ return action.transaction.getAddresses({accountAlias}).then(address => {
+ return chainClient().accounts.setMiningAddress({'miningAddress':address}).then(resp =>{
+ if (resp.status === 'fail') {
+ throw resp
+ }
+
+ return resp
})
- }
+ })
}
const setDefaultAccount = () =>{
return (dispatch) => {
return chainClient().accounts.query().then(result => {
const account = result.data[0].alias
- dispatch(switchAccount((account)))
- return account
+ return setMiningAddress(account).then(()=>{
+ dispatch(switchAccount((account)))
+ return account
+ })
})
}
}
switchAccount,
setDefaultAccount,
createAccount,
- createSuccess
+ createSuccess,
+ setMiningAddress
}
export default actions
}
componentDidMount() {
- this.props.fetchKeyItem().then(resp => {
- if (resp.data.length == 0) {
- this.props.updateAccountInit(false)
- this.redirectRoot(this.props)
- }else{
- this.props.updateAccountInit(true)
- this.props.fetchAccountItem().then(resp => {
- if (resp.data.length == 0) {
- this.props.switchAccount('')
- this.redirectRoot(this.props)
- }else{
- const aliasArray = resp.data.map(account => account.alias)
- if(!aliasArray.includes(this.props.currentAccount) ){
- this.props.setDefaultAccount()
- this.props.showRoot()
- }
- }
- })
- }
- })
if(this.props.lng === 'zh'){
moment.locale('zh-cn')
}else{
}
componentWillMount() {
- this.props.fetchInfo().then(() => {
- this.redirectRoot(this.props)
+ 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)