diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-04-10 01:55:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-10 01:55:46 +0800 |
commit | 4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1 (patch) | |
tree | 3439d92871f38765cf5dfa4ac310b11aeb5068bb /mascara/src/app/first-time/notice-screen.js | |
parent | 2511a9e634234135862259510a38b69308c2b81b (diff) | |
parent | 1e6f062bb6bbc39d6ab21a351fdb0d3bcab4d7d5 (diff) | |
download | tangerine-wallet-browser-4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1.tar tangerine-wallet-browser-4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1.tar.gz tangerine-wallet-browser-4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1.tar.bz2 tangerine-wallet-browser-4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1.tar.lz tangerine-wallet-browser-4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1.tar.xz tangerine-wallet-browser-4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1.tar.zst tangerine-wallet-browser-4cae3d3b0d2a9cc0279e44de256e7fc7e219dca1.zip |
Merge pull request #3921 from MetaMask/gh-3736-react-router
Add react-router integration
Diffstat (limited to 'mascara/src/app/first-time/notice-screen.js')
-rw-r--r-- | mascara/src/app/first-time/notice-screen.js | 105 |
1 files changed, 68 insertions, 37 deletions
diff --git a/mascara/src/app/first-time/notice-screen.js b/mascara/src/app/first-time/notice-screen.js index cbd8f9f5b..a449ccfa9 100644 --- a/mascara/src/app/first-time/notice-screen.js +++ b/mascara/src/app/first-time/notice-screen.js @@ -1,11 +1,14 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import Markdown from 'react-markdown' -import {connect} from 'react-redux' +import { connect } from 'react-redux' +import { withRouter } from 'react-router-dom' +import { compose } from 'recompose' import debounce from 'lodash.debounce' -import {markNoticeRead} from '../../../../ui/app/actions' +import { markNoticeRead } from '../../../../ui/app/actions' import Identicon from '../../../../ui/app/components/identicon' import Breadcrumbs from './breadcrumbs' +import { INITIALIZE_BACKUP_PHRASE_ROUTE } from '../../../../ui/app/routes' import LoadingScreen from './loading-screen' class NoticeScreen extends Component { @@ -16,8 +19,15 @@ class NoticeScreen extends Component { date: PropTypes.string, body: PropTypes.string, }), - next: PropTypes.func.isRequired, + location: PropTypes.shape({ + state: PropTypes.shape({ + next: PropTypes.func.isRequired, + }), + }), markNoticeRead: PropTypes.func, + history: PropTypes.object, + isLoading: PropTypes.bool, + noActiveNotices: PropTypes.bool, }; static defaultProps = { @@ -29,17 +39,24 @@ class NoticeScreen extends Component { } componentDidMount () { + if (this.props.noActiveNotices) { + this.props.history.push(INITIALIZE_BACKUP_PHRASE_ROUTE) + } + this.onScroll() } acceptTerms = () => { - const { markNoticeRead, lastUnreadNotice, next } = this.props - const defer = markNoticeRead(lastUnreadNotice) - .then(() => this.setState({ atBottom: false })) - - if ((/terms/gi).test(lastUnreadNotice.title)) { - defer.then(next) - } + const { markNoticeRead, lastUnreadNotice, history } = this.props + markNoticeRead(lastUnreadNotice) + .then(hasActiveNotices => { + if (!hasActiveNotices) { + history.push(INITIALIZE_BACKUP_PHRASE_ROUTE) + } else { + this.setState({ atBottom: false }) + this.onScroll() + } + }) } onScroll = debounce(() => { @@ -64,27 +81,29 @@ class NoticeScreen extends Component { isLoading ? <LoadingScreen /> : ( - <div className="first-view-main-wrapper"> - <div className="first-view-main"> - <div - className="tou" - onScroll={this.onScroll} - > - <Identicon address={address} diameter={70} /> - <div className="tou__title">{title}</div> - <Markdown - className="tou__body markdown" - source={body} - skipHtml - /> - <button - className="first-time-flow__button" - onClick={atBottom && this.acceptTerms} - disabled={!atBottom} + <div className="first-time-flow"> + <div className="first-view-main-wrapper"> + <div className="first-view-main"> + <div + className="tou" + onScroll={this.onScroll} > - Accept - </button> - <Breadcrumbs total={3} currentIndex={2} /> + <Identicon address={address} diameter={70} /> + <div className="tou__title">{title}</div> + <Markdown + className="tou__body markdown" + source={body} + skipHtml + /> + <button + className="first-time-flow__button" + onClick={atBottom && this.acceptTerms} + disabled={!atBottom} + > + Accept + </button> + <Breadcrumbs total={3} currentIndex={2} /> + </div> </div> </div> </div> @@ -93,12 +112,24 @@ class NoticeScreen extends Component { } } -export default connect( - ({ metamask: { selectedAddress, lastUnreadNotice }, appState: { isLoading } }) => ({ - lastUnreadNotice, +const mapStateToProps = ({ metamask, appState }) => { + const { selectedAddress, lastUnreadNotice, noActiveNotices } = metamask + const { isLoading } = appState + + return { address: selectedAddress, - }), - dispatch => ({ - markNoticeRead: notice => dispatch(markNoticeRead(notice)), - }) + lastUnreadNotice, + noActiveNotices, + isLoading, + } +} + +export default compose( + withRouter, + connect( + mapStateToProps, + dispatch => ({ + markNoticeRead: notice => dispatch(markNoticeRead(notice)), + }) + ) )(NoticeScreen) |