Browse Source

refactor(syncing): use UI components in Syncing

next
Tom Kirkpatrick 6 years ago
parent
commit
5b175347be
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 137
      app/components/Syncing/Syncing.js
  2. 136
      app/components/Syncing/Syncing.scss
  3. 4
      app/components/Syncing/index.js
  4. 20
      app/containers/Syncing.js
  5. 41
      stories/containers/syncing.stories.js

137
app/components/Syncing/Syncing.js

@ -1,23 +1,21 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { Redirect } from 'react-router-dom' import { Redirect } from 'react-router-dom'
import QRCode from 'qrcode.react'
import copy from 'copy-to-clipboard' import copy from 'copy-to-clipboard'
import Copy from 'components/Icon/Copy' import { Box, Flex } from 'rebass'
import ZapLogo from 'components/Icon/ZapLogo' import { Bar, Button, Heading, Header, Panel, QRCode, Text } from 'components/UI'
import { showNotification } from 'lib/utils/notifications' import { showNotification } from 'lib/utils/notifications'
import { FormattedMessage, injectIntl } from 'react-intl' import { FormattedMessage, injectIntl } from 'react-intl'
import messages from './messages' import messages from './messages'
import styles from './Syncing.scss'
class Syncing extends Component { class Syncing extends Component {
static propTypes = { static propTypes = {
address: PropTypes.string.isRequired, address: PropTypes.string.isRequired,
theme: PropTypes.object.isRequired,
hasSynced: PropTypes.bool, hasSynced: PropTypes.bool,
syncStatus: PropTypes.string.isRequired, syncStatus: PropTypes.string.isRequired,
syncPercentage: PropTypes.number, syncPercentage: PropTypes.number,
blockHeight: PropTypes.number, blockHeight: PropTypes.number,
setIsWalletOpen: PropTypes.func.isRequired,
lndBlockHeight: PropTypes.number, lndBlockHeight: PropTypes.number,
lndCfilterHeight: PropTypes.number, lndCfilterHeight: PropTypes.number,
lightningGrpcActive: PropTypes.bool lightningGrpcActive: PropTypes.bool
@ -29,8 +27,9 @@ class Syncing extends Component {
syncMessageExtraDetail: null syncMessageExtraDetail: null
} }
componentWillMount() { componentDidMount() {
const { syncStatus, intl } = this.props 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. // If we are still waiting for peers after some time, advise te user it could take a wile.
let timer = setTimeout(() => { let timer = setTimeout(() => {
@ -59,8 +58,7 @@ class Syncing extends Component {
lndBlockHeight, lndBlockHeight,
lndCfilterHeight, lndCfilterHeight,
lightningGrpcActive, lightningGrpcActive,
intl, intl
theme
} = this.props } = this.props
let { syncMessageDetail, syncMessageExtraDetail } = this.state let { syncMessageDetail, syncMessageExtraDetail } = this.state
@ -99,86 +97,61 @@ class Syncing extends Component {
} }
return ( return (
<div className={`${styles.container} ${theme.name}`}> <Panel width={1}>
<div className={styles.content}> <Panel.Header width={9 / 16} mx="auto">
<header> {hasSynced ? (
<ZapLogo width="70px" height="32px" /> <Header
</header> title={<FormattedMessage {...messages.sync_title} />}
subtitle={<FormattedMessage {...messages.sync_description} />}
{hasSynced === true && (
<div className={styles.hasNotSynced}>
<div className={styles.title}>
<h1>
<FormattedMessage {...messages.sync_title} />
</h1>
<p>
<FormattedMessage {...messages.sync_description} />
</p>
</div>
</div>
)}
{hasSynced === false && (
<div className={styles.hasSynced}>
<div className={styles.title}>
<h1>
<FormattedMessage {...messages.fund_title} />
</h1>
<p>
<FormattedMessage {...messages.fund_description} />
</p>
</div>
{address && address.length ? (
<div className={styles.address}>
<div className={styles.qrConatiner}>
<QRCode
value={address}
renderAs="svg"
size={100}
bgColor="white"
fgColor="#252832"
level="L"
className={styles.qrcode}
/> />
</div>
<section className={styles.textAddress}>
<span className={styles.text}>{address}</span>
<span className={styles.icon} onClick={copyClicked}>
<Copy />
</span>
</section>
</div>
) : ( ) : (
<div className={styles.loading}> <Header
<div className={styles.spinner} /> title={<FormattedMessage {...messages.fund_title} />}
</div> subtitle={<FormattedMessage {...messages.fund_description} />}
/>
)} )}
</div> <Bar my={3} />
</Panel.Header>
<Panel.Body width={9 / 16} mx="auto">
{hasSynced === false &&
address &&
address.length && (
<Flex alignItems="center" flexDirection="column" justifyContent="center">
<QRCode value={address} mx="auto" />
<Text my={3}>{address}</Text>
<Button size="small" onClick={copyClicked} mx="auto">
Copy address
</Button>
</Flex>
)} )}
</Panel.Body>
<section className={styles.progressContainer}> <Panel.Footer bg="secondaryColor" p={3}>
<h3> <Flex
alignItems="center"
flexDirection="column"
justifyContent="center"
width={9 / 16}
mx="auto"
>
<Text fontWeight="normal" mb={3}>
<FormattedMessage {...messages.sync_caption} /> <FormattedMessage {...messages.sync_caption} />
</h3> </Text>
<div className={styles.progressBar}> <Heading.h1 mb={2}>{syncMessage}</Heading.h1>
<div <Box width={1} css={{ height: '4px' }} bg="grey" mb={2}>
className={styles.progress} <Box
style={{ width: syncPercentage ? `${syncPercentage}%` : 0 }} width={syncPercentage ? `${syncPercentage}%` : 0}
css={{ height: '100%' }}
bg="lightningOrange"
/> />
</div> </Box>
<h4>{syncMessage}</h4>
{syncMessageDetail && ( {syncMessageDetail && <Text>{syncMessageDetail}</Text>}
<span className={styles.progressDetail}>{syncMessageDetail}</span> {syncMessageExtraDetail && <Text>{syncMessageExtraDetail}</Text>}
)} </Flex>
{syncMessageExtraDetail && ( </Panel.Footer>
<span className={styles.progressDetail}> </Panel>
<br />
{syncMessageExtraDetail}
</span>
)}
</section>
</div>
</div>
) )
} }
} }

136
app/components/Syncing/Syncing.scss

@ -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);
}
}

4
app/components/Syncing/index.js

@ -1,3 +1 @@
import Syncing from './Syncing' export Syncing from './Syncing'
export default Syncing

20
app/containers/Syncing.js

@ -2,9 +2,9 @@ import { connect } from 'react-redux'
import { withTheme } from 'styled-components' import { withTheme } from 'styled-components'
import { infoSelectors } from 'reducers/info' import { infoSelectors } from 'reducers/info'
import { lndSelectors } from 'reducers/lnd' 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' import withLoading from 'components/withLoading'
const mapStateToProps = state => ({ const mapStateToProps = state => ({
@ -16,7 +16,19 @@ const mapStateToProps = state => ({
lndBlockHeight: state.lnd.lndBlockHeight, lndBlockHeight: state.lnd.lndBlockHeight,
lndCfilterHeight: state.lnd.lndCfilterHeight, lndCfilterHeight: state.lnd.lndCfilterHeight,
lightningGrpcActive: state.lnd.lightningGrpcActive, 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)))

41
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 => (
<Page css={{ height: 'calc(100vh - 40px)' }}>
<Modal withHeader onClose={linkTo('Containers.Home', 'Home')} pb={0} px={0}>
{story()}
</Modal>
</Page>
))
.add('Syncing', () => {
const hasSynced = boolean('Has synced', false)
return (
<State store={store}>
<Syncing setIsWalletOpen={setIsWalletOpen} hasSynced={hasSynced} />
</State>
)
})
Loading…
Cancel
Save