-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display warning when backup not done
- Loading branch information
Showing
9 changed files
with
211 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { | ||
Card, | ||
createStyles, | ||
Grid, | ||
IconButton, | ||
makeStyles, | ||
Theme, | ||
Typography, | ||
} from "@material-ui/core"; | ||
import WarningIcon from "@material-ui/icons/Warning"; | ||
import React, { ReactElement } from "react"; | ||
import CloseIcon from "@material-ui/icons/Close"; | ||
|
||
type WarningMessageProps = { | ||
message: string; | ||
showCloseIcon?: boolean; | ||
onClose?: () => void; | ||
alignToStart?: boolean; | ||
additionalButtons?: { button: ReactElement; key: string }[]; | ||
}; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
warningMessage: { | ||
backgroundColor: theme.palette.warning.dark, | ||
color: theme.palette.warning.contrastText, | ||
marginBottom: theme.spacing(2), | ||
padding: theme.spacing(1), | ||
}, | ||
iconContainer: { | ||
display: "flex", | ||
}, | ||
}) | ||
); | ||
|
||
const WarningMessage = (props: WarningMessageProps): ReactElement => { | ||
const { | ||
message, | ||
showCloseIcon, | ||
onClose, | ||
alignToStart, | ||
additionalButtons, | ||
} = props; | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Grid item> | ||
<Card elevation={0} className={classes.warningMessage}> | ||
<Grid | ||
item | ||
container | ||
wrap="nowrap" | ||
justify="space-between" | ||
alignItems="center" | ||
> | ||
<Grid | ||
item | ||
container | ||
spacing={1} | ||
justify={alignToStart ? "flex-start" : "center"} | ||
alignItems="center" | ||
wrap="nowrap" | ||
> | ||
<Grid item className={classes.iconContainer}> | ||
<WarningIcon fontSize="small" /> | ||
</Grid> | ||
<Grid item> | ||
<Typography variant="body2" align="center"> | ||
{message} | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
{(showCloseIcon || additionalButtons?.length) && ( | ||
<Grid item container justify="flex-end" spacing={1}> | ||
{additionalButtons?.map((button) => ( | ||
<Grid item key={button.key}> | ||
{button.button} | ||
</Grid> | ||
))} | ||
{showCloseIcon && ( | ||
<Grid item> | ||
<IconButton | ||
color="inherit" | ||
size="small" | ||
onClick={() => (onClose ? onClose() : void 0)} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</Grid> | ||
)} | ||
</Grid> | ||
)} | ||
</Grid> | ||
</Card> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export default WarningMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
Button, | ||
Collapse, | ||
createStyles, | ||
makeStyles, | ||
Theme, | ||
} from "@material-ui/core"; | ||
import { inject, observer } from "mobx-react"; | ||
import React, { ReactElement, useEffect, useState } from "react"; | ||
import { useHistory } from "react-router-dom"; | ||
import { interval } from "rxjs"; | ||
import { catchError, exhaustMap, filter, take } from "rxjs/operators"; | ||
import api from "../api"; | ||
import WarningMessage from "../common/WarningMessage"; | ||
import { Path } from "../router/Path"; | ||
import { BackupStore, BACKUP_STORE } from "../stores/backupStore"; | ||
|
||
type SetupWarningProps = { | ||
backupStore?: BackupStore; | ||
}; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
wrapper: { | ||
width: "100%", | ||
marginBottom: theme.spacing(2), | ||
}, | ||
}) | ||
); | ||
|
||
const SetupWarning = inject(BACKUP_STORE)( | ||
observer( | ||
(props: SetupWarningProps): ReactElement => { | ||
const { backupStore } = props; | ||
const classes = useStyles(); | ||
const history = useHistory(); | ||
const [visible, setVisible] = useState(false); | ||
const [closeBtnVisible, setCloseBtnVisible] = useState(false); | ||
|
||
useEffect(() => { | ||
interval(1000).subscribe(() => | ||
setVisible( | ||
backupStore!.backupInfoLoaded && | ||
(!!backupStore!.defaultPassword || | ||
!backupStore!.mnemonicShown || | ||
!!backupStore!.defaultBackupDirectory) | ||
) | ||
); | ||
}, [backupStore]); | ||
|
||
useEffect(() => { | ||
const balanceSubscription = interval(5000) | ||
.pipe( | ||
exhaustMap(() => api.getbalance$()), | ||
catchError((e, caught) => caught), | ||
filter((value) => !!Object.keys(value.balances)?.length), | ||
take(1), | ||
filter( | ||
(value) => | ||
!Object.values(value.balances).some( | ||
(balance) => Number(balance.total_balance) > 0 | ||
) | ||
) | ||
) | ||
.subscribe({ | ||
next: () => setCloseBtnVisible(true), | ||
}); | ||
return () => balanceSubscription.unsubscribe(); | ||
}, []); | ||
|
||
return ( | ||
<Collapse in={visible} className={classes.wrapper}> | ||
<WarningMessage | ||
message="Secure your funds. Setup password, store mnemonic, and save backup data." | ||
alignToStart | ||
showCloseIcon={closeBtnVisible} | ||
onClose={() => setVisible(false)} | ||
additionalButtons={[ | ||
{ | ||
button: ( | ||
<Button | ||
size="small" | ||
color="inherit" | ||
variant="outlined" | ||
onClick={() => | ||
history.push(`${Path.SETTINGS}${Path.INITIAL_SETUP}`) | ||
} | ||
> | ||
Setup Now | ||
</Button> | ||
), | ||
key: "CloseWarningBtn", | ||
}, | ||
]} | ||
/> | ||
</Collapse> | ||
); | ||
} | ||
) | ||
); | ||
|
||
export default SetupWarning; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters