diff --git a/app/redux/node/actions.js b/app/redux/node/actions.js index 220939171..8ba563d1e 100644 --- a/app/redux/node/actions.js +++ b/app/redux/node/actions.js @@ -58,7 +58,7 @@ export const getMiningStatus = (): Action => async (dispatch: Dispatch): Dispatc return status; } catch (error) { console.error(error); // eslint-disable-line no-console - return 1; + return nodeConsts.MINING_UNSET; } }; diff --git a/app/redux/node/reducer.js b/app/redux/node/reducer.js index 10662c9e8..056df6401 100644 --- a/app/redux/node/reducer.js +++ b/app/redux/node/reducer.js @@ -6,7 +6,7 @@ import { SET_MINING_STATUS, SET_NODE_SETTINGS, INIT_MINING, SET_UPCOMING_REWARDS const initialState = { status: null, - miningStatus: nodeConsts.NOT_MINING, + miningStatus: nodeConsts.MINING_UNSET, rewardsAddress: null, genesisTime: 0, networkId: 0, diff --git a/app/screens/auth/Auth.js b/app/screens/auth/Auth.js index 7f0bff101..440c8f77c 100644 --- a/app/screens/auth/Auth.js +++ b/app/screens/auth/Auth.js @@ -12,6 +12,7 @@ import routes from '/routes'; import { rightDecoration } from '/assets/images'; import type { Action } from '/types'; import type { RouterHistory } from 'react-router-dom'; +import { nodeConsts } from '../../vars'; const Wrapper = styled.div` position: relative; @@ -47,8 +48,9 @@ type Props = { }; class Auth extends Component { - // eslint-disable-next-line react/sort-comp - getNodeStatusInterval: IntervalID; + getNodeStatusInterval: IntervalID; // eslint-disable-line react/sort-comp + + getMiningStatusInterval: IntervalID; // eslint-disable-line react/sort-comp render() { const { walletFiles } = this.props; @@ -80,11 +82,20 @@ class Auth extends Component { } await getNodeStatus(); this.getNodeStatusInterval = setInterval(getNodeStatus, 10000); - await getMiningStatus(); + const status = await getMiningStatus(); + if (status === nodeConsts.MINING_UNSET) { + this.getMiningStatusInterval = setInterval(async () => { + const status = await getMiningStatus(); + if (status !== nodeConsts.MINING_UNSET) { + clearInterval(this.getMiningStatusInterval); + } + }, 500); + } await getNodeSettings(); } componentWillUnmount(): void { + this.getMiningStatusInterval && clearInterval(this.getMiningStatusInterval); this.getNodeStatusInterval && clearInterval(this.getNodeStatusInterval); } } diff --git a/app/screens/main/Main.js b/app/screens/main/Main.js index d4f659038..ec7de2fb4 100644 --- a/app/screens/main/Main.js +++ b/app/screens/main/Main.js @@ -114,6 +114,8 @@ class Main extends Component { // eslint-disable-next-line react/sort-comp getNodeStatusInterval: IntervalID; + initialMiningStatusInterval: IntervalID; + miningStatusInterval: IntervalID; accountRewardsInterval: IntervalID; @@ -243,10 +245,15 @@ class Main extends Component { } async componentDidMount() { - const { getNodeStatus, getMiningStatus, getTxList, updateWalletFile, history } = this.props; + const { getNodeStatus, getMiningStatus, getTxList, updateWalletFile, miningStatus, history } = this.props; await getNodeStatus(); this.getNodeStatusInterval = setInterval(getNodeStatus, 10000); - const status = await getMiningStatus(); + this.initialMiningStatusInterval = setInterval(async () => { + const status = await getMiningStatus(); + if (status !== nodeConsts.MINING_UNSET) { + clearInterval(this.initialMiningStatusInterval); + } + }); this.txCollectorInterval = setInterval(() => getTxList({ notify: ({ hasConfirmedIncomingTxs }) => { notificationsService.notify({ title: 'Spacemesh', @@ -254,7 +261,7 @@ class Main extends Component { callback: () => history.push('/main/transactions') }); } }), 30000); - if (status === nodeConsts.IN_SETUP) { + if (miningStatus === nodeConsts.IN_SETUP) { this.miningStatusInterval = setInterval(() => { getMiningStatus(); }, 100000); @@ -263,11 +270,11 @@ class Main extends Component { } componentDidUpdate(prevProps: Props) { - const { status, miningStatus, getMiningStatus, getAccountRewards } = this.props; - if (status && prevProps.miningStatus === nodeConsts.NOT_MINING && miningStatus === nodeConsts.IN_SETUP) { - this.miningStatusInterval = setInterval(() => { status && getMiningStatus(); }, 100000); + const {miningStatus, getMiningStatus, getAccountRewards } = this.props; + if (prevProps.miningStatus === nodeConsts.NOT_MINING && miningStatus === nodeConsts.IN_SETUP) { + this.miningStatusInterval = setInterval(getMiningStatus, 100000); } - if (status && [nodeConsts.NOT_MINING, nodeConsts.IN_SETUP].includes(prevProps.miningStatus) && miningStatus === nodeConsts.IS_MINING) { + if ([nodeConsts.NOT_MINING, nodeConsts.IN_SETUP].includes(prevProps.miningStatus) && miningStatus === nodeConsts.IS_MINING) { clearInterval(this.miningStatusInterval); notificationsService.notify({ title: 'Spacemesh', @@ -275,7 +282,7 @@ class Main extends Component { callback: () => this.handleNavigation({ index: 0 }) }); } - if (status && miningStatus === nodeConsts.IS_MINING) { + if (miningStatus === nodeConsts.IS_MINING) { this.accountRewardsInterval = setInterval(() => getAccountRewards({ notify: () => { notificationsService.notify({ title: 'Spacemesh', @@ -287,6 +294,7 @@ class Main extends Component { } componentWillUnmount() { + this.initialMiningStatusInterval && clearInterval(this.initialMiningStatusInterval); this.miningStatusInterval && clearInterval(this.miningStatusInterval); this.accountRewardsInterval && clearInterval(this.accountRewardsInterval); this.txCollectorInterval && clearInterval(this.txCollectorInterval); diff --git a/app/screens/node/Node.js b/app/screens/node/Node.js index 8d683a058..2c3049465 100644 --- a/app/screens/node/Node.js +++ b/app/screens/node/Node.js @@ -250,6 +250,8 @@ class Node extends Component { return showFireworks ? this.renderFireworks() : this.renderIntro(); } else if (miningStatus === nodeConsts.NOT_MINING) { return this.renderPreSetup(); + } else if (miningStatus === nodeConsts.MINING_UNSET) { + return this.renderMiningUnset(); } return this.renderNodeDashboard(); }; @@ -303,6 +305,17 @@ class Node extends Component { ]; }; + renderMiningUnset = () => [ + Please wait,, +
, + waiting for smesher to return smeshing status., +
, + After retrieving status you will be redirected automatically., + + ]; + renderNodeDashboard = () => { const { status, totalEarnings, totalFeesEarnings, rewardsAddress } = this.props; const { isMiningPaused, copied } = this.state; diff --git a/app/vars/nodeConsts.js b/app/vars/nodeConsts.js index 2ad5f9211..f462e4b9a 100644 --- a/app/vars/nodeConsts.js +++ b/app/vars/nodeConsts.js @@ -1,4 +1,5 @@ const nodeConsts = { + MINING_UNSET: 0, NOT_MINING: 1, IN_SETUP: 2, IS_MINING: 3,