From 5b175347be2b3c1f3f82326df3b1209f2e23872b Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Mon, 19 Nov 2018 08:51:57 +0100 Subject: [PATCH] refactor(syncing): use UI components in Syncing --- app/components/Syncing/Syncing.js | 141 +++++++++++--------------- app/components/Syncing/Syncing.scss | 136 ------------------------- app/components/Syncing/index.js | 4 +- app/containers/Syncing.js | 20 +++- stories/containers/syncing.stories.js | 41 ++++++++ 5 files changed, 115 insertions(+), 227 deletions(-) delete mode 100644 app/components/Syncing/Syncing.scss create mode 100644 stories/containers/syncing.stories.js diff --git a/app/components/Syncing/Syncing.js b/app/components/Syncing/Syncing.js index 6132c536..25f4eb7d 100644 --- a/app/components/Syncing/Syncing.js +++ b/app/components/Syncing/Syncing.js @@ -1,23 +1,21 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { Redirect } from 'react-router-dom' -import QRCode from 'qrcode.react' import copy from 'copy-to-clipboard' -import Copy from 'components/Icon/Copy' -import ZapLogo from 'components/Icon/ZapLogo' +import { Box, Flex } from 'rebass' +import { Bar, Button, Heading, Header, Panel, QRCode, Text } from 'components/UI' import { showNotification } from 'lib/utils/notifications' import { FormattedMessage, injectIntl } from 'react-intl' import messages from './messages' -import styles from './Syncing.scss' class Syncing extends Component { static propTypes = { address: PropTypes.string.isRequired, - theme: PropTypes.object.isRequired, hasSynced: PropTypes.bool, syncStatus: PropTypes.string.isRequired, syncPercentage: PropTypes.number, blockHeight: PropTypes.number, + setIsWalletOpen: PropTypes.func.isRequired, lndBlockHeight: PropTypes.number, lndCfilterHeight: PropTypes.number, lightningGrpcActive: PropTypes.bool @@ -29,8 +27,9 @@ class Syncing extends Component { syncMessageExtraDetail: null } - componentWillMount() { - const { syncStatus, intl } = this.props + componentDidMount() { + const { setIsWalletOpen, syncStatus, intl } = this.props + setIsWalletOpen(true) // If we are still waiting for peers after some time, advise te user it could take a wile. let timer = setTimeout(() => { @@ -59,8 +58,7 @@ class Syncing extends Component { lndBlockHeight, lndCfilterHeight, lightningGrpcActive, - intl, - theme + intl } = this.props let { syncMessageDetail, syncMessageExtraDetail } = this.state @@ -99,86 +97,61 @@ class Syncing extends Component { } return ( -
-
-
- -
- - {hasSynced === true && ( -
-
-

- -

-

- -

-
-
+ + + {hasSynced ? ( +
} + subtitle={} + /> + ) : ( +
} + subtitle={} + /> )} + + - {hasSynced === false && ( -
-
-

- -

-

- -

-
- {address && address.length ? ( -
-
- -
-
- {address} - - - -
-
- ) : ( -
-
-
- )} -
- )} + + {hasSynced === false && + address && + address.length && ( + + + {address} + + + )} + -
-

+ + + -

-
-
+ {syncMessage} + + -
-

{syncMessage}

- {syncMessageDetail && ( - {syncMessageDetail} - )} - {syncMessageExtraDetail && ( - -
- {syncMessageExtraDetail} -
- )} -
-
-
+ + + {syncMessageDetail && {syncMessageDetail}} + {syncMessageExtraDetail && {syncMessageExtraDetail}} + + + ) } } diff --git a/app/components/Syncing/Syncing.scss b/app/components/Syncing/Syncing.scss deleted file mode 100644 index c85a1845..00000000 --- a/app/components/Syncing/Syncing.scss +++ /dev/null @@ -1,136 +0,0 @@ -@import 'styles/variables.scss'; - -.container { - position: relative; - width: 100%; - height: 100vh; - background: var(--primaryColor); -} - -.content { - color: var(--primaryText); - text-align: center; - background: var(--primaryColor); - - header { - text-align: left; - padding: 20px 40px; - } - - .title { - h1 { - font-size: 20px; - margin-bottom: 20px; - } - - p { - font-size: 12px; - } - } - - .hasNotSynced .title { - margin: 95px; - } - - .hasSynced .title { - margin: 30px; - } - - .address { - background: var(--primaryColor); - - .textAddress { - margin-top: 20px; - - span { - font-size: 12px; - - &.text { - background: var(--tertiaryColor); - padding: 10px; - } - - &.icon { - background: var(--secondaryColor); - padding: 10px; - cursor: pointer; - transition: all 0.25s; - color: var(--primaryText); - - &:hover { - opacity: 0.25; - } - } - - svg { - width: 12px; - height: 12px; - } - } - } - } - - .qrcode { - border-style: solid; - border-color: var(--primaryText); - border-width: 2px; - } -} - -.progressContainer { - color: var(--primaryText); - text-align: center; - padding: 40px 0; - background: var(--secondaryColor); - position: absolute; - height: 31vh; - width: 100%; - bottom: 0; - - h3 { - margin-bottom: 20px; - } - - .progressBar { - width: 75%; - max-width: 700px; - margin: 0 auto; - height: 10px; - border-radius: 5px; - background: var(--primaryColor); - } - - .progress { - background: var(--lightningOrange); - height: 10px; - border-radius: 5px; - transition: all 0.25s; - } - - h4 { - color: var(--lightningOrange); - margin-top: 10px; - } - - .progressDetail { - color: var(--lightningOrange); - font-size: 12px; - margin-top: 10px; - } -} - -.spinner { - border: 1px solid rgba(0, 0, 0, 0.1); - border-left-color: rgba(0, 0, 0, 0.4); - border-radius: 999px; - margin: 0 auto; - height: 75px; - width: 75px; - animation: animation-rotate 1000ms linear infinite; -} - -@keyframes animation-rotate { - 100% { - transform: rotate(360deg); - } -} diff --git a/app/components/Syncing/index.js b/app/components/Syncing/index.js index 791d5dd5..f4a18365 100644 --- a/app/components/Syncing/index.js +++ b/app/components/Syncing/index.js @@ -1,3 +1 @@ -import Syncing from './Syncing' - -export default Syncing +export Syncing from './Syncing' diff --git a/app/containers/Syncing.js b/app/containers/Syncing.js index 04bfa7f9..7c05de35 100644 --- a/app/containers/Syncing.js +++ b/app/containers/Syncing.js @@ -2,9 +2,9 @@ import { connect } from 'react-redux' import { withTheme } from 'styled-components' import { infoSelectors } from 'reducers/info' import { lndSelectors } from 'reducers/lnd' -import { onboardingSelectors } from 'reducers/onboarding' +import { setIsWalletOpen } from 'reducers/wallet' -import Syncing from 'components/Syncing' +import { Syncing } from 'components/Syncing' import withLoading from 'components/withLoading' const mapStateToProps = state => ({ @@ -16,7 +16,19 @@ const mapStateToProps = state => ({ lndBlockHeight: state.lnd.lndBlockHeight, lndCfilterHeight: state.lnd.lndCfilterHeight, lightningGrpcActive: state.lnd.lightningGrpcActive, - isLoading: infoSelectors.infoLoading(state) || onboardingSelectors.startingLnd(state) + isLoading: + infoSelectors.infoLoading(state) || + state.lnd.syncStatus === 'pending' || + !state.lnd.lightningGrpcActive || + !state.lnd.blockHeight || + !state.lnd.lndBlockHeight }) -export default connect(mapStateToProps)(withLoading(withTheme(Syncing))) +const mapDispatchToProps = { + setIsWalletOpen +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(withLoading(withTheme(Syncing))) diff --git a/stories/containers/syncing.stories.js b/stories/containers/syncing.stories.js new file mode 100644 index 00000000..095c1de0 --- /dev/null +++ b/stories/containers/syncing.stories.js @@ -0,0 +1,41 @@ +import React from 'react' +import { storiesOf } from '@storybook/react' +import { linkTo } from '@storybook/addon-links' +import { State, Store } from '@sambego/storybook-state' +import { Modal, Page } from 'components/UI' +import { Syncing } from 'components/Syncing' +import { boolean } from '@storybook/addon-knobs' + +const store = new Store({ + address: '2MxZ2z7AodL6gxEgwL5tkq2imDBhkBMq2Jc', + syncStatus: 'in-progress', + blockHeight: 123123, + lndBlockHeight: 1000, + lndCfilterHeight: 100, + isLoading: false, + syncPercentage: 30 +}) + +const setIsWalletOpen = () => ({}) + +storiesOf('Containers.Syncing', module) + .addParameters({ + info: { + disable: true + } + }) + .addDecorator(story => ( + + + {story()} + + + )) + .add('Syncing', () => { + const hasSynced = boolean('Has synced', false) + return ( + + + + ) + })