From 90e63d98cfe7e5fe8f20aa4b97ca615a18f08124 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 09:58:42 +0200 Subject: [PATCH 01/17] Adapt suscribers to the new API format --- src/store/middlewares/block.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/store/middlewares/block.js b/src/store/middlewares/block.js index 7cb9dd8db0..5e7b4aaa01 100644 --- a/src/store/middlewares/block.js +++ b/src/store/middlewares/block.js @@ -29,7 +29,9 @@ const blockListener = ({ getState, dispatch }) => { if (activeToken === tokenMap.LSK.key) { dispatch({ type: actionTypes.newBlockCreated, - data: { block }, + data: { + block: block.data.length ? block.data[0] : {}, + }, }); dispatch(forgersRetrieved()); } From 6228be93770a1f1b110fc037a9e3279c42db60ac Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 10:03:42 +0200 Subject: [PATCH 02/17] Remove uotdated hook --- src/hooks/useServiceSocketUpdates.js | 32 ---------------------------- 1 file changed, 32 deletions(-) delete mode 100644 src/hooks/useServiceSocketUpdates.js diff --git a/src/hooks/useServiceSocketUpdates.js b/src/hooks/useServiceSocketUpdates.js deleted file mode 100644 index 58fa063c9d..0000000000 --- a/src/hooks/useServiceSocketUpdates.js +++ /dev/null @@ -1,32 +0,0 @@ -import { useSelector } from 'react-redux'; -import { useState, useEffect } from 'react'; -import { subscribe, unsubscribe } from '@api/ws'; - -/** - * - * @param {object} event - Sock event data fired by Lisk Service - * @returns {array} - [boolean, function] - */ -const useServiceSocketUpdates = (event) => { - const serviceUrl = useSelector( - state => state.network.networks[state.settings.token.active].serviceUrl, - ); - const [isUpdateAvailable, setUpdateAvailable] = useState(false); - const reset = () => setUpdateAvailable(false); - - useEffect(() => { - subscribe( - serviceUrl, - event, - () => setUpdateAvailable(true), - () => {}, - () => {}, - ); - - return () => { unsubscribe(event); }; - }, [serviceUrl]); - - return [isUpdateAvailable, reset]; -}; - -export default useServiceSocketUpdates; From 340caad08b1f1df015477772d411cc558ec8b217 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 10:04:11 +0200 Subject: [PATCH 03/17] Use latest blocks to display the button --- .../shared/loadLatestButton/index.js | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/components/shared/loadLatestButton/index.js b/src/components/shared/loadLatestButton/index.js index 33d6313234..1e6335c145 100644 --- a/src/components/shared/loadLatestButton/index.js +++ b/src/components/shared/loadLatestButton/index.js @@ -1,33 +1,46 @@ -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; +import { useSelector } from 'react-redux'; +import PropTypes from 'prop-types'; + import { PrimaryButton } from '@toolbox/buttons'; import Icon from '@toolbox/icon'; -import useServiceSocketUpdates from '../../../hooks/useServiceSocketUpdates'; import styles from './loadLatestButton.css'; -const LoadLatestButton = ({ children, onClick, event }) => { - const [isUpdateAvailable, hideUpdateButton] = useServiceSocketUpdates(event); - const [hasUpdatedRecently, didUpdateRecently] = useState(false); +const shouldShow = { + block: (updateHeight, latestBlocks) => ( + latestBlocks.length > 0 + && latestBlocks[0].height > updateHeight + ), + transaction: () => (updateHeight, latestBlocks) => ( + latestBlocks.length > 0 + && latestBlocks[0].height > updateHeight + && latestBlocks[0].numberOfTransactions > 0 + ), +}; + +const LoadLatestButton = ({ children, onClick, entity }) => { + const { latestBlocks } = useSelector(state => state.blocks); + const [updateHeight, setUpdateHeight] = useState( + latestBlocks.length ? latestBlocks[0].height : 0, + ); const handleClick = () => { - hideUpdateButton(); - const timer = setTimeout(() => { - didUpdateRecently(false); - }, 10000); - didUpdateRecently(timer); + setUpdateHeight(latestBlocks[0].height); onClick(); }; - // willUnmount - useEffect(() => () => clearTimeout(hasUpdatedRecently), []); - - return (isUpdateAvailable && hasUpdatedRecently === false + return shouldShow[entity](latestBlocks, updateHeight) ? ( {children} ) - : null); + : null; +}; +LoadLatestButton.propTypes = { + entity: PropTypes.string.isRequired, + onClick: PropTypes.func.isRequired, }; export default LoadLatestButton; From 40006c3cfd92a7fc29f6bf809d427b6192edaa64 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 10:04:27 +0200 Subject: [PATCH 04/17] Update button properties --- src/components/screens/monitor/blocks/blocks.js | 2 +- src/components/shared/transactionsTable/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/screens/monitor/blocks/blocks.js b/src/components/screens/monitor/blocks/blocks.js index f1ff643a23..742a75198b 100644 --- a/src/components/screens/monitor/blocks/blocks.js +++ b/src/components/screens/monitor/blocks/blocks.js @@ -53,7 +53,7 @@ const Blocks = ({ {t('New blocks')} diff --git a/src/components/shared/transactionsTable/index.js b/src/components/shared/transactionsTable/index.js index db55cc2c21..129565d56d 100644 --- a/src/components/shared/transactionsTable/index.js +++ b/src/components/shared/transactionsTable/index.js @@ -64,7 +64,7 @@ const TransactionsTable = ({ {isLoadMoreEnabled && ( {t('New transactions')} From ef019a518a31e65487258d17a1e5b63cf666e4ed Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 10:25:52 +0200 Subject: [PATCH 05/17] Pass blocks using redux connect --- .../shared/loadLatestButton/index.js | 49 ++----------------- .../loadLatestButton/loadLatestButton.js | 47 ++++++++++++++++++ 2 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 src/components/shared/loadLatestButton/loadLatestButton.js diff --git a/src/components/shared/loadLatestButton/index.js b/src/components/shared/loadLatestButton/index.js index 1e6335c145..8343d9cc71 100644 --- a/src/components/shared/loadLatestButton/index.js +++ b/src/components/shared/loadLatestButton/index.js @@ -1,46 +1,7 @@ -import React, { useState } from 'react'; -import { useSelector } from 'react-redux'; -import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; -import { PrimaryButton } from '@toolbox/buttons'; -import Icon from '@toolbox/icon'; -import styles from './loadLatestButton.css'; +const mapStateToProps = state => ({ + latestBlocks: state.blocks.latestBlocks, +}); -const shouldShow = { - block: (updateHeight, latestBlocks) => ( - latestBlocks.length > 0 - && latestBlocks[0].height > updateHeight - ), - transaction: () => (updateHeight, latestBlocks) => ( - latestBlocks.length > 0 - && latestBlocks[0].height > updateHeight - && latestBlocks[0].numberOfTransactions > 0 - ), -}; - -const LoadLatestButton = ({ children, onClick, entity }) => { - const { latestBlocks } = useSelector(state => state.blocks); - const [updateHeight, setUpdateHeight] = useState( - latestBlocks.length ? latestBlocks[0].height : 0, - ); - - const handleClick = () => { - setUpdateHeight(latestBlocks[0].height); - onClick(); - }; - - return shouldShow[entity](latestBlocks, updateHeight) - ? ( - - - {children} - - ) - : null; -}; -LoadLatestButton.propTypes = { - entity: PropTypes.string.isRequired, - onClick: PropTypes.func.isRequired, -}; - -export default LoadLatestButton; +export default connect(mapStateToProps); diff --git a/src/components/shared/loadLatestButton/loadLatestButton.js b/src/components/shared/loadLatestButton/loadLatestButton.js new file mode 100644 index 0000000000..01b3ef2d5b --- /dev/null +++ b/src/components/shared/loadLatestButton/loadLatestButton.js @@ -0,0 +1,47 @@ +import React, { useState } from 'react'; +import { useSelector } from 'react-redux'; +import PropTypes from 'prop-types'; + +import { PrimaryButton } from '@toolbox/buttons'; +import Icon from '@toolbox/icon'; +import styles from './loadLatestButton.css'; + +const shouldShow = { + block: (updateHeight, latestBlocks) => ( + latestBlocks.length > 0 + && latestBlocks[0].height > updateHeight + ), + transaction: () => (updateHeight, latestBlocks) => ( + latestBlocks.length > 0 + && latestBlocks[0].height > updateHeight + && latestBlocks[0].numberOfTransactions > 0 + ), +}; + +const LoadLatestButton = ({ children, onClick, entity }) => { + const { latestBlocks } = useSelector(state => state.blocks); + const [updateHeight, setUpdateHeight] = useState( + latestBlocks.length ? latestBlocks[0].height : 0, + ); + + const handleClick = () => { + setUpdateHeight(latestBlocks[0].height); + onClick(); + }; + + return shouldShow[entity](latestBlocks, updateHeight) + ? ( + + + {children} + + ) + : null; +}; + +LoadLatestButton.propTypes = { + entity: PropTypes.string.isRequired, + onClick: PropTypes.func.isRequired, +}; + +export default LoadLatestButton; From 6c7efd73beca977ef7763e51543d60ed59cee885 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 10:40:38 +0200 Subject: [PATCH 06/17] Use the latestBlocks from HOC --- .../shared/loadLatestButton/loadLatestButton.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.js b/src/components/shared/loadLatestButton/loadLatestButton.js index 01b3ef2d5b..9fcd87e509 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.js @@ -1,5 +1,4 @@ import React, { useState } from 'react'; -import { useSelector } from 'react-redux'; import PropTypes from 'prop-types'; import { PrimaryButton } from '@toolbox/buttons'; @@ -18,8 +17,9 @@ const shouldShow = { ), }; -const LoadLatestButton = ({ children, onClick, entity }) => { - const { latestBlocks } = useSelector(state => state.blocks); +const LoadLatestButton = ({ + children, onClick, entity, latestBlocks, +}) => { const [updateHeight, setUpdateHeight] = useState( latestBlocks.length ? latestBlocks[0].height : 0, ); @@ -29,7 +29,7 @@ const LoadLatestButton = ({ children, onClick, entity }) => { onClick(); }; - return shouldShow[entity](latestBlocks, updateHeight) + return shouldShow[entity](updateHeight, latestBlocks) ? ( From 60419b2bfad521a72e3741564c4d2ad0d1c5a48c Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 10:40:45 +0200 Subject: [PATCH 07/17] Update unit tests --- .../loadLatestButton/loadLatestButton.test.js | 52 +++++-------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.test.js b/src/components/shared/loadLatestButton/loadLatestButton.test.js index 017866c358..11b0e9e2a5 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.test.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.test.js @@ -1,66 +1,42 @@ import { act } from 'react-dom/test-utils'; import React from 'react'; import { mount } from 'enzyme'; -import io from 'socket.io-client'; -import { subscribeConnections } from '@api/ws'; -import LoadLatestButton from '.'; +import LoadLatestButton from './loadLatestButton'; -jest.mock('socket.io-client'); - -const on = (ev, callback) => { - setTimeout(() => { - callback(ev); - }, 1); -}; const close = jest.fn(); -io.mockImplementation(() => ({ on, close })); describe('LoadLatestButton', () => { const props = { onClick: jest.fn(), - event: 'test.event', + entity: 'block', children: 'Test load button', - }; - const render = () => { - const wrapper = mount(); - return wrapper; + latestBlocks: [], }; it('renders empty by default', () => { - const wrapper = render(); + const wrapper = mount(); expect(wrapper).toBeEmptyRender(); }); - it('shows button on websocket event and hides the button on click', () => { - jest.useFakeTimers(); - - const wrapper = render(); + it('shows button when there is a new block', () => { + const wrapper = mount(); expect(wrapper).toBeEmptyRender(); + wrapper.setProps({ + latestBlocks: [ + { height: 11111112 }, + ], + }); act(() => { - jest.runOnlyPendingTimers(); + wrapper.update(); }); - wrapper.update(); expect(wrapper).toContainExactlyOneMatchingElement('button'); expect(wrapper).toHaveText(props.children); - wrapper.find('button').simulate('click'); + wrapper.find('button').at(0).simulate('click'); expect(props.onClick).toHaveBeenCalledWith(); act(() => { - jest.runOnlyPendingTimers(); + wrapper.update(); }); expect(wrapper).toBeEmptyRender(); - expect(subscribeConnections[props.event]).toBeDefined(); - }); - - it('clears the timeout before unmounting', () => { - jest.useFakeTimers(); - const wrapper = render(); - expect(subscribeConnections[props.event]).toBeDefined(); - expect(close).toHaveBeenCalledTimes(0); - - wrapper.unmount(); - expect(clearTimeout).toHaveBeenCalledTimes(1); - expect(close).toHaveBeenCalledTimes(1); - expect(subscribeConnections[props.event]).not.toBeDefined(); }); }); From 87484d132f101e906447c359d94e8337cf19d70e Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 11:47:30 +0200 Subject: [PATCH 08/17] Pass the component to Redux connect --- src/components/shared/loadLatestButton/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/shared/loadLatestButton/index.js b/src/components/shared/loadLatestButton/index.js index 8343d9cc71..7cad4a991b 100644 --- a/src/components/shared/loadLatestButton/index.js +++ b/src/components/shared/loadLatestButton/index.js @@ -1,7 +1,8 @@ import { connect } from 'react-redux'; +import LoadLatestButton from './loadLatestButton'; const mapStateToProps = state => ({ latestBlocks: state.blocks.latestBlocks, }); -export default connect(mapStateToProps); +export default connect(mapStateToProps)(LoadLatestButton); From 9c7ad8053c572c35ddc54a8ad7161d594e59865f Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 12:22:08 +0200 Subject: [PATCH 09/17] Add refresh icon --- src/assets/images/icons/refresh.svg | 3 +++ src/components/toolbox/icon/index.js | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 src/assets/images/icons/refresh.svg diff --git a/src/assets/images/icons/refresh.svg b/src/assets/images/icons/refresh.svg new file mode 100644 index 0000000000..b102b90a73 --- /dev/null +++ b/src/assets/images/icons/refresh.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/components/toolbox/icon/index.js b/src/components/toolbox/icon/index.js index d444281645..ce9a4012a9 100644 --- a/src/components/toolbox/icon/index.js +++ b/src/components/toolbox/icon/index.js @@ -158,6 +158,7 @@ import initialiseIcon from '../../../assets/images/icons/initialise-icon.svg'; import initialiseRegistration from '../../../assets/images/icons/initialise-registration.svg'; import warningYellow from '../../../assets/images/icons/warning-yellow.svg'; import linkIcon from '../../../assets/images/icons/link-icon.svg'; +import refresh from '../../../assets/images/icons/refresh.svg'; export const icons = { academy, @@ -316,6 +317,7 @@ export const icons = { arrowRightWithStroke, arrowRightWithStrokeDark, multisignatureTransaction, + refresh, }; const Icon = ({ name, noTheme, ...props }) => { From 0f1c2c796fecae6d5e1ab3063b92cdecc7c0e1fa Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 12:22:43 +0200 Subject: [PATCH 10/17] Update styles according to the design guide --- .../shared/loadLatestButton/loadLatestButton.css | 16 ++++++++++++++-- .../shared/loadLatestButton/loadLatestButton.js | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.css b/src/components/shared/loadLatestButton/loadLatestButton.css index 3bfc36f0f7..3a75a61165 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.css +++ b/src/components/shared/loadLatestButton/loadLatestButton.css @@ -4,7 +4,7 @@ } 100% { - transform: translateX(-50%) translateY(100px); + transform: translateX(-50%) translateY(50px); } } @@ -13,12 +13,24 @@ animation-fill-mode: forwards; position: absolute; z-index: 2; - width: 200px; transform: translateX(-50%); left: 50%; + background: var(--color-white); + color: var(--color-ultramarine-blue); + border-radius: 30px; + box-shadow: var(--box-shadow-standard), 0 0 0 10px var(--color-body-bg); & .icon { vertical-align: bottom; padding-right: 12px; } + + & .icon, + & span { + vertical-align: middle; + } + + &:hover { + box-shadow: var(--box-shadow-standard), 0 0 0 10px var(--color-body-bg); + } } diff --git a/src/components/shared/loadLatestButton/loadLatestButton.js b/src/components/shared/loadLatestButton/loadLatestButton.js index 9fcd87e509..75963e750f 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.js @@ -8,9 +8,9 @@ import styles from './loadLatestButton.css'; const shouldShow = { block: (updateHeight, latestBlocks) => ( latestBlocks.length > 0 - && latestBlocks[0].height > updateHeight + && latestBlocks[0].height > (updateHeight + 2) ), - transaction: () => (updateHeight, latestBlocks) => ( + transaction: (updateHeight, latestBlocks) => ( latestBlocks.length > 0 && latestBlocks[0].height > updateHeight && latestBlocks[0].numberOfTransactions > 0 @@ -32,8 +32,8 @@ const LoadLatestButton = ({ return shouldShow[entity](updateHeight, latestBlocks) ? ( - - {children} + + {children} ) : null; From da3ceb1dc92aa710dd9541400faa078a58d73e53 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 12:46:59 +0200 Subject: [PATCH 11/17] Do not display on app start --- .../shared/loadLatestButton/loadLatestButton.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.js b/src/components/shared/loadLatestButton/loadLatestButton.js index 75963e750f..5e757fb8db 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { PrimaryButton } from '@toolbox/buttons'; @@ -8,10 +8,12 @@ import styles from './loadLatestButton.css'; const shouldShow = { block: (updateHeight, latestBlocks) => ( latestBlocks.length > 0 + && updateHeight > 0 && latestBlocks[0].height > (updateHeight + 2) ), transaction: (updateHeight, latestBlocks) => ( latestBlocks.length > 0 + && updateHeight > 0 && latestBlocks[0].height > updateHeight && latestBlocks[0].numberOfTransactions > 0 ), @@ -29,6 +31,12 @@ const LoadLatestButton = ({ onClick(); }; + useEffect(() => { + if (latestBlocks.length > 0 && updateHeight === 0) { + setUpdateHeight(latestBlocks[0].height); + } + }, [latestBlocks.length]); + return shouldShow[entity](updateHeight, latestBlocks) ? ( From c69b89873dfd7aba1cb775280a443d74c83db125 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 12:47:18 +0200 Subject: [PATCH 12/17] Do not cover table titles --- src/components/shared/loadLatestButton/loadLatestButton.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.css b/src/components/shared/loadLatestButton/loadLatestButton.css index 3a75a61165..61053b3107 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.css +++ b/src/components/shared/loadLatestButton/loadLatestButton.css @@ -4,7 +4,7 @@ } 100% { - transform: translateX(-50%) translateY(50px); + transform: translateX(-50%) translateY(30px); } } From c4b246f5af207601c2fc8ebd3bb76cfc8f6ec7f9 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 12:49:08 +0200 Subject: [PATCH 13/17] Remove unused variables --- src/components/shared/loadLatestButton/loadLatestButton.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.test.js b/src/components/shared/loadLatestButton/loadLatestButton.test.js index 11b0e9e2a5..035600e233 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.test.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.test.js @@ -3,8 +3,6 @@ import React from 'react'; import { mount } from 'enzyme'; import LoadLatestButton from './loadLatestButton'; -const close = jest.fn(); - describe('LoadLatestButton', () => { const props = { onClick: jest.fn(), From 8f864ca78345d4f5a53db854676d679783f728b2 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 12:59:33 +0200 Subject: [PATCH 14/17] Make entity retricated to limited choices --- src/components/shared/loadLatestButton/loadLatestButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.js b/src/components/shared/loadLatestButton/loadLatestButton.js index 5e757fb8db..5f10c29562 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.js @@ -48,7 +48,7 @@ const LoadLatestButton = ({ }; LoadLatestButton.propTypes = { - entity: PropTypes.string.isRequired, + entity: PropTypes.oneOf(['block', 'transaction']), onClick: PropTypes.func.isRequired, }; From 2daea8ce78ecdbf9594cf242b086054cabfc131c Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 13:05:41 +0200 Subject: [PATCH 15/17] update unit tests --- .../shared/loadLatestButton/loadLatestButton.test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.test.js b/src/components/shared/loadLatestButton/loadLatestButton.test.js index 035600e233..0d0485fbeb 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.test.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.test.js @@ -8,7 +8,9 @@ describe('LoadLatestButton', () => { onClick: jest.fn(), entity: 'block', children: 'Test load button', - latestBlocks: [], + latestBlocks: [ + { height: 11111111 }, + ], }; it('renders empty by default', () => { @@ -21,7 +23,7 @@ describe('LoadLatestButton', () => { expect(wrapper).toBeEmptyRender(); wrapper.setProps({ latestBlocks: [ - { height: 11111112 }, + { height: 11111114 }, ], }); act(() => { From 0cf01e0141fcb6dba31ece54ff9f9029a5dbf4b9 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 13:20:39 +0200 Subject: [PATCH 16/17] Prevent crashes if wrong entity passed --- src/components/shared/loadLatestButton/loadLatestButton.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.js b/src/components/shared/loadLatestButton/loadLatestButton.js index 5f10c29562..f3b36955bf 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.js @@ -37,7 +37,7 @@ const LoadLatestButton = ({ } }, [latestBlocks.length]); - return shouldShow[entity](updateHeight, latestBlocks) + return shouldShow[entity] && shouldShow[entity](updateHeight, latestBlocks) ? ( From c70328cf1e09c9205e08e5930f49fcafa8c8d8b6 Mon Sep 17 00:00:00 2001 From: reyraa Date: Thu, 24 Jun 2021 13:20:48 +0200 Subject: [PATCH 17/17] Update test coverage --- .../shared/loadLatestButton/loadLatestButton.test.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/shared/loadLatestButton/loadLatestButton.test.js b/src/components/shared/loadLatestButton/loadLatestButton.test.js index 0d0485fbeb..681bd11010 100644 --- a/src/components/shared/loadLatestButton/loadLatestButton.test.js +++ b/src/components/shared/loadLatestButton/loadLatestButton.test.js @@ -13,8 +13,13 @@ describe('LoadLatestButton', () => { ], }; - it('renders empty by default', () => { - const wrapper = mount(); + it('renders accept transaction and block for entity and render empty by default', () => { + const blockProps = { ...props, entity: 'block' }; + let wrapper = mount(); + expect(wrapper).toBeEmptyRender(); + + const transactionProps = { ...props, entity: 'transaction' }; + wrapper = mount(); expect(wrapper).toBeEmptyRender(); });