aboutsummaryrefslogtreecommitdiffstats
path: root/mascara/src/app/first-time/notice-screen.js
blob: 8c9a0cd412dfe4d6c18b2b611f8f6c2bbec5c31f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, {Component, PropTypes} from 'react'
import Markdown from 'react-markdown'
import {connect} from 'react-redux';
import {markNoticeRead} from '../../../../ui/app/actions'
import Identicon from '../../../../ui/app/components/identicon'
import Breadcrumbs from './breadcrumbs'

class NoticeScreen extends Component {
  static propTypes = {
    address: PropTypes.string.isRequired,
    lastUnreadNotice: PropTypes.shape({
      title: PropTypes.string,
      date: PropTypes.string,
      body: PropTypes.string
    }),
    next: PropTypes.func.isRequired
  };

  static defaultProps = {
    lastUnreadNotice: {}
  };

  acceptTerms = () => {
    const { markNoticeRead, lastUnreadNotice, next } = this.props;
    const defer = markNoticeRead(lastUnreadNotice)

    if ((/terms/gi).test(lastUnreadNotice.title)) {
      defer.then(next)
    }
  }

  render() {
    const {
      address,
      lastUnreadNotice: { title, body }
    } = this.props;

    return (
      <div className="tou">
        <Identicon address={address} diameter={70} />
        <div className="tou__title">{title}</div>
        <Markdown
          className="tou__body"
          source={body}
          skipHtml
        />
        <button
          className="first-time-flow__button"
          onClick={this.acceptTerms}
        >
          Accept
        </button>
        <Breadcrumbs total={3} currentIndex={2} />
      </div>
    )
  }
}

export default connect(
  ({ metamask: { selectedAddress, lastUnreadNotice } }) => ({
    lastUnreadNotice,
    address: selectedAddress
  }),
  dispatch => ({
    markNoticeRead: notice => dispatch(markNoticeRead(notice))
  })
)(NoticeScreen)