Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #439 from ZbayApp/migration-file
Browse files Browse the repository at this point in the history
fixes to update flow
  • Loading branch information
NorbertBodziony authored Sep 2, 2020
2 parents bd7ad34 + 48876c7 commit 48b301f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 71 deletions.
61 changes: 21 additions & 40 deletions src/renderer/components/widgets/VaultUnlockerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React from 'react'
import PropTypes from 'prop-types'
import * as Yup from 'yup'
import { Formik, Form } from 'formik'
import { Redirect } from 'react-router'
import BigNumber from 'bignumber.js'

import Grid from '@material-ui/core/Grid'
import Typography from '@material-ui/core/Typography'
Expand All @@ -14,9 +12,7 @@ import Icon from '../ui/Icon'
import LoadingButton from '../ui/LoadingButton'

import icon from '../../static/images/zcash/logo-lockup--circle.svg'
import Tor from '../../containers/windows/Tor'
import electronStore from '../../../shared/electronStore'
import config from '../../../main/config'

const styles = theme => ({
paper: {
Expand Down Expand Up @@ -76,21 +72,21 @@ export const VaultUnlockerForm = ({
setDone,
tor,
node,
isLogIn
isLogIn,
checkForUpdate
}) => {
const isDev = process.env.NODE_ENV === 'development'
const vaultPassword = electronStore.get('vaultPassword')
const blockchainStatus = electronStore.get('AppStatus.blockchain.status')
const isRescanned = electronStore.get('AppStatus.blockchain.isRescanned')
const lastBlock = node.latestBlock.isEqualTo(0) ? 999999 : node.latestBlock
const isBlockchainFromExternalSouce = electronStore.get('isBlockchainFromExternalSource') && blockchainStatus !== config.BLOCKCHAIN_STATUSES.SUCCESS
const isSynced = (!node.latestBlock.isEqualTo(0) && node.latestBlock.minus(node.currentBlock).lt(10)) && new BigNumber(node.latestBlock).gt(755000)
React.useEffect(() => {
// for tests
// checkForUpdate()
}, [])
return (
<Formik
onSubmit={(values, actions) => {
onSubmit(values, actions, setDone)
}}
validationSchema={(vaultPassword || isDev) ? null : formSchema}
validationSchema={vaultPassword || isDev ? null : formSchema}
initialValues={initialValues}
>
{({ isSubmitting }) => (
Expand All @@ -115,11 +111,16 @@ export const VaultUnlockerForm = ({
<Icon className={classes.icon} src={icon} />
</Grid>
<Grid container item xs={12} wrap='wrap' justify='center'>
<Typography className={classes.title} variant='body1' gutterBottom>
<Typography
className={classes.title}
variant='body1'
gutterBottom
>
{vaultPassword ? 'Welcome Back' : 'Log In'}
</Typography>
</Grid>
{((!vaultPassword && !isDev) || (isDev && exists && !vaultPassword)) && (
{((!vaultPassword && !isDev) ||
(isDev && exists && !vaultPassword)) && (
<Grid container item justify='center'>
<PasswordField
name='password'
Expand All @@ -138,36 +139,16 @@ export const VaultUnlockerForm = ({
margin='normal'
text={vaultPassword ? 'Sign in' : 'Login'}
fullWidth
disabled={
isSubmitting ||
unlocking ||
(tor.enabled === true && tor.status !== 'stable') ||
!done ||
tor.status === 'loading' ||
(!isSynced && isLogIn)
}
inProgress={isSubmitting || unlocking || !done || tor.status === 'loading' || (!isSynced && isLogIn)}
disabled
inProgress
/>
</Grid>
{locked && (
<Grid item className={classes.torDiv}>
<Tor />
</Grid>
)}
</Grid>
{(!isSynced && isLogIn) && (
<Grid item container justify='center' alignItems='center'>
<Typography variant='body2' className={classes.status}>
{nodeConnected ? `Syncing (${node.currentBlock}/${lastBlock})` : `Starting up. This can take a while...`}
</Typography>
</Grid>
)}
{!isDev && !locked && !loader.loading && ((blockchainStatus !== 'SUCCESS' && !isBlockchainFromExternalSouce) || !isRescanned) && (
<Redirect to='/zcashNode' />
)}
{!locked && !loader.loading && nodeConnected && done && isSynced && (
<Redirect to='/main/channel/general' />
)}
<Grid item container justify='center' alignItems='center'>
<Typography variant='body2' className={classes.status}>
{'Updating please wait...'}
</Typography>
</Grid>
</Form>
)}
</Formik>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/widgets/update/UpdateModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const styles = theme => ({

export const UpdateModal = ({ classes, open, handleClose, handleUpdate, rejectUpdate }) => {
return (
<Modal open={open} handleClose={handleClose}>
<Modal open={open} handleClose={handleClose} isCloseDisabled>
<Grid container direction='column' className={classes.root} alignItems='center' justify='flex-start'>
<Grid className={classes.info} container justify='center'>
<Grid item>
Expand Down
50 changes: 20 additions & 30 deletions src/renderer/containers/widgets/VaultUnlockerForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useInterval } from '../hooks'
import torSelectors from '../../store/selectors/tor'
import torHandlers from '../../store/handlers/tor'
import electronStore from '../../../shared/electronStore'
import updateHandlers from '../../store/handlers/update'

export const mapStateToProps = state => ({
unlocking: vaultSelectors.unlocking(state),
Expand All @@ -30,7 +31,8 @@ export const mapDispatchToProps = dispatch =>
onSubmit: vaultHandlers.epics.unlockVault,
setVaultIdentity: vaultHandlers.epics.setVaultIdentity,
getStatus: nodeHandlers.epics.getStatus,
createZcashNode: torHandlers.epics.createZcashNode
createZcashNode: torHandlers.epics.createZcashNode,
checkForUpdate: updateHandlers.epics.checkForUpdate
},
dispatch
)
Expand All @@ -48,31 +50,22 @@ export const VaultUnlockerForm = ({
...props
}) => {
const [done, setDone] = useState(true)
useEffect(
() => {
const isNewUser = electronStore.get('isNewUser')
if (!isNewUser && !locked && nodeConnected) {
setVaultIdentity()
}
},
[locked, nodeConnected]
)
useEffect(
() => {
if (!locked) {
createZcashNode(tor.url)
}
},
[locked]
)
useEffect(
() => {
if (!locked && !loader.loading) {
setDone(true)
}
},
[loader.loading]
)
useEffect(() => {
const isNewUser = electronStore.get('isNewUser')
if (!isNewUser && !locked && nodeConnected) {
setVaultIdentity()
}
}, [locked, nodeConnected])
useEffect(() => {
if (!locked) {
createZcashNode(tor.url)
}
}, [locked])
useEffect(() => {
if (!locked && !loader.loading) {
setDone(true)
}
}, [loader.loading])

useInterval(getStatus, 5000)
return (
Expand All @@ -90,7 +83,4 @@ export const VaultUnlockerForm = ({
/>
)
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(VaultUnlockerForm)
export default connect(mapStateToProps, mapDispatchToProps)(VaultUnlockerForm)

0 comments on commit 48b301f

Please sign in to comment.