Skip to content

Commit

Permalink
- fix status icon
Browse files Browse the repository at this point in the history
- fix undefined label
  • Loading branch information
Motzart committed Dec 6, 2021
1 parent 78e0490 commit 57c6bfb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
15 changes: 11 additions & 4 deletions src/components/atoms/DropDown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ type Props = {

const DropDown = (props: Props) => {
const { viewStore } = props;
const network = toJS(viewStore.currentNetwork);
const networks = toJS(viewStore.networks);
const currentNetwork = toJS(viewStore.currentNetwork);

const onChange = ({ label }) => {
// use label for find selectedNetwork from array of networks
const selectedNetwork = networks.find((network) => (network.label === label));
viewStore.selectNetwork(selectedNetwork);
};

return (
<Dropdown
options={toJS(viewStore.networks)}
onChange={(e) => viewStore.selectNetwork(e)}
value={network}
options={networks}
onChange={onChange}
value={currentNetwork}
placeholder="Select an option"
/>
);
Expand Down
14 changes: 10 additions & 4 deletions src/helpers/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export const byteConverter = (x) => {
};

const divideNumber = (number) => {
const decimals = number.split('.')[1];
const afterDot = number.split('.')[1];
// correct decimals
const decimals = afterDot ? `.${afterDot}` : '';
const int = String(Math.trunc(number));
if (int.length <= 3) return int;
if (int.length <= 3) return `${int}${decimals}`;
let space = 0;
let dividedNumber = ' ';

Expand All @@ -26,7 +28,7 @@ const divideNumber = (number) => {
dividedNumber = int.charAt(i) + dividedNumber;
space++;
}
return `${dividedNumber.trim()}.${decimals}`;
return `${dividedNumber.trim()}${decimals}`;
};

export const smhCoinConverter = (amount: number) => {
Expand All @@ -51,7 +53,11 @@ export const smhCoinConverter = (amount: number) => {
}

// truncate to 3 decimals and truncate trailing fractional 0s
const s = parseFloat(v.toFixed(3)).toString();
// const s = parseFloat(v.toFixed(3)).toString(); previos version
const vString = v.toString();
const vDotIndex = vString.indexOf('.');
const s = vDotIndex === -1 ? vString : vString.slice(0, vDotIndex + 4);

// return { value: s, unit };
return `${divideNumber(s)} ${unit}`;
};
4 changes: 2 additions & 2 deletions src/pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const Home = (props: Props) => {
if (socketClient) {
socketClient.onmessage = (message) => {
const incomeData = JSON.parse(message.data);
setData(incomeData);
// TODO 24 it's simple num, should be getting from backend
if ((incomeData.lastlayer + 24) < incomeData.lastapprovedlayer || incomeData.issynced === false) {
uiStore.setNetworkStatus(ERROR_STATUS);
Expand All @@ -93,12 +92,13 @@ const Home = (props: Props) => {
} else {
uiStore.setNetworkStatus(SYNC_STATUS);
}
setData(incomeData);

setLastUpdatedTime(1000);
};

socketClient.onclose = (e) => {
uiStore.setNetworkStatus(ERROR_STATUS);
uiStore.setNetworkStatus(SYNCING_STATUS);
setData(false);
console.log('connection is closed.', e.reason);
};
Expand Down

0 comments on commit 57c6bfb

Please sign in to comment.