Skip to content

Commit

Permalink
Fixed undefined in smesher screen (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Vilensky authored Mar 25, 2020
1 parent 91b5d67 commit 63461d0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 7 additions & 1 deletion app/infra/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ const getFormattedTimestamp = (timestamp: string) => {

const getAddress = (key: string) => key.substring(24);

const formatBytes = (bytes) => {
if (bytes === 0) return 0;
return parseFloat((bytes / 1073741824).toFixed(4));
};

export {
testGetValueAndUnit,
formatSmidge,
Expand All @@ -172,5 +177,6 @@ export {
asyncForEach,
getFormattedTimestamp,
getAddress,
formatTxId
formatTxId,
formatBytes
};
9 changes: 7 additions & 2 deletions app/screens/node/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { connect } from 'react-redux';
import { getUpcomingRewards } from '/redux/node/actions';
import { CorneredContainer } from '/components/common';
import { WrapperWith2SideBars, Link, Button } from '/basicComponents';
import { nodeService } from '/infra/nodeService';
import { ScreenErrorBoundary } from '/components/errorHandler';
import { localStorageService } from '/infra/storageService';
import { fileSystemService } from '/infra/fileSystemService';
import { getAbbreviatedText, getFormattedTimestamp, getAddress, formatSmidge } from '/infra/utils';
import { getAbbreviatedText, getFormattedTimestamp, getAddress, formatSmidge, formatBytes } from '/infra/utils';
import { playIcon, pauseIcon, fireworks, copyToClipboard } from '/assets/images';
import { smColors, nodeConsts } from '/vars';
import type { RouterHistory } from 'react-router-dom';
Expand Down Expand Up @@ -160,6 +161,8 @@ class Node extends Component<Props, State> {

audio: any;

formattedCommitmentSize: number;

constructor(props) {
super(props);
const { location } = props;
Expand Down Expand Up @@ -227,6 +230,8 @@ class Node extends Component<Props, State> {
// }
const audioUrl = await fileSystemService.getAudioPath();
this.audio = new Audio(audioUrl);
const commitmentSize = await nodeService.getCommitmentSize();
this.formattedCommitmentSize = formatBytes(commitmentSize);
}

componentDidUpdate() {
Expand Down Expand Up @@ -296,7 +301,7 @@ class Node extends Component<Props, State> {
<Text key="3">Setup smeshing to join Spacemesh and earn Smesh rewards.</Text>,
<br key="4" />,
<br key="5" />,
<Text key="6">{`Setup requires ${nodeConsts.COMMITMENT_SIZE} GB of free disk space.`}</Text>,
<Text key="6">{`Setup requires ${this.formattedCommitmentSize} GB of free disk space.`}</Text>,
<Text key="7">You will start earning Smesh rewards in about 48 hours.</Text>,
<Footer key="footer">
<Link onClick={this.navigateToMiningGuide} text="SMESHING GUIDE" />
Expand Down
6 changes: 1 addition & 5 deletions app/screens/node/NodeSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CommitmentSelector } from '/components/node';
import { chevronLeftWhite } from '/assets/images';
import { fileSystemService } from '/infra/fileSystemService';
import { nodeService } from '/infra/nodeService';
import { formatBytes } from '/infra/utils';
import { smColors } from '/vars';
import type { RouterHistory } from 'react-router-dom';
import type { Account, Action } from '/types';
Expand Down Expand Up @@ -60,11 +61,6 @@ const PermissionError = styled.div`

const bntStyle = { position: 'absolute', bottom: 0, left: -35 };

function formatBytes(bytes) {
if (bytes === 0) return 0;
return parseFloat((bytes / 1073741824).toFixed(4));
}

type Props = {
accounts: Account[],
initMining: Action,
Expand Down

0 comments on commit 63461d0

Please sign in to comment.