From 57c6bfbe5db4290d54411e9a26e8ab7985173030 Mon Sep 17 00:00:00 2001 From: Alex_Molotsylo Date: Mon, 6 Dec 2021 12:33:14 +0200 Subject: [PATCH] - fix status icon - fix undefined label --- src/components/atoms/DropDown/index.js | 15 +++++++++++---- src/helpers/converter.js | 14 ++++++++++---- src/pages/Home/index.js | 4 ++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/atoms/DropDown/index.js b/src/components/atoms/DropDown/index.js index 4d00025..9ce51fa 100644 --- a/src/components/atoms/DropDown/index.js +++ b/src/components/atoms/DropDown/index.js @@ -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 ( viewStore.selectNetwork(e)} - value={network} + options={networks} + onChange={onChange} + value={currentNetwork} placeholder="Select an option" /> ); diff --git a/src/helpers/converter.js b/src/helpers/converter.js index a486d92..6f878f9 100644 --- a/src/helpers/converter.js +++ b/src/helpers/converter.js @@ -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 = ' '; @@ -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) => { @@ -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}`; }; diff --git a/src/pages/Home/index.js b/src/pages/Home/index.js index daf92fb..f001c9a 100644 --- a/src/pages/Home/index.js +++ b/src/pages/Home/index.js @@ -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); @@ -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); };