Skip to content

Commit

Permalink
Fix forgetting smeshing is enabled (#453)
Browse files Browse the repository at this point in the history
* Fixed app forget smeshing is enabled

* Fixed app forget smeshing is enabled
  • Loading branch information
Ilya Vilensky authored Mar 24, 2020
1 parent f2fa0d1 commit a92815c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/redux/node/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down
2 changes: 1 addition & 1 deletion app/redux/node/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 14 additions & 3 deletions app/screens/auth/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,8 +48,9 @@ type Props = {
};

class Auth extends Component<Props> {
// 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;
Expand Down Expand Up @@ -80,11 +82,20 @@ class Auth extends Component<Props> {
}
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);
}
}
Expand Down
24 changes: 16 additions & 8 deletions app/screens/main/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class Main extends Component<Props, State> {
// eslint-disable-next-line react/sort-comp
getNodeStatusInterval: IntervalID;

initialMiningStatusInterval: IntervalID;

miningStatusInterval: IntervalID;

accountRewardsInterval: IntervalID;
Expand Down Expand Up @@ -243,18 +245,23 @@ class Main extends Component<Props, State> {
}

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',
notification: `${hasConfirmedIncomingTxs ? 'Incoming' : 'Sent'} transaction approved`,
callback: () => history.push('/main/transactions')
});
} }), 30000);
if (status === nodeConsts.IN_SETUP) {
if (miningStatus === nodeConsts.IN_SETUP) {
this.miningStatusInterval = setInterval(() => {
getMiningStatus();
}, 100000);
Expand All @@ -263,19 +270,19 @@ class Main extends Component<Props, State> {
}

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',
notification: 'Your Smesher setup is complete! You are now participating in the Spacemesh network!',
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',
Expand All @@ -287,6 +294,7 @@ class Main extends Component<Props, State> {
}

componentWillUnmount() {
this.initialMiningStatusInterval && clearInterval(this.initialMiningStatusInterval);
this.miningStatusInterval && clearInterval(this.miningStatusInterval);
this.accountRewardsInterval && clearInterval(this.accountRewardsInterval);
this.txCollectorInterval && clearInterval(this.txCollectorInterval);
Expand Down
13 changes: 13 additions & 0 deletions app/screens/node/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ class Node extends Component<Props, State> {
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();
};
Expand Down Expand Up @@ -303,6 +305,17 @@ class Node extends Component<Props, State> {
];
};

renderMiningUnset = () => [
<BoldText key="1">Please wait,</BoldText>,
<br key="2" />,
<Text key="3">waiting for smesher to return smeshing status.</Text>,
<br key="4" />,
<Text key="5">After retrieving status you will be redirected automatically.</Text>,
<Footer key="footer">
<Link onClick={this.navigateToMiningGuide} text="SMESHING GUIDE" />
</Footer>
];

renderNodeDashboard = () => {
const { status, totalEarnings, totalFeesEarnings, rewardsAddress } = this.props;
const { isMiningPaused, copied } = this.state;
Expand Down
1 change: 1 addition & 0 deletions app/vars/nodeConsts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const nodeConsts = {
MINING_UNSET: 0,
NOT_MINING: 1,
IN_SETUP: 2,
IS_MINING: 3,
Expand Down

0 comments on commit a92815c

Please sign in to comment.